Prefix Sum Array Explained

Поділитися
Вставка
  • Опубліковано 30 січ 2025

КОМЕНТАРІ • 43

  • @gatusko123
    @gatusko123 2 роки тому +11

    This damn problem on LeetCode. Reading and trying to understand the solutions. But this video is the best one and the one finally understand it. Thank you very much man.

  • @walthertrgovac6087
    @walthertrgovac6087 4 роки тому +26

    You explained that really good, thank you! It helped me a lot :D

  • @kender2272
    @kender2272 Рік тому +8

    thank you, very well and simply explained, I'm writing my final school leaving exam soon, and I'm extending computer science(in my country you can choose extended additional subjects).

  • @rauljg143
    @rauljg143 4 роки тому +3

    Great explanation. Thank you. "Prefix sum" kept coming in the context of loop-unrollling and I'm like "back up. what's a prefix sum???" Now I get it and can move on!

    • @aakashtiwari836
      @aakashtiwari836 4 роки тому

      In which course and in which year you are???

    • @almuhimen8023
      @almuhimen8023 4 роки тому

      What is loop unrolling?

    • @MiketheCoder
      @MiketheCoder  3 роки тому

      loop unrolling is when you try to unroll the loop in assembly to make it more efficient, that's super exhausting to do though

  • @dThapa966
    @dThapa966 Рік тому +3

    This was explained extremely well. Thank you very much !!

  • @Relatable_coder
    @Relatable_coder 7 місяців тому

    Giving a codeforces contest ,this really came in clutch,Great work!!

  • @jeyburns.t9209
    @jeyburns.t9209 2 місяці тому

    Finally someone who explains this simple

  • @sunnyday12131
    @sunnyday12131 3 роки тому +2

    Thanks for this, finally I got to know what prefix sum is and helps me solve leetcode 370!

  • @pranavsudhir7645
    @pranavsudhir7645 4 роки тому +1

    Amazing explanation Michael. Great job. Subscribed to your channel.

  • @thisjoman
    @thisjoman 4 роки тому +6

    love you bro

  • @taal7245
    @taal7245 3 роки тому +15

    damn.. I just want to grab that pencil right off his hands, sharpen it. Then give it back to him!

  • @abrarmasumabir3809
    @abrarmasumabir3809 2 роки тому

    Thanks brother! That was really cool!

  • @justmeandmy
    @justmeandmy 9 місяців тому +2

    What I'm struggling with is understanding how and when to use it for things beyond the prefix sum algo itself. eg - I know that facebook coding puzzle Director of Photography can be used to solve it, but I still don't really understand how to spot the use cases.

  • @KevinBuii
    @KevinBuii 4 місяці тому

    Great explanation thank you!

  • @egecalskan6355
    @egecalskan6355 4 роки тому

    This video was very helpful, thank you!

  • @prajwalchoudhary4824
    @prajwalchoudhary4824 4 роки тому +2

    great explanation

    • @MiketheCoder
      @MiketheCoder  4 роки тому +3

      Thank you!!

    • @juliancruz87
      @juliancruz87 4 роки тому

      @@MiketheCoder you're such a great teacher explaining it!

  • @atulkrjha
    @atulkrjha Рік тому +1

    Hi Mike great video, So i am like little confused if it is given to calculate sum between 2 indexes except 0 i.e sum between 3 to 5 index why do we do PS[5] - PS[3-1] and not PS[5] - PS[3]

    • @MiketheCoder
      @MiketheCoder  Рік тому +2

      It's because sometimes people like to start their prefix sum as value 0 first or not.
      Let's say you have:
      Arr: [1, 2, 3, 4, 5, 6]
      Pref: [1, 3,6, 10, 15, 21]
      Sum index 3 to 5:
      4 + 5 + 6 = 15
      To get that you need to do: 21 - 6 = pref[5] - pref[2]
      But if you start your prefix sum at 0:
      Pref: [0, 1, 3, 6, 10, 15, 21]
      21 - 6 = pref[5 + 1] - pref[3]
      It depends how you want to start your prefix sum

    • @atulkrjha
      @atulkrjha Рік тому

      @@MiketheCoder Isn't our prefixSum would have length > than our original array if we start from 0?

    • @MiketheCoder
      @MiketheCoder  Рік тому +1

      @@atulkrjha Yup, it really depends on the individual how they want to code it.

  • @mirsahib596
    @mirsahib596 11 місяців тому +1

    So prefix sum is basically a version of sliding window technique

  • @Computervirusworld
    @Computervirusworld Місяць тому

    thanks bro

  • @ohmegatech666
    @ohmegatech666 3 місяці тому

    So it's just caching / memoizing for one speicific function (getting prev sum) basically

  • @Yazan_Majdalawi
    @Yazan_Majdalawi Рік тому

    Thanks!

  • @srajputplays8054
    @srajputplays8054 Рік тому

    noice😊

  • @mandeepkhadka388
    @mandeepkhadka388 4 роки тому +2

    Can you also make a video on implementing a parallel version of Prefix Sum?

    • @MiketheCoder
      @MiketheCoder  4 роки тому

      With multithreading???? Maybe. I’ll think about it.

  • @bahrawy07
    @bahrawy07 2 роки тому +1

    man ily

  • @سلمىخالدمحمدراشد
    @سلمىخالدمحمدراشد 3 роки тому +2

    great explanation