Maxie and Minnie

Published by persolut in

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 an array of length 2, Maxie and Minnie. Leading zeros are not permitted.

Examples

maxmin(12340) ➞ new long[] { 42310, 10342 }

maxmin(98761) ➞ new long[] { 98761, 18769 }

maxmin(9000) ➞ new long[] { 9000, 9000 }
# Sometimes no swap needed.

maxmin(11321) ➞ new long[] { 31121, 11123 }

Notes

All inputs are positive, 64-bit integers (type = long).

Watch a quick demo on how Edabit works.