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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Graph Theory
  4. Jogging Cats
  5. Discussions

Jogging Cats

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • racuna1
    1 year ago+ 0 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.)

    1|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature