← Questions

Follow one-way links to the endpoint or the last node before a loop

0
OpenAICodingLast asked Oct 2026

A network has nodes joined by one-way links, and each node links to at most one other node. Starting from a given node, follow the links and return the endpoint: the last node the walk reaches before running out of links. If the walk falls into a loop instead, return the last node visited before the loop closes, that is, before the walk would revisit a node.

Say how you detect the loop, and give the time and space of your approach.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding