Tap here to switch tabs
Problem
Submissions

Problem: Maximum Difference by Remapping a Digit

med
30 min
Try to solve the Maximum Difference by Remapping a Digit problem.

Statement

You are given an integer num.

You can apply the following operation to num:

  • Choose a digit dd (0≤d≤90 \leq d \leq 9) appearing in num.

  • Choose a new digit rr (0≤r≤90 \leq r \leq 9).

  • Replace every occurrence of dd in num with rr.

Return the difference between the maximum value and the minimum value you can obtain by applying this operation independently for each case.

Note:

  • The resulting number is allowed to have leading zeros.

  • The chosen digit dd must be mapped to the same digit rr across all of its occurrences in num.

Constraints:

  • 1≤1 \leq num ≤108\leq 10^8

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Difference by Remapping a Digit

med
30 min
Try to solve the Maximum Difference by Remapping a Digit problem.

Statement

You are given an integer num.

You can apply the following operation to num:

  • Choose a digit dd (0≤d≤90 \leq d \leq 9) appearing in num.

  • Choose a new digit rr (0≤r≤90 \leq r \leq 9).

  • Replace every occurrence of dd in num with rr.

Return the difference between the maximum value and the minimum value you can obtain by applying this operation independently for each case.

Note:

  • The resulting number is allowed to have leading zeros.

  • The chosen digit dd must be mapped to the same digit rr across all of its occurrences in num.

Constraints:

  • 1≤1 \leq num ≤108\leq 10^8