LINK-P1

Remove a station

Practice 1 of 6Linked lists9 tests

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

  1. Hint 1Nudge
  2. Hint 2Approach Open hint 1 first
  3. Hint 3Pseudocode Open hint 2 first
  4. Worked solutionlast resort Opens after all 3 hints
Python waits for a wider screensolution.py

Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.

9 tests, not run yet
Test results
#TestResultReads · time
1In the middleNot run
2At the headNot run
3Two in a rowNot run
4Every nodeNot run
5Empty listNot run
6Not thereNot run
7Last nodeNot run
8Same nodesNot run
9200,000 nodesNot run