Subarray with sum 0 | GeeksforGeeks | Hashing data structure | Leetcode DSA series | Prefix Sum
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
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
Thanks a lot....that diagram of presum1==presum2 cleared everything
Thanks ☺️ please share this channel to everyone please
Thanks for explaining this prefix sum concept in ease way 😊
Keep learning 👍
THANK YOU BHAIYA ,aapki video dekhnese phele solve hi nahi ho paa raha tha
thanks for explaining bro
Your way of explaining is amazing... thank you so much sir 👏👏
Thanks a lot
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.
}
}
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
Why is the result false for this list [200, 100, -13589, -4, 13589], and it should be true?
and which sub-array will give you sum = 0 ?
you great really
explanation is toooooooo good.
Your are too
Thanks alooooooot 😀😀
Nice question ❤
thanku
Keep it continue
Thanks!!!
That's the plan!
keep learning buddy and be consistent and share my channel with your college groups that helps me a lot
@@HelloWorldbyprince surely, BTW I have done my graduation, now I m working
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
Awesome Explaination😍
thanks bhaiya for such a good explaination.
keep learning and keep sharing my channel with your friends and in colleges thanks satyam
watched 2 time because of variable name prefSum1 and prefSum2... 6:33 .. you said ki "vaule aaya one" .. overall explanation was very good..
Thanks for the support buddy Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
Bhai thodi aur jldi jldi videos daalo and medium level pblm please
you are the best.........masum.
thanks
First view sir you are 🔥sir
Thanks for the support 💞
Thank you so much, that was easy!
You're welcome!
Excellent tutorial
Thanks buddy ❤️
Life is not about achieving things.
Its about progress*. It will suit more.
12/18 done (8.12.22)
Great Video
chamak gya... thanks
good
Bhaiya, not just tree, graph as well.
Please start ASAP.
Thank you sir
Thanks a lot for this video
yee unordered map se nahi hota ??
So nice of you
Sir, how initially we compare s.find with s.end as there is no element inserted???
Same question
thanks bhaiya got everything..
yee unordered map se nahi hota ??
Amazing bro keep learning
Thank you so muchhh
well explained
Is this code also works for finding the number of subarray with sum as 0
Exactly 😊
9:18 hash on additon we get -6 not 0
Great vid
Thanks Amit for your support
why we use here set is not it will discard duplicacy!! but duplicacy discard krne ki jrurat toh h hi nhi?
2:29 here u go
Thank you bhaiya
wah bhaiya jii
// 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
//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
8:43 pe hash me -1 kese aya , it should be 1 ??
and wo kaise ?
s.insert(prefixSum) ka means samjha dijiye sir
Bhaiya why we have write s.find()! = S.end ,,means we are not checking end element of hash table
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
Iterator
sir,variable size window sliding se approch kr skte??????
u can but how?
bool subArrayExists(int arr[], int n)
{
//Your code here
unordered_mapmp;
for(int i=1;i
07:50 sir maharashtra se ho kya
😇
Ye series khatm hone ke baad please, aap interview prblms in java me videos banana.
Bhaiya graph samaj nehi at hay ...ap hi ho plz smja do ... plz jaldi upload karo graph with concept
Ekdum yaar graph kuch v nahi hai
Ekdum aasan
🔥😍
7:30
If prefixSum1 is 1 and prefixsum2is 2 then how can thier difference be 0?
Who said it's 1 and 2 , they could be any value , just there difference is 0
@@vaibhavbansal1244 he said listen carefully
@@ogbuddha7835 1 and 2 are names given to the variables , prefixsum1 and prefixsum2
@@vaibhavbansal1244 sahi bola bhai 🤣🤣
Finally doubt is cleared Hahaha
you are not teaching good, wasted my time. Uff. Ache se smjh ke pdhao please. Disliked it.