← Amplitude Interview Insights

Amplitude·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Did a technical phone screen for a software engineer role at Amplitude. One linked list problem, but the edge cases made it way less straightforward than I expected going in.

Questions Asked (1)

Q1

Given the head of a singly linked list and an integer K, swap the K-th node from the end with the head node in-place (O(1) extra memory) and return the new head.

Algorithms & Data Structures
Author's notes

The base case tripped me up more than the main logic.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use the two-pointer technique to find the K-th node from the end in one pass, then perform the swap by adjusting pointers carefully, handling edge cases like K=1 or K equal to the list length. Ensure O(1) extra memory by only using a few pointer variables and no additional data structures.

Pro tip: Clarify with the interviewer whether K is 1-indexed from the end (i.e., K=1 means the last node) and whether swapping with the head when the K-th node is the head itself should be a no-op. Also, consider drawing the list and pointer movements to avoid mistakes.

1. Understand the problem and edge cases

Restate the problem to ensure clarity: swap the K-th node from the end with the head. Identify edge cases: empty list, K <= 0, K > length, K=1 (last node), K=length (head itself), and list with only one node.

2. Find the K-th node from the end

Use two pointers: move the first pointer K nodes ahead, then move both pointers until the first reaches the end. The second pointer will be at the K-th node from the end. Keep track of the node before it for pointer adjustments.

3. Perform the swap

Handle cases: if K-th node is the head, no swap needed. Otherwise, adjust pointers: set the previous node's next to head, head's next to the K-th node's next, and the K-th node's next to the original second node (or null if K=1). Update the new head to be the K-th node.

4. Return the new head

After swapping, return the new head, which is the K-th node from the end (unless K equals the length, in which case the head remains the same).

Key Points to Mention

  • Two-pointer technique for finding the K-th node from the end in one pass.
  • Handling edge cases: K=1, K=length, empty list, K out of bounds.
  • Maintaining O(1) extra space by using only a constant number of pointers.
  • Careful pointer manipulation to avoid losing references, especially when K=1 or K=length.
  • Time complexity: O(N) where N is the number of nodes.
  • Clarifying assumptions with the interviewer (e.g., 1-indexed K, behavior for invalid K).

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