DSA interview question
A word-puzzle game shows a grid of letters, and the player claims a word is hidden in it. The word must be traced through horizontally or vertically adjacent cells, and no cell may be used twice in the same word. The game must verify the claim instantly. The standard approach is backtracking DFS from every cell that matches the first letter: step to a neighbour matching the next letter, mark the current cell as used while exploring deeper, and unmark it when backing out so other paths can use it.
Example: grid ABCE / SFCS / ADEE, word "ABCCED" → true.
bool exist(vector<vector<char>>& board, const string& word);
Input (board, word) | Output | Explanation |
|---|---|---|
(ABCE/SFCS/ADEE, "ABCCED") | true | A→B→C→C→E→D |
(ABCE/SFCS/ADEE, "SEE") | true | |
(ABCE/SFCS/ADEE, "ABCB") | false | The B can't be reused |
(a, "a") | true | A 1 × 1 grid |
(ab/cd, "abdc") | true | a→b→d→c |
(ab/cd, "abcd") | false | b and c aren't adjacent |
(Confirm: moves are up, down, left and right only, no diagonals; each cell is used at most once per word; the board is restored afterwards.)
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