Trains the technique from
LeetCode 1323Maximum 69 NumberThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A counter shows the number num, and every one of its digits is a 6 or a 9. At most one digit may be swapped, turning a 6 into a 9 or a 9 into a 6. Leaving the counter untouched is allowed.
Return the largest number the counter can be made to show.
Example 1
Lifting the leading digit gives 96, which beats lifting the second one.
Example 2
The leading digit is already a nine, so the earliest six is the second digit, and lifting it gives 9996.
Example 3
Every digit is already a nine, so the counter is best left untouched.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def maximum69_number(num: int) -> int:public int maximum69Number(int num)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.