Numbers can be classified into three groups: increasing, decreasing and bouncy. Increasing numbers are like 12345, where none of the digits to the right are less than the ones to the left. Decreasing numbers are the reverse, example 54321. Bouncy numbers are those which are not increasing and decreasing, example 54231.
For any given digit n, there are x numbers less than n, which are bouncy, and n-x numbers which are either increasing or decreasing. Let’s call this ratio (x/n-x) as bouncy ratio. For numbers less than 100, this ratio is 0. It keeps increasing as we increase n.
The problem is to write an efficient program which takes the ratio as input (say, z), and finds the smallest number n such that the ratio of (x/n-x) is z. Again, please avoid brute force.