Find Time Required to Eliminate Bacterial Strains - Problem
You are given an integer array timeReq and an integer splitTime. In the microscopic world of the human body, the immune system faces an extraordinary challenge: combatting a rapidly multiplying bacterial colony that threatens the body's survival.
Initially, only one white blood cell (WBC) is deployed to eliminate the bacteria. However, the lone WBC quickly realizes it cannot keep up with the bacterial growth rate. The WBC devises a clever strategy to fight the bacteria:
- The ith bacterial strain takes
timeReq[i]units of time to be eliminated. - A single WBC can eliminate only one bacterial strain. Afterwards, the WBC is exhausted and cannot perform any other tasks.
- A WBC can split itself into two WBCs, but this requires
splitTimeunits of time. - Once split, the two WBCs can work in parallel on eliminating the bacteria.
- Only one WBC can work on a single bacterial strain. Multiple WBCs cannot attack one strain in parallel.
You must determine the minimum time required to eliminate all the bacterial strains. Note that the bacterial strains can be eliminated in any order.
Input & Output
Example 1 — Basic Case
$
Input:
timeReq = [4, 2, 6], splitTime = 3
›
Output:
9
💡 Note:
Split the WBC (cost 3). At time 3, we have 2 WBCs. Assign strain 6 to WBC1 (completes at time 9) and strains 4,2 to WBC2 (completes at time 3+4+2=9). Total time is max(9,9) = 9.
Example 2 — No Splitting Needed
$
Input:
timeReq = [1, 1, 1], splitTime = 10
›
Output:
3
💡 Note:
Split cost (10) is very high. Better to use single WBC: 1+1+1=3 total time.
Example 3 — Beneficial Splitting
$
Input:
timeReq = [10, 10], splitTime = 1
›
Output:
11
💡 Note:
Split WBC (cost=1), then assign one strain to each WBC: max(1+10, 1+10) = 11. Better than single WBC taking 20 time.
Constraints
- 1 ≤ timeReq.length ≤ 104
- 1 ≤ timeReq[i] ≤ 104
- 1 ≤ splitTime ≤ 104
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code