Problem · String

Minimum Operations to Remove Characters in Frequency Order (Find Min Deletions :)

HardAmazonNEW GRADOA
See Amazon hiring insights

(Look into LC 664. Strange Printer may help :)

Given a string, determine the minimum number of operations (deletions) required to make the string empty.

You can perform the deletion operation as many times as you prefer::

  • Pick any group of consecutive chars in the string, with a group size s ranging from 1 up to the curr len of the string. Delete them only when all the chars in this group are the same.
  • Function Description

    Complete the function minimumOperationsToRemove in the editor.

    minimumOperationsToRemove has the following parameter:

    1. String s: the string to be processed

    Returns

    int: the minimum number of operations required

    Examples
    01 · Example 1
    s = "abaca"
    return = 3
    Pick s = 1: remove "b" -> "aaca" Pick s = 1: remove "c" -> "aaa" Pick s = 3: since all the a's are together remove all a's at once. Now it is empty. We can make the input string empty in just 3 operations. So, we return 3 as the answer.
    More Amazon problems
    drafts saved locally
    public int minimumOperationsToRemove(String s) {
      // write your code here 
    }
    
    s"abaca"
    expected3
    sign in to submit