Although it is an easy problem and likely there is a clever way to solve it using just mathematical tricks, I decided to do a full implementation of Depth-First Search (DFS). Notice that the "visited" requires you to also use the cardinality of the number of steps taken. Code is down below, cheers, ACC.
Receive updates from Another Casual Coder for free, starting right now.
We can deliver them by email, via your phone or you can read them from a personalised news page on follow.it.
This way you won't miss any new article from Another Casual Coder. Unsubscribe at any time.
Site title: Another Casual Coder