Day 85 of 100 days dsa coding challenge
Source: Dev.to
Challenge Overview
Taking on a new challenge: solving GeeksforGeeks POTD daily and sharing my solutions! ๐ป๐ฅ
Problem
Minimum time to fulfil all orders
GeeksforGeeks โ Minimum time to fulfil all orders
Difficulty: HardโAccuracy: 66.7%
Geek is organizing a party at his house. For the party, he needs exactly n donuts for the guests. Geek decides to order the donuts from a nearby restaurant, which has m chefs and each chef has a rank r.
Solution Approach
The problem can be solved using binary search on the answer (time). For a given time mid, we compute how many donuts each chef can make and sum them up. If the total is at least n, we try a smaller time; otherwise, we increase the time.
def minimum_time(ranks, n):
# Helper to compute donuts a chef with rank r can make in given time t
def donuts_made(r, t):
# Solve r * k * (k + 1) / 2 = n:
break
if total >= n:
high = mid
else:
low = mid + 1
return low
The function minimum_time returns the smallest time required for the chefs to produce at least n donuts.