Step 3 of 4
Node Deletion
You start from the build so far — your own work where you have written it, the reference build where you have not. Either way this step stands on its own.
Implement deleteAt(index) to unlink and remove nodes.
- If
index < 0orindex >= length, returnnull/None. - If deleting head (
index === 0), updatethis.head = this.head.next. If the list only had 1 node, also clearthis.tail = null. - If deleting an internal or tail node, traverse to
index - 1and rewireprev.next = prev.next.next. If deleting the last node, updatethis.tail = prev. - Decrement
this.lengthand return the removed node's value.
Your build
Running is free — Submit is what records the step. Or press ⌘↩
Tests
1 case| call | type | expected | result |
|---|---|---|---|
| runOps([["append","A"],["append","B"],["append","C"],["deleteAt",1],["toArray"],["deleteAt",0],["toArray"],["deleteAt",0],["toArray"],["size"]]) | deletes nodes from head, middle, and tail | [null,null,null,"B",["A","C"],"A",["C"],"C",[],0] | — |
Hints
Stuck? Hints open one at a time, each giving a little more away.
2 hints left