<p>You are given a <strong>0-indexed</strong> integer array <code>tasks</code>, where <code>tasks[i]</code> represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the <strong>same difficulty level</strong>.</p>

<p>Return <em>the <strong>minimum</strong> rounds required to complete all the tasks, or </em><code>-1</code><em> if it is not possible to complete all the tasks.</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> tasks = [2,2,3,3,2,4,4,4,4,4]
<strong>Output:</strong> 4
<strong>Explanation:</strong> To complete all the tasks, a possible plan is:
- In the first round, you complete 3 tasks of difficulty level 2. 
- In the second round, you complete 2 tasks of difficulty level 3. 
- In the third round, you complete 3 tasks of difficulty level 4. 
- In the fourth round, you complete 2 tasks of difficulty level 4.  
It can be shown that all the tasks cannot be completed in fewer than 4 rounds, so the answer is 4.
</pre>

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

<pre>
<strong>Input:</strong> tasks = [2,3,3]
<strong>Output:</strong> -1
<strong>Explanation:</strong> There is only 1 task of difficulty level 2, but in each round, you can only complete either 2 or 3 tasks of the same difficulty level. Hence, you cannot complete all the tasks, and the answer is -1.
</pre>

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

<ul>
	<li><code>1 &lt;= tasks.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= tasks[i] &lt;= 10<sup>9</sup></code></li>
</ul>

<p>&nbsp;</p>
<p><strong>Note:</strong> This question is the same as <a href="https://leetcode.com/problems/minimum-number-of-operations-to-make-array-empty/description/" target="_blank">2870: Minimum Number of Operations to Make Array Empty.</a></p>

class Solution:
    def minimumRounds(self, tasks: List[int]) -> int:
        """
        - intilize at min_round and counter
        - sort all the element from low to high
        - iterate through all elements, starting with count = 1, element 1
        -  if current element is different
            - if count < 2: return -1
            - if count >= 2: increment round, reset counter to 1
        - if the current element is same as previous element:
            -  if counter+1 <= 3, increment the counter
            - if counter+1 > 3, reset counter to 1, incrmenet the round

        """
        """
        - hash table to recocrd occurance 
        - if the number mode 3 is 0, 2: then if 0, then it is num/3, else num/3 + 2
        - if the number mode 3 is 1:
            - if number mode 2 is 0, then round += num/2 
            - return 0
        """
        ocrr = {}
        rounds = 0
        for num in tasks:
            ocrr[num] = ocrr.get(num, 0)  + 1
        for num, oc in ocrr.items():
            if oc == 1:
                return -1
            if not oc%3:
                rounds += oc//3
            else:
                rounds += (oc//3) + 1
        return rounds

        # ocrr = {}
        # rounds = 0
        # for num in tasks:
        #     ocrr[num] = ocrr.get(num,0) + 1
        # for num, ocr in ocrr.items():
        #     if  ocr>3 and ocr%3 == 1:
        #         ocr = ocr-2
        #         rounds +=1
        #     if not ocr%3:
        #         rounds += ocr//3
        #     elif ocr>3 and ocr%3 == 2:
        #         rounds += (ocr//3) + 1
        #     elif ocr%2 == 0:
        #         rounds += ocr//2
        #     else:
        #         return -1  
        # return rounds
        # tasks.sort()
        # rounds, counter = 0,1 
        # print(tasks)
        # for i in range(1, len(tasks)):
        #     if tasks[i] != tasks[i-1]:
        #         if counter < 2: return -1
        #         if counter >= 2:
        #             rounds +=1 
        #             counter = 1
        #     else:
        #         if counter+1 <= 3:
        #             counter +=1
        #         else:
        #             counter = 1
        #             rounds +=1
        # if counter >= 2:
        #     return rounds+1
        # elif counter <2:
        #     return -1
        # return rounds
727