Several children want turns on a video game machine. Each turn takes one time slot, and only one child can play during a slot.
A child may request multiple turns. After finishing a turn, that child must wait for a fixed number of complete slots before playing again.
Other children may play during the waiting period. If no child is currently allowed to play, the machine remains unused for that slot.
The requested turns may be arranged in any order. Find the minimum number of time slots needed to complete every requested turn.
GameMachinePlanner
public int minimumSlots(List<String> turnRequests, int waitingSlots)
turnRequests is the name of a child requesting one turn.waitingSlots is the minimum number of complete slots that must occur between two turns taken by the same child.turnRequests list must not be modified.1 ≤ turnRequests.size() ≤ 10,0001 ≤ turnRequests.get(i).length() ≤ 20"gaurav" and "GauRav" represent the same child, and their requested turns must be counted together.0 ≤ waitingSlots ≤ 100turnRequests and its elements are never null.minimumSlots( turnRequests = List.of("Aarav", "Aarav", "Aarav", "Aarav", "Diya", "Diya", "Diya", "Kabir"), waitingSlots = 2)
Output: 10
One optimal arrangement is: Aarav, Diya, Kabir, Aarav, Diya, unused, Aarav, Diya, unused, Aarav.
minimumSlots( turnRequests = List.of("Mira", "Rohan", "Mira", "Tara", "Rohan", "Neel", "Mira"), waitingSlots = 1)
Output: 7
The children can be arranged so that every slot is used while leaving at least one complete slot between repeated turns of the same child.
minimumSlots( turnRequests = List.of("Ishaan", "Ishaan", "Ishaan", "Ishaan", "Zoya", "Zoya"), waitingSlots = 3)
Output: 13
There are not enough turns from other children to fill every waiting period, so some slots must remain unused.