Medium · Math

Maximum Swap

Given an integer num in [0, 10⁸], return the largest number you can get by swapping two of its digits at most once.

Examples

Example 1

{
  "num": 2736
}

Output: 7236

Example 2

{
  "num": 9973
}

Output: 9973

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Math problems