Pattern Recognition Drill
Easy Linked Lists
The Problem
Insert value val at position k (0-indexed) in a linked list.
What approach would you use?
Think about it before scrolling down.
Walk to node k-1, set new_node.next = node.next, node.next = new_node. O(k) time.
Common Trap
Don't forget the edge case: inserting at position 0 (head) needs special handling or a dummy node.