DSA interview question
A robot vacuum maps a square room as an n × n grid: 1 is a free tile and 0 is furniture. It starts at the top-left tile and must reach the charging dock at the bottom-right, moving Down, Left, Right or Up one tile at a time and never revisiting a tile on the same trip. The planning screen should list every possible route as a string of moves (like DRDDRR), in lexicographic order. Backtracking explores moves in alphabetical order (D, L, R, U), marks tiles on the current path, and unmarks them when backing out.
Example: maze 1000 / 1101 / 1100 / 0111 → DDRDRR DRDDRR.
vector<string> findPaths(const vector<vector<int>>& maze); // sorted; empty if unreachable
| Input maze (rows) | Output | Explanation |
|---|---|---|
1000 / 1101 / 1100 / 0111 | DDRDRR DRDDRR | |
10 / 10 | (none) | The destination is blocked |
11 / 11 | DR RD | |
01 / 11 | (none) | The start is blocked |
111 / 101 / 111 | DDRR RRDD | Two ways around the centre |
(Confirm: moves are D, L, R, U only; a tile can't be revisited on one path; if the start or destination is 0, return no paths.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in