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.
Additional comment for clarity. The bases are there because adding to all but the chosen one is not completely the same as subtracting from only the chosen one. (Not until we consider adding the bases 0, 1, 2).
For example, to elaborate on the given example, if we had 0 4 4, under the division of (int)delta / 5 + delta % 5 / 2 + delta % 5 % 2 / 1 without bases, we technically cannot account for the option of -5 because we can't apply that to the number delta 4 (or if delta = 3 for that regard). Try running through delta = 4 on your own and you'll see what I mean.
Adding +1 (or +2 for delta = 3) here would fix that problem. We only need bases 0, 1, 2 to account for delta = 3 or 4. Once delta = 2, the superior choice would be to -2 and not -5, so we don't need additional bases.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Equal
You are viewing a single comment's thread. Return to all comments →
Additional comment for clarity. The bases are there because adding to all but the chosen one is not completely the same as subtracting from only the chosen one. (Not until we consider adding the bases 0, 1, 2).
For example, to elaborate on the given example, if we had 0 4 4, under the division of (int)delta / 5 + delta % 5 / 2 + delta % 5 % 2 / 1 without bases, we technically cannot account for the option of -5 because we can't apply that to the number delta 4 (or if delta = 3 for that regard). Try running through delta = 4 on your own and you'll see what I mean.
Adding +1 (or +2 for delta = 3) here would fix that problem. We only need bases 0, 1, 2 to account for delta = 3 or 4. Once delta = 2, the superior choice would be to -2 and not -5, so we don't need additional bases.