Drop the Kth Most Recent Event From a Singly Linked Log
Last updated: November 29, 2026
Quick Overview
An activity log is a singly linked list from oldest to newest. Remove the node that is k positions from the end (k = 1 is the newest) in a single pass and return the head.
0
0
0 solved
An activity log is a singly linked list from oldest to newest. Remove the node that is k positions from the end (k = 1 is the newest) in a single pass and return the head.
A Google phone screen staple that tests the lead-and-lag pointer technique. The interviewer listens for a one-pass approach and for correct handling when the node to delete is the head.
What the Interviewer Expects
- Use a dummy node so deleting the head needs no special case
- Advance a lead pointer k steps first, then move both together
- Stop the lag pointer at the node before the target
- Clarify k is valid (1 <= k <= length) or handle the invalid case
- Explain why one pass matters for a streamed log
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the kth from last without deleting it.
- The log is too long to store and arrives as a stream; how do you keep the last k items?
- Delete every kth node from the end in one pass.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: head and k with 1 <= k <= n.
- Output: head after removing the kth node from the end.
- One pass, O(1) extra space....
High-Level Design
Place both pointers on a dummy node in front of the head. Move lead k + 1 steps so the gap between lead and lag is k + 1 links. Then advance both until lead falls off the end; lag now sits j...