Find Minimum Time to Defuse All Bombs (For off-campus 2025 batch hiring :)
Updated
Problem statement
There are N bombs in a row. Bomb i (counted from 0) takes defuseTime[i] seconds to defuse and explodes at time detonationTime[i], counted from now.
You can defuse only one bomb at a time. You start at time 0 and you choose the order. A bomb is safe if you finish defusing it at or before its explosion time.
Return the minimum time needed to defuse all the bombs, which is the time when the last bomb is finished. If no order saves every bomb, return -1.
Complete the function findMinimumTimeToDefuseAllBombs in the editor.
findMinimumTimeToDefuseAllBombs has the following parameters:
int[] defuseTime: the seconds needed to defuse each bombint[] detonationTime: the time at which each bomb explodes
The function returns an int: the minimum time to defuse all the bombs, or -1 if it is not possible.
Function
findMinimumTimeToDefuseAllBombs(defuseTime: int[], detonationTime: int[]) → intExamples
Example 1
defuseTime = [2, 1, 3, 1]detonationTime = [4, 9, 8, 2]return = 7Work on the bomb that explodes soonest first. Bomb 3 takes 1 second and explodes at 2, so it is done at time 1. Bomb 0 takes 2 seconds and explodes at 4, so it is done at time 3. Bomb 2 takes 3 seconds and explodes at 8, so it is done at time 6. Bomb 1 takes 1 second and explodes at 9, so it is done at time 7. Every bomb is finished before it explodes and the last one is done at time 7, so the answer is 7.
Constraints
1 ≤ N ≤ 2 * 105defuseTime.length = detonationTime.length = N1 ≤ defuseTime[i], detonationTime[i] ≤ 109
More Uber interview questions
- Random Bingo Card GeneratorONSITE INTERVIEW · Seen Dec 2026
- Travelers per Consecutive City TripletONSITE INTERVIEW · Seen Dec 2026
- Worst-Performing Ads by CTR in a Campaign TreePHONE SCREEN · Seen Nov 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Max Points on a LinePHONE SCREEN · Seen Oct 2026
- Online Meeting Scheduler with Fixed RoomsONSITE INTERVIEW · Seen Oct 2026
- Convex Function MinimizationPHONE SCREEN · Seen Oct 2026
- Meeting Rooms IIPHONE SCREEN · Seen Oct 2026
- Merge Meeting IntervalsPHONE SCREEN · Seen Oct 2026
- Minimum Meeting Rooms with AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Hiking Club Fastest PaceInfosys · OAInfosys interview questions
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Minimum Cost of Every K-Capable Model SetTikTok · OATikTok interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions