FastPrepMinimum Number of Frogs Croaking
Problems/Minimum Number of Frogs Croaking

Minimum Number of Frogs Croaking

Cerebras logoCerebras● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Cerebras live coding phone screen for a new-grad full-stack engineer role. The report gives only the name of the first coding question, a well-known exercise about counting croaking frogs, with no statement, examples or limits.

We used the standard form of that exercise: return the fewest frogs that can produce the mixed-together croaks, or -1 when the string is not made of complete, in-order croaks. We chose the limits (1 to 10^4 letters, shorter than the usual maximum) and the examples.

Our version is about 80% the same as the reported question.

You are given a string croakOfFrogs that records frogs croaking. One croak is the five letters c, r, o, a, k, said in that order by one frog. Several frogs can croak at the same time, so the letters of different croaks can be mixed together in the string.

Return the minimum number of different frogs needed to produce the whole string. Every letter belongs to exactly one croak. A frog says one croak at a time, and after it says k it can start another croak later in the string.

If the string cannot be split into complete croaks this way, for example because a letter comes before the letter it must follow, or a croak is not finished when the string ends, return -1.

Function

minNumberOfFrogs(croakOfFrogs: String) → int

Examples

Example 1

croakOfFrogs = "ccroakroak"return = 2

The first two letters are both c, so two frogs start croaking at the same time. The first frog says r, o, a, k and finishes; then the second frog says r, o, a, k. Two frogs are needed.

Example 2

croakOfFrogs = "croakcroakcr"return = -1

One frog croaks twice. Then a frog starts a third croak with c and r, but the string ends before o, a and k. An unfinished croak makes the string invalid, so the answer is -1.

Example 3

croakOfFrogs = "croakcrcoakroak"return = 2

The first frog finishes croak, then starts again with c, r. The next c must come from a second frog, because the first one is in the middle of its croak. The first frog then says o, a, k, and the second frog says r, o, a, k. There are three croaks, but never more than two at once, so two frogs are enough.

Constraints

  • 1 <= croakOfFrogs.length <= 10^4
  • croakOfFrogs consists only of the letters 'c', 'r', 'o', 'a' and 'k'.

More Cerebras interview questions

  • Implement Binary Search From ScratchPHONE SCREEN · Seen Sep 2025
  • Dense Vector Dot ProductONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Business Account KYC Verification — Parts 1–5Stripe · PHONE SCREENStripe interview questions
  • Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Read Across Sound TracksAirbnb · PHONE SCREENAirbnb interview questions
  • Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • K-Step Bit Flip with RetentionCisco · PHONE SCREENCisco interview questions
  • Elevator Scheduling SimulationOpenAI · PHONE SCREENOpenAI interview questions
  • File Storage ServiceCresta · PHONE SCREENCresta interview questions
  • String Interpolation with a Missing-Value ModeMongoDB · PHONE SCREENMongoDB interview questions

Interview reports that mention this question

  • Cerebras interviews · November 2026
See Cerebras hiring insights
Saved
class Solution {
    public int minNumberOfFrogs(String croakOfFrogs) {
        // Write your code here.
    }
}
Checking account…