Subarray Sum Equals K | Count Subarrays with Sum Equals K | Hashmap Interview Questions Playlist

Sdílet
Vložit
  • čas přidán 17. 10. 2020
  • Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
    NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the problem count of subarray sum equals K using hashmaps in java. In this problem,
    1. You are given an array of integers(arr) and a number K.
    2. You have to find the count of subarrays whose sum equals k.
    To attempt and to submit this question, click here: www.pepcoding.com/resources/d...
    For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
    #hashmaps #datastructure #algorithms
    Have a look at our result: www.pepcoding.com/placements
    Follow us on our FB page: / pepcoding
    Follow us on Instagram: / pepcoding
    Follow us on LinkedIn: / pepcoding-education

Komentáře • 173

  • @sleepypanda7172
    @sleepypanda7172 Před 2 lety +35

    I understood within the first 1:11 minutes because your way of explaining was crystal clear. Thanks a lot!

  • @vadirajjahagirdar9342
    @vadirajjahagirdar9342 Před 3 lety +34

    Best teacher for coding on CZcams. Hands down, nobody is even close to him. Thanks Sir. I wish to meet you one day and thank you for your videos.

  • @sachinkarve5272
    @sachinkarve5272 Před 2 lety +2

    Excellent. As someone said, the solution was clear within the first minute. Awesome!

  • @vandanabanny7550
    @vandanabanny7550 Před 2 lety

    I was searching for this video, you nailed it. Thanks a ton :)

  • @thegreekgoat98
    @thegreekgoat98 Před rokem +2

    One of the brilliant explanation to this problem on entire CZcams

  • @aakashyadav6228
    @aakashyadav6228 Před 3 lety

    Congratulations on 50K. Many more achievements to come !!

  • @Joyddep
    @Joyddep Před 3 lety

    Thanks for the explanation. Great visualization!

  • @ArjunSingh-of6vm
    @ArjunSingh-of6vm Před 3 lety +16

    literally nice way to explain

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta,
      I am glad you liked it. I also hope that you are watching till end.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

  • @sachinsharma905
    @sachinsharma905 Před 3 lety +1

    Great Explanation. Thank you for your help

  • @SarabjotSingh294
    @SarabjotSingh294 Před 3 lety

    This is a really great explanation! Great work.

  • @piyushgaur6188
    @piyushgaur6188 Před 3 lety

    Sir ji DilJeet aapki explanation.....PEPCODING ROCKS👌❤

  • @cavi8779
    @cavi8779 Před 2 lety

    poori u tube mein sabse acha coding explanation aap hi kre ho.....jb b kisi qsn mein fnstaa hoon or us qsn ki aap ki vdo mil jaati hai to man bahoot hi khush hoo jata hai😊😊

  • @vetiarvind
    @vetiarvind Před 2 lety +3

    Amazing, i am not a hindi native speaker but i understood your explanation perfectly. Nice idea of doing a run through the array and explaining k and y-k and maintaining count of prefix sum occurance.

  • @Vishalkumar-nl2ud
    @Vishalkumar-nl2ud Před 2 lety

    Thank you for explanation, it really helps me.

  • @sameersondur9030
    @sameersondur9030 Před 3 lety +11

    Absolutely Fantastic!! I am amazed by your ease to explain.
    Appreciate your help. I will send your links to my friends who are prepping.

  • @gayatrih2241
    @gayatrih2241 Před 4 měsíci

    Your explanation has always been helpful!

  • @iuashrafi
    @iuashrafi Před rokem

    Great sir ! thankyou so much !

  • @kartiksoni5302
    @kartiksoni5302 Před 2 měsíci

    BEST EVER EXPLANATION.

  • @aashritamutkiri5071
    @aashritamutkiri5071 Před 2 lety

    Very well explained!!!! Thank you sir!!!!!!

  • @harshagirish4579
    @harshagirish4579 Před 3 lety

    Excellent video. Great explanation

  • @uniqueanshu4268
    @uniqueanshu4268 Před rokem

    OMG.. What a explanation !🎉

  • @artyCrafty4564
    @artyCrafty4564 Před 8 měsíci

    Underrated channel

  • @nikhilagrawal9217
    @nikhilagrawal9217 Před 7 měsíci

    Thanks a lot for this video. Seeing this for my interview preparation.

  • @sujan_kumar_mitra
    @sujan_kumar_mitra Před 2 lety +1

    Your dry run skills are really good!

  • @SanaAnsari9618
    @SanaAnsari9618 Před 5 měsíci

    After watching your video I got this problem, I tied up with this problem since long . finally you made me rid of it.

  • @vishalbarvaliya2849
    @vishalbarvaliya2849 Před 2 lety

    Sir.....apni jaaan & puri shiddat se padhata hai..ki...bas yahi efforts se kisika bhi interest and intuitions badh jayenge. Hats OFF

  • @tishaagarwal9435
    @tishaagarwal9435 Před 2 lety

    thank u for the explanation

  • @tanvitripathi5743
    @tanvitripathi5743 Před 2 lety +1

    Very kind person

  • @mercerkace2023
    @mercerkace2023 Před 2 lety

    Thanks for this easy explanation.

  • @niteenautade
    @niteenautade Před 2 lety

    Very well explained!

  • @md.rejwanahmed293
    @md.rejwanahmed293 Před 23 dny

    Thanks a lot man. Finalyy i have understood

  • @abhishekkumargupta3605

    finally got it, thanks a lot😊

  • @pankajkohli9263
    @pankajkohli9263 Před 3 lety +4

    Very Nice explanation. Thanks for covering the edge case scenario when index from 0 to "i" itself is sum. I have solved this problem before but never thought of this case. Thanks again Sumeet Sir, Thanks Pepcoding :)

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

  • @ravimishra8632
    @ravimishra8632 Před 2 lety +5

    Had trouble getting this ques, 4th video for on this question. Finally got it. Thanks a lot. You teaching style is great!

  • @saicharank9143
    @saicharank9143 Před rokem +1

    Awesome explanation

  • @GhostRider....
    @GhostRider.... Před rokem

    Very clear explanation sir 🔥🔥

  • @atulsingh1438
    @atulsingh1438 Před 2 lety

    Awesome explanation 🔥

  • @ShabnamKhan-cj4zc
    @ShabnamKhan-cj4zc Před 3 lety

    Awsome explanation. Thanks a lot for explaining in simple terms. Keep doing the great work.

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thankyou beta!
      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
      Keep learning and keep loving Pepcoding😊

  • @dhruvasoni6454
    @dhruvasoni6454 Před 2 lety

    best explaination sir, abhi ek hi video dekh rha thaa and he told me , rat ko imeediate apki dekhi and crsytal clear ++, app c++ mein bhi code kare, it would helpfull for many students

  • @tarunsingh5615
    @tarunsingh5615 Před rokem

    lovely explaination

  • @sunilpanchal1498
    @sunilpanchal1498 Před 2 lety

    Great explanation sir, Keep it up

  • @sahilkaul6199
    @sahilkaul6199 Před rokem

    Thanks for teaching bhai

  • @pranays6503
    @pranays6503 Před rokem

    Best explanation sir :)

  • @shreyasvishwakarma8979
    @shreyasvishwakarma8979 Před 3 lety +2

    Thank you sir! Great Explanation so far!

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Glad it was helpful! and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @mansigoyal4796
    @mansigoyal4796 Před 3 lety +1

    Best channel ever. Sir you teach questions in very friendly way. Thanku sir 😊

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta!
      I am glad you liked it. I also hope that you are watching till the end and trying to understand the what, how, and especially why of the problem. If you like our efforts, will you like to review us here - g.page/Pepcoding/review?rc

  • @hehebohey3747
    @hehebohey3747 Před 3 měsíci

    I was soo confused for this problem But sir you Have Explained Excellent

  • @DeepakSaini7900
    @DeepakSaini7900 Před 3 lety +1

    Gazab explain sir maza aa gya

  • @ZentrexGaming
    @ZentrexGaming Před 2 lety

    sir maza aagaya firse

  • @UEI_HimadriShekharChakraborty

    Moment at 1:00 , made all my confusions disappear , was stuck for a while till now. Thanks sir

  • @tejasgulati3080
    @tejasgulati3080 Před 3 lety +10

    Thank you soo much. You are a savant at explaining these. This is the most straightforward video on the topic. Keep up the good work my man!

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

    • @rahulranjan7567
      @rahulranjan7567 Před 3 lety

      Savant, yes thats the word I would use to describe his explaining skills. He can single handedly jack up the toughness levels of interviews and this will happen in coming days. After his videos it becomes easy to visualize stuffs. Bass DP nahi phoot rahi merese lol

    • @ridgeadam8442
      @ridgeadam8442 Před 2 lety

      I know Im randomly asking but does any of you know of a trick to get back into an Instagram account?
      I stupidly lost my login password. I would appreciate any assistance you can offer me

    • @isaacbobby8571
      @isaacbobby8571 Před 2 lety

      @Ridge Adam Instablaster ;)

    • @ridgeadam8442
      @ridgeadam8442 Před 2 lety

      @Isaac Bobby i really appreciate your reply. I got to the site through google and I'm trying it out now.
      Looks like it's gonna take quite some time so I will get back to you later when my account password hopefully is recovered.

  • @sinister_rules
    @sinister_rules Před rokem

    next level teacher👌👌

  • @akhileshkumarsingh3322

    gajab!!

  • @rudreshajgaonkar
    @rudreshajgaonkar Před 2 lety

    Gajab explanation. Ek number bhai.

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Hope you love the explanation.
      For better experience and well organised content visit - nados.io and keep supporting us. 🙂

  • @sahiljain2524
    @sahiljain2524 Před 3 lety

    Nice explanation pata hi nhi chala kab khatam ho gya 😅.. Thank you 🙌

  • @madanmohanpachouly6135

    bahut sahee.

  • @leslieamaron8053
    @leslieamaron8053 Před 3 lety +6

    Bro, thanks for explaining everything with so much patience. Finally samajh me aaya ki subarrays += map[prefSum - k] kyu kar rhe hai.
    Possible variations of question:
    > Find if subarray with sum exists; find range
    > Find biggest/smallest subarray with sum; range
    > Find no. of subarrays with sum; find ranges

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thankyou
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

    • @sriramvemaraju845
      @sriramvemaraju845 Před 2 lety +1

      Please try to explain in english. I understand hindi no worries for me. I could not find this explanation anywhere on CZcams. You have a unique skill and deserve to have an international audience.

  • @heenasharma5076
    @heenasharma5076 Před 3 lety

    Ur explanation is always very fluid in all your videos...must watch

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thankyou beta,
      I am glad you liked it. I also hope that you are watching till end.
      Will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms)

  • @akhileshparmar1061
    @akhileshparmar1061 Před 3 lety

    You nicely explained this solution especially why 0 frequency should be added at the beginning. Thanks for making this video.

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @sourvad
    @sourvad Před 3 lety

    Ah finally I get it, thanks!

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Keep learning and keep growing😊
      If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

  • @GauravThinks
    @GauravThinks Před 6 měsíci

    sumeet sir's explanation is 💎

  • @keshav9541
    @keshav9541 Před 2 měsíci

    sir i try to clear this question from many youtuber but the way you clearly show dry run hands down sir

  • @tanishkumar6682
    @tanishkumar6682 Před rokem

    understood

  • @atmanirbharladka4467
    @atmanirbharladka4467 Před 2 lety +1

    I watched 3-4 videos for this question. Here, I understood the concept in the first 1 min.

    • @Pepcoding
      @Pepcoding  Před 2 lety +2

      Glad it helped!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @muskansawa2802
    @muskansawa2802 Před 3 lety

    tysm , itna acha hota hai jab koi hindi mai batat hai , kyuki i also think in hindi , dusre tutorial samjne mai jyada time lagta hai , thanks thanks thanks!

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thank you so much and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @sparshgupta9900
    @sparshgupta9900 Před 3 lety

    Literally feel aati hai sir aapse padke. The reason is aap proper teacher lagte ho..jaisa hame 12 and iit tak mile hai and unse padkar feel aata hai padai kaa

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @leetcode7091
    @leetcode7091 Před rokem

    First 1 min made me understand the solution.

  • @DSA_Coding
    @DSA_Coding Před 2 lety

    gjb sir

  • @abhishekrai4325
    @abhishekrai4325 Před 3 lety

    Thank you sir ji 🙏❤️

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Keep learning, keep supporting

  • @hiteshbhatia5609
    @hiteshbhatia5609 Před rokem

    but how to print all those subarrays because if frequency of any sum is greater then 1 then how would we get more then 1 subarrays starting index from hashmap so that we can print all subarrays?

  • @KinnarKansara
    @KinnarKansara Před 3 lety

    Nicely explained!!

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Glad you liked it
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      czcams.com/users/Pepcodingabout?view_as=subscriber
      For clearing your doubts, you can join our community on telegram
      t.me/pepcoding

  • @mrprime557
    @mrprime557 Před 2 lety

    Amazing !!!

    • @Pepcoding
      @Pepcoding  Před 2 lety

      For better experience visit on nados.pepcoding.com
      Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @gautamkhatik251
    @gautamkhatik251 Před 2 lety

    wish I could have been watch this video before, was able to save a big amount of time

  • @sahilanand30
    @sahilanand30 Před 2 lety +1

    Best explanation

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad you think so!
      For better experience and well organised content visit - nados.io

  • @SumitSingh-ui4do
    @SumitSingh-ui4do Před 2 lety

    Great explanation ❤️🙏🙏🙏

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad it was helpful!
      Keep learning.
      And for better experience and well organised content visit nados.pepcoding.com

  • @moozaheed9568
    @moozaheed9568 Před 2 lety

    Love from BD

  • @bhatnagarcapital
    @bhatnagarcapital Před 5 měsíci

    wow!

  • @subhamoyburman3093
    @subhamoyburman3093 Před 3 lety

    Bhaiya itne accha kaise samjha lete ho aap

  • @shivammehta9661
    @shivammehta9661 Před 3 lety

    Very Nice Explanation.....Keep making videos

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Sure. Keep learning, Keep growing and keep loving Pepcoding!😊

  • @_inspireverse___
    @_inspireverse___ Před 2 lety +1

    Wow ! So much wow

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad you liked it!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @rahulpothula1902
    @rahulpothula1902 Před 2 lety

    will it run for the test case [1], target = 0??

  • @kanhaiyatulsyan7560
    @kanhaiyatulsyan7560 Před 3 lety

    can we not put (0,1) in starting and check if sum==k at any instant then we do count++;

  • @syedhabeebuddin101
    @syedhabeebuddin101 Před 3 lety

    Thankssssssss!

  • @RajeshKumar._.16
    @RajeshKumar._.16 Před rokem

    nice

  • @kishorchintalchere
    @kishorchintalchere Před 3 lety

    Best explanation 🔥🔥✌️✌️👍👌👌

    • @Pepcoding
      @Pepcoding  Před 3 lety

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      czcams.com/users/Pepcodingabout?view_as=subscriber

  • @Satyam_-bb5ly
    @Satyam_-bb5ly Před 2 lety

    Could you please make a video on maximum subarray sum closest to k ?

  • @rajugoud6465
    @rajugoud6465 Před 3 lety +1

    Great work Bro..

    • @Pepcoding
      @Pepcoding  Před 3 lety +2

      Thankyou beta!
      I am glad you liked it. I also hope that you are watching till the end and trying to understand the what, how, and especially why of the problem. If you like our efforts, will you like to review us here - g.page/Pepcoding/review?rc

  • @eshanikabhattacharjee383
    @eshanikabhattacharjee383 Před 3 lety +1

    how to get the intuition for such tricks

  • @mohitv7405
    @mohitv7405 Před 2 lety

    How can we display the subarray?

  • @muskansawa2802
    @muskansawa2802 Před 3 lety

    subha se jis problem mai fail hori thi , ek baar yeh vedio dekh ke hogaya , maine ferquency nai count kiya tha yeh mera mistake tha! itni khushi XD i wish i could give this vedio a heart ❤❤

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

  • @balwantyadav724
    @balwantyadav724 Před 3 lety +1

    sir ekdam mast padhaate ho aap har topic ko.. fan ho gya aapka sir

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @adarshupadhyay8738
    @adarshupadhyay8738 Před 2 lety +2

    sum 15 has a frequency 2 but bhaiya in the second occurence of sum 15 you have written 1 below it. it should be 2 not 1.

  • @drishtdyumnshrivastava5313

    nc explanation
    ....tnks

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta!
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
      Keep learning and keep loving Pepcoding😊

  • @aryashjain7893
    @aryashjain7893 Před rokem

    what if we take target-sum instead

  • @karthiklv29
    @karthiklv29 Před 2 lety +1

    Even though i dont understand hindi very well, i come here for the amazing explanations :)

  • @samarthsingh663
    @samarthsingh663 Před 2 lety

    Sir first of all thing thank you for the explanation but i wanted to know why 2 pointer approach is failing here.

  • @cenacr007
    @cenacr007 Před 2 lety

    Everytime I face a coding problem and come to utube to look for a solution, my only hope is I find a solution video by Sumeet Sir.

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Happy to help!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @arupdas2210
    @arupdas2210 Před 2 lety

    I have just one doubt. If k=0 then "ans" should be "ans-1" and if ans-1

  • @1991deeps
    @1991deeps Před 3 lety +1

    You should write continuous sub-array as this solution would not do for non-continuous sub-arrays.

  • @alokkulkarni10
    @alokkulkarni10 Před 3 lety +2

    Explanation mast hai.. English subtitles add kar do, International viewers bhi add ho jayenge

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thankyou!
      Hnji, krvata hu add beta technical team ko bol k

  • @sauravsemwal1346
    @sauravsemwal1346 Před 3 lety

    Sir , aapka explanation bhut bdiya hai...
    Video ke title me leetcode problem no. bhi dal do easily search me aayega.....