Anyone facing difficulty in understanding... Exactly K distinct = Atmost K distinct - Atmost K-1 distinct and you can find Atmost K distinct in 0(n) .....;)
i tried this for 2 days continuously without any help , still was able to reach only n square ,,This method takes O(n) ,Thank you!! but i believe it can be done using a single hashmap and within 30-40 lines of code ,using atmost k substring logic
@mayank sharma class Solution { public: long long int solve(string s,int k){ int n=s.size(); int i=0; //starting point of the window int j=0; //ending point of the window long long int ans=0; int dist_cnt=0; int hash_count[26]={}; while(jk){ hash_count[s[i]-97]--; if(hash_count[s[i]-97]==0){ dist_cnt--; } i++; } ans+=j-i+1; j++; } return ans; } long long int substrCount (string s, int k) { //code here. long long int ans=solve(s,k)-solve(s,k-1); return ans; } };
Hanji beta we are very near now. Feeling very strong about 10th Jan. Finances ki tension thi, aadhi si solve ho gai, baaki ke workflows ban gae. I will get back to what i enjoy - making videos
Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.
bhai agar tab count ko increment karege toh choti substring jo characters ko release karte hue ayyi h ve reh jaegi aabcbcdbca ismai karke dekh (ab) reh jaega or kuch or bhi
Its because the count of charachter itsel will be the number of substrings formed for the k=1 case but for the other cases we have to find the difference to calculate number of substrings formed for that particular instance.
Thankyou beta! I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
interviewer ne hint nahi diya kuch? mujhse bhi nahi ho raha tha par gfg pe at most k characters ka hint dekh kar khud se kar liya maine to interview me hints nahi dete kya aisa?
This question was asked for me in amazon SDE1 On-campus online assessment 2022
thanks sir. The way you did the dry run made the concepts clear for this ques
Anyone facing difficulty in understanding...
Exactly K distinct = Atmost K distinct - Atmost K-1 distinct
and you can find Atmost K distinct in 0(n) .....;)
Yes how it works?
@@Kashish_Batra yes I understand now.
@@Kashish_Batra In which year you right now
@@Kashish_Batra kyu bhai?
@@Kashish_Batra Ab aap place hogaye ho kya?
Thank You So Much for this wonderful video................🙏🙏🙏🙏🙏🙏
very nice and easy explanation sir
Thanks a lot for such nice content
please continue on youtube sir🙏
i tried this for 2 days continuously without any help , still was able to reach only n square ,,This method takes O(n) ,Thank you!! but i believe it can be done using a single hashmap and within 30-40 lines of code ,using atmost k substring logic
Sir abhi count of at most ki video dekhi hai
to simple bhi to kr skte hai isko count at most k minus count of at most (k-1) krke?
a tough one!!
as always , awesome explanation :)
this can be easily done by doing count of atmost k - count of atmost k-1
but for k = 1 answer will be same as count of atmost k
@mayank sharma class Solution
{
public:
long long int solve(string s,int k){
int n=s.size();
int i=0; //starting point of the window
int j=0; //ending point of the window
long long int ans=0;
int dist_cnt=0;
int hash_count[26]={};
while(jk){
hash_count[s[i]-97]--;
if(hash_count[s[i]-97]==0){
dist_cnt--;
}
i++;
}
ans+=j-i+1;
j++;
}
return ans;
}
long long int substrCount (string s, int k)
{
//code here.
long long int ans=solve(s,k)-solve(s,k-1);
return ans;
}
};
Sir u r really great.. god bless u sir
you can use this loop too for finding answer for k=1
public static int solutionForOne(String str)
{
int ans=1;
int count=1;
for(int i=1;i
ye vala reupload hona cheye sir iske intuition thik se samje nhi😞
Sir isme count of atmost K - count of atmost k-1 nikal ke kia hai. wo zyada easy hai
bilkul sahi. dhyaan se dekhie, ghoom firr ke ye wahi kar rha hai
easiest c++ soln using hash map
int hash[26];
int count,index,ans=0;
for(int i=0;i
nice solution!
TLE
sir intermediate wala module kab tak complete upload karoge
Hanji beta we are very near now. Feeling very strong about 10th Jan. Finances ki tension thi, aadhi si solve ho gai, baaki ke workflows ban gae. I will get back to what i enjoy - making videos
@@Pepcoding ok sir thank you for replying
nicely explained
Sir isko longesr substring with k distinct me jab bhi ans update kar rhe h waha counter update karke nhi kar sakte?
Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.
bhai agar tab count ko increment karege toh choti substring jo characters ko release karte hue ayyi h ve reh jaegi
aabcbcdbca ismai karke dekh (ab) reh jaega or kuch or bhi
@@virenderkumar9480 thanks buddy,it helped a lot
thanks... you save my efforts!!
can someone explain why we are using two hashmap cant we solve it using one hashmap like the earlier one
Its because the count of charachter itsel will be the number of substrings formed for the k=1 case but for the other cases we have to find the difference to calculate number of substrings formed for that particular instance.
Wow sir amazing 😍😍
this can be easily done by doing count of atmost k - count of atmost k-1
but for k = 1 answer will be same as count of atmost k
can you explain the intuition behind this?
@@PriyanshuKumar-wu4wk Check Leetcode 992 discussion section's most voted answer
Excellent Explaination Sir ...
Thankyou beta!
I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Nicely explained
same code is giving TLE in nados
Use arrays instead of hashmap, arrays could reduce the time taken.
Use C++or java as language
@@ashwinnema06 gives output limit exceeded
master piece
Approach samajh gya implement karne me time lag gya par 1 ghante me khudse hogya
Good.
For better experience, visit nados.io, where you will get well curated content and career opportunities
Amazing!
Glad you think so, for better experience and well curated content sign up on nados.io and start learning.
sir ye video site pr nhi hai
Hanji daal denge
Sir 2 Sliding window ka intuition aayega kaise?
When asked on .arrays or strings, 2.substring or sub array ,3.given k in problem statement
sir why we are running loop till str.length-1;
@Shubham Kumar Thanks for the clarification
bro pta chlaa? str.length()-1 tak loop run kyo ho rha h?
@@rounaq_khandelwal bhai apn increment starting mai krta hai isliya woh str.length()-1 krta hai warna idx out of bound hozaya ga
@@divyanshuagarwal1912 thanks bud!
@@rounaq_khandelwal which year bro
Aaj amazon ne pucha , meri fath gai , Kash pahle dekha hota.... :(
Bhai, nados.pepcoding.com pe ye sara content free of charge hai. Web dev hai aur core bhi
@@Pepcoding i know bhaiya, mane to course bhi le rakaha ha pep pe, bhot questions kiye the, almost 500, bas yahi nahi kiya tha :(
interviewer ne hint nahi diya kuch? mujhse bhi nahi ho raha tha par gfg pe at most k characters ka hint dekh kar khud se kar liya maine to interview me hints nahi dete kya aisa?
Kaafi mushkil tha question yaar
Can anyone please tell me this code's Time Complexity?
O(2n)==O(n) ,we are adding n times to hashmap and we are removing n times ,so doing 2n operations (or 4n for 2 hashmaps ,still O(n))
If I get a job above 15 LPA by studying your course I promise you that I will pay your course fees through donating money on youtube
Mili ?
@@rahulbhagat4023 abhi tak toh nhi abhi apply nhi kar sakta mera March tak ka contract he
So it means u r already placed somewhere
@@rahulbhagat4023 Yes I just want a huge hike
confusing......
:(
Acha nahi hai?
@@Pepcoding intuition samajh nii aayi iski🙁