Company: Visa_17sep
Difficulty: medium
Smallest String After Reversals Problem Description Given a string word , you can reverse the order of some 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_{k-1}| w_k ... w_{n-1} (i.e., within |...| ) produces |w_{k-1} ... w_0| w_k ... w_{n-1} . Reversing the last k characters of a string w_0 ... w_{n-k-1} |w_{n-k} ... w_{n-1}| (i.e., within |...| ) 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 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²) will fit within the execution time limit. Examples Example 1: Input: word = "dbaca" Output: "abdca" Explanation: Let's consider all possible reverse operations: Reversing the first 1 character results in the following: "dbaca". Reversing the first 2 charac