Solve BFS and grid tasks
UberSoftware Engineer · OnsiteLast updated
This collection evaluates understanding of search techniques (binary search and BFS), graph and grid traversal, state-space shortest-path reasoning, randomized placement with adjacency counting, and attention to implementation quality and complexity trade-offs.
The coding rounds included several algorithmic problems:
-
Threshold search with binary search: You are given floors
1..nand an APIcanOperate(floor)that returnstrueif an elevator can safely serve that floor andfalseotherwise. There exists a highest safe floorTsuch that all floors<= Tare safe and all floors> Tare unsafe. FindTusingO(log n)calls. -
Shortest path on a combination lock: A lock has four wheels, each showing a digit
0-9. In one move, you may increment or decrement exactly one wheel by1, with wraparound (9 -> 0,0 -> 9). Given a start state, a target state, and a set of blocked states that cannot be visited, return the minimum number of moves needed to reach the target, or-1if it is impossible. -
Nearest exit in a 2D grid: You are given a rectangular grid containing walls and open cells, plus a starting cell inside the grid. You may move up, down, left, or right through open cells. Return the minimum number of steps needed to reach any open boundary cell other than the starting cell, or
-1if no exit exists. -
Generate a random minesweeper board: Given
rows,cols, andN, generate arows x colsboard with exactlyNmines placed uniformly at random in distinct cells. Then fill each non-mine cell with the number of adjacent mines in the eight neighboring positions. The implementation should emphasize clean code, simple logic, and avoidance of unnecessary auxiliary data structures when possible.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.