less than 1 minute read

Given a string s, return the lexicographically smallest string that can be made if you can make at most one swap between two characters in the string.

Constraints

  • n ≤ 10,000 where n is the length of s.

https://binarysearch.com/problems/Lexicographic-Swap

Examples

Example 1

Input

  • s = cbca

Output

  • answer = abcc

Explanation

We swap the first "c" and "a"

Solution

Leave a comment