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.
This can be solved in O(q) time, once you realize that the even/odd parity of the hackonacci(n) function is periodic, with a prime period.
Print out the (Y/N) pattern of the Hackonacci Matrix for, say n=41 and see what I mean. It's easier to see if you use something like * and . instead of Y and N.
This means you don't need a 2000x2000 array or carry around a huge memoization table for the hackonacci function.
Hint: Do write up the slow, straightforward implementation of the problem statement to give yourself something to compare your optimized output to. The test cases here are pretty thin.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hackonacci Matrix Rotations
You are viewing a single comment's thread. Return to all comments →
This can be solved in O(q) time, once you realize that the even/odd parity of the hackonacci(n) function is periodic, with a prime period.
Print out the (Y/N) pattern of the Hackonacci Matrix for, say n=41 and see what I mean. It's easier to see if you use something like * and . instead of Y and N.
This means you don't need a 2000x2000 array or carry around a huge memoization table for the hackonacci function.
Hint: Do write up the slow, straightforward implementation of the problem statement to give yourself something to compare your optimized output to. The test cases here are pretty thin.