Solved two important Matrix problems in Java today 1. Set Matrix Zeroes Implemented a better approach using extra row and column arrays Then explored the optimal approach using the first row and column as markers Helped me understand space optimization concepts more clearly 2. Rotate Image (Matrix Rotation) First transposed the matrix (diagonal swapping logic) Then reversed each row to achieve 90° rotation Strengthened my understanding of in-place matrix manipulation Gradually becoming more comfortable with matrix problems in DSA. Trying to stay consistent and improve step by step 🙂 Code is available on my GitHub 👇 https://lnkd.in/g-Km2-kt If anyone has suggestions or knows a better approach, please feel free to share 🙌 #DSA #Java #MatrixProblems #ProblemSolving #CodingJourney #LearningInPublic #Consistency
Java Matrix Problems Solved: Zeroes and Rotation
More Relevant Posts
-
Day 25 of #100DaysOfLeetCode 💻✅ Solved #167. Two Sum II – Input Array Is Sorted on LeetCode using Java. Approach: • Used Two Pointer technique since the array is already sorted • Initialized one pointer at the beginning and one at the end • Calculated the sum of both elements • If sum < target, moved left pointer forward • If sum > target, moved right pointer backward • Returned 1-based indices as required in the problem Performance: ✓ Runtime: 1 ms (Efficient with O(n) time complexity) ✓ Memory: Constant extra space (O(1)) Key Learning: ✓ Understood when to apply Two Pointer technique instead of HashMap ✓ Improved ability to optimize space complexity ✓ Strengthened pattern recognition for sorted array problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #TwoPointers #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 7 | Problem 1 – Sentence Similarity III (LeetCode 1813) Solved Problem 1 by determining whether two sentences can become equal by inserting a group of words at exactly one position. Approach: • Split both sentences into word arrays using split(" ") • Ensured the smaller sentence is used as the base for comparison • Matched common words from the beginning (prefix match) • Matched common words from the end (suffix match) • Checked if prefix + suffix matches covered all words of the smaller sentence This problem strengthened my understanding of: • Two-pointer technique • String manipulation • Logical comparison of sequences Continuing my 15-Day 50+ String DSA Challenge 🚀 #DSA #Java #StringProblems #LeetCode #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
Day 1/100 – LeetCode Challenge 🚀 Problem: #867 Transpose Matrix Difficulty: Easy Language: Java Approach: Nested Loop with Index Swapping Time Complexity: O(m × n) Space Complexity: O(m × n) 🔍 Key Insight: The transpose of a matrix swaps rows and columns. If original matrix is m × n, the result will be n × m. Careful index handling is important to avoid dimension errors. 🧠 Solution Brief: Created a new matrix with reversed dimensions. Traversed the original matrix using nested loops. Assigned result[j][i] = matrix[i][j] to swap row and column indices. Returned the transposed matrix. this solution is basicaly bruteforce approach 📌 What I Learned: Even simple matrix problems improve understanding of 2D array traversal and index manipulation. Consistency starts today — 99 more days to go 💪 #LeetCode #Day1 #100DaysOfCode #Java #DSA #ProblemSolving #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
Day 20 of #100DaysOfLeetCode 💻✅ Solved #21. Merge Two Sorted Lists problem on LeetCode in Java. Approach: • Handled edge cases where either list is empty • Used a dummy node to simplify merging logic • Maintained a pointer current to build the new list step-by-step • Compared nodes from both lists and linked the smaller one • Connected any remaining nodes after one list ends • Returned dummy.next as the new head of the merged list Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 44.26 MB (Beats 75% submissions) Key Learning: ✓ Strengthened understanding of linked list pointer manipulation ✓ Learned to merge two lists without creating extra nodes ✓ Improved confidence in multi-pointer problems and list traversal Learning one problem every single day 🚀 #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 36 of #100DaysOfLeetCode 💻✅ Solved #111. Minimum Depth of Binary Tree on LeetCode using Java. Approach: • Used recursive approach to calculate minimum depth • Returned 0 when root is null (base case) • If one subtree is null, avoided taking minimum of 0 (handled edge case carefully) • Returned 1 + minimum depth of valid subtree • Ensured correct handling of skewed trees Performance: ✓ Runtime: 6 ms ✓ Memory: 82.20 MB Key Learning: ✓ Understood difference between minimum depth and maximum depth logic ✓ Learned importance of handling null subtree cases correctly ✓ Improved confidence in solving binary tree recursion problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTree #Recursion #TreeProblems #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 96 of #100DaysOfCode Solved LeetCode #1461 – Check If a String Contains All Binary Codes of Size K ✅ A solid mix of sliding window + bit manipulation, where efficiency really matters. Key Takeaways: -> Using rolling hash / bitmask to track binary substrings -> Avoiding substring overhead for better performance -> Understanding the limit: total required codes = 2^k -> Early pruning with length checks for optimization Language: Java -> Runtime: 6 ms (Beats 100%) ⚡ -> Memory: 47.73 MB Almost at the finish line — one binary string at a time 💻🔥 #LeetCode #Java #BitManipulation #SlidingWindow #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Solved a few interesting Array problems in Java 1.Minimum Removals to Balance Array Sorted the array first and applied a sliding window / two-pointer approach Goal was to keep elements where max ≤ min × k and remove the rest 2.Shuffle the Array Rearranged elements from the form [x1,x2…xn,y1,y2…yn] → [x1,y1,x2,y2…] Practiced index manipulation and clean iteration logic Good for understanding array positioning problems 3.Transformed Array (Circular Shift Logic) Implemented shifting based on element values (positive → forward, negative → backward) Used modulo arithmetic for circular indexing Helped in index calculations Trying to stay consistent and learn something new regularly 😊 Code is Available on my GitHub https://lnkd.in/guwCQJcw If anyone has suggestions or knows a better approach, please feel free to share 🙌 #DSA #Java #ArrayProblems #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
Day 23 of #100DaysOfLeetCode 💻✅ Solved #19. Remove Nth Node From End of List on LeetCode using Java. Approach: • Used a dummy node to handle edge cases (like removing the head) • Initialized two pointers: fast and slow • Moved fast pointer n+1 steps ahead to maintain a gap • Traversed both pointers together until fast reached null • Slow pointer stopped just before the node to delete • Updated links to remove the target node in one pass Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 43.77 MB Key Learning: ✓ Mastered two-pointer (fast & slow) technique ✓ Understood importance of dummy node for edge cases ✓ Solved the problem in a single traversal (O(n) time, O(1) space) Consistency is building confidence 🚀 #Java #LeetCode #DSA #LinkedList #TwoPointers #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 17 of #100DaysOfCode Solved the Concatenation of Consecutive Binary Numbers problem today using Bit Manipulation + Modulo Arithmetic in Java. Instead of converting numbers to binary strings, we shift the current result left by the number of bits in i and add i. We increase the bit count only when i is a power of 2 using: (i & (i - 1)) == 0 #Java #DSA #BitManipulation #LeetCode #CodingJourney #PlacementPrep
To view or add a comment, sign in
-
🚀 #100DaysOfCode | Day 35 📌 LeetCode : Minimum Depth of Binary Tree Today I solved the Minimum Depth of Binary Tree problem using Java. The goal was to find the shortest path from the root node to the nearest leaf node. I applied a recursive approach while carefully handling edge cases where one subtree is null. Instead of directly taking the minimum of both sides, I ensured the solution correctly skips null paths to avoid incorrect depth calculations. 📌 Key takeaways: 🔹 Understood the difference between minimum and maximum depth logic 🔹 Learned the importance of handling null child nodes 🔹 Strengthened recursion and tree traversal concepts 🔹 Improved problem-solving accuracy in edge cases This problem helped me think more clearly about tree structures and reinforced the importance of precise base conditions in recursion. #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
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