c, r, o, a, k in exactly that order. Frogs call at the same time, so their letters are interleaved in one string recording, yet each frog's own letters keep their order. Once a frog finishes a call, it may start another one.
Return the smallest number of frogs that could have produced this recording. If the recording cannot be split entirely into complete croak calls, return -1.recording="ccrorakoak" → 2
The second frog starts its croak before the first one has finished, so two of them sound at once: c·ro·ak··· and ·c··r··oak.
recording="croakcroak" → 1
The same frog can croak twice in a row.
recording="croakc" → -1
The last croak stops after its first letter, so the recording is impossible and the answer is -1.
recording contains only the letters c, r, o, a, krecording="ccrorakoak"
2
Run checks the first 3 tests in your browser. Submit checks all 199 tests on the server, hidden ones included.