Skip to main content
Medium Matrix High frequency

Search a 2D Matrix II

Open on LeetCode

Approach Summary

Start at top-right. If target < current, move left. If target > current, move down. Each step eliminates a row or column.

How to Recognize This Pattern

  • Rows and columns sorted independently — start at a corner
  • Top-right corner: left decreases, down increases

Complexity Analysis

Time Complexity

O(m + n)

Space Complexity

O(1)

Tags

Array Binary Search Divide and Conquer Matrix

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee