Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

61. Search a 2D Matrix

MediumDay 18 of 60Binary Search

You are given an m x n integer matrix where each row is sorted left to right, and the first value of every row is greater than the last value of the row above it. Return true if target is in the matrix. The solution must be O(log(m * n)).

Example 1
Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
Output: true
Example 2
Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
Output: false
Constraints
  • 1 <= m, n <= 100
  • -10^4 <= matrix[i][j], target <= 10^4
Hints
Frequently asked at: Amazon, Microsoft, Apple, Bloomberg
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min