Problem · String
Lexicographically Minimum Stack Encryption
Learn this problemProblem statement
You are given a string originalString. Start with two empty strings: temporaryString and encryptedString.
Repeat either of the following operations until both originalString and temporaryString are empty:
- Remove the first character of
originalStringand append it totemporaryString. - Remove the last character of
temporaryStringand append it toencryptedString.
Choose the operation order that produces the lexicographically smallest possible encryptedString, and return that string.
Function
minimumEncryptedString(originalString: String) → StringExamples
Example 1
originalString = "dby"return = "bdy"Move d and then b into the temporary stack. Pop b first, then arrange the remaining legal moves to produce bdy.
Example 2
originalString = "vgxgpu"return = "ggpuxv"The minimum legal encrypted string is ggpuxv.
Constraints
1 <= originalString.length() <= 200000originalStringcontains lowercase English letters.
More Rippling problems
- Delivery Cost TrackerPHONE SCREEN · Seen Jul 2026
- Corporate Card Expense RulesPHONE SCREEN · Seen Jun 2026
- Camel CardsPHONE SCREEN · Seen May 2026
- Article Vote TrackerPHONE SCREEN · Seen May 2026
- Employee Resource Access ManagementONSITE INTERVIEW · Seen Jan 2026
- Limit an Organization Tree's HeightONSITE INTERVIEW · Seen Aug 2025
- Distributed System RecoveryOA · Seen Jul 2025
- Server Upgrade PlanningOA · Seen Jul 2025