Factory Machines

You are managing a factory with multiple machines working simultaneously. You are given an integer array nums where each element represents the number of seconds a specific machine takes to manufacture a single product. You are also given an integer t, representing the total target number of products you need to make.

Because the machines work at the same time and independently, you can freely let them run as long as needed. Your goal is to find the shortest possible time (in seconds) required to manufacture at least t products.

Example 1:

Input: nums: [3, 2, 5], t =7

Output: 8

Explanation:

After exactly 8 seconds:

  • Machine 1 (takes 3s) makes 2 products (8 / 3 = 2).
  • Machine 2 (takes 2s) makes 4 products (8 / 2 = 4).
  • Machine 3 (takes 5s) makes 1 product (8 / 5 = 1). Total products = 2 + 4 + 1 = 7. No shorter time can achieve 7 products.

Example 2:

Input: nums: [2, 2, 2], t = 6

Output: 4

Explanation:

All machines take 2 seconds. After 4 seconds, each machine has produced exactly 2 items, yielding the 6 required products perfectly.

Now Your Turn!

Pick the correct output for the given input

Input: nums: [1, 100], t = 5

(What is the absolute minimum time needed to make 5 products?)

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= nums.length <= 2 x 105
  • 1 <= t <= 109
  • 1 <= nums[i] <= 109

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
long long minTime(vector<int>& nums, int target) {
// Write your code here
}
};
Test Case

Input:

Nums
T