FastPrepStaircase Search In A Sorted Matrix
Problems/Staircase Search In A Sorted Matrix

Staircase Search In A Sorted Matrix

Motive logoMotive● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Motive onsite report for a full-time role directly names the Search a 2D Matrix II problem. The task is the staircase search.

Our version is about 99% the same as the reported question.

You are given a nonempty rectangular integer matrix matrix and an integer target.

Every row is sorted in nondecreasing order from left to right. Every column is sorted in nondecreasing order from top to bottom. Adjacent rows are not required to form one globally sorted list.

Return true if target appears in matrix, and false otherwise.

Function

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

Examples

Example 1

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

Starting at the top-right value 7, move left because 5 is smaller, then move down because 4 is smaller than 5. The next cell is 5.

Example 2

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

The same walk from 7 reaches the bottom-right value 9 without seeing 10.

Constraints

  • 1 <= matrix.length, matrix[i].length <= 300.
  • matrix is rectangular: every row has the same length.
  • -10^9 <= matrix[i][j], target <= 10^9.
  • Each row is sorted nondecreasing left to right.
  • Each column is sorted nondecreasing top to bottom.

More Motive Onsite Interview questions

  • Group AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
  • Longest Equal-Zero-One SubarrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
  • Maximum Weighted Sum After Left RotationsONSITE INTERVIEW · Seen Jan 2026
  • Valid Parenthesis StringPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Dec 2025
  • Target Triplet SumONSITE INTERVIEW · Seen Dec 2025
  • Validate IP AddressONSITE INTERVIEW · Seen Dec 2025
  • Generate Palindromic PermutationsONSITE INTERVIEW · Seen Dec 2025
  • Minimum Swaps to Group Circular OnesONSITE INTERVIEW · Seen Dec 2025
  • Search in Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
  • Search a Row and Column Sorted MatrixAmazon · ONSITE INTERVIEW
  • Search a 2D MatrixWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • K-th Smallest Value in a Sorted MatrixPhonePe · ONSITE INTERVIEWPhonePe interview questions
  • Staircase Search In A Sorted MatrixGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Place K Buildings to Minimize Maximum Grid DistanceOracle · ONSITE INTERVIEWOracle interview questions
  • Sub-matrix SumsIMC Trading · OAIMC Trading interview questions
  • Kth Smallest Value in a Row- and Column-Sorted MatrixOpenAI · PHONE SCREENOpenAI interview questions
  • Largest Sub-GridMathWorks · OAMathWorks interview questions
  • Grid Path With the Most ClearanceDocuSign · OADocuSign interview questions
All Motive interview questionsSee Motive hiring insights
Saved
class Solution {
    public boolean staircaseSearch(int[][] matrix, int target) {
      // Write your code here.
    }
}
Checking account…