← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Google SWE coding round, one question with a follow-up, interviewer was chill and the whole thing wrapped up with time to spare.

Questions Asked (1)

Q1

Reverse a linked list between two given positions, then modify your solution to do it in-place.

Algorithms & Data Structures
Author's notes

The base problem wasn't bad, got through it and did a dry run without too much fumbling.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem: reverse the nodes between positions m and n (1-indexed) in a singly linked list. For the initial solution, consider extracting the sublist, reversing it, and reconnecting; then optimize to in-place by adjusting pointers in a single pass.

Pro tip: Use a dummy node to simplify edge cases where m=1, and always draw the list and pointer movements before coding to avoid losing references.

1. Clarify requirements and edge cases

Confirm 1-indexed positions, whether m and n are guaranteed valid, and if the list can be empty or have only one node. Discuss edge cases like m=1, m=n, and n equals list length.

2. Design initial approach

Propose a straightforward method: traverse to node at m-1, extract the sublist from m to n, reverse it, and reconnect. Analyze time and space complexity (O(n) time, O(n) space if using extra list).

3. Optimize to in-place

Modify to reverse the sublist in-place using three pointers (prev, curr, next) while traversing. Keep track of the node before m (prev_m) and the first node of sublist (start) to reconnect after reversal.

4. Implement and test

Write clean code with a dummy node to handle m=1. Walk through examples, including edge cases, and verify pointer updates. Mention time O(n) and space O(1).

5. Discuss trade-offs and extensions

Compare the two approaches, highlighting in-place efficiency. If time permits, discuss variations like reversing in groups of k or handling doubly linked lists.

Key Points to Mention

  • Use of dummy node to simplify edge cases (especially when m=1)
  • Pointer manipulation: tracking prev, curr, next, and boundary nodes (prev_m, start)
  • Time and space complexity: O(n) time, O(1) space for in-place
  • Edge cases: m=1, m=n, n equals length, empty list
  • In-place reversal technique without extra data structures
  • Clear variable naming and drawing diagrams to explain logic

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