Binary Search pattern
Search a 2D Matrix
Given an m x n matrix where each row is sorted left-to-right and the first integer of each row is greater than the last integer of the previous row, determine whether a target value exists in the matrix in O(log(m·n)) time. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 74
- Medium
- 1 approach
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
Binary SearchLeetCode 74
Medium
The approach
- 01 Binary search the flattened grid O(log(m·n))O(1) space
What you will learn
- How to read Search a 2D Matrix and spot the binary search pattern in it
- Binary search the flattened grid: O(log(m·n)) time, O(1) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Binary Search
See Search a 2D Matrix run, step by step
Sign in and this page opens on the animation, with all 11 Binary Search problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.