Remove Nth Node From End
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Strip the story away and this Bloomberg OA question, reported in February 2021, is one pointer gap on a singly linked list. Find the node before the target, then skip over the target. That's the whole thing. The hinted tag says graph, but ignore it. This is a linked list problem, and it's a classic. If your brain freezes on pointer logic under a timer, StealthCoder is the safety net running invisibly during the live OA. Still, you should know the shape of this one before you sit down, because the edge case is where people lose points.
The problem
Remove the n-th node from the end of the singly linked list and return its head. Function removeNthFromEnd(head: ListNode, n: int) → ListNode Examples Example 1 head = [1,2,3,4,5] n = 2 return = [1,2,3,5] The value 4 is second from the end. Constraints The list contains between 1 and 10^5 nodes. 1 <= n <= list length.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is two pointers with a fixed gap. Add a dummy node before head. Start fast and slow both at the dummy. Move fast forward n+1 steps, so the gap between them is n nodes. Then advance both until fast hits null. Slow now sits right before the node to delete, so set slow.next = slow.next.next. Return dummy.next. One pass, O(n) time, O(1) space. The common pitfall is removing the head itself, which happens when n equals the list length. Without the dummy node you need a special case, and that's where off-by-one bugs and null pointer errors show up. Also don't count the length first unless you want two passes, which still works but looks weaker. If you blank on the gap setup mid-assessment, StealthCoder can hand you the dummy-node version in real time.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Remove Nth Node From End cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as remove nth node from end of list. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Remove Nth Node From End FAQ
How hard is Remove Nth Node From End really?+
It's easy to medium. The idea is short, but pointer bugs are common. Most failures come from off-by-one gaps or deleting the head. If you can write the dummy node version from memory, you're fine. Practice it once or twice and it sticks.
What's the trick to solve it in one pass?+
Use two pointers with a gap of n nodes. Move the fast pointer ahead first, then move both until fast reaches the end. The slow pointer lands just before the node you want to remove. Then you rewire one next pointer and you're done.
Why use a dummy node here?+
It handles the case where the head gets removed. When n equals the list length, the target is the first node and there's no previous node to rewire. A dummy before head gives you one, so you skip the special case and return dummy.next.
Is this linked list pattern still asked at Bloomberg?+
It was reported for Bloomberg in February 2021, and linked list pointer problems keep showing up across OAs. I can't tell you how often Bloomberg asks it now. Know the two-pointer gap pattern and you're covered for close variants too.
How do I prepare for this in 48 hours?+
Write the solution by hand twice, once with a length count and once with the gap method. Test n equal to 1, n equal to the length, and a single node list. Those three cases catch nearly every bug. Then move on to other pointer problems.