Naive Approach: The simplest approach is to remove the smallest character with a smaller index in the string in each step and keep on adding the cost to the total cost. Print the final cost after this operation.
Time Complexity:_ O(N2)_
Auxiliary Space:_ O(1)_
#arrays #hash #mathematical #searching #strings #frequency-counting #java-hashmap