GCJ Qualification Round 2017 Problem B. Tidy Numbers
Problem Statement : https://code.google.com/codejam/contest/3264486/dashboard#s=p1 Description : Basically you are given a number and one has to find the largest number whose digits are all in increasing order. For example given 132 , largest number less than this where all digits are in increasing order is 129 since 9 > 2 > 1 For input 200 , output should be 199 My Approach : Since the input can be very large, I am keeping the number in string rather than integer.This also save all modulo and division operation. Start scanning from right hand side . Case 1 : If number at the index is 0 , make it as 9 and also decrements number at previous index. Do this until it is non-zero. Case 2 : If number at this index is smaller than its previous , for example 32 , since 2 is smaller than 3 we know the best we can do is,make this index 9. Not only this index but all the indices on right side of this index should be 9 as well. ...