Day 72/100 Completed ✅ 🚀 Solved LeetCode – Matrix Diagonal Sum (Java) ⚡ Implemented an efficient approach to calculate the sum of both primary and secondary diagonals of a square matrix in a single traversal. Avoided double-counting the center element by handling the odd-sized matrix case separately. 🧠 Key Learnings: • Efficient diagonal traversal in a matrix • Handling overlapping elements (center in odd n) • Writing optimal O(n) solutions instead of nested loops • Clean and concise index-based logic 💯 This problem improved my understanding of matrix patterns and how to optimize traversal by reducing unnecessary iterations. 🔗 Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #matrix #arrays #problemSolving #100DaysOfCode 🚀
Solved LeetCode Matrix Diagonal Sum in Java
More Relevant Posts
-
Day 77/100 Completed ✅ 🚀 Solved LeetCode – Search a 2D Matrix II (Java) ⚡ Implemented an efficient approach by starting from the top-right corner of the matrix and eliminating rows or columns based on comparison with the target. This reduces the search space at every step, achieving O(m + n) time complexity. 🧠 Key Learnings: • Smart traversal in a sorted 2D matrix • Eliminating search space using row & column properties • Moving left (col--) when value is greater • Moving down (row++) when value is smaller • Better than brute-force (O(m × n)) approach 💯 This problem improved my understanding of matrix traversal strategies and how to optimize searching using sorted properties. 🔗 Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #matrix #problemSolving #optimization #arrays #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
Day 71/100 Completed ✅ 🚀 Solved LeetCode – Reshape the Matrix (Java) ⚡ Implemented an efficient matrix transformation approach by mapping elements from the original matrix to the reshaped matrix using a single traversal. Instead of creating intermediate structures, used index manipulation (count / c, count % c) to place elements correctly while maintaining row-wise order. 🧠 Key Learnings: • Understanding how to map 2D indices into a linear traversal • Efficiently converting between different matrix dimensions • Handling edge cases where reshape is not possible • Writing clean and optimized nested loop logic 💯 This problem strengthened my understanding of matrix traversal and index mapping techniques, which are very useful in array and grid-based problems. 🔗 Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #matrix #arrays #problemSolving #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
Day 76/100 Completed ✅ 🚀 Solved LeetCode – Search a 2D Matrix (Java) ⚡ Implemented an optimized binary search approach by treating the 2D matrix as a flattened sorted array. Converted 1D index into 2D coordinates (row = mid / m, col = mid % m) to efficiently locate the target in O(log(m × n)) time. 🧠 Key Learnings: • Applying binary search on a 2D matrix • Converting 1D index to 2D (row & column mapping) • Reducing time complexity from O(m × n) → O(log(m × n)) • Importance of problem observation (matrix behaves like sorted array) 💯 This problem strengthened my understanding of binary search variations and how to apply it beyond simple 1D arrays. 🔗 Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #matrix #binarysearch #arrays #optimization #problemSolving #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
Day 9/ #100DaysOfCode Solved LeetCode 1848: Minimum Distance to the Target Element. Approach: The problem can be solved using a straightforward linear traversal. Iterate through the array and check for indices where the value equals the target. For each such index, compute the absolute difference between the current index and the given start index. Maintain a variable to track the minimum distance encountered during the traversal. Solution Insight: Initialize a variable with a large value (e.g., Integer.MAX_VALUE). Traverse the array once. Whenever the target element is found, update the minimum distance using Math.abs(i - start). Return the minimum value after the loop. Complexity: Time Complexity: O(n) Space Complexity: O(1) Result: 72/72 test cases passed with optimal runtime performance. This problem reinforces the importance of simple iteration and careful tracking of minimum values in array-based problems. #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #Algorithms
To view or add a comment, sign in
-
-
Day 90 of #100DaysOfCode – Unique Binary Search Trees II Today’s problem was all about generating all structurally unique BSTs for values from 1 to n. At first glance, it feels tricky because it's not just counting trees — we actually need to build every possible tree structure. 💡 Key Insight: Pick each number i as the root Recursively build: Left subtree from [1 ... i-1] Right subtree from [i+1 ... n] Combine every left & right subtree pair 🌳 This is a classic Recursion + Backtracking problem and is closely related to Catalan Numbers. 📌 Example: For n = 3, we get 5 unique BSTs ⚡ What I learned today: How recursion can generate combinations of structures Importance of base case (start > end → null) Combining subproblems effectively 💻 Time Complexity: Approximately O(4ⁿ / √n) Consistency is key — 90 days strong and still going 💪 Next target: 💯 #DSA #Java #LeetCode #Recursion #BinaryTree #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 68/100 Completed ✅ 🚀 Solved LeetCode – Split Array Largest Sum (Java) ⚡ Applied an efficient Binary Search on Answer approach to split the array into k subarrays such that the largest subarray sum is minimized. Instead of trying all possible splits, optimized the solution by searching within the range of maximum element and total sum, and validating using a greedy strategy. 🧠 Key Learnings: Identifying binary search applicability in partition-based problems Defining search space using max element (lower bound) and total sum (upper bound) Using greedy logic to check feasibility of splitting into k subarrays Minimizing the maximum subarray sum through efficient validation 💯 This problem strengthened my understanding of partition problems and reinforced how binary search can be used for optimization rather than direct searching. 🔗 Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #binarysearch #problemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 57 of #100DaysOfLeetCode Today’s problem focused on finding the minimum distance between a target element and a given index in an array. I solved it using a simple and efficient approach: Traversed the array once Checked for target occurrences Calculated distance using absolute difference Maintained the minimum value throughout Runtime: 0 ms (Beats 100%) Optimized space usage Key takeaway: Even straightforward iteration can lead to highly optimized solutions when combined with the right logic. #LeetCode #Java #DataStructures #Algorithms #100DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
💻 Day 35 of #LeetCode Journey 🔥 Solved: 19. Remove Nth Node From End of List Today’s problem was all about mastering Linked Lists and understanding the power of the Two Pointer technique. 🔍 Key Idea: Instead of calculating the length, I used a smart approach with fast and slow pointers. Move the fast pointer n steps ahead Then move both pointers together This helps locate the node to remove in a single pass ⚡ Why this approach? Efficient: O(n) time complexity No extra space required Clean and optimal solution 🧠 What I learned: Using a dummy node simplifies edge cases (like removing the head) Two-pointer technique is very powerful in linked list problems 📌 Problem Link: https://lnkd.in/gxXDR-YV #Java #DataStructures #LinkedList #CodingJourney #100DaysOfCode #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 70 - Next Greater Node Understanding how to find the next larger value for each node using stack optimization. Approach: • Convert linked list → array for easy indexing • Use a stack to track indices • Compare current value with stack top • Update results when a greater value is found Key Insight: Monotonic stack helps avoid unnecessary comparisons Time Complexity: O(n) Space Complexity: O(n) #Day70 #LeetCode #Java #CodingPractice #TechJourney #DSA #LinkedList
To view or add a comment, sign in
-
-
Day 72 of #100DaysOfCode Problem: Convert Sorted Array to Height-Balanced BST Today I learned how to efficiently convert a sorted array into a balanced Binary Search Tree using Divide & Conquer. Key Insight: Pick the middle element as the root to maintain balance. Recursively build: Left subtree from left half Right subtree from right half This ensures: Optimal height Faster search operations ⏱ Time Complexity: O(n) 📦 Space Complexity: O(log n) Consistency is the real game changer #DSA #Java #BinaryTree #LeetCode #CodingJourney
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development