Largest Swap

Published by Pickle in

Create a function that takes a two-digit number and determines if it's the largest of two possible digit swaps.

To illustrate:

LargestSwap(27) ➞ false

LargestSwap(43) ➞ true

If 27 is our input, we should return false because swapping the digits gives us 72, and 72 > 27. On the other hand, swapping 43 gives us 34, and 43 > 34.

Examples

LargestSwap(14) ➞ false

LargestSwap(53) ➞ true

LargestSwap(99) ➞ true

Notes

Numbers with two identical digits (third example) should yield true (you can't do better).

Watch a quick demo on how Edabit works.