Tap here to switch tabs
Problem
Submissions

Problem: Search a 2D Matrix II

Search a 2D Matrix II asks whether a target exists in a matrix whose rows and columns are sorted in ascending order, returning true or false.

Statement

Given an integer matrix matrix with m rows and n columns, determine whether the integer target exists in matrix.

The matrix has the following ordering properties:
Each row of matrix is sorted in ascending order from left to right.
Each column of matrix is sorted in ascending order from top to bottom.

Return true if target is present in matrix, otherwise return false.

Constraints:

  • m == matrix.length

  • n == matrix[i].length

  • 1≤‘n‘,‘m‘≤3001 \leq `n`, `m` \leq 300

  • −109≤‘matrix[i][j]‘≤109-10^9 \leq `matrix[i][j]` \leq 10^9

  • All the integers in each row are sorted in ascending order.

  • All the integers in each column are sorted in ascending order.

  • −109≤‘target‘≤109-10^9 \leq `target` \leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Search a 2D Matrix II

Search a 2D Matrix II asks whether a target exists in a matrix whose rows and columns are sorted in ascending order, returning true or false.

Statement

Given an integer matrix matrix with m rows and n columns, determine whether the integer target exists in matrix.

The matrix has the following ordering properties:
Each row of matrix is sorted in ascending order from left to right.
Each column of matrix is sorted in ascending order from top to bottom.

Return true if target is present in matrix, otherwise return false.

Constraints:

  • m == matrix.length

  • n == matrix[i].length

  • 1≤‘n‘,‘m‘≤3001 \leq `n`, `m` \leq 300

  • −109≤‘matrix[i][j]‘≤109-10^9 \leq `matrix[i][j]` \leq 10^9

  • All the integers in each row are sorted in ascending order.

  • All the integers in each column are sorted in ascending order.

  • −109≤‘target‘≤109-10^9 \leq `target` \leq 10^9