← sunrise Interview Insights

sunrise·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Interviewed for a software engineer role at Sunrise and got hit with a linked list reversal question. Pretty standard stuff but they wanted both iterative and recursive solutions, which tripped me up a bit on the recursive side.

Questions Asked (1)

Q1

Given the head of a singly linked list, reverse it and return the new head. Implement both an iterative solution and a recursive one.

Algorithms & Data Structures
Author's notes

The iterative version came out fine, three pointers, prev starts null, walk through the list swapping next pointers.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then explain the iterative approach using three pointers (prev, curr, next) to reverse the links in one pass. Follow with the recursive approach, highlighting the base case and the recursive step that reverses the rest of the list and adjusts pointers. Finally, compare time and space complexities and discuss trade-offs.

Pro tip: Mention that while recursion is elegant, it uses O(n) stack space, so iterative is preferred for large lists to avoid stack overflow. Also, write clean code with meaningful variable names and handle edge cases like empty list or single node.

1. Clarify requirements and edge cases

Confirm the function signature, input/output, and constraints. Discuss edge cases: empty list, single node, and list with multiple nodes.

2. Explain iterative approach

Describe using three pointers: prev (initially null), curr (head), and next. Iterate through the list, reversing the link at each step, and finally return prev as the new head.

3. Explain recursive approach

Define base case: if head is null or head.next is null, return head. Recursively reverse the rest, then set head.next.next = head and head.next = null, returning the new head from recursion.

4. Analyze complexity and trade-offs

State that both approaches run in O(n) time. Iterative uses O(1) space, while recursive uses O(n) space due to call stack. Discuss when to prefer each.

5. Test with examples

Walk through a small example (e.g., 1->2->3->null) for both approaches to verify correctness and demonstrate understanding.

Key Points to Mention

  • Three-pointer technique for iterative reversal
  • Base case and recursive step for recursive reversal
  • Time complexity O(n) for both, space complexity O(1) vs O(n)
  • Edge cases: empty list, single node
  • Pointer manipulation details (e.g., saving next before changing links)
  • Trade-offs: recursion elegance vs stack overflow risk

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.