2Brute2Best
🔥0

Minimum Number of Arrows to Burst Balloons

Medium·LeetCode #452 Pro OnlyBasic Reinforcement
LeetCode
01

Problem Statement

Balloons are taped to a wall. Each balloon is given only by where it spans along the x-axis: [x_start, x_end].

You can shoot arrows straight up from any point x. An arrow at x bursts every balloon with x_start ≤ x ≤ x_end, and keeps flying.

Return the fewest arrows needed to burst all the balloons.

Note that an arrow exactly on the edge counts: an arrow at x = 2 bursts both [1, 2] and [2, 3].

Input

An array points where points[i] = [x_start, x_end].

Output

One integer: the minimum number of arrows.

Example 1
Input: points = [[10,16], [2,8], [1,6], [7,12]]
Output: 2

An arrow at x = 6 bursts [2,8] and [1,6]. An arrow at x = 11 bursts [10,16] and [7,12].

Example 2
Input: points = [[1,2], [3,4], [5,6], [7,8]]
Output: 4

No two balloons share any point, so each needs its own arrow.

Example 3
Input: points = [[1,2], [2,3], [3,4], [4,5]]
Output: 2

An arrow at x = 2 bursts [1,2] and [2,3]. An arrow at x = 4 bursts [3,4] and [4,5].

Constraints
  • • 1 ≤ points.length ≤ 10^5
  • • points[i].length == 2
  • • −2^31 ≤ x_start < x_end ≤ 2^31 − 1
02

Pattern Recognition Clues

Recognising these key signals in the problem description immediately identifies the pattern:

“an arrow bursts every balloon it touches”
→ One point can cover many intervals. Group intervals that share a point.
“minimum number of arrows”
→ Greedy choice of where each point goes: as far right as the most urgent balloon allows.
“x_start ≤ x ≤ x_end”
→ Edges count, so touching balloons share an arrow. The check is `start > arrow` for a new arrow.
03

Approach Complexity Ladder

Brute Force — try every set of shooting spotsO(2^N · N²)O(N)

Try every subset of balloon end points as arrow spots; keep the smallest that bursts all

Better — repeatedly shoot the balloon that ends firstO(N²)O(N)

Each round: scan for the earliest end still flying, shoot there, burst everything it touches

Optimal — sort by end, one passO(N log N)O(1)

Sort by end; shoot a new arrow at a balloon's end only when it starts after the last arrow

Brute Force Intuition

Only balloon ends are worth shooting at: slide any arrow right until it reaches the first end among the balloons it bursts, and it still bursts all of them. So collect the distinct ends, try every subset of them, and keep the smallest subset that hits every balloon.

Recognition rule for this sub-pattern:

Pick or remove intervals to optimise coverage. Sorting by end and keeping the earliest finisher leaves the most room.
Remember this · Intervals
Trigger
Input is [start, end] pairs; overlap, merge, insert, meeting rooms, free time, minimum removals.
Think
After sorting, do I only ever need to compare against the most recent interval?
Key question
Sort by start or by end — which one makes the greedy choice obvious?
Brute2Best Pro Content

Unlock Complete Visual Walkthrough & Optimal C++

The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.

All 440 visual dry runs & algorithms
Interactive step-by-step playback with pointer & array state transitions
52 comprehensive LLD chapters
Interactive UML diagrams, real-world stories (Food Delivery, Trading, RPG), and practice solutions
40 C++ basics labs & hardware memory models
Vtables, byte layouts, assembly insights, and multi-threading race conditions
Production-ready C++23 source code
Modern idioms, clean contracts, time/space complexity derivations, and interview takeaways

First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.

Beyond The LeetCode Problem

How this concept connects to System Design & C++ Systems

Bridge DSA with production engineering

Top engineering interviews test whether you understand how algorithms like Intervals translate into production architectures and low-level memory mechanics.