Tap here to switch tabs
Problem
Submissions

Problem: Max Difference You Can Get From Changing an Integer

Max Difference You Can Get From Changing an Integer asks you to make two digit changes, replacing all matches each time, and return the greatest difference between resulting numbers without leading zeros.

Statement

You are given an integer num. You will apply the following operation exactly two times:

  1. Select a digit x (0≤x≤90 \leq x \leq 9) and a digit y (0≤y≤90 \leq y \leq 9). The digit y can be equal to x.

  2. Replace every occurrence of x in the decimal representation of num with y.

  3. The resulting integer cannot have leading zeros and cannot be equal to 00.

Let a and b be the integers obtained from the first and second operations, respectively.

Return the maximum possible value of a −- b.

Constraints:

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Max Difference You Can Get From Changing an Integer

Max Difference You Can Get From Changing an Integer asks you to make two digit changes, replacing all matches each time, and return the greatest difference between resulting numbers without leading zeros.

Statement

You are given an integer num. You will apply the following operation exactly two times:

  1. Select a digit x (0≤x≤90 \leq x \leq 9) and a digit y (0≤y≤90 \leq y \leq 9). The digit y can be equal to x.

  2. Replace every occurrence of x in the decimal representation of num with y.

  3. The resulting integer cannot have leading zeros and cannot be equal to 00.

Let a and b be the integers obtained from the first and second operations, respectively.

Return the maximum possible value of a −- b.

Constraints:

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