Burst Balloon Dynamic Programming[Leetcode]

Поделиться
HTML-код
  • Опубликовано: 4 ноя 2024

Комментарии • 130

  • @meganlee5897
    @meganlee5897 6 лет назад +12

    d[i][j] means:
    1) if range [i to j] is to be burst AND all other range [0 to i] and [j to len] are STILL THERE.
    2) dp[i][j] is the max value to get for condition 1)
    3) to calculate d[i][j], we examine all k (i

    • @aaronnarain
      @aaronnarain 6 лет назад +1

      Literally the first point here made me understand the whole video. I was struggling to understand any of the other comments trying to explain the video. Thanks a lot.

    • @freesoulrahul
      @freesoulrahul 5 лет назад +1

      This really helped me understand the solution. Thanks.

    • @TamLe-hb6cp
      @TamLe-hb6cp Год назад

      thank you! Your comment helps me understand the video

    • @persevere1052
      @persevere1052 3 месяца назад

      very elegant

  • @sudheerreddy55
    @sudheerreddy55 4 года назад +1

    Thanks for putting up recursive solutions for DP problems, that helps to understand the approach taken.

  • @meganlee5897
    @meganlee5897 7 лет назад +6

    notes:1) I think this reduce to matrix multiplication chain problem. 2) the 2-d Grid represents a range of subarray i to j. 3) Cell in grid notes down the local max value result and the index of last balloon to collect the burst order at the end. 4) The last ballon to burst in range i to j means if we burst this last ballon all i to j r gone and the rest of balloons r untouched.5) code implementation for loop len->start index of subarray->last balloon to burst

  • @Randomisticful
    @Randomisticful 2 года назад

    You are one of the best mentors! Please keep up with the same methods. Amazing! Thank you!

  • @dwh19891218
    @dwh19891218 5 лет назад +8

    Boom 💥 lets use bottom up two-d dynamic programming to solve the problem.

  • @rafaelpadilla3467
    @rafaelpadilla3467 7 лет назад +37

    Tushar Roy Great video!
    **But I think there is a mistake on **15:32** **
    If 2 is the last balloon to burst with length 3, you should check on the table [1,1] = 15, but you considered 3.
    For that you should have: 15+40+ (3*5*1) = 70 instead of 58.
    Please, check that and tell me if I'm mistaken.

    • @warriorwithin81
      @warriorwithin81 6 лет назад +2

      it was overlooked since there was another value greater than this, yes it should be 70

    • @DanDan-zs6wg
      @DanDan-zs6wg 5 лет назад +1

      Yes, you are exactly correct. This was a problem in the video. He should have read 15 instead of 3.

    • @heyitsme5408
      @heyitsme5408 4 года назад

      I also think so

  • @Paradise-kv7fn
    @Paradise-kv7fn 5 лет назад +82

    Just telling the idea and NOT telling HOW we actually get to the idea to solve a problem is not really useful...

    • @VikramKumar-wd4dr
      @VikramKumar-wd4dr 5 лет назад +5

      isko nhi aata hai bro. lets just appreciate what he is doing. because many times you won't get any other soln than his. getting something is better than nothing

    • @Paradise-kv7fn
      @Paradise-kv7fn 5 лет назад +5

      @@VikramKumar-wd4dr "isko nai aata hai bro" hahaha...considering that he has worked for top companies like Apple before, I think he probably has good problem solving skills...so he might be able to explain the thought process as well.

    • @ljkb23
      @ljkb23 4 года назад +5

      He explained the idea. The idea is to break the problem down to simpler problems and use those sub problems to solve the bigger problem. So find the maximum value of all the subarrays and then we can find our answer from building off that. Start with the smallest subarray length possible (1) and do all of those subarrays then build up to length 2, 3, ... n. For example if we are trying [3,4,1,2] then start with subarray [3] and calculate by taking the max results of previously calculated values to the right and previously calculated values to the left (both are 0 in this case since we have length of 1) plus 1 X 3 X 2 = 6 (the values to multiply from left right and current value). So the idea is at each position we calculate our value by multiplying it with the right and left with ourself then we add the previously calculated results that did the same process. Repeat this process for all the other subproblems and build up from there. Once we fill out all the subproblems we will have our answer. It's an optimization problem so we have to try all possibilities and using dynamic programming we can cache or memoize the intermediate results for later re-use to solve the larger problem. Another solution would be to use recursion with memoization which has the same idea of breaking the problem down to smaller sub problems. You get to the idea by noticing the recursive nature of the problem.

    • @jacobsanchez1587
      @jacobsanchez1587 3 года назад

      Hard problems can be so frustrating! I had a similar idea as Tushar (not perfect, hence why I'm watching this), but I arrived at the idea by reading the entire chapter of Dynamic Programming in the CLRS book.

  • @VikrantSingh4
    @VikrantSingh4 7 лет назад +3

    A minor observation, you can take out the code for leftvalue and rightvalue out of the innermost 'for' loop as it's value is independent of 'k'. It saved some processing in my brain. Great video!

  • @tharunm8823
    @tharunm8823 4 года назад +21

    If took me a while to even understand, don't know how to think of this during an interview...

    • @FelipePrietoHome
      @FelipePrietoHome 4 года назад +8

      I'm not sure if he mentioned this in the video, but the algorithm he is using is not just a dynamic programming algorithm. It's also a divide and conquer algorithm, it's just done bottom up. First solve the problem using a recursive divide and conquer algorithm, then you can add memoization or convert it to a bottom up algorithm like his. It would still be tough to get this running perfect in an interview.

    • @rahulchudasama9363
      @rahulchudasama9363 3 года назад +5

      @@FelipePrietoHome This algorithm is a variation of Matrix Chain Multiplication. If you know that then this will be easy to a bit.

    • @biswamohandwari780
      @biswamohandwari780 3 года назад

      @@rahulchudasama9363 writing the bottom up is very difficult to understand really it is amusing how this guy is teaching very easily.

  • @GauravSehrawat8888
    @GauravSehrawat8888 8 лет назад +8

    Awesome videos. One request, before starting the solution if you could direct watchers to pause the video and try it themselves by giving a hint or so, that would be very encouraging.

  • @elifcaner6130
    @elifcaner6130 3 месяца назад

    this is my last exam and I'm studying with you. Hope that I pass the exam and finally graduate. Your videos are awesome!

  • @cristianouzumaki2455
    @cristianouzumaki2455 3 года назад +1

    Tushar , your content is very useful to us . Although you don't explain how you reach there but I think that's understandable keeping in mind the list of companies you have worked at already( maybe these come naturally to you.)

  • @sindhurakilaru4819
    @sindhurakilaru4819 4 года назад

    So, in the 2 examples where the dp tables are constructed, all the indices at each cell(i,i) is either i or j. So, it is easy to backtrack the order of the balloons that are burst. For example in both the cases cell(0,3) is 3. so we can consider 3rd index balloon burst first and we move to cell(0,2) but how to backtrack if cell(0,3) has 2 as an index. This happens in your example of (1,3,5,8) where 5,1,3,8 is the order of bursting. So, in this case how to backtrack? if 2 is the index then split is from (0,1) and (3,3). In this case, how to find the next order?? So, I think, for this solution, we cannot backtrack to find the order of the balloons or we have to always consider the end indices bursting at the last in order to find the order of the bursting balloons!! Anyone please feel free to correct me if I am missing anything.

  • @am3ya
    @am3ya 8 лет назад +17

    No doubt, outstanding video. :)
    Wondering if you could cover up the brain storming process (behind the scenes for the future problems).
    I believe it would be helpful to see and learn 'how you derived the algorithm for any new problem statement'.

    • @murali1790able
      @murali1790able Год назад

      he just copied the solution from leetcode.

  • @aj_prakash
    @aj_prakash 6 лет назад +1

    Thanks for the video. Nice walkthrough of the complete problem !!

  • @darshanbari2439
    @darshanbari2439 5 лет назад

    best channel for coding!
    The way he explains is the best!

    • @Gagandeep-ou7cs
      @Gagandeep-ou7cs 5 лет назад +1

      I can't under anything.If in the first step array size is 1 and last balloon to burst is 5 then we have only one ballon, How can be multiply 5 with left and right balloon then when there are no ballons ?

  • @atishnarlawar1177
    @atishnarlawar1177 6 лет назад

    Last Baloon to Burst-
    Suppose you have balloons at index 0 1 2 3 4 and you are considering balloons 1 2 3. When It say 2 is last balloon to burst in 1,2,3 I multiply 2 with 0 and 4 which are balloons outside range 1,2,3. If 2 was first balloon to burst then it would have multiplied 2 with 1 and 3.

  • @dadas7852
    @dadas7852 7 лет назад

    dp[i][j] means bursting all the balloons between [i,j] in the original array.
    So dp[1][1] means burst only the second ballon in the array, that is why it is 3 * 1 * 5 = 15.

  • @gizmogaurav
    @gizmogaurav 8 лет назад +13

    can you please explain .
    when you said consider a subset which starts at one and ends at one.
    for e-g .
    1 3 5 8
    you said if subset of length 1 that starts at 1 and ends at 1
    then answer you get is -> 0 + 0 + 3*1*5=15
    how can you add 3*1*5 , when 1 is the only element in the subset and is last element to burst.?

    • @Gagandeep-ou7cs
      @Gagandeep-ou7cs 5 лет назад +1

      that's exactly I was thinking.

    • @RakeshKumar-gg3jv
      @RakeshKumar-gg3jv 4 года назад +1

      Because profit from subarray [1,1] depends on its neighbours..

    • @vipinpurohit2155
      @vipinpurohit2155 3 года назад

      I had same issue, will try to clear it. it's not last element of array, its just the last element of this subset 1 {3} 5 8. so other array elements are there.
      => 0 + 0 + 3*1*5=15
      => total coins 3 earns from left of this subset + total coins 3 earns from right of this subset + to coins it earns from its surroundings.

  • @rahulchudasama9363
    @rahulchudasama9363 3 года назад

    Nice Explaination Tushar....
    This algorithm is a variation of Matrix Chain Multiplication. If you know that then this will be easy to a bit.

  • @damnoish
    @damnoish 8 лет назад +19

    I think there's an error. At 15:32 for length 3, index 2, (1,1) should be 15, right?
    Thank you for making this video.
    EDIT: oh, that has already been answered.

    • @Stwjjs
      @Stwjjs 3 года назад

      wait, where it has been answered?

    • @ujone0000
      @ujone0000 3 года назад

      think so too

  • @WateryIce54321
    @WateryIce54321 6 лет назад

    The intuition behind how this problem gets broken down into sub-problems is beyond me.
    It's easy enough to translate the balloon value into a function ( v(i) = v(i-1) + v(i) + v(i+1) ) and consider all n! permutations; but, somehow you saw that only continuous sub-arrays need to be taken into consideration. The motivation there is more important than the algorithm details in my opinion.

    • @FelipePrietoHome
      @FelipePrietoHome 4 года назад +1

      I agree with you, he didn't explain how to arrive at his solution. I'm not sure if he mentioned this in the video, but the algorithm he is using is not just a dynamic programming algorithm. It's also a divide and conquer algorithm, it's just done bottom up. First solve the problem using a recursive divide and conquer algorithm, then you can add memoization or convert it to a bottom up algorithm like his.

  • @atuljatia6279
    @atuljatia6279 4 года назад

    The best explanation for this question.

  • @myvinbarboza3038
    @myvinbarboza3038 2 года назад

    Tushar Roy you rock !!!

  • @johnz1611
    @johnz1611 7 лет назад +2

    I don't understand what you mean by last balloon to burst. When you are considering arrays of length = 1, you say it is the last balloon to burst.. for example, in your ex 3,1,5,8.. when we are considering 3, if three is the last balloon to burst, it means that 1,5,8 have all burst already .. i.e., 3 is the only balloon.. so the value should be 1*3*1. Similarly, when 1 is the last balloon to burst, we are considering just one balloon array, so even 1 does not have anything on the left and right, which means the value should be 1*5*1 .. how are you taking it as 3*1*5 ? Please clarify.... Otherwise, great efforts in making the videos and totally appreciate your work

  • @CHANDANKUMAR-zh9oe
    @CHANDANKUMAR-zh9oe 7 лет назад +1

    How to proceed if total value will be the sum of ballon[left] * ballon[right].If there is no balloon in left then 1*ballon[right].If there is no balloon in right then 1*ballon[left].If there is no balloon in either side then value at the position itself.
    Please help me to proceed with this.
    Thanks.

  • @RaviKumar-vk6ib
    @RaviKumar-vk6ib 4 года назад

    Awesome video big fan loads of love

  • @depression_plusplus6120
    @depression_plusplus6120 2 года назад

    Future notes for myself:- hey it's just a simple MATRIX CHAIN MULTIPLICATION. But we need to add 1 and 1 at the begin and end because unlike matrix chain multiplication, we can have our first balloon or the last balloon popped and if that happens i-1 or i+1 will be absurd and that's why we add 1 and 1 in the start and end to balance this situation.

  • @ronakgupta7492
    @ronakgupta7492 8 лет назад +1

    Hi tushar your videos are so much helpful . could you please make a video for best time to buy and sell with cool down from leetcode . i have gone through your video for k transaction but still not quite intuitive to do cool down one . Would really appreciate your help . Thanks for the great work.

  • @sashankgondala152
    @sashankgondala152 5 лет назад

    We don't actually need to store the index. Just storing the value should be sufficient.

  • @s1337m
    @s1337m 7 лет назад +7

    Why do you consider elements out of the subarray when calculating the burst total?

    • @govindagarwal2389
      @govindagarwal2389 3 года назад

      I think it is beacuse while solving for let's say length 3, we first require max result of length 2 and then we burst the third balloon, i.e. result of length 2 was calculated while all the balloons were not burst and hence will influence the result of length 2. Influence of outer elements on result of subarray is the reason this question is solved using Dynamic Programming and not divide and concur. hope this helps.

  • @karanvishwakarma8276
    @karanvishwakarma8276 4 года назад

    Sir you are the best

  • @bryanbocao4906
    @bryanbocao4906 6 лет назад +1

    Thanks and I really love your video! I have one question at 15:54, isn't the 1to1 value is 15 in the table? So it should be 2 -> 15 + 40 + 3x5x1 = 70? (Never mind, I just realized there have been some discussions regarding this.

    • @Stwjjs
      @Stwjjs 3 года назад

      where?

  • @AbhinavJain658
    @AbhinavJain658 8 лет назад

    Can we do it using heaps as well?
    Maintain left and right pointers for each balloon.
    Put all the elements except the first and last in a min heap .
    Then pop the elements and add the sum obtained upon each popping off of the element. Also simultaneously update the left and right indices for the right and left balloons of the current popped balloon respectively.
    If there are more than 2 balloons with the same value then select the one which has a larger valued neighbour.
    At the end just remove the smaller of the 2 corner elements and then the larger corner element.

  • @gauravmishra139
    @gauravmishra139 8 лет назад

    Hello Tushar. I am a regular follower of your videos and you are simply fab. I have a request. If possible, please make a video tutorial on DP with bit masking as I am struggling a lot to understand the topic (taking in consideration spoj problem ASSIGN). Thanks in advance.

  • @ameyapatil1139
    @ameyapatil1139 5 лет назад

    Very well explained.

  • @deepak-ui5li
    @deepak-ui5li 6 лет назад

    Thank you Tushar Roy :) you are the best

  • @JohnWilliamDomingo
    @JohnWilliamDomingo 8 лет назад

    Could you please break down the time complexity a bit more? I can tell it's simple but I'm pretty new to asymptotic analysis. Thank you Tushar!

  • @shuxuannie1470
    @shuxuannie1470 8 лет назад

    Another best of the best Algorithm video!!!

  • @dharmendrabhojwani
    @dharmendrabhojwani 5 лет назад

    did not understand the explanation given by Tushar. Even thought we are considering 1 length ballon but an effect goes to other ballon.

  • @vinodkumarPrajapativnd
    @vinodkumarPrajapativnd 8 лет назад +2

    today in our campus placements at MNNIT Allahabad Samsung asked this problem. time given was 3 hrs still couldn't complete.hope had watched it earlier.... :(

  • @caitlinmclaren2695
    @caitlinmclaren2695 2 года назад

    We don't need to keep track of which index gives the best value.

  • @rajatsharma_02
    @rajatsharma_02 7 лет назад +1

    pls post more , dont stop posting pls

  • @Kreamax
    @Kreamax 8 лет назад

    Very interesting. What are the applications? I can't find anything refering to this...

  • @tanmaysinghal8370
    @tanmaysinghal8370 2 года назад

    How is he able to store 2 values in the T matrix by just using int? Shouldnt be create a class that contains 2 values???????

  • @Gagandeep-ou7cs
    @Gagandeep-ou7cs 5 лет назад +1

    I can't under anything.If in the first step array size is 1 and last balloon to burst is 5 then we have only one ballon, How can be multiply 5 with left and right balloon then when there are no ballons ?

  • @gaumappp
    @gaumappp 5 лет назад +1

    Hi @Tushar, great video. Question for you, why do you need to keep track of the last popped balloon in a sub-array while you seem to never use it?

  • @tsubasanikaidou2536
    @tsubasanikaidou2536 4 года назад

    you helped me get over it!

  • @amitrk23
    @amitrk23 6 лет назад

    Great Explanation.
    Thank You :)

  • @huyangquang1711
    @huyangquang1711 8 лет назад

    Great video as usual.
    btw, can you make a video about Square Root Decomposition?

  • @nostalgiagames6214
    @nostalgiagames6214 6 лет назад +1

    Can we solve this by using Linked List and backtracking? I think the problem is much clearer to simulate with linked list.

    • @SamuelEvans1991
      @SamuelEvans1991 5 лет назад +1

      You CAN solve it with backtracking but it will be slow... O(N!).

  • @rishithakur6342
    @rishithakur6342 4 года назад

    @tushar if i solve this problem in 0(n^3) if I have to optimize this into o(n^2) or o(n) will it possible ?

  • @christy_yinyan8449
    @christy_yinyan8449 8 лет назад +1

    Hi, Tushar, Can you pls explain "Alien Dictionary Leetcode" on your next video? Thank you so much!

  • @tzzz4882
    @tzzz4882 8 лет назад

    Hi, when you calculate cell(1, 3), if index 2 is the last index to operate, should that be 15+40+15 = 70 instead of 3+40+15?

    • @tzzz4882
      @tzzz4882 8 лет назад

      Alright, thank you.

  • @MrMuntasir66
    @MrMuntasir66 8 лет назад +1

    could u plz make a video on this:Generate integer from 1 to 7 with equal probability using rand5()

  • @ameyapatil9682
    @ameyapatil9682 5 лет назад

    Outstanding !

    • @Gagandeep-ou7cs
      @Gagandeep-ou7cs 5 лет назад

      I can't under anything.If in the first step array size is 1 and last balloon to burst is 5 then we have only one ballon, How can be multiply 5 with left and right balloon then when there are no ballons ?

  • @mengqianliu4299
    @mengqianliu4299 8 лет назад

    I still confused about the beginning. U said think about len = 1, and it is the last ballon to burst. Let's the second element 2. left side and right side are both nothing. so why the value is not 1 * 1 * 1, but it's 1*3*5? You said that's the last ballon u need to burst right?

    • @prabasheghorebaire
      @prabasheghorebaire 7 лет назад +1

      Initially I also thought the same but one thing you need to understand that here when we are selecting only a subproblem for say i to j the problem has to be dealt in context to the entire array, its not complete independent and the order of elements in the entire array effects all the subproblems. so when selecting subproblem i to j we are just bursting those balloons but have to consider rest of the balloons for the last one.

  • @ADORABLE-KRISHIKA
    @ADORABLE-KRISHIKA 2 года назад

    good

  • @rohanagarwal25
    @rohanagarwal25 4 года назад

    pls upload some questions on graph

  • @true_human_007
    @true_human_007 6 лет назад

    I am still unable to visualize the formula you used in. I got the formula and understand the solution.
    I am still wondering how you derived the formula. Which one to add and which one to consider and which one not to consider.

    • @FelipePrietoHome
      @FelipePrietoHome 4 года назад

      He is essentially doing a divide and conquer algorithm from the bottom up. The divide and conquer algorithm for this problem is a recursive function that for every element in the array, calls itself for the items on the left and the items on the right. Once you realize this works. Then convert it to a bottom up solution and you will end up with something very similar to him

  • @victoro9969
    @victoro9969 7 лет назад

    Is there any way to solve this in less complexity than o(n^2)?

  • @dhanashreegodase4445
    @dhanashreegodase4445 3 года назад

    great

  • @manikdeepsingh2171
    @manikdeepsingh2171 8 лет назад

    please make a video on longest arithmetic progressions.

  • @ayushjindal4981
    @ayushjindal4981 17 дней назад

    I know it is Hard , but is it Very Hard?

  • @sushantsikka3813
    @sushantsikka3813 8 лет назад

    plz do a video on scapegoat trees

  • @kamalsmusic
    @kamalsmusic 8 лет назад

    Hi, I noticed you had code for this problem in your github: www.geeksforgeeks.org/reorder-a-array-according-to-given-indexes/
    However, I don't exactly understand why the algorithm works. Could you perhaps make a video for this problem, please?

    • @kamalsmusic
      @kamalsmusic 8 лет назад

      Here is the problem.
      essentially: Given two integer arrays of same size, “arr[]” and “index[]”, reorder elements in “arr[]” according to given index array. It is not allowed to given array arr’s length.
      Example:
      Input: arr[] = [10, 11, 12];
      index[] = [1, 0, 2];
      Output: arr[] = [11, 10, 12]
      index[] = [0, 1, 2]
      Input: arr[] = [50, 40, 70, 60, 90]
      index[] = [3, 0, 4, 1, 2]
      Output: arr[] = [40, 60, 90, 50, 70]
      index[] = [0, 1, 2, 3, 4]

  • @vinayak186f3
    @vinayak186f3 3 года назад

    Ye kaise kaise questions puch rhe hai interviews me 😥

  • @DhruvPatel-kg5ut
    @DhruvPatel-kg5ut 6 лет назад

    Could not understand at 8:04

  • @mandeepsharma8305
    @mandeepsharma8305 7 лет назад

    Aho-Corasick algorithm pleasse

  • @rohollahmoosavitayebi3004
    @rohollahmoosavitayebi3004 7 лет назад +1

    Based on my understanding, the explanation at some point is not right!
    I think it should be "FIRST balloons to burst" and incorrectly he said "LAST balloon to burst". It means, at the first round, as brought in diagonal squares in the DP's matrix, we assume that if a balloon is the first balloon to burst what will be the value.
    By the way, the explanation for the top right of the matrix (which consider as the last balloon to burst" is right.

    • @tusharroy2525
      @tusharroy2525  7 лет назад

      No it is the last balloon to burst.

    • @rohollahmoosavitayebi3004
      @rohollahmoosavitayebi3004 7 лет назад

      Since at the first round (sub-array with length 1), we only have one balloon, FIRST and LAST balloon are refer to the same element and from that point maybe you right.
      But your algorithm consider that as the FIRST balloon to burst (and because of this you multiply that balloon with its two adjacent). So, based on this logic it's better to mentioned that as FIRST balloon to burst to prevent misunderstanding for others.
      By the way, thank you for your effort and nice explanation.

    • @tusharroy2525
      @tusharroy2525  7 лет назад +1

      Let me clarify it. Suppose you have balloons at index 0 1 2 3 4 and you are considering balloons 1 2 3
      When I say 2 is last balloon to burst in 1,2,3 I multiply 2 with 0 and 4 which are balloons outside range 1,2,3. If 2 was first balloon to burst then I would have multiplied 2 with 1 and 3.

    • @rohollahmoosavitayebi3004
      @rohollahmoosavitayebi3004 7 лет назад

      This one is correct. What I mean was at the first round, when you consider sub-array with length 1. In that case, your algorithm consider balloon to burst as FIRST. But your explanation mentioned it as LAST, and this part make ambiguous the process for audience. To clarify, consider index 1 (value 1) in your video (at 5:15). When you wanna calculate it, you said 3*1*5. It means you consider this balloon as the FIRST one and because of this you multiply 1 with 3 and 5 (the left and right adjacent).

    • @dadas7852
      @dadas7852 7 лет назад

      dp[1][1] means only burst 1 ballon and that is the ballon in index 1. That is why you confused this part because when you only burst one balloon the fist one is also the last one........

  • @ameyapatil1139
    @ameyapatil1139 5 лет назад

    Can any genius solve this in interview without "seen it before" ?

    • @evantheking
      @evantheking 5 лет назад

      no . dont beat yourself up . anyone who ask this , they probably dont want to hire you

    • @Gagandeep-ou7cs
      @Gagandeep-ou7cs 5 лет назад

      @@evantheking I can't under anything.If in the first step array size is 1 and last balloon to burst is 5 then we have only one ballon, How can be multiply 5 with left and right balloon then when there are no ballons ?

  • @melaniemckerrow7789
    @melaniemckerrow7789 7 лет назад

    sorry

  • @thejussingh2096
    @thejussingh2096 6 лет назад +2

    Very Poor Explaination

  • @murali1790able
    @murali1790able Год назад

    worst explanation

  • @sahilk335
    @sahilk335 8 лет назад +12

    can you please explain .
    when you said consider a subset which starts at one and ends at one.
    for e-g .
    1 3 5 8
    you said if subset of length 1 that starts at 0 and ends at 0
    then answer you get is -> 0 + 0 + 1*1*3 =3
    how can you add 1*1*3 , when 1 is the only element in the subset and is last element to burst.?

    • @Null_pointer_exceptn
      @Null_pointer_exceptn 8 лет назад +1

      yup, my doubt as well.

    • @piyush12121
      @piyush12121 8 лет назад

      Do not get confined within that subarray. It's a typical bottom up DP approach.
      Perhaps his explanation was a bit ambiguous but it makes sense once you think if that was the last balloon to burst how much value would you get ? The answer is : nums[-1] * nums[i] * nums[n].

    • @waiphyo1980
      @waiphyo1980 8 лет назад +1

      i think length = 1 means.. in this array {3, 1, 5, 8}, what is the max number if only 1 burst. and so forth.
      So he can still takes the adjacent balloons as they are still there.

    • @musfiqniazrahman
      @musfiqniazrahman 6 лет назад +1

      Add value only when there is a burst. Otherwise, the value is 0 (no balloons are burst).
      For example, say, subarray of size=3 is for index [0 1 2], we are bursting three balloons.
      If we burst balloon 0 last, we are not bursting any balloon on the left of balloon 0. So, we get value of 0 from left.
      We are bursting two balloons from right of balloon 0. We are bursting [1 2] from right in this case. The value for bursting [1 2] calculated is 135.
      So, for three balloon bursts from subarray [0 1 2],
      If we burst balloon 0 last, we get value = 0 (no burst on left) + 135 (two bursts on right) + 1 * 3 * 8
      If we burst balloon 1 last, we are bursting one from left and one from right before bursting balloon 1. So, the value we get: 3 (one burst on left) + 40 (one burst on right) + 1 * 1 * 8
      If we burst balloon 2 last, we are bursting two balloons on left (ie, [0 1]) and not bursting any balloons on right. So, the value we get: 30 (two bursts on left) + 0 (no burst on right) + 1 * 5 * 8