Leetcode 77 Problem 4 - Split Array With Same Average

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

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

  • @vicente3j
    @vicente3j 3 หลายเดือนก่อน +1

    In 9:02, I believe there's an error. Since we're looking through elements in possible subsets of size 1, this means that B must equal 5, since this is the size of the other subset. Using the formula we would take 5 * 42 / 6 = 30, and since 30 isn't found in the first list, we continue. Recall that each row in the DP matrix represents sums of size A. Fortunately, you find the result is still true at A = 2, looking for sum of 4 * 42 / 6 = 24, and we find it.
    Great video regardless, you are AMAZING at explaining.

  • @munteanionut3993
    @munteanionut3993 3 ปีที่แล้ว

    Thank you so much! One tip, if I may: the way you wrote it on the whiteboard: "only possible if sum * i % n == 0 for i from 1 to n - 1" suggests that the problem is only solvable if: FOR EVERY i --> the sentence "sum * i % n == 0" stands. I listened closely to what you said between 04:37 - 04:53 and this became clear, but I just thought it could be useful to point out. Thanks again! And God bless! Nice work!

  • @mohitthakur6609
    @mohitthakur6609 6 ปีที่แล้ว +5

    nice men i don't think there is any youtube channel like this gd work

  • @xingrandeng9611
    @xingrandeng9611 6 ปีที่แล้ว +2

    Nice solution! But I do have trouble understanding the complexity of the most inner loop. Could you please explain more on it? Why it is bounded by 10^5n? Thank you!

  • @stellay7732
    @stellay7732 5 ปีที่แล้ว +1

    May I know why this loop [ for (int i = m; i >= 1; -- i) ] not going in the direction from 1 to ls.size() -1. Thanks.

  • @rahul-patil
    @rahul-patil 5 ปีที่แล้ว +2

    End formula is {summation of Ai = B * sum % n} then why are we checking it against 0 ?
    Please clarify.
    Thanks.

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

      summation of Ai must equal a whole number which implies our RHS must also be a whole number or in other words, B*sum % n must leave no remainder.

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

    Now that I understand more) Could you drop the previous sums before building the next one?
    Like: Can we do this with the partition of size 1? Nope - build partitions of size 2. Drop the previous ones?

    • @code_report
      @code_report  6 ปีที่แล้ว +2

      yea, i think that would work. and it would be more efficient

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

      Could you explain this a bit more, please.?

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

    great work. surprised the views are so low.

  • @arkadybabaev341
    @arkadybabaev341 2 ปีที่แล้ว

    It seems weird to me, that we sum up numbers this way: so we will also store sums of the same number several times. So we can store sum in "sums", which contains the same value several times. This "sum" may not be valid, but we can find it in a search loop, getting a false positive result.

    • @arkadybabaev341
      @arkadybabaev341 2 ปีที่แล้ว

      if we have input 2,12,18,16,19,3. sum = 70. 70*3/6 = 35, so it is possible. When we will calculate a second level of our matrix, we will have there 16+3. When we will calculate third level of our matrix, we will add there 16 again, so we will get there 16+3+16 = 35. And so the algo will return true, when it is not correct.

  • @ayushbhandarkar8394
    @ayushbhandarkar8394 ปีที่แล้ว

    Just Brilliant !!

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

    In pruning, we can just check (sum%n), correct me if I'm Wrong.

    • @vikramkumar-dh5uk
      @vikramkumar-dh5uk 5 ปีที่แล้ว

      nope, you have to check whether it is possible or not by multiplying by each element with sum and taking mod. lets say sum%n!= 0, but still there may be some case where sum*i%n==0. hope you get it.

  • @johnsagar5305
    @johnsagar5305 3 ปีที่แล้ว

    Omg🔥..
    Brilliant solution man..
    Thank you ❤️🔥

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

    can this be implemented in C ?

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

    Interesting algorithm, thanks

  • @basilbeirouti79
    @basilbeirouti79 ปีที่แล้ว

    This is not O(n^3) it's O(2^n)

  • @wuaaron662
    @wuaaron662 6 ปีที่แล้ว +2

    God, everyone knows leetcode

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

    Brilliant!

  • @techgianttechyforever
    @techgianttechyforever 3 ปีที่แล้ว

    amazing

  • @ALLABOUTUFC-ms8nt
    @ALLABOUTUFC-ms8nt 10 หลายเดือนก่อน

    WOW

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

    This is giving TLE.