October Lunchtime: MAXNUM 3 Implementation

My soution to the problem was to first handle the case where the number is odd by checking the last two digits. In case the number is even, I check for the sum and find the candidate digits, i.e,

digit (MOD 3) = sum of digits of the number (MOD 3)

Finding the leftmost index where the next digit is greater than the current, in case there aren’t any pick the rightmost such that next digit is less than the current, if there aren’t any return -1.

I am unable to find the mistake in my implementation, could someone be kind enough to point out the mistake here?
Thanks.

I don’t know anything in python so I can’t help you with what’s wrong in your code but I’ve found out this test case which when run on your code gives wrong output.

I hope this helps.

Input:

1

660

Your Output:

60

Correct Output:

66

1 Like

Thank you! This helped a lot!

You’re welcome

Just had to change the equality for the leftMost index from greater to strictly greater. Thanks again : )