FastPrepDefuse the Bombs
Problems/Defuse the Bombs

Defuse the Bombs

Uber logoUber● MediumOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Janet must defuse N bombs, numbered from 1 to N. Bomb i has a timer and explodes Yi seconds from now. Defusing bomb i takes Xi seconds. Janet can work on only one bomb at a time, and she starts at time 0. Each bomb must be finished before its timer runs out, or exactly when it runs out.

Decide whether Janet can defuse all the bombs in time. If she can, return the minimum total time needed to defuse them all. If she cannot, return -1.

Complete the function defuseBombs in the editor.

defuseBombs has the following parameter:

  • int[][] bombInfo: an array of N pairs [Xi, Yi]. Xi is the time Janet needs to defuse bomb i, and Yi is the time at which bomb i explodes

The function returns an int: the minimum total time to defuse all the bombs if it is possible, otherwise -1.

Function

defuseBombs(bombInfo: int[][]) → int

Examples

Example 1

bombInfo = [[2, 4], [1, 9], [1, 8], [4, 9], [3, 12]]return = 11

Work on the bombs in the order of their timers: [2, 4], then [1, 8], then [1, 9], then [4, 9], then [3, 12]. They finish at times 2, 3, 4, 8 and 11. Each finish time is at or before its timer (4, 8, 9, 9 and 12), so Janet defuses all bombs. She never waits, so the total time is 2 + 1 + 1 + 4 + 3 = 11.

Constraints

  • 1 ≤ N ≤ 2 × 105, where N is bombInfo.length
  • 1 ≤ Xi, Yi ≤ 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
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public int defuseBombs(int[][] bombInfo) {
      // write your code here
    }

}
Checking account…