midSearching
Search in a 2D Matrix (Sorted)
Updated Apr 28, 2026
Short answer
Treating the 2D matrix as a virtual 1D array and performing Binary Search.
Deep explanation
Intermediate searching challenges involve non-standard data structures or specific constraints. Treating the 2D matrix as a virtual 1D array and performing Binary Search.
Real-world example
Finding a word in a partially organized document.
Common mistakes
- Using O(n) for a 2D matrix search when O(log(m*n)) is possible.
Follow-up questions
- Why is mid = (low + high) // 2 potentially dangerous?