Minimum Number of Arrows to Burst Balloons - Leetcode 452 - Python

  Рет қаралды 19,320

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 25
@1vader
@1vader 8 ай бұрын
Notice that you are never using prev[0]. You don't actually need to merge intervals, it's enough to just keep track of the earliest ending point. That's the latest point where the arrow can be shot to pop the balloons so far and at that point, all the other overlapping balloons are also popped and therefore become completely irrelevant.
@yang5843
@yang5843 8 ай бұрын
A good follow-up question to intervals from yesterday's
@DeathSugar
@DeathSugar 8 ай бұрын
i've made a mess yesterday compared to today's
@sanchitbajaj02
@sanchitbajaj02 8 ай бұрын
When I read this problem, it goes over my head but after a few minutes of explanation, I thought it was almost the same as yesterday
@DebopriyoBasu
@DebopriyoBasu 8 ай бұрын
Not sure about balloons, but my head did burst. This is an excellent explanation!
@elizabeth00653
@elizabeth00653 8 ай бұрын
Love your clear engaging solutions
@dineshkumarkb1372
@dineshkumarkb1372 8 ай бұрын
Wow. Initialising the arrow count to n and decrementing was clever. I've always tripped myself up initialising result to 0 or 1. But yeah, like you said, having the result set to 1 is more intuitive as we already have a balloon in our prev variable. Ofcourse it goes without saying, Great work as always :)
@kanishkkala16
@kanishkkala16 8 ай бұрын
my intuition was also to decrement from n
@anmolkhurana490
@anmolkhurana490 4 ай бұрын
could not burst ballons with minimum arrows, but bursted my head with just this one question!
@pastori2672
@pastori2672 8 ай бұрын
what if they miss
@MP-ny3ep
@MP-ny3ep 8 ай бұрын
Great explanation as always. Thank you
@SC2Edu
@SC2Edu 8 ай бұрын
Super clear as usual, thanks
@OrphanedZombie
@OrphanedZombie 8 ай бұрын
We can just track the end of the previous interval in a variable prevEnd. No need to care about the starting value of the previous interval.
@mahesh_bvn
@mahesh_bvn 8 ай бұрын
Hey, can you solve leetcode 790(Domino and Tromino Tiling). Seems baffling
@eleven-2806
@eleven-2806 8 ай бұрын
can someone tell me why this cant be solved by merge intervals and returning size?
@sauravsingh4497
@sauravsingh4497 8 ай бұрын
For once when I read the title I thought the problem was the crackhead problem "burst balloons"
@LlamaBG
@LlamaBG 8 ай бұрын
awesome
@yang5843
@yang5843 8 ай бұрын
My approach was to use greedy, have a left and right bound for the first balloon, if the next balloon fits inside the bound, then don't do anything, and reduce the left and right bounds to be the min/max of the two balloons, otherwise increase the return value and set the left and right bound to be the new balloon. class Solution { public int findMinArrowShots(int[][] points) { int rc = 0; Arrays.sort(points,(a,b)->a[0]==b[0]?a[1]-b[1]:a[0]-b[0]); int i = 0; long minL = Long.MIN_VALUE; long minR = Long.MIN_VALUE; while ( i < points.length ) { int l = points[i][0]; int r = points[i][1]; // System.out.println(l+" "+r); if ( minL
@yang5843
@yang5843 8 ай бұрын
Java Solution class Solution { public int findMinArrowShots(int[][] points) { Arrays.sort(points,(a,b)->a[0]==b[0]?Integer.compare(a[1],b[1]):Integer.compare(a[0],b[0])); int rc = points.length; int[] prev = points[0]; for (int i=1;i
@pastori2672
@pastori2672 8 ай бұрын
btw why is the time complexity nlong instead of n ** 2 because apparently min() takes linear time and its nested within a loop
@1vader
@1vader 8 ай бұрын
min() takes linear time over the number of elements it has to select the minimum from, which in this case is always 2, a constant. You have to be very careful with general statements like "f takes linear amount of time" without considering its inputs in relation to the input of the actual problem.
@pastori2672
@pastori2672 8 ай бұрын
@@1vader oh right you're right
@ObaidKnight
@ObaidKnight 8 ай бұрын
Neet I'm losing motivation, I need some encouragement
@luciferdesuza1541
@luciferdesuza1541 8 ай бұрын
Ask your hand for it😂
@joshk9571
@joshk9571 8 ай бұрын
enjoy being broke. someone has to flip the burgers for me
Rotating the Box - Leetcode 1861 - Python
15:14
NeetCodeIO
Рет қаралды 6 М.
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 5 МЛН
The IMPOSSIBLE Puzzle..
00:55
Stokes Twins
Рет қаралды 166 МЛН
Minimum Cost to Hire K Workers - Leetcode 857 - Python
19:01
NeetCodeIO
Рет қаралды 14 М.
Contiguous Array - Leetcode 525 - Python
15:41
NeetCodeIO
Рет қаралды 28 М.
Minimum Height Trees - Leetcode 310 - Python
23:30
NeetCodeIO
Рет қаралды 21 М.
Bitwise AND of Numbers Range - Leetcode 201 - Python
18:25
NeetCodeIO
Рет қаралды 14 М.
Coin Change - Dynamic Programming Bottom Up - Leetcode 322
19:23
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 300 М.
Burst Baloons - Dynamic Programming - Leetcode 312 - Python
21:20
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 5 МЛН