Fresh C++ SWE (Intern) first-round interview report
Last week I had my first round for the C++ SWE (intern) position, a 1-hour Zoom coding interview.
We spent a few minutes at the start briefly chatting about background, then moved into the problem.
The question: given a binary tree where each node has an integer value, and a target, determine whether there's a path from root to leaf where the sum of all the node values along the path equals the target.
The interviewer added a few conditions:
- Node values can be negative
- An empty tree returns false
- The path must go all the way to a leaf — it can't stop early at an internal node
I solved it with DFS — at each node I subtract the current value from the target, and when I reach a leaf I check whether the remaining value equals the current node's value. Both recursive and iterative work; I wrote the recursive version.
No test cases were given, so I had to think through the edge cases myself: a single node, negative values, and empty left/right subtrees.
The follow-up was to return all paths that satisfy the condition. I said I could maintain the current path during the DFS, use backtracking to add and remove nodes, and save the path whenever I hit a valid leaf. I basically finished writing this too.
Overall it was easier than I expected — the main question felt like a LeetCode Easy, and the follow-up just added a bit more implementation detail. The interviewer cared more about edge cases and explaining my thought process, and didn't ask any C++ fundamentals questions.
There were a few minutes left at the end for questions, and the whole thing came in right around one hour. I'm still waiting to hear back.
Discussion
Loading comments…