| ||When returning from vacation, you have to delete some unwanted email messages in your inbox, like spam or other unimportant messages. Your inbox consists of several pages that each contain the same number of messages (except possibly the last page). Each message has two corresponding buttons that allow you to: |
- add the message to the current selection
- remove the message from the current selection
In addition, each page has three buttons with the following functions:
- select all messages on the current page
- delete all selected messages on the current page
- advance to the next page of messages (unless you're already on the last page)
Selections do not extend across pages, and advancing to the next page deselects everything that is currently selected. Also, deleting messages will not cause later messages in the inbox to scroll up to the current page.
For example if you have four email messages on one page and you would like to delete the second one, you could select it and then click on delete for a total of two clicks. An alternative is to select all messages, then deselect all other messages except the second, and then click delete, for a total of five clicks.
Naturally, you would like to clean up your inbox with as few clicks as possible. Furthermore, you are allowed to choose the number of emails to display per page. If you decide to display K messages per page, the first K messages will be on the first page, the next K messages will be on the second one, and so on. Obviously, the last page might contain less than K messages. Note that you need to check all pages of messages, even if they do not contain any messages that must be deleted.
You will be given a String messages containing a description of email messages in the order they appear in your inbox. The 'D' character denotes a message that should be deleted, while a '.' character denotes an email that should be kept. You will also be given two ints, low and high, denoting the inclusive lower and upper bounds of the number of messages on each page. You should choose how many emails to display per page such that the number of clicks needed is minimal, and then return the number of clicks.
|Parameters:||String, int, int|
|Method signature:||int fewestClicks(String messages, int low, int high)|
|(be sure your method is public)|
|-||messages will contain between 1 and 50 characters, inclusive.|
|-||Each character of messages will be either 'D' or '.'.|
|-||low will be between 1 and the number of characters in messages, inclusive.|
|-||high will be between low and the number of characters in messages, inclusive.|
|No messages to delete here. Since we can display all messages in one page, there is no need to click any button.|
|Your only choice here is to display 5 messages per page. Select the two messages from the first page and then click delete for a total of three clicks. One more click is needed for advancing to the next page. For the second page, you have two options: first select all messages and then deselect the third and fifth ones, or select each of the three 'D' messages individually. Both options require three clicks. After the selection is made, click delete.|
|Display 6 messages per page.|
|Remember that you need to check all pages.|
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.