We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Simple solution: DFS from each intersection (1 .. N) until recursion hits depth 4. When at depth, check if path to current node forms a cycle. Once a cycle is found, add it to a set if it is new (i.e., not isomorphic to discovered cycles). Size of the set is the solution.
Code is left as an exercise for the reader. (Also my code is terrible.)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Jogging Cats
You are viewing a single comment's thread. Return to all comments →
Simple solution: DFS from each intersection (1 .. N) until recursion hits depth 4. When at depth, check if path to current node forms a cycle. Once a cycle is found, add it to a set if it is new (i.e., not isomorphic to discovered cycles). Size of the set is the solution.
Code is left as an exercise for the reader. (Also my code is terrible.)