# Max Difference You Can Get From Changing An Integer: Practice Notes

Max Difference You Can Get From Changing An Integer shows up often in coding rounds. Here is how I talk through it when the interviewer is watching.

## Key idea

You may remap one digit x to another digit y (leading zeros are not allowed in the final number unless the number is 0). To maximize, replace the leftmost digit that is not 9 with 9 (map that digit everywhere). To minimize you'd map the first non-zero to 1 (or the first non-zero-or-one after a leading 1), but here we only need the maximum, so one greedy pass is enough. The answer is maxNum - num after that single remapping? No: the problem asks for the maximum value obtainable after at most one such remapping, which is just the remapped number itself.

## Steps to say out loud

1. Restate the input and the exact ask, and nail down constraints and overflow.
2. Name the pattern (binary search on the answer, monotonic stack or deque, interval / interval-DP, string hashing, graph traversal, or shortest paths) and why a nested scan or naive search fails.
3. Code it, then trace a short example plus one empty or already-solved edge case.

## Complexity

O(d) for d digits.

## Common mistake

Remapping a later digit instead of the leftmost non-9, or allowing a leading zero when minimizing (not needed here) and accidentally applying that rule to the maximum.

## Practice tip

Time yourself: two minutes to explain, ten to code, three to test edges. Disclosure: I work on Linkjob AI. I also keep a practice cheat sheet at real-time interview help.