Deviopath › TypeScript

Singly Linked List

Hard · Data Structures

Implement LinkedList<T> with nodes ({ value, next }) and both head and tail pointers, so append is O(1).

- append(value) / prepend(value) add at the end / start.

- insertAt(index, value) inserts so the new value ends up at index. Valid indexes are 0 to size; otherwise return false.

- removeAt(index) removes and returns the value at index, or undefined if the index is invalid.

- remove(value) removes the FIRST node with that value (===) and returns true, or false if not found.

- reverse() reverses the list in place.

- toArray() returns the values from head to tail. size is a getter.

Keep tail correct after every operation. The driver runList(ops) is already written; its "nodes" op walks from your public head and returns the values, or false if tail is not the last node.

Next: Get a Value by Path