The iterative part was fine, three pointers, done.
Start by clarifying the problem and edge cases, then implement the iterative solution with three pointers (prev, curr, next), and finally implement the recursive solution with a clear base case. Explain the time and space complexity of each approach and discuss trade-offs.
Pro tip: Mention that the recursive solution uses O(n) stack space, which can cause stack overflow for large lists, so the iterative solution is preferred in production. Also, handle edge cases like empty list and single node explicitly.
Ask if the list is singly linked, if we need to handle empty list, and if we can modify the list in place. Confirm that we should return the new head.
Use three pointers: prev (initially null), curr (head), and next. Iterate through the list, reversing the next pointer of each node, and finally return prev as the new head.
Base case: if head is null or head.next is null, return head. Recursively reverse the rest of the list, then set head.next.next = head and head.next = null, returning the new head from the recursion.
Iterative: O(n) time, O(1) space. Recursive: O(n) time, O(n) space due to call stack. Discuss when to use each.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.