Lexicographically Smallest End Reversal
Problem statement
For every nonempty prefix length, reverse that prefix and leave the rest unchanged. Also do the same for every nonempty suffix length.
Return the lexicographically smallest string among all produced results.
Function
smallestEndReversal(text: String) → StringExamples
Example 1
text = "cba"return = "abc"Reversing the entire prefix yields abc.
Example 2
text = "abcd"return = "abcd"A length-one reversal leaves the already smallest string unchanged.
Constraints
1 <= text.length <= 2000- text contains lowercase English letters.