Nodes that each point to the next one.
O(N) time · O(N) spaceSingly and doubly linked list operations: traversal, reversal, and pointer manipulation.
6 algorithms1 variant7 problems
6 algorithms. Each one stands alone.
Nodes that each point to the next one.
O(N) time · O(N) spaceA linked list stores values in separate nodes joined by pointers, so adding or cutting a node is cheap but reaching position i means walking there from the head. These seven pages cover the list types you will meet and the pointer problems interviewers ask most often. The same moves turn up inside LRU caches, undo history and round-robin schedulers.
You never get to jump. Every page here holds one, two or three pointers and moves them forward node by node, and the whole skill is choosing which pointers to carry and in what order to rewrite next. Several pages also run two pointers at different speeds or a fixed distance apart, which lets one walk answer a question about the middle, the end or a loop.
Pick the list type by how you move through it: forward only, both ways, or round and round. Pick the technique by what you must find: a reversal needs three pointers, a middle or a loop needs two speeds, and a distance from the end needs a count or a gap. The common bug on every page is writing a next pointer before saving where it used to lead.