Reported August 2024
Uberbreadth first search

Matrix Transformation

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

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

Uber asked this in August 2024, and it's a breadth-first-search problem dressed up as a matrix transformation. You're likely working with a grid where you need to find distances, shortest paths, or spread patterns from one or more starting points. The catch is recognizing when to use BFS instead of DFS or dynamic programming. If you blank on the approach during the OA, StealthCoder runs invisibly and flags the pattern in real time so you don't waste 15 minutes on the wrong strategy.

Pattern and pitfall

Matrix transformation problems using BFS almost always involve multi-source shortest path or reachability. You start with one or more seeds (cells, targets, or sources) and expand outward level by level, updating every cell with its distance or state. The pattern: initialize a queue with all starting cells, mark them visited, then iterate through the queue processing neighbors. Common pitfall is trying to modify the matrix in place during iteration or forgetting to track visited cells, which leads to infinite loops. BFS guarantees the shortest distance in unweighted grids. StealthCoder helps you recognize the shape of the problem fast so you can code the queue-based expansion without overthinking.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Matrix Transformation 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as walls and gates. If you have time before the OA, drill that.

⏵ The honest play

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

Uber reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Matrix Transformation FAQ

Is this problem asking for shortest path or transforming the whole matrix?+

Usually both. You transform the matrix by computing distance or state for every cell from one or more sources. BFS ensures you process cells in distance order, so the first time you reach a cell is the shortest path. If the problem says 'update all cells' or 'spread from source', that's the tell.

Do I need a 2D visited array or can I mark visited in the input matrix?+

Both work. Marking in-place is faster and saves memory, but read the problem carefully. If it says 'don't modify input' or you're asked to return the original matrix unchanged, use a separate visited set or 2D boolean array. Most Uber OAs allow in-place marking.

What if there are multiple sources or obstacles?+

Multi-source BFS: add all sources to the queue at the start, mark them as visited with distance 0. For obstacles, skip them during neighbor exploration. The queue handles everything in the right order. This is the most common variant Uber uses.

How do I avoid TLE with large grids?+

Visit each cell exactly once. Use a visited array and check it before adding neighbors to the queue. Don't re-queue cells. With proper visited tracking, time is O(rows x cols), which is optimal for matrix problems.

Should I use a deque or a regular queue?+

Regular queue (or list with pop(0) in Python) works fine for standard BFS. Deque is faster for pop-from-front, but both pass. Focus on correctness. If the problem has weighted edges or needs 0-1 BFS, then deque becomes critical, but Uber usually sticks to unweighted grids.

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

OA at Uber?
Invisible during screen share
Get it