TopCoder problem "RemovingDigits" used in SRM 396 (Division II Level Three)



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)
    
"12345"
"513"
Returns: "24"
If we remove the digits '5', '3', '1' we get the number 24.
1)
    
"112352"
"1123"
Returns: "52"
There are two choices. We can either get a "25" or a "52". The largest is "52".
2)
    
"123456654321"
"612534"
Returns: "654321"
Removing the first half of our number gives us the maximum result.
3)
    
"654321123456"
"612534"
Returns: "654321"
Removing the last half of our number gives us the maximum result.
4)
    
"2654982765982365"
"2345978"
Returns: "698265265"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8721

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=12168&pm=8721

Writer:

asal1

Testers:

PabloGilberto , Olexiy , Andrew_Lazarev , ivan_metelsky

Problem categories:

Greedy, Search, String Manipulation