Search a 2D Matrix

Medium Solved

Description

You are given an m × n integer matrix with the following properties:

  • Each row is sorted in ascending order.
  • The first integer of each row is greater than the last integer of the previous row.

Given an integer target, return true if target is in the matrix, otherwise return false.

Input format:

  • Line 1: 2D matrix (JSON array)
  • Line 2: Integer target

Examples

Input:
[[1,3,5,7],[10,11,16,20],[23,30,34,60]]
3

Output:
true
Input:
[[1,3,5,7],[10,11,16,20],[23,30,34,60]]
13

Output:
false

Note:

Print true or false only.

No submissions yet.

Discuss binary search on matrix, row reduction, and flattening techniques.

Test Cases