Problem
Lexicographically Smallest After One Substring Rotation
Learn this problemProblem statement
You are given a string s. You must choose one non-empty contiguous substring of s and rotate that substring to the right by one position exactly once.
Rotating a substring to the right by one position moves its last character to the front of that substring, while every other character in the substring shifts one position to the right.
Return the lexicographically smallest string that can be obtained after performing the operation.
Function
smallestStringAfterOneRotation(s: String) → StringExamples
Example 1
s = "baca"return = "abac"Choose the whole string baca. Rotating it right by one position moves the last character to the front, giving abac, which is the lexicographically smallest result obtainable.
Example 2
s = "cba"return = "acb"Choose the whole string "cba". Rotating it right gives "acb", which is the smallest possible result.
Constraints
sis non-empty.- The operation must be performed exactly once. Choosing a substring of length
1leaves the string unchanged.
More Amazon problems
- HTTP Request RedirectionOA · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Permutation SorterOA · Seen Jul 2026
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026