Search a 2D Matrix

Medium
ArrayMatrixBinary SearchAmazonMicrosoft
You are given an m x n matrix where each row is sorted ascending and the first integer of each row is greater than the last integer of the previous row. Print whether the target value exists in the matrix. Input format: - First line: m n target - Next m lines: n integers each Print `true` or `false`.

Constraints

1 <= m, n <= 1000
-10^9 <= matrix[i][j], target <= 10^9
The matrix is sorted as described.

Sample tests

Sample 1

Sample 2

Sign in to submit