Lexicographically Smallest After One Substring Rotation
MediumAsked in:Amazon•Stage:Online Assessment
Problem Statement
Given a string s, you may select any non‑empty substring and rotate it left by one position (the first character of the substring moves to its end). Perform at most one such operation to obtain the lexicographically smallest possible string and return it.
Input Format
A single line containing the string s, where 1 ≤ |s| ≤ 10^5.
Output Format
Print the lexicographically smallest string achievable after applying at most one substring rotation.
Constraints
- 1 <= n <= 10^5
- String s consists of lowercase English letters
- Only one substring rotation may be performed