Trains the technique from
LeetCode 2231Largest Number After Digit Swaps by ParityThis 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. Any two of its digits may be swapped, as often as you like, provided the two are both odd or both even.
Return the largest number the counter can be made to show.
Example 1
Every digit is odd, so they can all be swapped with each other and falling order is largest.
Example 2
Every digit is even, so again they arrange into falling order.
Example 3
The two odd digits are both 1 and the two even digits are both 2, so no swap changes anything.
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 largest_integer(num: int) -> int:public int largestInteger(int num)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.