Maximum Contiguous Subsequence - Dynamic Programming

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024

ความคิดเห็น • 25

  • @JayPatel12928
    @JayPatel12928 5 ปีที่แล้ว +2

    I want you to know that, among all the explanations on youtube, your's is the best one.

  • @fitoor0997
    @fitoor0997 9 ปีที่แล้ว +13

    beautifully explained!!! saved a lot of time of mine..

  • @neobonzi
    @neobonzi 7 ปีที่แล้ว

    By far the best explanation of the cost function out of all the videos I've seen on youtube

    • @jackkalman8195
      @jackkalman8195 7 ปีที่แล้ว

      too bad its wrong. [-1,-2] is the counter example.

    • @AjayByadgi
      @AjayByadgi 7 หลายเดือนก่อน

      @@jackkalman8195 lol noob he said if its all negative just take the largest value (-1) in the list

  • @sbonelo
    @sbonelo 8 ปีที่แล้ว +6

    Extremely helpful, thank you so much

  • @SmartProgramming
    @SmartProgramming 6 ปีที่แล้ว

    awesome explanation, keep it up, thank you 👍👍🙂🙂

  • @KrishanuKonar
    @KrishanuKonar 8 ปีที่แล้ว +2

    What happens when when two sub-sequences generate same sum??
    Should we take the longer one or the shorter one? Marking the number red would only give the most recent solution(subsequence).

  • @ffatheranderson
    @ffatheranderson 5 ปีที่แล้ว

    Thank you. Very good explanation.

  • @sabio234
    @sabio234 8 ปีที่แล้ว +1

    Do you have any which teaches how to come up with a formula to solve DP ?

  • @kameshsriram
    @kameshsriram 6 ปีที่แล้ว +1

    I think the problem you are solving is Maximum contiguous sub-array but not Maximum Contiguous Subsequence

  • @technomissilecraft4532
    @technomissilecraft4532 8 ปีที่แล้ว

    please upload travelling salesman problem,Bellman Ford algorithm.

  • @jasdn93bsad992
    @jasdn93bsad992 5 ปีที่แล้ว

    A[i] could be a negative number, in taht case, S[i] = S[i-1];

  • @thanga2317
    @thanga2317 5 ปีที่แล้ว

    is this subsequence or subarray ? if its subsequence then answer should be 2 + 3 + 5 = 10. correct me if am wrong .

    • @RooonilWazlib
      @RooonilWazlib 5 ปีที่แล้ว

      Contiguous means you can't skip anything in the sequence. You have a starting index and an ending index and take the sum of all the values within that subsequence.

  • @eithanmartinez2852
    @eithanmartinez2852 4 ปีที่แล้ว

    Do you have the pseudocode?

  • @PreethaDatta
    @PreethaDatta 8 ปีที่แล้ว

    how would you define s? the code in c++ that is

  • @chuongxl
    @chuongxl 6 ปีที่แล้ว

    great :) thank!

  • @groupsvkg
    @groupsvkg 7 ปีที่แล้ว

    For A = [-6, 2, -4]
    S(2) = -2 or 2 ?

    • @jackkalman8195
      @jackkalman8195 7 ปีที่แล้ว

      his algorithm is wrong lol.. idk why so many ppl thumbed up

    • @oliverliu9205
      @oliverliu9205 7 ปีที่แล้ว +2

      S(0) = -6, S(1) = either -6 + 2 or 2, we will take 2. S(2) = either 2 - 4, or -4. We will take 2-4 = -2.
      But now you take the maximum number from this array, so the final answer is 2.

    • @matheusrotta1589
      @matheusrotta1589 6 ปีที่แล้ว

      His algorithm is correct, you take the maximum in the array afterwards.

    • @ffatheranderson
      @ffatheranderson 5 ปีที่แล้ว

      @@jackkalman8195 it works perfect for me.

  • @jackkalman8195
    @jackkalman8195 7 ปีที่แล้ว

    Bro what about this input [-1,-2]? your algorithm returned -2 and obviously the answer should be -1 lol

    • @oliverliu9205
      @oliverliu9205 7 ปีที่แล้ว +3

      His algorithm is right and yourself are wrong.
      the solution array would be:
      [-1,-2]
      But now you take the maximum number from this array, which is -1.
      Remember, S[i] is the largest contiguous sum you can get ENDING AT (NOT UP TO) index i. Therefore you cannot simply take the last element in the solution array.