Minimum Number of Frogs Croaking - Problem
You are given the string croakOfFrogs, which represents a combination of the string "croak" from different frogs, that is, multiple frogs can croak at the same time, so multiple "croak" are mixed.
Return the minimum number of different frogs to finish all the croaks in the given string.
A valid "croak" means a frog is printing five letters 'c', 'r', 'o', 'a', and 'k' sequentially. The frogs have to print all five letters to finish a croak. If the given string is not a combination of a valid "croak" return -1.
Input & Output
Example 1 — Basic Overlapping
$
Input:
croakOfFrogs = "croakcroak"
›
Output:
1
💡 Note:
One frog can say the entire sequence: first "croak" then second "croak". Only 1 frog needed.
Example 2 — Simultaneous Frogs
$
Input:
croakOfFrogs = "crcoakroak"
›
Output:
2
💡 Note:
Need 2 frogs: Frog1 says "c-r-o-a-k" and Frog2 says "c-r-o-a-k" with interleaved timing.
Example 3 — Invalid Sequence
$
Input:
croakOfFrogs = "croakcrook"
›
Output:
-1
💡 Note:
Contains invalid character 'o' after 'o' - not following proper croak sequence.
Constraints
- 1 ≤ croakOfFrogs.length ≤ 105
- croakOfFrogs[i] is either 'c', 'r', 'o', 'a', or 'k'
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code