Dodomeki
Sign in

123. The Fewest Arrows

Medium

A maintenance crew needs to pop balloons represented by closed horizontal intervals. Each balloon is described by [inicio, fim], and a vertical arrow shot at position x pops every balloon for which inicio <= x <= fim.

Given baloes, return the minimum number of arrows needed to pop every balloon. If there are no balloons, return 0.

Example 1
Input: baloes = [[10,16],[2,8],[1,6],[7,12]]
Output: 2
Explanation: An arrow at 6 pops two balloons, and another at 12 pops the remaining two.
Example 2
Input: baloes = [[-2,1],[1,4],[1,1]]
Output: 1
Explanation: One arrow at position 1 pops all three balloons, since interval endpoints are included.
Example 3
Input: baloes = []
Output: 0
Explanation: With no balloons, no arrows are needed.
Constraints
  • 0 <= baloes.length <= 10^5
  • baloes[i].length == 2
  • -10^9 <= baloes[i][0] <= baloes[i][1] <= 10^9
IntervalsGreedySorting
Caso 1
baloes =
[[10,16],[2,8],[1,6],[7,12]]
Expected =
2
Caso 2
baloes =
[[-2,1],[1,4],[1,1]]
Expected =
1
Caso 3
baloes =
[]
Expected =
0

Run checks these 3 cases. Submit runs all 12, including hidden ones.