Intermediate
Walk a graph with a hop limit
triples is a list of (left, relation, right). Write reachable(start, triples, max_hops) that follows edges from left to right for up to max_hops hops and returns the sorted list of nodes reached (not including start).
A node must be visited once only, so a loop in the data cannot make the walk run for ever.
What Check tests
- One hop finds direct neighbours
- More hops go further
- Zero hops reaches nothing
- A loop does not run for ever
- A missing start gives an empty list
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.