Given an input string, the algorithm finds the most beautiful string that can be obtained from the input