Company: Autodesk_14oct
Difficulty: medium
Lexicographically Smallest String After Reversal Problem Description Given a string word , you can reverse some of the characters from the beginning or from the end of word to get new strings. Reversing the first k characters of a string w_0 w_1 ... w_{n-1} (i.e. within [0 ... k-1] ) produces w_{k-1} ... w_1 w_0 w_k ... w_{n-1} . Reversing the last k characters of a string w_0 w_1 ... w_{n-1} (i.e. within [n-k ... n-1] ) produces w_0 ... w_{n-k-1} w_{n-1} ... w_{n-k} . Your task is to iterate over all possible new strings that can be formed by this way, and return the alphabetically smallest one. Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(word.length^3) will fit within the execution time limit. Examples Example 1: Input: word = "abdca" Output: "abdca" Explanation: Let's consider all possible reverse operations: Reversing the first 1 character results in the following: "abdca" Reversing the first 2 characters res