Contiguous Array | Using same Pattern Approach | Similar Problems | Leetcode 525

preview_player
Показать описание
This is the 86th Video of our Playlist "Arrays 1D/2D : Popular Interview Problems".
In this video we will try to solve a very good pattern problem : Contiguous Array | Using same Pattern Approach | Similar Problems | Leetcode 525

Share your learnings on LinkedIn, Twitter (X), Instagram, Facebook(Meta) with the hashtag #codestorywithmik & feel free to tag me.

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.

Problem Name : Contiguous Array | Using same Pattern Approach | Similar Problems | Leetcode 525
Company Tags : Meta, Google

Approaches Summary :
We are using the same pattern approach just like Leetcode-560, 930, 1074.
The provided approach is a solution to a problem aiming to find the maximum length of a contiguous subarray with an equal number of 0s and 1s within a given vector nums. The algorithm utilizes an unordered map mp to store the cumulative sum of the array elements encountered so far, with the key being the cumulative sum and the value being the index at which the sum was achieved. The algorithm iterates through the vector, updating the cumulative sum based on the value of the current element (incrementing by 1 for 1s and decrementing by 1 for 0s). At each step, it checks if the current cumulative sum exists in the map. If it does, it updates the maximum length (maxL) by taking the difference between the current index and the index stored in the map for that cumulative sum. Otherwise, it adds the current cumulative sum and its corresponding index to the map. Finally, the algorithm returns the maximum length found, which represents the length of the longest contiguous subarray with an equal number of 0s and 1s.

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

✨ Timelines✨
00:00 - Introduction
03:22 - Why not Sliding Window ?
06:10 - Intuition using pattern Leetcode-560
10:51 - Complete Dry Run
18:14 - Coding it up
21:03 - Time & Space

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear
Рекомендации по теме
Комментарии
Автор

I can't believe I was able to solve this on my own. Thank you so much mik, i have seen improvements in me.

wearevacationuncoverers
Автор

i was trying with sliding window .. it really got messy ... finally got it .. thank you so much

ankanbrahmachary
Автор

I was here to know why we put currSum in map in else block and you exactly covered it in the end 😅
Thank you so much ❤

FanIQQuiz
Автор

I am good in developement but not in logics and DSA, mik helping me a loi with his efforts. Thanks for your geniun efforts,

amanjha
Автор

thanks bhai, dry run tk dekhe apka fir ban gya khud se..

AnkitJha-pzdc
Автор

The optimization was so cool ✌
POTD DONE [16.3.24] ✅✅

oqant
Автор

Thanks a lot bhaiya ❤❤pehla approach mind mei sliding window hi aya tha lekin apne ache se explain kar dia kyu nahi hoga sliding window

gauravbanerjee
Автор

bas aapka hi intezar tha.
And Congrats, i noticed you have already crossed many other youtubers in subs count like aryan, vivek, algo made easy etc. (no offence to anyone) but I thin it's all because of your hard work and uniqueness and honesty in delivering all information in every video.

EB-otuu
Автор

thank you so much dude as I am stuck with this part of taking a length

aelishkumar
Автор

Thanks for telling last point also why we are putting the mp[cumSum] = i; in else block.

nawazthezaifre
Автор

Your slightly variated format of similar type problems with their expalnation is what make me subscribe your channel . Thank You so much !!🥰

secretvibz
Автор

Bhaiya please Leetcode 2031 wale problem Kara do please please please
❤❤❤❤

Shivam-wlfg
Автор

Leetcode 2031 and GFG-count the substring same problem haiiii please Kara

Shivam-wlfg
Автор

To solve this question take a Hashmap with keys 0 &1 and now iterate through the array and increase the value of 0&1 correspindingly.Now again iterate through the array if 0 or 1 is occured decrease the val, if the values of 1 and 0 are equal return the length of remaining array which isnt visited.
CANT WE SOLVE THIS USING THIS APPROACHH

advaithmahendrakar
Автор

Walmart ne bhi poocha h abhi 1 ghante pahele

nikhil_squats
Автор

i used sliding window but getting tle for long test cases so now i am here

kabir
Автор

Sir can we say that /*LEETCODE 974. Subarray Sums Divisible by K*/ =>this Problem also falls under these PATTERN .Because in this problem also. We maintained a MAP and we Used to see if the remainder if got now, Exist in map already or not. And then we drew conclusions from it .

closer
Автор

Bhaiya plz make video on leetcode 2831, also explain one thing sb logo ne is question me explain nhi kiya jb window ka size reduce kiya hai tb agar maximum frequency wala element out of window jaa rha h tb bhi maxf(count of most frequent element in that window) ko same he rkha h reduce nhi kiya?? bohot confusion hora h isme

aryanZzz..
Автор

public int findMaxLength(int[]nums){
int n=nums.length;
int[]cnt=new int[2*n+2];
int curSum=n, ans=0;
for(int i=0;i<n;i++){
curSum+=(nums[i]<<1)-1;
if(curSum==n){
ans=i+1;
}else if(cnt[curSum]==0){
cnt[curSum]=i+1;
}else{
ans=Math.max(ans, i-cnt[curSum]+1);
}
}
return ans;
}
🎉❤

dayashankarlakhotia
Автор

Bhai please handle each problem individually there are some new visitors also on your channel and they shouldn't be told to refer other video if it is possible to explain the previous concept then explain it

socify