← 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 problem. 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 solution.

Algorithms & Data Structures
Author's notes

The iterative version I could do in my sleep, three pointers, walk the list, done.

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. Next, describe the recursive approach where you recursively reverse the rest of the list and adjust pointers, emphasizing the base case and call stack. Finally, compare time and space complexity 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 iterative is often preferred in production. Also, write clean code with meaningful variable names and handle edge cases like empty list and single node upfront.

1. Clarify and Edge Cases

Confirm the problem: reverse a singly linked list and return new head. Ask about constraints (e.g., list size, memory limits) and handle edge cases: empty list, single node, two nodes.

2. Iterative Approach

Explain using three pointers: prev (initially null), curr (head), and next. Iterate while curr is not null, reversing the link and advancing pointers. Return prev as new head.

3. 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. Return new head from recursion.

4. Complexity Analysis

State time complexity O(n) for both. Space: iterative O(1), recursive O(n) due to call stack. Discuss trade-offs and when to use each.

5. Test and Validate

Walk through an example (e.g., 1->2->3->null) for both approaches, verifying pointer changes. Mention testing edge cases and potential pitfalls like losing references.

Key Points to Mention

  • Three-pointer technique for iterative reversal (prev, curr, next)
  • Recursive base case and pointer manipulation (head.next.next = head)
  • Time complexity O(n) and space complexity O(1) iterative vs O(n) recursive
  • Edge cases: empty list, single node, two nodes
  • Stack overflow risk in recursive solution for large lists
  • Importance of not losing the next node reference during reversal

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