|
| 1 | +<h2><a href="https://leetcode.com/problems/maximum-difference-by-remapping-a-digit/?envType=daily-question&envId=2025-06-14">2566. Maximum Difference by Remapping a Digit</a></h2><h3>Easy</h3><hr><p>You are given an integer <code>num</code>. You know that Bob will sneakily <strong>remap</strong> one of the <code>10</code> possible digits (<code>0</code> to <code>9</code>) to another digit.</p> |
| 2 | + |
| 3 | +<p>Return <em>the difference between the maximum and minimum values Bob can make by remapping <strong>exactly</strong> <strong>one</strong> digit in </em><code>num</code>.</p> |
| 4 | + |
| 5 | +<p><strong>Notes:</strong></p> |
| 6 | + |
| 7 | +<ul> |
| 8 | + <li>When Bob remaps a digit <font face="monospace">d1</font> to another digit <font face="monospace">d2</font>, Bob replaces all occurrences of <code>d1</code> in <code>num</code> with <code>d2</code>.</li> |
| 9 | + <li>Bob can remap a digit to itself, in which case <code>num</code> does not change.</li> |
| 10 | + <li>Bob can remap different digits for obtaining minimum and maximum values respectively.</li> |
| 11 | + <li>The resulting number after remapping can contain leading zeroes.</li> |
| 12 | +</ul> |
| 13 | + |
| 14 | +<p> </p> |
| 15 | +<p><strong>Example 1:</strong></p> |
| 16 | + |
| 17 | +<pre> |
| 18 | +<strong>Input:</strong> num = 11891 |
| 19 | +<strong>Output:</strong> 99009 |
| 20 | +<strong>Explanation:</strong> |
| 21 | +To achieve the maximum value, Bob can remap the digit 1 to the digit 9 to yield 99899. |
| 22 | +To achieve the minimum value, Bob can remap the digit 1 to the digit 0, yielding 890. |
| 23 | +The difference between these two numbers is 99009. |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p><strong>Example 2:</strong></p> |
| 27 | + |
| 28 | +<pre> |
| 29 | +<strong>Input:</strong> num = 90 |
| 30 | +<strong>Output:</strong> 99 |
| 31 | +<strong>Explanation:</strong> |
| 32 | +The maximum value that can be returned by the function is 99 (if 0 is replaced by 9) and the minimum value that can be returned by the function is 0 (if 9 is replaced by 0). |
| 33 | +Thus, we return 99.</pre> |
| 34 | + |
| 35 | +<p> </p> |
| 36 | +<p><strong>Constraints:</strong></p> |
| 37 | + |
| 38 | +<ul> |
| 39 | + <li><code>1 <= num <= 10<sup>8</sup></code></li> |
| 40 | +</ul> |
0 commit comments