Count of Interesting Subarrays | Using Studied Concept | Dry Run | Leetcode 2845 | codestorywithMIK

preview_player
Показать описание


Hi Everyone, this is the 149th video of our Playlist "Arrays 1D/2D : Popular Interview Problems".
Now we will be solving a good array prefix-sum problem - Count of Interesting Subarrays | Using Studied Concept | Detailed | Dry Run | Leetcode 2845 | codestorywithMIK

We will solve it using the same concept as Leetcode-974. We will do a recap and build intuition and solve it easily.

Problem Name : Count of Interesting Subarrays | Using Studied Concept | Detailed | Dry Run | Leetcode 2845 | codestorywithMIK
Company Tags : will update later

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

Video Summary :
The problem asks us to count subarrays where the number of elements satisfying nums[i] % modulo == k is congruent to k modulo modulo. We keep a running count (sum) of such elements and use the modulo of this sum to track patterns. By using a hash map to store the frequency of each modulo result, we efficiently count the number of valid subarrays ending at each index. The key trick is recognizing that if (sum[i] - sum[j]) % modulo == k, then we can rearrange this to find how many previous prefix sums satisfy that condition.

✨ Timelines✨
00:00 - Introduction
0:35 - Motivation
1:04 - Problem Explanation
5:13 - Thought Process behind counting
17:26 - Recap Leetcode - 974 and Maths Proof
28:28 - Dry Run
34:42 - Coding it up

#MIK #mik #Mik
#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 #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik
Рекомендации по теме
Комментарии
Автор

Yesterday I got an email from hr that you have secured an.SDE position for 9lpa and that happiness was crazy !
Thank you so much bhaiya for creating such informative and helpful videos! Your content played a huge role in DSA, which helped me secure a job offer for a 9LPA position. I'm truly grateful for your hard work. Your efforts are making a real difference in people's careers.
I wish you and your family.
One myntra I always had " chalo karta hai story sa code"
Thankyou
❤🎉

shivam
Автор

A brief explanation of the modular magic at 23:50 -
Suppose (a-b) mod m = c, then we can also write it as (a-c) mod m = b.
Proof : (a-b) mod m = c, then a-b = p*m + c, where p > 0. Bring c to left and b to right, then
a-c = p*m + b, which means (a-c) mod m = b.

Here, bhaiya specifically shifted r2 to right because we need to find the count of such r2 we have seen previously.
Thanks bhaiya, as usual understood clearly💯

arjunprasad
Автор

PDF link is too helpful to revise things quickly. 🧡🧡🧡

priyadarshi
Автор

thanks i solved it by my own and i was surprised that your solution is same as mine....thanks this is bcz of u man

ompawar
Автор

Felt easy after solving leetcode 974
Modulo properties are extremely helpful

aws_handles
Автор

Leetcode-974 was enough to solve this. Thank you

gui-codes
Автор

Aaj subah hi leetcode 974 karliya tha and same concept se ye solve hogaya. Bas ek hint lena pada mujhe about converting to 1 and 0
Thanks a lot MIK

FanIQQuiz
Автор

// BRUTE SOLUTION => for this problem

long long nums, int modulo, int k) {
int n = nums.size();


long long result = 0;

for(int i = 0; i < n; i++){
long long count = 0;
vector<int> arr ;
for(int j = i; j < n; j++){

if(nums[j] % modulo == k) arr.push_back(nums[j]);
int count = arr.size();

if(count % modulo == k) result++;
}

arr = {};

}

return result;
}

deepeshgaharwar
Автор

Thank you soo much sir, may god always bless you

juturtaur
Автор

Was waiting since morning. Then saw your insta story.

AkashGupta-pjdp
Автор

Its better if you provide Ipad notes as it will save time while creating notes otherwise subscribers always need to pause and notedown things and this will take lot of time.

AmandeepSingh-uqwp
Автор

Well explained
Thanku sir :)
One question how to do revision for DSA??

anayajain-dh
Автор

Nice one MIK, keep it up. We also .... keep Going. Let's grow together & build a strong community.
while (1)
printf("Thanks, MiK😇);

hareesh_sureddy
Автор

can you come up with leetcode contest question. And thanks for these videos♥

AKASHKUMAR-lili
Автор

Hello Bhaiya, could you please add a short Java explanation (around 2 minutes) to the video? I understand the C++ logic, but the different Java structure sometimes causes problems, especially when adapting code from GitHub for LeetCode.

AbhishekRaghuvanshiYT
Автор

Can we not use sliding window and update the count while adding new element to the window and also when shrinking the window?

mohammedyasser
Автор

I got lost in mod properties, apart from this question was easy

nikhil_squats
Автор

Bhaiya ek dsa sheet bna dete aap to mjaa aajata

Nikhil-hutz
Автор

public long countInterestingSubarrays(List<Integer>num, int m, int k){
int n=nums.size();
if(k>n) return 0;
int[]cnt=new int[n+1];
cnt[0]=1;
long ans=0; int sum=0;
for(int x:nums){
x%=m;
if(x==k)
++sum;
sum%=m;
int r=sum-k;
if(r<0)r+=m;
if(r<n)
ans+=cnt[r];
cnt[sum]++;
}
return ans;🎉❤

dayashankarlakhotia
Автор

dp playlist complete kara dijye please

Engineeringlife
visit shbcf.ru