DSA interview question
A decision-tree debugger lists every path from the root to a leaf, like "1->2->5", so analysts can see each complete chain of decisions. A DFS carries the path built so far. At a leaf it records the finished path; otherwise it extends the path with the child and recurses. Passing the path by value (or appending and then undoing) keeps sibling branches from seeing each other's nodes.
Example: [1, 2, 3, null, 5] → ["1->2->5", "1->3"].
vector<string> binaryTreePaths(TreeNode* root); // leaf paths from left to right
| Input (level order) | Output | Explanation |
|---|---|---|
[1, 2, 3, null, 5] | ["1->2->5", "1->3"] | |
[1, 2, 3, 4, 5, 6, 7] | ["1->2->4", "1->2->5", "1->3->6", "1->3->7"] | |
[1, null, 2, null, 3] | ["1->2->3"] | One leaf |
[1] | ["1"] | The root is a leaf |
[] | [] |
(Confirm: a leaf has no children; paths are listed in left-to-right order of their leaves.)
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