FastPrepSearch a Row-and-Column Sorted Matrix
Problems/Search a Row-and-Column Sorted Matrix

Search a Row-and-Column Sorted Matrix

AMD logoAMD● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks to search a sorted square n×n matrix without defining its sorting order. This authored practice generalizes the shape to a rectangular row-and-column sorted matrix, including empty and zero-column shapes; bounds and interface are authored. Approximate source match75%.

Return whether target occurs in matrix. Rows are nondecreasing left to right, and columns are nondecreasing top to bottom. Values may repeat. The flattened matrix need not be sorted; an empty matrix or a matrix with zero columns contains no value.

Function

searchSortedMatrix(matrix: int[][], target: int) → boolean

Examples

Example 1

matrix = [[1,4,7],[2,5,9],[3,6,10]]target = 6return = true

Value6 is at row2,column1 using zero-based coordinates.

Example 2

matrix = [[1,4,7],[2,5,9]]target = 8return = false

Eight is absent even though it lies between existing values.

Constraints

  • 0 <= matrix.length <= 100.
  • 0 <= matrix[r].length <= 100.
  • -1000000 <= matrix[r][c] <= 1000000.
  • -1000000 <= target <= 1000000.
  • All rows have equal length, and every row and every column is nondecreasing.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public boolean searchSortedMatrix(int[][] matrix, int target) {
    // Write your code here.
}
Checking account…