Grab a Random Linked List Node - Coding Interview Question

Опубликовано: 05 Май 2026
на канале: Team AlgoDaily
340
4

Given a linked list, can you write a method to get a random node within it? Let's assume you're given a random node generator. The linked list will have at least 2 nodes, and may look something like this:

1 - 2 - 3 - 4

The odds of getting any number between 1 and 4 inclusive should be the exactly the same.

You have access to this definition of a Linked List node:

```
function Node(val) {
this.val = val;
this.next = null;
}
```

---

Try to solve this at https://algodaily.com/challenges/grab...