Ctrl K

Digit Repaint Spread

Medium
You are given a positive integer number. A repaint picks a digit x and a digit y (possibly equal to x) and replaces **every** occurrence of x in the decimal form of the number with y. The result must not start with a zero and must not be zero. Two repaints are applied to the original number independently of each other: the first produces a, the second produces b. Return the largest possible value of a - b.
Example 1
number=2702 → 8008

Largest: turn every 2 into 9 to get 9709. Smallest: turn every 2 into 1 to get 1701. The spread is 9709 − 1701 = 8008.

Example 2
number=1090 → 8090

Largest: 1 → 9 gives 9090. The leading 1 cannot go lower (no leading zero allowed), so turn 9 into 0 to get 1000. The spread is 8090.

Example 3
number=7 → 8
Constraints
  • 1 ≤ number ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSmallest Number From Digit Factors MediumOne Digit Swap MediumLargest Number With Non-Decreasing Digits MediumFewest Guests by Lanyard Color MediumUp or Down for Every Post Medium
loading Python…
Input
number=2702
Expected
8008

Run checks the first 3 tests in your browser. Submit checks all 75 tests on the server, hidden ones included.