#1419
Minimum Number of Frogs Croaking
specialist · 860 · lc medium +31 · failed · 51.1% accepted · 1,123 likes · top 40%
Description
The string croakOfFrogs is formed by interleaving multiple instances of the word "croak", one per frog, with frogs potentially croaking simultaneously. Each frog must emit the full sequence 'c' -> 'r' -> 'o' -> 'a' -> 'k'. Return the minimum number of frogs required to produce the given string, or -1 if the string is not a valid interleaving of complete croaks.
Example 1:
Input: croakOfFrogs = "croakcroak"
Output: 1
Explanation: One frog yelling "croak" twice.
Example 2:
Input: croakOfFrogs = "crcoakroak"
Output: 2
Explanation: The minimum number of frogs is two.
The first frog could yell "crcoakroak".
The second frog could yell later "crcoakroak".
Example 3:
Input: croakOfFrogs = "croakcrook"
Output: -1
Explanation: The given string is an invalid combination of "croak" from different frogs.
Code
1
2
3