Chapter 12 - Python Quest
Linked Lists
Build node chains, follow references, race pointers, reverse arrows, and merge linked paths.
Trailhead Peek
A hiking trail uses signposts linked by arrows. The guide wants a quick peek at the first two stops without walking the whole trail.
Write trailhead_peek(head) so it returns the head of a new linked list containing copies of the first two values. If the chain has fewer than two nodes, copy every value that exists. Leave the original chain unchanged.
Sample checks
trailhead_peek(["map","bridge","cave"])returns["map","bridge"]Explanation: head points to map, and map.next points to bridge; the cave is a third node, so this two-node peek does not include it
trailhead_peek(["lake"])returns["lake"]Explanation: head points to lake, but lake.next is None, so only one value exists to collect
Hint
Hints are ready when you want one.
Lesson reference
Review: Head, next, and None
Your Python
trailhead_peek
Judge
Ready
Run your code when it feels ready.
