Given an integer num, return the maximum number that can be formed by swapping at most two digits once.
num
Constraints:
0≤0 \leq0≤ num ≤105\leq 10^5≤105
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the problem correctly:
Maximum Swap
Given the following input, what is the maximum number you can obtain by swapping two digits at most once?
num = 123451234512345
54321
52341
54123
We have a game for you to play. Rearrange the logical building blocks to better understand how to solve this problem.
Implement your solution in the following coding playground.