Linked List Random Node
A medium-tier problem at 64% community acceptance, tagged with Linked List, Math, Reservoir Sampling. Reported in interviews at Nvidia and 0 others.
You've got a linked list and need to return a random node. Sounds simple. It's not. The catch: you don't know the list length upfront, you can't traverse it twice, and you need uniform distribution. Nvidia has asked this one. Most candidates either hardcode a length (wrong), traverse twice (disqualified), or freeze when they realize they can't precompute. The 64% acceptance rate reflects exactly that wall. If you blank on reservoir sampling during your OA, StealthCoder surfaces the working approach in seconds, invisible to the proctor.
Companies that ask "Linked List Random Node"
Linked List Random Node is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderThe trick is reservoir sampling, a statistical pattern that feels foreign if you haven't seen it. Walk the list once. For node i, generate a random number from 0 to i inclusive. If it equals 0, that's your answer. Continue to the end. Why this works: by the final node, every node has exactly 1/n chance of being selected, even though you never knew n. The math feels like magic until you reverse-engineer it. Common failure: using `Math.random() % length` when you don't have length. Another: thinking you need to store all nodes. You don't. StealthCoder hedges the interview moment when you realize your first approach violated the constraints and you've burned five minutes.
Pattern tags
You know the problem.
Make sure you actually pass it.
Linked List Random Node recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Linked List Random Node interview FAQ
Is reservoir sampling really necessary here?+
Yes. The constraint is single-pass access without knowing list length. Any two-pass solution or precomputed length fails the problem statement. Reservoir sampling is the only O(n) time, O(1) space approach that guarantees uniform randomness. It's taught in systems and databases but rarely in LeetCode drills.
Why do companies ask this if it's not a common pattern?+
Because it tests whether you can reason under constraints, stay calm when your intuition fails, and apply an unfamiliar mathematical pattern correctly. Nvidia and similar companies care about algorithmic depth. A 60% acceptance rate means it separates strong candidates from those who panic or memorize without understanding.
What's the failure mode most people hit?+
Trying to traverse the list twice to get length first, then pick a random index. That violates the single-pass constraint. Second common error: storing all nodes in an array, which breaks O(1) space. The problem is testing whether you know the one-pass, constant-space trick exists.
How does Math relate to the solution?+
Probability and counting. The proof that reservoir sampling gives uniform distribution involves combinatorics. You need to understand why selecting node i with probability 1/(i+1) at step i guarantees each node has 1/n final probability. The math topic flags that this isn't just code mechanics.
Is this still asked at big tech companies?+
Yes, though infrequently outside database and systems interviews. When it appears, it's usually at companies building distributed systems or running heavy statistical workloads. Nvidia's appearance here reflects that. It's worth drilling if you're targeting senior or systems-focused roles.
Want the actual problem statement? View "Linked List Random Node" on LeetCode →