Search⌘ K
AI Features

Solution: Maximum Swap

Explore how to solve the maximum swap problem by applying a greedy algorithm to identify and swap digits to form the largest number. This lesson guides you through scanning digits from right to left, tracking the best swap candidates, and implementing the solution efficiently with linear time 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 ...