Reported December 2025
Motivematrix

Staircase Search In A Sorted Matrix

Reported by candidates from Motive's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Motive OA. Under 2s to a working solution.
Founder's read

A 300 by 300 matrix means 90,000 cells, and the Motive OA reported in December 2025 wants you to skip most of them. Scanning every cell works but misses the point. The staircase search starts at a corner and throws away a full row or column on every step. It's the sorted-matrix search, and the hinted BFS label is misleading. If you freeze on the pointer logic, StealthCoder is a quiet safety net during the live OA. Know the walk before you open the invite.

The problem

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 = 5
return = true
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 = 10
return = false
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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Start at the top-right corner. If the value equals target, return true. If the value is bigger than target, everything below it in that column is bigger too, so move left. If the value is smaller, everything to its left in that row is smaller too, so move down. Each step kills a row or a column, so you finish in at most rows + columns steps, O(m + n) time and O(1) space. The common pitfall is starting at top-left, where both directions increase and you can't decide. Another is treating it as one globally sorted list and binary searching the flattened array, which fails because adjacent rows aren't ordered. Watch the loop bounds: row < m and col >= 0. If you blank on which corner works, StealthCoder can hand you the loop during the live OA, but the logic is five lines you can own.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Staircase Search In A Sorted Matrix cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as search a 2d matrix ii. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Motive's OA.

Motive reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Staircase Search In A Sorted Matrix FAQ

What's the trick in the Motive staircase search problem?+

Start at the top-right or bottom-left corner. From there, one direction increases and the other decreases, so every comparison eliminates a whole row or column. You end up with a single while loop and two pointers, no recursion needed.

Why not use BFS even though it's hinted?+

BFS would visit up to 90,000 cells and ignores the sorted structure. The staircase walk uses the ordering to discard a row or column per step, finishing in about 600 steps worst case. BFS is correct but wastes the whole setup.

Can I binary search each row instead?+

Yes. It's O(m log n), which passes the 300 by 300 limits. It's a fine fallback if you forget the staircase. The staircase is faster at O(m + n) and shorter to code once you see it.

Why doesn't flattening and binary searching work?+

The problem says adjacent rows aren't required to form one sorted list. The last element of one row can exceed the first of the next. Flattened binary search needs a global order, so it gives wrong answers on inputs like the examples.

How do I prepare for this in 48 hours?+

Code the staircase walk from scratch three times. Test on a 1 by 1 matrix, a single row, a single column, and a target smaller than the minimum. Practice the pointer moves until you can say why each direction is safe.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Motive.

OA at Motive?
Invisible during screen share
Get it