← Back to challenges

Maxie and Minnie

PythonHardnumbersstrings

Instructions

Maxie is the largest number that can be obtained by swapping two digits, Minnie is the smallest. Write a function that takes a number and returns Maxie and Minnie. Leading zeros are not permitted.

Examples

maxmin(12340) ➞ (42310, 10342)

maxmin(98761) ➞ (98761, 18769)

maxmin(9000) ➞ (9000, 9000)
# Sometimes no swap needed.

maxmin(11321) ➞ (31121, 11123)

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.