Mid/SeniorCountingString

Minimum Number of Frogs Croaking

You are given the string croakOfFrogs, which represents a combination of the string "croak" from different frogs. Multiple frogs can croak at the same time, so multiple "croak" strings may be mixed together.

Return the minimum number of different frogs needed to finish all the croaks in the given string.

A valid "croak" means a frog prints the five letters 'c', 'r', 'o', 'a', and 'k' sequentially. Each frog has to print all five letters to finish a croak. If the given string is not a combination of valid "croak" strings, return -1.

Example 1
InputcroakOfFrogs = "croakcroak"
Output1
One frog yells "croak" twice.
Example 2
InputcroakOfFrogs = "crcoakroak"
Output2
The minimum number of frogs is two.

Constraints

  • 1 <= croakOfFrogs.length <= 10^5
  • croakOfFrogs is either 'c', 'r', 'o', 'a', or 'k'.

Asked at 2 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate