๐ธ Picture a peaceful pond where multiple frogs are croaking simultaneously! You're given a string croakOfFrogs that represents the overlapping sounds of different frogs, where each frog must say "croak" in the exact sequence: 'c' โ 'r' โ 'o' โ 'a' โ 'k'.
Your task is to determine the minimum number of frogs needed to produce all the croaking sounds in the given string. Each frog can only say one letter at a time and must complete the full sequence "croak" before starting again.
Important: If the input string cannot be formed by valid frog croaking (e.g., letters out of order, incomplete sequences), return -1.
Example: In the string "crcoroakoak", we need at least 2 frogs because they overlap in their croaking patterns.
Input & Output
Constraints
- 1 โค croakOfFrogs.length โค 105
- croakOfFrogs is either 'c', 'r', 'o', 'a', or 'k'
- Each frog must complete the exact sequence 'c' โ 'r' โ 'o' โ 'a' โ 'k'