PROBLEM STATEMENT
Manao lives in a country where the prices of all goods are positive integers. He is setting up a
company that sells microwaves, and needs to decide the best price at which to sell them. Recently,
he heard of a new psychological discovery: the more trailing 9's a price has, the more attractive
it is to the customer. For example, 9099 has two trailing 9's, and 8909 has only one trailing 9,
so the first price is more attractive.
Manao knows that he can only afford to sell microwaves at a price no less than minPrice, and
believes that customers will only buy the microwaves if they cost no more than maxPrice. Help
Manao by finding an integer between minPrice and maxPrice, inclusive, which has the maximum
possible number of trailing 9's. If there are several candidates, return the largest one.
DEFINITION
Class:MicrowaveSelling
Method:mostAttractivePrice
Parameters:int, int
Returns:int
Method signature:int mostAttractivePrice(int minPrice, int maxPrice)
CONSTRAINTS
-minPrice will be between 1 and 1,000,000, inclusive.
-maxPrice will be between minPrice and 1,000,000, inclusive.
EXAMPLES
0)
460
680
Returns: 599
Of all the prices between 460 and 680, 499 and 599 have the maximum number of trailing 9's. Since
599 is larger, it is Manao's price of choice.
1)
10
1000
Returns: 999
999 has three trailing 9's, and no other number in the given range has this property.
2)
1255
2999
Returns: 2999
Note that 2999 is still an acceptable price.
3)
20
25
Returns: 25
There are no numbers with trailing 9's between 20 and 25.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.