java.lang.Object
g1401_1500.s1419_minimum_number_of_frogs_croaking.Solution

public class Solution extends Object
1419 - Minimum Number of Frogs Croaking.<p>Medium</p> <p>You are given the string <code>croakOfFrogs</code>, which represents a combination of the string <code>&quot;croak&quot;</code> from different frogs, that is, multiple frogs can croak at the same time, so multiple <code>&quot;croak&quot;</code> are mixed.</p> <p><em>Return the minimum number of</em> different <em>frogs to finish all the croaks in the given string.</em></p> <p>A valid <code>&quot;croak&quot;</code> means a frog is printing five letters <code>'c'</code>, <code>'r'</code>, <code>'o'</code>, <code>'a'</code>, and <code>'k'</code> <strong>sequentially</strong>. The frogs have to print all five letters to finish a croak. If the given string is not a combination of a valid <code>&quot;croak&quot;</code> return <code>-1</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> croakOfFrogs = &ldquo;croakcroak&rdquo;</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> One frog yelling &ldquo;croak**&rdquo;** twice.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> croakOfFrogs = &ldquo;crcoakroak&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The minimum number of frogs is two. The first frog could yell &ldquo;<strong>cr</strong>c<strong>oak</strong>roak&rdquo;. The second frog could yell later &ldquo;cr<strong>c</strong>oak<strong>roak</strong>&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> croakOfFrogs = &ldquo;croakcrook&rdquo;</p> <p><strong>Output:</strong> -1</p> <p><strong>Explanation:</strong> The given string is an invalid combination of &ldquo;croak**&rdquo;** from different frogs.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= croakOfFrogs.length <= 10<sup>5</sup></code></li> <li><code>croakOfFrogs</code> is either <code>'c'</code>, <code>'r'</code>, <code>'o'</code>, <code>'a'</code>, or <code>'k'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minNumberOfFrogs

      public int minNumberOfFrogs(String s)
    • reduce

      public void reduce(int[] f)