09. Largest Number in One Swap
β GFG solution to the Largest Number in One Swap problem: find the lexicographically largest string by swapping at most one pair of characters using greedy last-occurrence tracking. π
π§© Problem Description
π Examples
Example 1
Input: s = "768"
Output: "867"
Explanation: Swapping the 1st and 3rd characters (7 and 8) gives the lexicographically largest string "867".Example 2
Input: s = "333"
Output: "333"
Explanation: All characters are identical; any swap yields the same result.π Constraints
β
My Approach
Greedy + Last Occurrence Array
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated