Magicsheet logo

Minimum Rounds to Complete All Tasks

Medium
25%
Updated 8/1/2025

Minimum Rounds to Complete All Tasks

What is this problem about?

The Minimum Rounds to Complete All Tasks problem gives you a list of tasks where each task has a difficulty level. In each round, you can complete either 2 or 3 tasks of the same difficulty level. Find the minimum number of rounds to complete all tasks, or return -1 if it's impossible. This Minimum Rounds to Complete All Tasks interview question tests greedy reasoning with a mathematical twist.

Why is this asked in interviews?

Amazon and Anduril ask this medium-level problem because it cleanly tests the interplay of counting, greedy math, and hash tables. It verifies that candidates can think about problems in terms of partition math (how to express a number as a sum of 2s and 3s) and apply it efficiently. The array, hash table, counting, and greedy interview pattern is directly demonstrated.

Algorithmic pattern used

Use a hash map to count the frequency of each task difficulty. For each frequency f:

  • If f == 1: impossible → return -1.
  • If f % 3 == 0: use f/3 rounds (all groups of 3).
  • If f % 3 == 1: use (f-4)/3 + 2 rounds (one group of 4 = 2+2, rest in 3s).
  • If f % 3 == 2: use (f-2)/3 + 1 rounds (one group of 2, rest in 3s).

Equivalently, the formula is ceil(f / 3) for f ≥ 2.

Example explanation

Tasks: [2, 2, 3, 3, 2, 4, 4, 4, 4, 4].

  • Frequency map: {2: 3, 3: 2, 4: 5}.
  • f=3: ceil(3/3) = 1 round.
  • f=2: ceil(2/3) = 1 round.
  • f=5: ceil(5/3) = 2 rounds (3+2).
  • Total: 1 + 1 + 2 = 4 rounds.

Common mistakes candidates make

  • Not detecting the impossible case (f == 1) before computing rounds.
  • Using integer division without the ceiling, undercounting rounds.
  • Trying to manually enumerate splits instead of using the ceil formula.
  • Forgetting that tasks of different difficulties must be completed independently.

Interview preparation tip

Mathematical greedy problems reward candidates who can derive formulas instead of simulating. Practice writing out the cases for small values (f=1 through f=6) to discover the ceiling pattern. The insight that "ceil(f/3) rounds" handles all cases except f==1 is elegant once seen. Whenever a problem involves partitioning a count into fixed-size groups, think immediately about ceiling division — it's a compact and powerful tool.

Similar Questions