Practice/Google/Leetcode 2259. Remove Digit From Number to Maximize Result
CodingMust
You are given a string representing a positive integer and a specific digit character. Your task is to remove exactly one occurrence of this digit from the number string to create the largest possible resulting number. The digit is guaranteed to appear at least once in the number.
The key challenge is determining which occurrence of the target digit to remove when multiple instances exist. You must preserve the original order of all remaining digits.
number consists of digits from '1' to '9'digit is a digit from '1' to '9'digit occurs at least once in numberExample 1:
Input: number = "123", digit = "3" Output: "12" Explanation: The digit '3' appears only once. Removing it leaves "12".
Example 2:
` Input: number = "1231", digit = "1" Output: "231" Explanation: The digit '1' appears twice (positions 0 and 3).
Example 3:
` Input: number = "551", digit = "5" Output: "51" Explanation: Both '5' digits can be removed: