Interview Questions/Coding/Minimum Time to Bake All Cakes

Minimum Time to Bake All Cakes

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Minimum Time to Bake All Cakes

You are given an integer array speeds representing the baking speeds of some bakers. speeds[i] is the speed factor of the i-th baker. A baker with speed s can bake n cakes in: s×n² minutes. You are also given an integer cakes, representing the total number of cakes that need to be baked. Return the minimum time required to bake all the cakes. All bakers can bake cakes simultaneously.

Examples

Example 1
Input:
speeds = [3, 1, 4, 2]
cakes = 10
Output:
16

Explanation: Baker with speed 3 bakes 2 cakes: 3 × 2² = 12 minutes Baker with speed 1 bakes 4 cakes: 1 × 4² = 16 minutes Baker with speed 4 bakes 2 cakes: 4 × 2² = 16 minutes Baker with speed 2 bakes 2 cakes: 2 × 2² = 8 minutes Total cakes baked = 2 + 4 + 2 + 2 = 10 So, minimum time = 16.

Approach hint

use binary search on time

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp