Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Frogs Croaking

med
30 min
Try to solve the Minimum Number of Frogs Croaking problem.

Statement

You are given a string croakOfFrogs representing a combination of sounds made by different frogs simultaneously croaking the word "croak". Multiple frogs can croak at the same time, resulting in their letters being interleaved.

A valid croak consists of the characters 'c', 'r', 'o', 'a', and 'k' produced in that exact sequential order. A single frog may croak multiple times, but it must complete all five characters of one croak before starting another.

Return the minimum number of distinct frogs required to produce the given string croakOfFrogs. If the string is not a valid sequence of croaks, return −1-1.

Constraints:

  • 1≤1 \leq croakOfFrogs.length ≤105\leq 10^5

  • croakOfFrogs consists only of the characters 'c', 'r', 'o', 'a', and 'k'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Frogs Croaking

med
30 min
Try to solve the Minimum Number of Frogs Croaking problem.

Statement

You are given a string croakOfFrogs representing a combination of sounds made by different frogs simultaneously croaking the word "croak". Multiple frogs can croak at the same time, resulting in their letters being interleaved.

A valid croak consists of the characters 'c', 'r', 'o', 'a', and 'k' produced in that exact sequential order. A single frog may croak multiple times, but it must complete all five characters of one croak before starting another.

Return the minimum number of distinct frogs required to produce the given string croakOfFrogs. If the string is not a valid sequence of croaks, return −1-1.

Constraints:

  • 1≤1 \leq croakOfFrogs.length ≤105\leq 10^5

  • croakOfFrogs consists only of the characters 'c', 'r', 'o', 'a', and 'k'.