Company: Nxtwave_30nov
Difficulty: medium
Smaller Than Reverse Description Alice is playing with strings. She had a question. Help her to solve it. A string s consisting of lowercase alphabets is given. She wants the string to be lexicographically smaller than the reverse of the string. To do that, she can do the following operation: pick any 2 indices i and j and swap s[i] and s[j] . She needs to know the minimum number of operations to make the string s lexicographically smaller than the reverse of the string. If it is not possible to make s lexicographically smaller than the reverse of s , return -1 . Example 1 Input: n = 5 s = "psnab" Output: 1 Explanation: She can swap indices 0 and 4. Thus s will become "bsnap". The reverse of the new string is "pansb". "bsnap" is lexicographically smaller than "pansb". This requires 1 operation. Example 2 Input: n = 3 s = "aaa" Output: -1 Explanation: It is not possible to make the string lexicographically smaller than its reverse. As all the characters are the same, swapping any charac