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) | (be sure your method is public) |
|
|
|
|
Constraints |
- | minPrice will be between 1 and 1,000,000, inclusive. |
- | maxPrice will be between minPrice and 1,000,000, inclusive. |
|
Examples |
0) | |
| | 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) | |
| | Returns: 999 | 999 has three trailing 9's, and no other number in the given range has this property. |
|
|
2) | |
| | Returns: 2999 | Note that 2999 is still an acceptable price. |
|
|
3) | |
| | Returns: 25 | There are no numbers with trailing 9's between 20 and 25. |
|
|