You’ve practiced the problems where the data is made of references:
- Linked lists trade instant access by position for cheap relinking. You walked them node by node, reversed one in place, removed a node counted from the end, and sent two runners at different speeds to find a middle or a loop with O(1) extra space.
- Recursion solves a problem by trusting a smaller call. It’s clear and often the best first answer, but every pending call holds a stack frame, and V8 throws a
RangeErroronce the stack runs out, often after just ten thousand or so frames. - Trees let each subtree report back a count, a depth, or a verdict. When the question is about rows, you go level by level. When the tree can be deeper than the call stack allows, you keep your own stack in an array.
Things to Remember in an Interview
- Draw the boxes and arrows for a small example before you write code, and redraw them after every reassignment.
- Compare nodes with
===. Two objects with the same data are still two different nodes. - End lists with
nullon purpose, and set thenextof a node you remove tonullas well. - Read optional children with
?? [], and ask how deep and how wide the input can get before you choose recursion. - Remember that
{ ...node }copies one level. UsestructuredClone()or copy each level yourself when you need an independent tree.