Given a string str, consisting of lowercase English alphabets, the task is to calculate the sum of indices(1-based indexing) of the characters removed to obtain an empty string by the following operations:

  • Remove the smallest alphabet in the string.
  • For multiple occurrences of the smallest alphabet, remove the one present at the smallest index.
  • After removal of each character, the indices of all characters on its right reduces by 1.

#arrays #hash #mathematical #recursion #searching #strings #frequency-counting #java-hashmap #segment-tree

Sum of indices of Characters removed to obtain an Empty String based
1.35 GEEK