Maximum Difference by Remapping a Digit
You are given an integer num. You know that Bob will sneakily remap one of the 10 possible digits (0 to 9) to another digit.
Return the difference between the maximum and minimum values Bob can make by remapping exactly one digit in num.
Notes:
- When Bob remaps a digit
d1to another digitd2, Bob replaces all occurrences ofd1innumwithd2. - Bob can remap a digit to itself, in which case
numdoes not change. - Bob can remap different digits for obtaining minimum and maximum values respectively.
- The resulting number after remapping can contain leading zeroes.
Example 1
Input
num = 11891Output
99009Remapping digit 1 to 9 gives the maximum value 99899, while remapping digit 1 to 0 gives the minimum value 890, so the difference is 99009.
Example 2
Input
num = 90Output
99The maximum value is 99 by replacing 0 with 9, and the minimum value is 0 by replacing 9 with 0, so the difference is 99.
Constraints
- 1 <= num <= 10^8