Solved LeetCode 240 Search a 2D Matrix II with Top-Right Traversal

Day 90/100 🚀 | #100DaysOfDSA Solved LeetCode 240 – Search a 2D Matrix II today. Approach: Used the top-right corner traversal (greedy + matrix property). Key observation: • Each row is sorted left → right • Each column is sorted top → bottom So: • Start at top-right corner • If current value > target → move left (col--) • If current value < target → move down (row++) • If equal → found This eliminates one row or column in each step. Time Complexity: O(m + n) Space Complexity: O(1) Key takeaway: For sorted 2D matrices, don’t jump to binary search immediately — sometimes a clever starting point (like top-right) gives a simpler linear solution. #100DaysOfDSA #LeetCode #DSA #Java #Matrix #BinarySearch #Greedy #ProblemSolving #Consistency

  • text

To view or add a comment, sign in

Explore content categories