FastPrepLexicographically Smallest After One Substring Rotation
Problems/Lexicographically Smallest After One Substring Rotation

Lexicographically Smallest After One Substring Rotation

Amazon logoAmazonFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given a string s. Choose one non-empty substring of s, which is a run of characters that sit next to each other. Rotate that substring to the right by one position. You must do this exactly once.

Rotating a substring to the right by one position moves its last character to the front of that substring. Every other character in the substring shifts one position to the right.

Return the lexicographically smallest string you can get after the rotation. The lexicographically smallest string is the one that comes first when you compare two strings character by character: at the first position where they differ, the string with the smaller character code comes first, so every uppercase letter comes before every lowercase letter.

Function

smallestStringAfterOneRotation(s: String) → String

Examples

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. No other choice gives a string that comes earlier in dictionary order, so this is the answer.

Example 2

s = "cba"return = "acb"

Choose the whole string "cba". Rotating it right gives "acb". No other choice gives a string that comes earlier in dictionary order, so this is the answer.

Constraints

  • s is non-empty.
  • The operation must be performed exactly once. Choosing a substring of length 1 leaves the string unchanged.

More Amazon Online Assessment questions

  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Nov 2026

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public String smallestStringAfterOneRotation(String s) {
      // write your code here
    }
}
Checking account…