Search⌘ K
AI Features

Solution: Maximum Swap

Explore how to apply a greedy algorithm to maximize an integer by swapping two digits once. Understand the step-by-step approach of scanning digits from right to left, identifying optimal swap positions, and implementing the solution with linear time and space complexity.

Statement

Given an integer num, return the maximum number that can be formed by swapping at most two digits once.

Constraints:

  • 00 \leq num 105\leq 10^5 ...