The problem
A linked list holds the stations on a route. Remove every node whose value is x, and return the head of what is left. The other nodes keep their order.
list 1, 2, 6, 3, 4, 5, 6, remove 6 -> 1, 2, 3, 4, 5
list 6, 6, 1, 6, remove 6 -> 1
list 7, 7, 7, remove 7 -> None (empty)
The tests build the list from nodes with a value and a next, pass you the head, then walk from the head you return, following next, and compare the values they find. An empty list is None.
Change the links of the nodes you are given. Do not build a new list.
Limits
- Up to 200,000 nodes.
Builds on LINK-1 Nodes and references and LINK-2 Insert and delete.
Continue on a laptop
Practice runs Python in the browser and needs a keyboard and a wider screen. Read the problem and open hints here, then write your solution on a laptop. Progress is saved per browser for now, so hints opened here stay on this device.
Need a hint?0 of 3 opened
- Hint 1Nudge
- Hint 2Approach Open hint 1 first
- Hint 3Pseudocode Open hint 2 first
- Worked solutionlast resort Opens after all 3 hints
Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.
| # | Test | Result | Reads · time |
|---|---|---|---|
| 1 | In the middle | Not run | |
| 2 | At the head | Not run | |
| 3 | Two in a row | Not run | |
| 4 | Every node | Not run | |
| 5 | Empty list | Not run | |
| 6 | Not there | Not run | |
| 7 | Last node | Not run | |
| 8 | Same nodes | Not run | |
| 9 | 200,000 nodes | Not run |