FastPrepFastPrep
Problem Brief

Find Minimum Operations

OA

A scheduler manages multiple processes with priorities represented by the letters a, b, and c. Its goal is to optimize the schedule to achieve a specific sequence.

The operations available to the scheduler are as follows:

  • Choose a process with priority a, b, or c.
  • Insert the chosen process into the scheduling queue at any position.
  • Determine the minimum number of scheduling operations required to ensure that the scheduling queue follows the repeating pattern "abc".

    Function Description

    Complete the function findMinOperations in the editor below.

    findMinOperations takes the following parameters:

    • string s: the scheduling queue

    Returns

    int: the minimum number of operations required to make the queue a concatenation of 'abc' several times

    Constraints

    • 1 ≤ |s| ≤ 10^5
    • s consists only of characters 'a', 'b', and 'c'.

    1Example 1

    Input
    s = "abb"
    Output
    3
    Explanation

    Transform the queue to abcabc by inserting two letters c and one letter a. The string "abcabc" is the concatenation of "abc" two times.

    The minimum number of scheduling operations required is 3.

    2Example 2

    Input
    s = "aa"
    Output
    4
    Explanation

    Insert 'b' and 'c' after the first and second 'a' to transform the string to abcabc.

    3Example 3

    Input
    s = "ac"
    Output
    1
    Explanation

    Insert 'b' between 'a' and 'c' to transform the string to abc.

    public int findMinOperations(String s) {
      // write your code here
    }
    
    Input

    s

    "abb"

    Output

    3

    Sign in to submit your solution.