Splitting a Word
InterviewTime limit2sMemory limit128 MB
Split a lowercase word into three nonempty parts, reverse each part, and find the lexicographically smallest concatenation among all splits.
- Level
Easy2 of 10
- Topics
- String, Brute force, Implementation
- Solved
- No attempts yet
Problem
You are given a word consisting only of lowercase English letters. Split the word into three contiguous parts. Each part must have length at least 1.
Reverse each part separately, then concatenate the reversed parts in the same order as the split. Among all strings that can be made this way, find the lexicographically smallest one.
Input
The first line contains a word consisting of lowercase English letters. Its length is between 3 and 50, inclusive.
Output
Output the lexicographically smallest string that can be made.