Follow one-way links to the endpoint or the last node before a loop
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.
No answer yet. Write the first one; the best answer gets endorsed.
