Minimum Rounds to Complete All Tasks
Updated
Problem statement
You are given an integer array tasks. tasks[i] is the difficulty level of task i.
In one round you finish either 2 or 3 tasks, and all tasks finished in that round must have the same difficulty level.
Return the smallest number of rounds needed to finish every task. If it is impossible, return -1.
Function
minimumRounds(tasks: int[]) → intExamples
Example 1
tasks = [5,5,5,7,7,9,9,9,9]return = 4Level 5 has 3 tasks: one round of 3. Level 7 has 2 tasks: one round of 2. Level 9 has 4 tasks: two rounds of 2. That is 1 + 1 + 2 = 4 rounds.
Example 2
tasks = [3,8,3]return = -1There is only one task of level 8. A round needs at least 2 tasks of the same level, so this task can never be finished.
Example 3
tasks = [6,6,6,6,6,6,6]return = 3There are 7 tasks of level 6. Use one round of 3 and two rounds of 2: 3 + 2 + 2 = 7. Two rounds can finish at most 6 tasks, so 3 rounds is the best.
Constraints
1 <= tasks.length <= 10^51 <= tasks[i] <= 10^9
More Infosys Online Assessment questions
- Lowest Common Ancestor with a Changing RootOA · Seen Nov 2026
- Minimum Leaf Path Sum over All RootsOA · Seen Nov 2026
- Split Array to Minimize the Largest SumOA · Seen Nov 2026
- Cherry PickupOA · Seen Nov 2026
- Lexicographically Smallest Grid Path with One Letter ChangeOA · Seen Nov 2026
- Minimum Cost to Supply Water with Wells and PipesOA · Seen Nov 2026
- Minimum Cost to Tile a Strip with Widths 1, 2, and 3OA · Seen Nov 2026
- Count Equal-Distinct Character PartitionsOA · Seen Oct 2026
- Maximum Alternating-Index Packet ValueOA · Seen Oct 2026
- Usable Water with Contaminated PillarsOA · Seen Oct 2026
Similar questions at other companies
- Maximum MEXAtlassian · OAAtlassian interview questions
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Task Scheduler with CooldownGoDaddy · OA
- Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Get Triplet CountIBM · OAIBM interview questions
- Minimum Values with Even Powers of TwoVisa · OAVisa interview questions
- Resource AllocationMaven Securities · OAMaven Securities interview questions