Subarrays Sums Divisible by K (Leetcode 974) Algorithm Explained

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

NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the problem count subarrays with sum divisible by 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 is divisible by K.

#hashmaps #datastructure #algorithms

Рекомендации по теме
Комментарии
Автор

The negative mod trick is main part to identify in this problem.. Thanks for explaining that 👍🏼

champ
Автор

Sir you are a legend. You make everything look so easy.

prateekkatiyar
Автор

Hello @pepcoding, can you please explain Leetcode 523? Its using HashMap but there is no good explaination.

hemaladani
Автор

your repititive explanation is so amazing sir😍😍
make things learned while watching the video🤩🤩🤩

Manish-wwlg
Автор

You missed a case of if(rem==0) then also count++ becuse its the sum staring from first index and need to be checked seperately

nishanttiwari
Автор

Awesome 👍. Your explanation looks so good that I can code directly without any second thought. Thanks a lot bro 👏👍

sandeepgampa
Автор

I am very happy that I have discovered this channel, but sad also why not earlier, Anyways now i think my placements prep is going to be OP :)

aisakyunhotahai
Автор

Best possible explaination for this sum

VikasGupta-oklh
Автор

a lotttt better than any other solutions on YT

yapping_yash
Автор

What a simplified and well explained solution

aratibhandare
Автор

#include <bits/stdc++.h>
int subArrayCount(vector<int> &arr, int k) {
map<int, int> mpp;
mpp[0]=1;
int count=0, presum=0, rem=0;
for(int i=0;i<arr.size();i++)
{
presum+=arr[i];
rem = ((presum%k)+k)%k;
count+=mpp[rem];
mpp[rem]+=1;
}
return count;
// Write your code here.
}
is this right in
c++?

prathameshpawar
Автор

why did you added 0, 1 in the hashmap initially? Can you please explain that?

lambarahul
Автор

Just 1 min into the video, liked the way you are explaining. LIKED the video.

KAUSHALDOKANIA
Автор

I just can not thank this guy enough :)

sahilhemnani
Автор

line no. 9. -> should be map.put(0, -1) instead of map.put(0, 1) isn't it? please confirm. thanks.

gautamtyagi
Автор

Subscribed it... Pahla video dekhne par hi subscribe kar liye... Bhai kitne patience ke sath padhate ho... Its just awesome/amazing...More power to u brother.

JGyanRaj
Автор

It would be better if you could explain how you came to conclusion that the remainders should be equal .

directhit
Автор

Mazza aagya Waah kaafi time ke baad 2 videos dekhi hai ek saath !!!! Keep going

Elon-musk-
Автор

Nice video keep on making such videos.

paragroy
Автор

good explanation sir if possible try to provide c++ solution

abc-ymzs