Skip to main content
LeetCode 74, Medium. Topics: Array, Binary Search, Matrix. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:

Problem

You are given an m x n integer matrix matrix with the following two properties:
  • Each row is sorted in non-decreasing 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 matrix or false otherwise. You must write a solution in O(log(m * n)) time complexity.

Examples

Example 1
Example 2

Constraints

  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m, n <= 100
  • -10^4 <= matrix[i][j], target <= 10^4

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Grind, NeetCode 150, NeetCode 250, NeetCode All.
Last modified on August 25, 2026