SAP | New Grad 2021 | Online Assessment | USA

Find the largest number equal to or less than given number N where all digits must be in increasing order.
e.g,

Input : 573
Output: 569

Input: 1234
Output: 1234

Brute force will be to decrease given number by 1 until digits are not in increasing order. What will be an optimal approach?

Comments (5)