Maximum Swap - Problem
You are given an integer num. You can swap two digits at most once to get the maximum valued number.
Return the maximum valued number you can get.
Input & Output
Example 1 — Basic Swap
$
Input:
num = 2736
›
Output:
7236
💡 Note:
Swap the first digit 2 with the second digit 7 to get 7236, which is the maximum possible value with a single swap.
Example 2 — No Improvement Possible
$
Input:
num = 9973
›
Output:
9973
💡 Note:
The digits are already in optimal order from left to right, no single swap can improve the value.
Example 3 — Single Digit
$
Input:
num = 1
›
Output:
1
💡 Note:
Single digit number cannot be improved by swapping.
Constraints
- 0 ≤ num ≤ 108
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code