Subarray with sum 0 | GeeksforGeeks | Hashing data structure | Leetcode DSA series | Prefix Sum

Sdílet
Vložit
  • čas přidán 7. 09. 2024
  • This is the video under the series of DATA STRUCTURE & ALGORITHM in a HASHING Playlist. We are going to solve the problem "Subarray with 0 sum" from geeks for geeks which are solved by using unordered_set in c++
    Given an array of positive and negative numbers. Find if there is a subarray (of size at least one) with 0 sum.
    Input:
    5
    4 2 -3 1 6
    Output:
    Yes
    Explanation: 2, -3, 1 is the subarray with sum 0.
    We also Provide courses on Competitive Programming and Data structure and Algorithms. Please see our Full Playlist on our Channel.
    ----------------------------------------------------------------------------------------
    Subarray with 0 sum: practice.geeks...
    code in This Video: github.com/Pri...
    Pdf in this video: github.com/Pri...
    ----------------------------------------------------------------------------------------
    *Unacademy *
    INVITATION CODE: HELLOWORLD
    Daily classes and courses: unacademy.com/...
    Open for All classes: unacademy.cc/da...
    BATCHES FOR INTERMEDIATES
    UPRISE (Track 1): Complete Course on Transitioning from Python to C++: bit.ly/3dCWfxB
    UPRISE (Track 2): Complete Course on Transitioning from JAVA to C++: bit.ly/3sEwZv5
    Prodigy 2.0: Advanced Data Structures and Algorithms: bit.ly/3dC2vWh
    BATCHES FOR BEGINNERS
    SUMMIT 2.0- Comprehensive Course on Data Structures and Algorithms: bit.ly/2RVLfTF
    Check out the star educators here: unacademy.cc/Ed...
    ----------------------------------------------------------------------------------------
    *Follow me *
    LinkedIn► / iamprince
    Facebook► / helloworldofficials
    Instagram► / helloworldbyprince
    Twitter► / prince_king_
    Telegram► telegram.me/he...
    ----------------------------------------------------------------------------------------
    ►Our Playlists on:-
    ►Competitive Programming: • How to start Competiti...
    ►C++ Full Course : • L-01 || Introduction a...
    ►Algorithms: • L-01 || Prefix Sum Arr...
    ►Data Structure: • Data Structures with C...
    ------------------------------------------------------------------------
    🌟 Please leave a LIKE ❤️ and SUBSCRIBE for more AMAZING content! 🌟
    ✨ Tags ✨
    how to find Subarray with 0 sum
    question asked in Goldman Sachs interview
    how to crack Goldman Sachs online test
    how to crack Goldman Sachs
    off-campus placement
    how to learn to code for beginners
    Subarray with 0 sum
    hashing in data structure
    Best Telegram channel for Off-campus Placement drive
    hashing in a data structure in Hindi
    unordered_set
    #hashing #geeksforgeeks #programming

Komentáře • 86

  • @rohitrajput2097
    @rohitrajput2097 Před 4 měsíci +1

    00:02 Understanding the importance of the subarray with sum 0 question.
    01:28 Finding subarray with sum 0 using hashing
    02:47 Understanding memory location in a nutshell
    04:15 Creating a function with a loop and 500 silencers for a specific calculation
    05:40 Identifying subarrays with sum 0
    07:05 Understanding prefix sum and subarrays
    08:34 Understanding the concept of subarrays and prefix sum
    10:13 Understanding subarrays with sum 0

  • @anweshangoswami5636
    @anweshangoswami5636 Před 2 lety +4

    Thanks a lot....that diagram of presum1==presum2 cleared everything

  • @nutankumari9977
    @nutankumari9977 Před 2 lety +4

    Thanks for explaining this prefix sum concept in ease way 😊

  • @41_adityasakpal20
    @41_adityasakpal20 Před rokem +1

    THANK YOU BHAIYA ,aapki video dekhnese phele solve hi nahi ho paa raha tha

  • @adityamehra8239
    @adityamehra8239 Před měsícem

    thanks for explaining bro

  • @AmberSparrow876
    @AmberSparrow876 Před 9 měsíci

    Your way of explaining is amazing... thank you so much sir 👏👏

  • @tanmaykumar5124
    @tanmaykumar5124 Před rokem

    vector hash; // ? hash arr to store the sum
    int prevsum=0; // ? taking the prevsum for store prifixSumArr.
    for(int i = 0; i < size; i++){
    if(arr[i] == 0) return "no"; // ? if we found a 0 in between then directly send yes.
    else if(binary_search(hash.begin(), hash.end(),prevsum+arr[i])){
    return "yes"; // ? if we get the prefix sum stored in hash before then we return true/yes.
    }
    }

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

    class Solution{
    public:
    //Complete this function
    //Function to check whether there is a subarray present with 0-sum or not.
    bool subArrayExists(int arr[], int n)
    {
    //Your code here
    unordered_sets;
    int currsum = 0;
    s.insert(0);
    for(int i=0; i

  • @RafaelCostaBraga
    @RafaelCostaBraga Před 9 měsíci +1

    Why is the result false for this list [200, 100, -13589, -4, 13589], and it should be true?

  • @DIVYAGUPTA-wu9oy
    @DIVYAGUPTA-wu9oy Před 2 lety +1

    you great really
    explanation is toooooooo good.

  • @RitikaBaliyan-go3pn
    @RitikaBaliyan-go3pn Před měsícem

    Nice question ❤

  • @amitpatel41246
    @amitpatel41246 Před 3 měsíci +1

    thanku

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

    Keep it continue
    Thanks!!!

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

      That's the plan!
      keep learning buddy and be consistent and share my channel with your college groups that helps me a lot

    • @avinashdharme2234
      @avinashdharme2234 Před 3 lety

      @@HelloWorldbyprince surely, BTW I have done my graduation, now I m working

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

    In this example {-3,4,-3,-1,1} when u stopped at interator 3 previous array which is (-3,4,-3) not having the sum 0

  • @mayurigawande5973
    @mayurigawande5973 Před rokem

    Awesome Explaination😍

  • @satyamgupta6030
    @satyamgupta6030 Před rokem

    thanks bhaiya for such a good explaination.

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před rokem

      keep learning and keep sharing my channel with your friends and in colleges thanks satyam

  • @akarshitgupta6359
    @akarshitgupta6359 Před rokem +2

    watched 2 time because of variable name prefSum1 and prefSum2... 6:33 .. you said ki "vaule aaya one" .. overall explanation was very good..

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před rokem +1

      Thanks for the support buddy Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @MilindGupta
    @MilindGupta Před 3 lety +3

    Bhai thodi aur jldi jldi videos daalo and medium level pblm please

  • @masumali8356
    @masumali8356 Před rokem

    you are the best.........masum.

  • @Sonukumar-um3cs
    @Sonukumar-um3cs Před 3 lety +3

    First view sir you are 🔥sir

  • @gokulnaathbaskar9808
    @gokulnaathbaskar9808 Před 11 měsíci

    Thank you so much, that was easy!

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

    Excellent tutorial

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

    Life is not about achieving things.
    Its about progress*. It will suit more.

  • @oqant0424
    @oqant0424 Před rokem +1

    12/18 done (8.12.22)

  • @yellaharshavardhan9851

    Great Video

  • @harsh_govind
    @harsh_govind Před rokem +1

    chamak gya... thanks

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

    Bhaiya, not just tree, graph as well.
    Please start ASAP.

  • @rangamadar8929
    @rangamadar8929 Před rokem

    Thank you sir

  • @shashwatdev2371
    @shashwatdev2371 Před 2 lety

    Thanks a lot for this video

  • @anujpradhan480
    @anujpradhan480 Před rokem +1

    Sir, how initially we compare s.find with s.end as there is no element inserted???

  • @krishnakumar-kh5vo
    @krishnakumar-kh5vo Před 2 lety

    thanks bhaiya got everything..

  • @salmaniproductions1104

    Thank you so muchhh

  • @debapriyoray9522
    @debapriyoray9522 Před rokem

    well explained

  • @andiamakaza24
    @andiamakaza24 Před 3 lety +3

    Is this code also works for finding the number of subarray with sum as 0

  • @DilSeengineer4
    @DilSeengineer4 Před 18 dny

    9:18 hash on additon we get -6 not 0

  • @amitraj-vu5oe
    @amitraj-vu5oe Před 2 lety +1

    Great vid

  • @ferihayalmaz2337
    @ferihayalmaz2337 Před rokem

    why we use here set is not it will discard duplicacy!! but duplicacy discard krne ki jrurat toh h hi nhi?

  • @hiyou8833
    @hiyou8833 Před rokem

    2:29 here u go

  • @anonymous090
    @anonymous090 Před 2 lety

    Thank you bhaiya

  • @aadilkhan4867
    @aadilkhan4867 Před rokem

    wah bhaiya jii

  • @DevottamChakraborty
    @DevottamChakraborty Před rokem

    // Why this is not working ?
    // i have used else , is that the reason?
    bool subArrayExists(int arr[], int n)
    {
    unordered_setmp;
    int prefixsum=0;
    for(int i=1;i

  • @champof7seas623
    @champof7seas623 Před rokem

    //Why this is not working
    class Solution{
    public:
    //Complete this function
    //Function to check whether there is a subarray present with 0-sum or not.
    bool subArrayExists(int arr[], int n)
    {
    map mp;
    mp[0]++;
    long long int sum = 0;
    for(int i=0;i

  • @memesbyanony
    @memesbyanony Před 9 měsíci

    8:43 pe hash me -1 kese aya , it should be 1 ??

  • @AnuragSharma-dv6mh
    @AnuragSharma-dv6mh Před rokem

    s.insert(prefixSum) ka means samjha dijiye sir

  • @PranavPrajapati-hd2eu
    @PranavPrajapati-hd2eu Před 2 lety

    Bhaiya why we have write s.find()! = S.end ,,means we are not checking end element of hash table

    • @prayagrajwade8699
      @prayagrajwade8699 Před 2 lety

      Bro its mean that we are checking till the end and if the sum is already there in hash map then we are returning true

    • @darsisriguruaakash
      @darsisriguruaakash Před 2 lety

      Iterator

  • @srijanshahi8587
    @srijanshahi8587 Před rokem

    sir,variable size window sliding se approch kr skte??????

  • @masumali8356
    @masumali8356 Před rokem

    bool subArrayExists(int arr[], int n)
    {
    //Your code here
    unordered_mapmp;
    for(int i=1;i

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

    07:50 sir maharashtra se ho kya

  • @alientech2668
    @alientech2668 Před rokem

    😇

  • @vaibhavkumar1391
    @vaibhavkumar1391 Před 3 lety +3

    Ye series khatm hone ke baad please, aap interview prblms in java me videos banana.

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

    Bhaiya graph samaj nehi at hay ...ap hi ho plz smja do ... plz jaldi upload karo graph with concept

  • @bhupeshpattanaik7150
    @bhupeshpattanaik7150 Před 3 lety

    🔥😍

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

    7:30
    If prefixSum1 is 1 and prefixsum2is 2 then how can thier difference be 0?

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

      Who said it's 1 and 2 , they could be any value , just there difference is 0

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

      @@vaibhavbansal1244 he said listen carefully

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

      @@ogbuddha7835 1 and 2 are names given to the variables , prefixsum1 and prefixsum2

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

      @@vaibhavbansal1244 sahi bola bhai 🤣🤣

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety

      Finally doubt is cleared Hahaha

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

    you are not teaching good, wasted my time. Uff. Ache se smjh ke pdhao please. Disliked it.