FastPrepFastPrep
Problem Brief

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

NEW GRADOA
See Amazon online assessment and 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

    1Example 1

    Input
    s = "abaca"
    Output
    3
    Explanation
    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.
    public int minimumOperationsToRemove(String s) {
      // write your code here 
    }
    
    Input

    s

    "abaca"

    Output

    3

    Sign in to submit your solution.