Problem Statement |
| You are given two Strings, number and digits. Each String contains only digits between 1 and 9, inclusive. For each occurrence of a digit in digits, you must remove a single occurrence of that digit from number. Your goal is to end up with the largest possible remaining number after all the necessary digits are removed. Return this number as a String. |
|
Definition |
| Class: | RemovingDigits | Method: | maxNumber | Parameters: | String, String | Returns: | String | Method signature: | String maxNumber(String number, String digits) | (be sure your method is public) |
|
|
|
|
Constraints |
- | number will contain between 1 and 50 characters, inclusive. |
- | digits will contain between 0 and n-1 characters, inclusive, where n is the number of characters in number. |
- | Each character in number and digits will be a non-zero digit ('1'-'9'). |
- | The number of occurrences of each digit in number will be greater than or equal to the number of occurrences of that digit in digits. |
|
Examples |
0) | |
| | Returns: "24" | If we remove the digits '5', '3', '1' we get the number 24. |
|
|
1) | |
| | Returns: "52" | There are two choices. We can either get a "25" or a "52". The largest is "52". |
|
|
2) | |
| | Returns: "654321" | Removing the first half of our number gives us the maximum result. |
|
|
3) | |
| | Returns: "654321" | Removing the last half of our number gives us the maximum result. |
|
|
4) | |
| "2654982765982365" | "2345978" |
| Returns: "698265265" | |
|