Skip to content
CodeItRaw
Linked Lists

Lesson 1/4

A linked list is a chain of nodes, each carrying a value and a link to the next one. It differs from a Python list in this: there are no indices and the length is written nowhere. All you hold is the first node (head); you get to the rest by following the next links. The last node's next is None.

largest = head.val
node = head.next
while node is not None:
largest = max(largest, node.val)
node = node.next
return largest
This is the pattern for walking a linked list: a pointer starts at head and moves on with node = node.next until it is None. Every one-pass pattern you know from lists (counting, summing, carrying the best) fits inside this loop unchanged.

The chain's strength is inserting and removing in the middle: changing two links is enough, and no element is shifted. Its weakness is finding things: getting to the k-th element takes k steps of walking.

Tasks

Tasks open in order. Solve them all and the next lesson opens.

This lesson's tasks open when the lessons before it are finished. You can read the explanation now.

  1. 01

    Count the Chain

    Function

  2. 02

    Append at the End

    Code reading · Read the Big-O

If you would rather not wait for the order, every problem is open without locks: Problem list