Prefix Sum Algorithm | Prefix Sum Array | Difference Array | Range Sum QueryO(1) | EP2

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ก.ย. 2024
  • Prefix sum algorithm is mainly used for range query and the complexity of prefix sum algorithm is O(n).
    This video explains the working of prefix sum algorithm.
    This is the second part of the video and please watch the first part (why you must learn prefix sum algorithm) before watching this.
    ✅ Why you must learn prefix sum algorithm part one link : • Why You Must Learn Pre...
    🙋 Problem to solve : • Array Manipulation Hac...
    🔴 Subscribe for more and hit the bell 🔔🔔🔔 icon to get video updates:
    / @javaaidtutorials
    👍 Like us on Facebook: / hackerranksolutiontuto...
    💎Share this video with a TH-camr friend: • Prefix Sum Algorithm |...
    ✚ Join our community ►
    👉 Coding interview preparation group: / codingip
    👉 Telegram link for algorithmic tutorial: t.me/javaaid
    👉 Telegram link for hackerrank solutions: t.me/hackerran...
    ✅ Recommended playlists ►
    👉 All hackerrank solutions: • How To Master In Data ...
    👉 New To JAVAAID ? Watch These Videos: • Prefix Sum Algorithm |...
    👉 Algorithms Fundamental: • Algorithms Fundamental
    👉 Coding Interview Questions: • Coding Interview Quest...
    👉 Dynamic Programming Tutorial For Beginner: • Dynamic Programming Te...
    👋 Let’s Connect ►
    Git Hub: github.com/kan...
    Twitter: / kanahaiyagupta
    Linked in: / kanahaiya-gupta
    Facebook: / coolkanahaiya
    Instagram: / coolkanahaiya
    #JAVAAID #HackerRankSolutions #HackerRankTutorials #implementation #prefixsum #HackerRank #JavaAidTutorials #Programming #DataStructures #algorithms #coding #competitiveprogramming #JavaAidTutorials #Java #codinginterview #problemsolving #KanahaiyaGupta #hackerrankchallenges

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

  • @JavaAidTutorials
    @JavaAidTutorials  5 ปีที่แล้ว +19

    Hello Coding Lover,
    If you have any doubts , please let me know in comments.

  • @MiketheCoder
    @MiketheCoder 5 ปีที่แล้ว +52

    Damn. I did this in a codechef contest, and I didn't even know what it was :) !! Thanks for this!!

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

      most welcome..!! 😃

    • @sridevipatil8565
      @sridevipatil8565 4 ปีที่แล้ว +2

      I saw your video on prefix algorithm

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

      @@sridevipatil8565 yay! Thank you!

    • @hil449
      @hil449 3 ปีที่แล้ว +2

      wow really? Thats so awesome, to come up with something real by yourself on the fly

  • @bidishadas832
    @bidishadas832 4 ปีที่แล้ว +25

    Extremely well explained. Thank You So Much, Sir.

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

    Liked before I even finished watching. So simply explained, slowly and well visualised, and you don't try to sound smart by complicating things. Thank you!

  • @hil449
    @hil449 3 ปีที่แล้ว +12

    Thank you so much man. This algorithm is sooo smart yet so simple. Its just mind blowing. And your explanation is very good. Thank you man, you should be proud of yourself because you're helping tons of people here

  • @amangoel8724
    @amangoel8724 4 ปีที่แล้ว +3

    you made my day

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

    Wow, just awesome man... This thing will now solve every possible problem in an array within O(n) time like Maximum Subarray sum, and all.

  • @visheshvaidya8625
    @visheshvaidya8625 10 หลายเดือนก่อน

    Range query formula will be valid when value of i>0 otherwise it gives out of array lower bound runtime error...
    Thank you sir for providing such amazing lecture on prefix
    sum.

  • @akshat2808bspr
    @akshat2808bspr 4 ปีที่แล้ว +2

    nice one

  • @vibekdutta6539
    @vibekdutta6539 5 ปีที่แล้ว +10

    This is an awesome channel, keep the videos coming sir, we need them!

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

      Thanks for the compliment Vivek. these kinds of comments really motivate me to do more and better.
      thanks for watching and keep commenting ..:)

    • @vibekdutta6539
      @vibekdutta6539 5 ปีที่แล้ว +4

      And these kinds of channel help us grow, thanks

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

      thanks@@vibekdutta6539Dutta. I really appreciate it.

  • @yasirahmed4197
    @yasirahmed4197 3 ปีที่แล้ว +2

    Nice explanation

  • @mdkashifraza2603
    @mdkashifraza2603 2 ปีที่แล้ว +1

    Thanks for the clear explanation of this concept.

  • @gkarthik55
    @gkarthik55 9 วันที่ผ่านมา

    Excellent😃

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

    Well explained, thanks for the video.

  • @hirunh4703
    @hirunh4703 3 ปีที่แล้ว +1

    You are better than my Professor at my university Thanks a lot

  • @emmanuelay3956
    @emmanuelay3956 3 ปีที่แล้ว +1

    Very useful, thank you for sharing.

  • @saravinfotech
    @saravinfotech 4 ปีที่แล้ว +2

    I just stumbled up on your videos and this was the second video I watched after watching why Pre-fix algorithm. I really liked that you had first put up a video to say what is the difficulty the Algorithm is going to address and then explaining the alogrithm. Wonderful job, keep going.
    Is there a specific order which you would recommend for us to follow though the datastructure course? Also can you please add the Hacker rank challenges which might use the specific algorithms which you explain. That would help us practice online on things you teach as well.
    Appreciate your good work.

    • @JavaAidTutorials
      @JavaAidTutorials  4 ปีที่แล้ว +2

      Thanks a lot @Saravanan for your detailed feedback, I really appreciate the effort you have put in just to write this feedback which generally people ignore but trust me it really motivate us to do more for you all.
      I can see you have query upon the video sequence which is a valid ask but i have chosen topic randomly for my channel to see which topic people are liking or getting views because my channel is very small, so need good amount of view for growing.
      we have currently 55 videos on our channel but once we add couple of more videos, will define the proper track or playlist how a person should watch the content to gain most out of it. but for now you can pick any playlist or may be start with NEW TO JAVAAID playlist.
      Will are trying to add some problems on video description, so that people can go and solve it after watching the tutorial.
      Thanks for the appreciation...!!
      If you find our content helpful please do share among your friends.

    • @saravinfotech
      @saravinfotech 4 ปีที่แล้ว +1

      @@JavaAidTutorials will definitely do

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

      Thank you..!!

  • @VugloTVTVVugloTVTV-jv8rk
    @VugloTVTVVugloTVTV-jv8rk 4 หลายเดือนก่อน

    Many thanks sir for sharing 🙂

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

    Best video about this topic all across internet

  • @Noone-kl6sc
    @Noone-kl6sc 3 ปีที่แล้ว +1

    nicely explained

  • @preshitha169
    @preshitha169 3 ปีที่แล้ว +1

    useful

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

    i understood it and i enjoyed :) learning this

  • @mb77mb66
    @mb77mb66 3 ปีที่แล้ว +1

    Thank you sir for this video.

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

    such good explaination, thank yoouuu

  • @sanjeevkumar-iw2lz
    @sanjeevkumar-iw2lz 2 ปีที่แล้ว +1

    very good explanation, got it in one go🔥. Thank you

  • @KevinTheDev2009
    @KevinTheDev2009 9 หลายเดือนก่อน

    Great video, you saved me tons of time!

  • @Spider-Man_67
    @Spider-Man_67 ปีที่แล้ว +1

    Sir, I'm in love with your crystal clear explanation, MAZA AAGYA...GOING TO subscribe your channel now!!!!

  • @amangoel8724
    @amangoel8724 4 ปีที่แล้ว +1

    Awesome Brother keep doing the good work

  • @Spiegeldondi
    @Spiegeldondi 3 ปีที่แล้ว +1

    very good and detailed explanation!

  • @praveenambati7804
    @praveenambati7804 4 ปีที่แล้ว +1

    Watching your first video. Amazing ! Impressed of your explanation. Subscribed (Y) cheers !!

  • @surbhitamrakar1638
    @surbhitamrakar1638 3 ปีที่แล้ว +1

    Simple clear and accurate explanation..

  • @shashankdavalgiomprakash2109
    @shashankdavalgiomprakash2109 2 ปีที่แล้ว +1

    Amazingly explained!!

  • @Rahulmohan-mv6nq
    @Rahulmohan-mv6nq 3 ปีที่แล้ว +1

    Excellent expalanation!

  • @CodeNCode-rm8ci
    @CodeNCode-rm8ci 2 ปีที่แล้ว

    Thank you so much sir......very nicely explained.

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

    nice, it's help me so much

  • @quocthinh10a25
    @quocthinh10a25 2 ปีที่แล้ว +1

    keep doing the good work you helped me alot

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

    Gold!

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

    Best explanation! Thank you Bro

  • @ankitkumarsingh9815
    @ankitkumarsingh9815 4 ปีที่แล้ว +2

    God bless you Sir!... Thanks for these great tutorials. Please keep doing this, we all love the way you explain us.

    • @JavaAidTutorials
      @JavaAidTutorials  4 ปีที่แล้ว +1

      Thank you very much for your feedback..!!

    • @ankitkumarsingh9815
      @ankitkumarsingh9815 4 ปีที่แล้ว +1

      @@JavaAidTutorials please make this channel for competetive coding using JAVA. It would be really great for us.

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

      Yaa, i am trying my best to help people who is preparing for competitive programming.but without your support its not possible.
      So please support us by sharing our Channel.

  • @angkonnath-fw4wu
    @angkonnath-fw4wu ปีที่แล้ว +1

    thanks for this tuto

  • @harishkulkarni7244
    @harishkulkarni7244 2 ปีที่แล้ว +1

    Your explanation is very useful sir, and what a great algorithm!

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

    very well explained thnx

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

    Thank you so much! Now i got why A[i-1]!

  • @mistershaya
    @mistershaya 3 ปีที่แล้ว +1

    Thank you, it was very helpful.

  • @sanjuktasharma00
    @sanjuktasharma00 10 หลายเดือนก่อน

    Amazing explanation!

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

    salute to you, improved my code, thank you

  • @dikatsogaleboe3640
    @dikatsogaleboe3640 3 ปีที่แล้ว +1

    This was well explained. Thank you!

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

    This is the most brilliant example on the internet

  • @pritisha1
    @pritisha1 3 ปีที่แล้ว +1

    Very clear and helpful visuals, thank you

  • @shashankmishra001
    @shashankmishra001 4 หลายเดือนก่อน

    Great explanation ❤

  • @ashwini6740
    @ashwini6740 2 หลายเดือนก่อน

    grt explanation,tq

  • @punithajeeva6702
    @punithajeeva6702 3 ปีที่แล้ว +1

    Thank you so much sir! Slowly & clearly explained !! Keep up the good work 😊

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

    Good explanation, thanks!

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

    thanks for making it easy sir

  • @deeproy7292
    @deeproy7292 3 ปีที่แล้ว +1

    thanks man...never thought in such a way

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

      Glad to know that someone learnt something new from my channel. 🙂
      Keep learning , keep growing.

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

    loved the video, Thanks Javaaid

  • @longhk24492
    @longhk24492 11 หลายเดือนก่อน

    Nice tutorial

  • @MrTaekbeen
    @MrTaekbeen 3 ปีที่แล้ว +1

    Great explanation! You saved my life

  • @elernen9619
    @elernen9619 4 ปีที่แล้ว +1

    Your videos are so good, I don't even skip the ads

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

    thanks for this video, it was usefull ...

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

    You just clear my doubts very easy , Thank you sir
    😇

  • @ShreyaSingh-yl9ec
    @ShreyaSingh-yl9ec 3 ปีที่แล้ว +1

    Such a wonderful and easy explanation! Thank youu Sir.

  • @nehemiahdevineedi2028
    @nehemiahdevineedi2028 3 ปีที่แล้ว +1

    Fantastic Explanation! Thank you, Sir.

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

    Nice

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

    So clear thank you!

  • @ajayreddytutorials
    @ajayreddytutorials 4 ปีที่แล้ว +1

    Nice one bro 👍

  • @muralikrish9515
    @muralikrish9515 4 ปีที่แล้ว +1

    Thanks brother really i like your explanation.

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

    This is mind blowing algorithm

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

    i found this very useful to solve array manipulation problem by watching urs that video

  • @vivekvitthalraopatil2775
    @vivekvitthalraopatil2775 4 ปีที่แล้ว +1

    great job! this channel is going to cross 100k this year.

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

      Thanks a lot for your wonderful comment.
      All goodies in your mouth.. 🙂
      Let's see, but if you find my channel helpful, please share with others.

  • @nilanjansarkar100
    @nilanjansarkar100 3 ปีที่แล้ว +1

    Wonderful video. But it would have helped, if you had given an actual problem to demonstrate this technique like you did for the two pointer technique

    • @JavaAidTutorials
      @JavaAidTutorials  3 ปีที่แล้ว +1

      thanks, we have added one video link in the description which will help to understand how prefix sum algorithm can be used in actual coding problem.
      🙋 Problem to solve : th-cam.com/video/hDhf04AJIRs/w-d-xo.html

    • @nilanjansarkar100
      @nilanjansarkar100 3 ปีที่แล้ว +1

      @@JavaAidTutorials Thanks!

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

    your visualization makes everything easier brother thanks for videos

  • @antonu17
    @antonu17 4 ปีที่แล้ว +1

    Thank you for the explanation. Clear and concise!

  • @thrivecoder1843
    @thrivecoder1843 4 ปีที่แล้ว +1

    To the point sir, thank you so much ✌️

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

    Explained very clearly ✔

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

    Just one word. CLEAN.

  • @ЕвгенийСавицкий-й2щ
    @ЕвгенийСавицкий-й2щ 4 ปีที่แล้ว +1

    Thanks a lot! Good explanation!

  • @monicaceisel3139
    @monicaceisel3139 4 ปีที่แล้ว +1

    Fantastic explanation! Thank you! Very understandable

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

    THANKS for this keep making more such videos

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

      most welcome @Ashish.
      I am trying my best ..!!
      mean while, if you find it useful , please share it among your friends..!!

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

    Thank you so much for publishing this video. It helped a lot. If you get the time then please upload more.

  • @merhawifissehaye6307
    @merhawifissehaye6307 4 ปีที่แล้ว +6

    The significance of the algorithm is visible when you have m queries to make. Having an O(n) complexity just to calculate the sum of a range of elements is not better than using an ordinary for loop. Both have O(n) complexity. But for m queries , the ordinary for loop ha O(m*n) whereas the prefix sum has O(m + n) complexity. Better to close your video that way. Nice explanation though.

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

      Thanks for the feedback. will keep this thing in mind while making future tutorials.

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

      i was looking for this comment

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

    Awesome content !!
    Sir, very good explanation with pictures understood it very better.
    Thank You.

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

      Thanks a lot, @SagaRock101 for your compliment.

  • @venpro8705
    @venpro8705 4 ปีที่แล้ว +1

    Super bro

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

    Thank you so much for all your videos. Your explanations are so clear and concise.

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

    Simple and clean explanation!

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

      Thanks a lot, Joydeep for appreciating.
      Keep watching..!!

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

    great video

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

    Marvelous Explanation !!! Hats off

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

    Very clear! Thank you!

  • @cadenphillips2244
    @cadenphillips2244 4 ปีที่แล้ว +1

    thank you for the explanation!

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

    Very neat and great presentation

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

    Thanks a lot. It was very helpful.

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

    Thanks for posting!!

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

    great video! my professor made this sound way more complicated than it is lol. now i need to learn how to do this applied to 2d arrays

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

    This is really nice! Thanks for the clear explanation!

  • @Anna_handcrafts
    @Anna_handcrafts 4 ปีที่แล้ว +1

    thanks mate

  • @Eng_Aya
    @Eng_Aya 3 ปีที่แล้ว +1

    Thank you

  • @arkadiyshuvaev
    @arkadiyshuvaev 4 ปีที่แล้ว +1

    Well done, great work! I have been really impressed by your simple explanation :)

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

      Thanks you very much for your feedback.😊

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

    Love your video, very clear explanation.

  • @sarthakyadav9950
    @sarthakyadav9950 3 ปีที่แล้ว +1

    The explanation was very nice.But i have a query
    So to after applying this algorithm we can access the sum of any index or range of indexes in O(1) time complexity but to find the prefix sum array the complexity is still going to be O(n) so how is this really optimised?

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

      In a situation where you have up to n queries for example, the algorithm will still be O(n) instead of O(n²) if you do the sum in normal way

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

    This is really awesome channel.... thanks and keep up the good work !!!