ASAPUtils Logo ASAPUtils
Week 4

Search a 2D Matrix

Search a 2D Matrix by treating row-major cells as one virtual sorted array, with index-to-coordinate arithmetic, C++ and JavaScript solutions, complexity, and a flattened interactive trace.

medium Arrays Binary Search O(log(m*n)) time · O(1) space Open on LeetCode ↗

The problem

Given a matrix whose rows are ascending and whose first value in each row is greater than the previous row's last value, return whether a target is present in logarithmic time.

matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3 -> true

Related Problems