Linked Lists
8 min · Python examples
Chain nodes with next pointers: traverse, count, and update without shifting a whole array.
Techniques · Linked Lists0/5 cleared
Enemy 1 of 5
This builds a chain of three nodes, each pointing to the next, then walks from the first node to the end while counting them. Press Run to see the count printed.
Why this works
A singly linked list stores values in nodes. Each node holds a value and a next pointer to the following node.
Traverse by walking from head with a while loop: cur = cur.next until cur is None. Inserting at the front is O(1); finding by index is O(n).
You
Syntax Skeleton
Loading editor…
Target output: 3