You are given a string number representing a positive integer and a character digit.

Return the resulting string after removing exactly one occurrence of digit from number such that the value of the resulting string in decimal form is maximized. The test cases are generated such that digit occurs at least once in number.

&nbsp;
Example 1:

Input: number = "123", digit = "3"
Output: "12"
Explanation: There is only one '3' in "123". After removing '3', the result is "12".


Example 2:

Input: number = "1231", digit = "1"
Output: "231"
Explanation: We can remove the first '1' to get "231" or remove the second '1' to get "123".
Since 231 &gt; 123, we return "231".


Example 3:

Input: number = "551", digit = "5"
Output: "51"
Explanation: We can remove either the first or second '5' from "551".
Both result in the string "51".


&nbsp;
Constraints:


	2 &lt;= number.length &lt;= 100
	number consists of digits from '1' to '9'.
	digit is a digit from '1' to '9'.
	digit occurs at least once in number.


class Solution:
    def removeDigit(self, number: str, digit: str) -> str:
        
        # Initializing the last index as zero
        last_index = 0
        
        #iterating each number to find the occurences, \
        # and to find if the number is greater than the next element \ 

        for num in range(1, len(number)):
            
            # Handling [case 1] and [case 2]
            if number[num-1] == digit:
                if int(number[num]) > int(number[num-1]):
                    return number[:num-1] + number[num:]
                else:
                    last_index = num - 1
        
        # If digit is the last number (last occurence) in the string [case 3]
        if number[-1] == digit:
            last_index = len(number) - 1

        return number[:last_index] + number[last_index + 1:]
class Solution {
    public String removeDigit(String number, char digit) {
        List<String> digits = new ArrayList<>();
        for (int i = 0; i < number.length(); i++) {
            if (number.charAt(i) == digit) {
                String stringWithoutDigit = number.substring(0, i) + number.substring(i + 1);
                digits.add(stringWithoutDigit);
            }
        }
        Collections.sort(digits);
        return digits.get(digits.size() - 1);
    }
}
class Solution {
public:
    string removeDigit(string number, char digit) {
        string res = "";
        for(int i=0; i<number.size(); i++){
            if(number[i] == digit){
                string temp = number.substr(0, i) + number.substr(i+1);
                res = max(res, temp);
            }
        }
        return res;
    }
};
/**
 * @param {string} number
 * @param {character} digit
 * @return {string}
 */
var removeDigit = function(number, digit) {

    let str = [];
    let flag = 0;
    for (let i = 0; i < number.length; i++) {
        if (number[i] == digit ) {
            let temp = number.substring(0, i) + number.substring(i+1);
            str.push(temp);
        }
    }

    str.sort();
    return str[str.length-1];
};
Remove Digit From Number to Maximize Result