Ctrl K

Fewest Darts for the Balloons

Medium
Balloons hang on a wall. Balloon balloons[i] = [left, right] covers the horizontal span from left to right, inclusive; its height does not matter. A dart is thrown straight up from any point x. It flies forever and pops every balloon with left ≤ x ≤ right. Return the smallest number of darts that pops every balloon.
Example 1
balloons=[[4, 9], [1, 5], [11, 14], [8, 12]] → 2

A shot at x = 5 pops [1, 5] and [4, 9]; a shot at x = 11 pops [8, 12] and [11, 14].

Example 2
balloons=[[0, 3], [3, 6], [6, 9]] → 2

Touching an edge counts: x = 3 hits the first two, and the third needs its own shot.

Example 3
balloons=[[-5, 20], [0, 1], [2, 3]] → 2

[0, 1] and [2, 3] do not overlap, so two shots are needed, and the wide balloon is hit by either.

Constraints
  • 1 ≤ len(balloons) ≤ 10⁵
  • balloons[i] = [left, right]
  • -2³¹ ≤ left ≤ right ≤ 2³¹ - 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBiggest Number From Pieces MediumStudios for Recording Sessions MediumLow, High, Low MediumStrictly Low, High, Low MediumFewest Meetings to Cancel Medium
loading Python…
Input
balloons=[[4, 9], [1, 5], [11, 14], [8, 12]]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.