엔지니어 게시판
LeetCode 솔루션 분류

[1/4] 2244. Minimum Rounds to Complete All Tasks

컨텐츠 정보

본문

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

Return the minimum rounds required to complete all the tasks, or -1 if it is not possible to complete all the tasks.

 

Example 1:

Input: tasks = [2,2,3,3,2,4,4,4,4,4]
Output: 4
Explanation: 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.

Example 2:

Input: tasks = [2,3,3]
Output: -1
Explanation: 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.

 

Constraints:

  • 1 <= tasks.length <= 105
  • 1 <= tasks[i] <= 109
Accepted
118.6K
Submissions
186.6K
Acceptance Rate
63.5%
태그

관련자료

댓글 1

학부유학생님의 댓글

  • 익명
  • 작성일
from collections import Counter
import math
class Solution:
    def minimumRounds(self, tasks: List[int]) -> int:
        return max(-1, sum(math.ceil(val/3) if val > 1 else float('-inf') for val in Counter(tasks).values()))
전체 396 / 1 페이지
번호
제목
이름

최근글


인기글


새댓글


Stats


  • 현재 접속자 180 명
  • 오늘 방문자 4,463 명
  • 어제 방문자 5,697 명
  • 최대 방문자 11,134 명
  • 전체 회원수 1,094 명
알림 0