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.
I do not understand why you are doing the sqrt(). To me Greedy does not work for this problem.
Consider N = 168. With just doing it greedily (use sqrt) we are going to have:
168 -> 14 -> 7 -> 6 -> 3 -> 2 -> 1 -> 0 (which has 7 steps). But this one has 6 steps:
168 -> 24 -> 6 -> 3 -> 2 -> 1 -> 0.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Down to Zero II
You are viewing a single comment's thread. Return to all comments →
I do not understand why you are doing the sqrt(). To me Greedy does not work for this problem. Consider N = 168. With just doing it greedily (use sqrt) we are going to have: 168 -> 14 -> 7 -> 6 -> 3 -> 2 -> 1 -> 0 (which has 7 steps). But this one has 6 steps: 168 -> 24 -> 6 -> 3 -> 2 -> 1 -> 0.