LeetCode Solution: Search in 2D Matrix

🚀 Day 24 of my #100DaysOfCode Journey Today, I solved the LeetCode problem Search in 2D Matrix. Problem Insight: Given a sorted 2D matrix, the goal is to efficiently determine whether a target value exists. Approach: Started from the top-right corner of the matrix If the current element equals target → return true If target is smaller → move left (col--) If target is larger → move down (row++) This works because the matrix is sorted row-wise and column-wise, allowing us to eliminate one row or column at each step. Time Complexity: O(m + n) — linear traversal across rows and columns Takeaway: A smart starting point (top-right corner) can significantly optimize search problems in 2D structures. #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #Matrix

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories