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.
The theory your running is close. I think you mis-explain it, given that you actually passed the test cases.
modulo 1: 5 needs to be subtracted 9 times; modulo 2: 5 needs to be subtracted 3 times. Remember, 5 needs to appear a number of times divisible by 3. If the current number is divisible, and you remove 1 or 2, the resulting number can not mathematically be divisible by 3.
You also need to add an additional check to make sure that you actually have enough 5s to remove the required number. If not, that should be the only case where you can not make a proper number, resulting in a "-1".
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and The Beast
You are viewing a single comment's thread. Return to all comments →
The theory your running is close. I think you mis-explain it, given that you actually passed the test cases.
modulo 1: 5 needs to be subtracted 9 times; modulo 2: 5 needs to be subtracted 3 times. Remember, 5 needs to appear a number of times divisible by 3. If the current number is divisible, and you remove 1 or 2, the resulting number can not mathematically be divisible by 3.
You also need to add an additional check to make sure that you actually have enough 5s to remove the required number. If not, that should be the only case where you can not make a proper number, resulting in a "-1".