You are viewing a single comment's thread. Return to all comments →
You can solve this easily using a bit of math:
If the number(say 66317) is not divisible by 3, it will leave a modulo of either 0,1 or 2. If I decrease the number by 5, I am basically making it a multiple of 3, and the remaning digits will be a multiple of 5 as I am subtracting it from the number.
modulo 0 implies number divisibile
modulo 1 implies 5 needs to be subtracted twice.
modulo 2 implies 5 needs to be subtracted once.
Correct me if I am wrong. Completed all the test cases in 0-0.01s