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.
Made this harder for myself by not seeing that the numbers in the array have to be distinct. This is mentioned in the introduction but not when stating the parameters. This typescript satisfies the test cases and all the examples with duplicates that I tested. Too long for a comment:
https://gist.github.com/MullPointer/5ce0d0ef6b40ba5306e8cb69f2a9aa70
It could definitely be optimized more as the recursion will still go out of control if there are too many repeats, so too many possible cycles to test.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lily's Homework
You are viewing a single comment's thread. Return to all comments →
Made this harder for myself by not seeing that the numbers in the array have to be distinct. This is mentioned in the introduction but not when stating the parameters. This typescript satisfies the test cases and all the examples with duplicates that I tested. Too long for a comment: https://gist.github.com/MullPointer/5ce0d0ef6b40ba5306e8cb69f2a9aa70 It could definitely be optimized more as the recursion will still go out of control if there are too many repeats, so too many possible cycles to test.