Bursting Balloons Problem

Given an array ARR of size N, where each element represents the height of a balloon. The task is to destroy all balloons by shooting arrows from left to right. When an arrow hits a balloon, it continues its path at a height decreased by 1. Determine the minimum number of arrows needed to burst all balloons.

Input:

The first line of input contains an integer N, denoting the size of the array.
The second line of input contains N space-separated integers representing the heights of the balloons.

Output:

Return a single integer, which is the minimum number of arrows required to burst all balloons.

Example:

Input:
N = 5
ARR = [2, 3, 4, 5, 1]
Output:
3

Constraints:

  • 1 <= N <= 5*105
  • 1 <= ARR[i] <= 109
  • Time Limit: 1sec

Note:

You are not required to print the output; it is already managed. Just implement the function.
AnswerBot
3d

Find the minimum number of arrows needed to burst all balloons by shooting arrows from left to right.

  • Sort the array in non-decreasing order to make it easier to calculate the minimum number of arrows ...read more

Help your peers!
Add answer anonymously...
Samsung Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter