Description
Description
Editorial
Editorial
Solutions
Solutions
Submissions
Submissions
Medium

You are given two integers, numAdults and numChildren.

A candy store has two queues. The adults' queue holds numAdults adults, while the children's queue holds numChildren children followed by another child named Bob, for a total of numChildren + 1 children.

Every 5 minutes, starting at time 0, the store opens a bag of 12 candies and immediately hands them out, one candy per person, to the people at the front of the queues.

The candies in each bag are split as follows:

  • 8 candies go to the children's queue and 4 go to the adults' queue.
  • If either queue has fewer people than its share, its unused candies go to the other queue.

Each person leaves the queue after receiving a candy. Any candies left after both queues are empty remain unused.

Return the time, in minutes, at which Bob receives his candy.

 

Example 1:

Input: numAdults = 9, numChildren = 15

Output: 5

Explanation:

  • At time = 0, 4 adults and 8 children receive candies from the first bag.
  • After the distribution, 5 adults remain in the adults' queue, and 7 children remain ahead of Bob, making him the 8th child in the children's queue.
  • At time = 5, the second bag is opened, and Bob receives a candy. Therefore, the answer is 5.

Example 2:

Input: numAdults = 6, numChildren = 16

Output: 5

Explanation:

  • At time = 0, 4 adults and 8 children receive candies from the first bag.
  • After the distribution, 2 adults remain in the adults' queue, and 8 children remain ahead of Bob, making him the 9th child in the children's queue.
  • At time = 5, the second bag is opened. The remaining 2 adults receive candies, leaving 10 candies for the children's queue. Since Bob is the 9th child in the queue, he receives a candy. Therefore, the answer is 5.

Example 3:

Input: numAdults = 7, numChildren = 3

Output: 0

Explanation:

  • At time = 0, the first bag is opened. There are 7 adults and 4 children (including Bob), for a total of 11 people.
  • The children's queue uses 4 of its 8 candies. Its 4 unused candies go to the adults' queue, giving it 8 candies, enough for all 7 adults.
  • Everyone receives a candy, including Bob. Therefore, the answer is 0.

 

Constraints:

  • 0 <= numAdults, numChildren <= 100​​​​​​​
 
Code
Code
Testcase
Testcase
Test Result
Test Result