<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>&#39;c&#39;</code>, <code>&#39;r&#39;</code>, <code>&#39;o&#39;</code>, <code>&#39;a&#39;</code>, and <code>&#39;k&#39;</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>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> croakOfFrogs = &quot;croakcroak&quot;
<strong>Output:</strong> 1 
<strong>Explanation:</strong> One frog yelling &quot;croak<strong>&quot;</strong> twice.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> croakOfFrogs = &quot;crcoakroak&quot;
<strong>Output:</strong> 2 
<strong>Explanation:</strong> The minimum number of frogs is two. 
The first frog could yell &quot;<strong>cr</strong>c<strong>oak</strong>roak&quot;.
The second frog could yell later &quot;cr<strong>c</strong>oak<strong>roak</strong>&quot;.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> croakOfFrogs = &quot;croakcrook&quot;
<strong>Output:</strong> -1
<strong>Explanation:</strong> The given string is an invalid combination of &quot;croak<strong>&quot;</strong> from different frogs.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= croakOfFrogs.length &lt;= 10<sup>5</sup></code></li>
	<li><code>croakOfFrogs</code> is either <code>&#39;c&#39;</code>, <code>&#39;r&#39;</code>, <code>&#39;o&#39;</code>, <code>&#39;a&#39;</code>, or <code>&#39;k&#39;</code>.</li>
</ul>

from collections import deque

class Solution:
    # def minNumberOfFrogs(self, croakOfFrogs: str) -> int:
    #     if croakOfFrogs[0] !='c':
    #         return -1
        
    #     que_list = deque()
    #     count = 0 
    #     check_name = ['c', 'r', 'o', 'a', 'k']
    #     i = 0 
    #     while i < len(croakOfFrogs): 
    #         if croakOfFrogs[i] == 'c':
    #             if i == 0:
    #                 count +=1
    #             elif i != 0 and que_list:
    #                 count += 1 
    #             for index, char in enumerate(check_name): 
    #                 if croakOfFrogs[i] == char:
    #                     i += 1
    #                 else: 
    #                     que_list.append(check_name[index:])
    #             print(i, count, que_list)
    #         else: 
    #             for i in len(que_list):
    #                 index = 0
    #                 while que_list[i][index] == croakOfFrogs[i]:
    #                     del que_list[i][index]
    #                     index +=1

    #         if not que_list:
    #             return count
    #         else: 
    #             return -1


    def minNumberOfFrogs(self, croakOfFrogs: str) -> int:
        freq = [0]*5 
        curr_frog, max_frog = 0, 0 

        for c in croakOfFrogs: 
            i = "croak".index(c)
            freq[i] += 1 

            if i == 0:
                curr_frog += 1
            # Check if croak is in sequence. 
            elif i and freq[i-1] < freq[i]:
                return -1 
            elif i == 4:
                curr_frog -= 1 
            
            max_frog = max(max_frog, curr_frog)
        
        return max_frog if curr_frog == 0 else -1      
        #         que_list.append(check_name)
        #         que_list.popleft()
        #         elif string !='': 
        #             count += 1 
        #         string += check_name
                
        #     elif croakOfFrogs[i] == string[0]: 
        #         string = string[1:] 
        #     i += 1 
        # if string =='':
        #     return count
        # else: 
        #     return -1

        
174