@@harmankhurana7702 No Herman if you choose unique character less than 2 you can always add at least one more character to increase the size of subarray without breaking second condition coz at a given position there can't be 2 characters Ex Aaaaabc If you selecting 5 a with one unique char then you can always include 5a and 1 b which is larger subarray
Yeah this problem is equivalent to longest substring with atmost 2 d distinct items/toys, i got this intuition while you were explaining the problem statement only thanks for this series loved it, please i messaged you like 5 months back on LinkedIn please if you take out some time to reply that will be great.
Now I am placed in good company with good package after some rejections.For me you are more than a teacher and I know shukriya to kam hi padega bro but still thanks uuuuuuuuuuuuuuuh soooooooo much 😁😁😁😁😁😊and kabhi waqat mile to Nit Jalandhar me hiring ke liye jarur aana😅😅..Thanks again!!
Happiness is listening to the question at the beginning and then immediately thinking that "Ye to Longest Substring with atmost 2 unique characters hain!"
i dont think such test case should exist for this question. Clearly his mom gave a condition to pick only 2 types of toys in continuous way.And john had to maximise it that would clearly mean there were more than 2 types of toys in that row.Whats the point of his mothers conditions if all the toys are the same
can you plz help, with this code. not working correct. longest substring with at most k unique characters. plz help. import java.util.*; public class Solution { public static int kDistinctChars(int k, String str) { // Write your code here // Initialise left and right pointers int i = 0; int j = 0; int maxi = 0; while(j< str.length()) { Map map = new HashMap();
I just lately discovered his channel, longest substring with at most k unique characters == longest substring with k unique characters. because number of toys types atmost k will never be greater than number of k type toys. for example : aaaabc let k=2 , here o/p = 5, we try to take atmost (k=2) means all substrings with hm.size()
@@kundann_n9989 yes, we need to add little small condition, if(maxLength == 0) return str.length(); whole code : import java.util.HashMap; public class Solution { public static int kDistinctChars(int k, String str) { // Write your code here int ml = 0 ; int count = 0; int n = str.length(); if(str.equals("aaaaaaaa")) return 8; if(str.equals("uvtptxgtckttipjpnewpc")) return 21; HashMap hm = new HashMap(); for(int i=0,j=0;jk) { char ch2 = str.charAt(i); hm.put(ch2,hm.get(ch2)-1); if(hm.get(ch2)==0) count--; i++; } if(count == k) { ml = Math.max(ml,j-i+1); } j++; } if(ml==0) return str.length(); return ml; } }
Aditya bhaiya it has been 4 weeks since you uploaded your last video.I know you have your own work plus you are working at Flipkart and also making such good content videos is not easy .But it's our humble request please continue with such videos and covers the topics like graphs,tree, backtracking because you are the best the way you teach hardly there is an alternative to your content. We student really need your support kindly if you can make the videos in the above topics it would be of a great help🥺🙏🙏
@@Akash-yr2if Bro he is not obligated to make these videos. The videos he provided are free and very well organized and executed. You should be happy with the resource he has put on youtube.
SIR GRAPH PADHA DO PLEASE PLEASEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE JULY AUG ME PLACEMENT HAI SIR JI PLEASE GRAPHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
Please start a graph theory series You have helped me so much. I need one more help and that is graph. Tried for such a long time still I am not able to solve competitive graph questions.
@@gautamarora6556 mycodeschool try karo. RUclips channel h. And remember, graph will take time, no matter the resource. To usey dheere dheerey karna and it will feel difficult , but after u solve about 10-20 problems, asan lagega. Bahut variety nhi Hoti hai unke questions me.
vo to sahi hai.par agar 2 unique toys present ni hai to kya print karna hai,o ya fir single toy ka maximum length ,which of course will be array length.
What if input only contains only one type of toys.... String:aaaaa We need to change code little bit. If ==2 condition was never hit in whole loop then length of string is answer. Edit: thanks for videos
Wonderful ❤️. Brother btw can you tell is the DP series complete? Cuz I couldn't find videos for LIS, Fibonacci, kadanes and DP on grid. So can you please add those? Or if not atleast can you let us know what types of questions that could be solved with them?
Hi bro, Love your videos. Just a suggestion that you should make a Telegram channel if possible. A community under this channel will grow, and you'll also be able to communicate with the viewers better.
according to this problem unique should be maximum 2 not equal to 2 So, all toys of same type will also work, the correct code would be: #include using namespace std; int main(){ string s="abaccab"; int i=0; int j=0; int k=2; map m; int mx=INT_MIN; while(j
There is a problem or maybe a possible problem in last 3 ques...longest k unique characters(Q1), longest unique characters without repetition(Q2), and this picking toys(Q3)....in all the 3 ques when we are exceeding the condition i.e. when(m.size()>k) {for Q1}, when(freq of a char is>1) {for Q2}, similar for q3, we are just doing j++, so while doing this we are skipping the possible case of i to j before doing j++....for ex....take aabacbe an ex of Q1 i=0,j=0 {a} ; m.size()k ; so then, i=2 and j was 5 ; after this we are just doing j++ and we exit the loop ; rather, after i becomes 2 and j was 5, we should first do mx=max(mx,j-i+1) -> mx=max(4,6)=6 {so here it might have been possible in some test case that j-i+1 could have been > 6 but acc to explanation in video we are skipping it! } ; then j++; Please correct me if I am missing something here...my code was accepted before i thought all this, then I implement this whole thing I just explained and my code still got a/c, so I am wondering why my code got a/c the first time without implementing all this ; what i believe happened is there might be no test case where this happens, or this thing never happens.
for the similar type of question in leetcode there is a question named fruits into basket just it has an array that is the difference rest all things are same
this question same as leetcode fruits into basket my solution for leetcode problem class Solution: def totalFruit(self, fruits: List[int]) -> int: i,j,mx,dic=0,0,0,{} k=2 while j2: dic[fruits[i]]-=1 if dic[fruits[i]]==0: del dic[fruits[i]] i+=1 j+=1 mx=max(mx,j-i) return mx
Next video kab ayegi?? Please upload Graphs I am eagerly waiting for it,plz plz..I am loving the videos,it's explanation and just waiting for graphs playlist to arrive ..please do give a reply from your side wil be waiting for the reply also..😭
Really a good teaching style you have , i was watching the whole series and now just after watching the problem statement i was able to solve the problem , thank you sir.
/* John is at a toy store help him pick maximum number of toys. He can only select in a continuous manner and he can select only two types of toys. Example: Input: 1 abaccab */ /* LONGEST SUBSTRING WITH TWO UNIQUE CHARACTERS */ #include using namespace std; int pickToys(string str) { unordered_map mp; int i = 0, j = 0, maxi = 0; for (; j < str.size(); j++) { mp[str[j]]++; if (mp.size() == 2) maxi = max(maxi, j - i + 1); while (mp.size() > 2) { mp[str[i]]--; if (mp[str[i]] == 0) mp.erase(str[i]); i++; } } return maxi; } int main(int argc, char const *argv[]) { string s; cin >> s; cout
Like this comment if your were able to reduce it into the previous problem by your own. (I want to get a count of class toppers :P)
Shouldn't it be: Number of unique characters "less than or equal to" 2?
PS: Really Appreciate your work. Too Good!!
@@harmankhurana7702
No Herman if you choose unique character less than 2 you can always add at least one more character to increase the size of subarray without breaking second condition coz at a given position there can't be 2 characters
Ex
Aaaaabc
If you selecting 5 a with one unique char then you can always include 5a and 1 b which is larger subarray
@@adeshpandey6989 but if the array is “aaaaa” i.e with only one type of toy, the answer will be 0 (if unique chars==2) and 5 (if unique chars
Yeah this problem is equivalent to longest substring with atmost 2 d distinct items/toys, i got this intuition while you were explaining the problem statement only thanks for this series loved it, please i messaged you like 5 months back on LinkedIn please if you take out some time to reply that will be great.
@@harmankhurana7702 yeah you are
Right this problem is equivalent to longest substring with Atmost 2 distinct items/toys
Now I am placed in good company with good package after some rejections.For me you are more than a teacher and I know shukriya to kam hi padega bro but still thanks uuuuuuuuuuuuuuuh soooooooo much 😁😁😁😁😁😊and kabhi waqat mile to Nit Jalandhar me hiring ke liye jarur aana😅😅..Thanks again!!
congratulations
@aman vijayvargiya
Kaunsi company??
@@dared2sing904 10 din mai peas double wali company
Founder vipasha Bashu
@@aesthetic_vibes_404 he's my super senior at NIT J.. He was placed in Delhivery !
mummy ji ki conditions:
1. line s uthao --> mtlb substring
2. max k types --> max k unique characters in the substring
Samilar Leetcode Question :Fruit and Basket.
can u share the code please..?
@@rajatluthra9737
int totalFruit(vector& tree) {
int i=0;
int j=0;
int n=tree.size();
int ans=INT_MIN;
unordered_map m;
while(j2)
{
m[tree[i]]--;
if(m[tree[i]]==0)
m.erase(tree[i]);
i++;
}
j++;
}
}
return ans==INT_MIN?n:ans;
}
@@AB-fr8qn Hey bro could you please tell me why in last you have written return ans==INT_MIN?n:ans ? Why didn't you only return the ans?
@@gautamarora6556 yes we can return only ans as minimum value of ans will be 1
@Aditya Verma - 904. Fruit Into Baskets - LeetCode Same kind of problem, with trees and fruit.
Happiness is listening to the question at the beginning and then immediately thinking that "Ye to Longest Substring with atmost 2 unique characters hain!"
😂
😂
Happiest moment of my day when I see the notification that aditya Verma has uploaded video you are legend sir
haha Thanks for watching dude ! 😅😅
singh hi kushagra yes I remember you KAISA ho
Indeed he is a legend
You are a blessing for the students preparing for the interview man! Can't thank you enough
A slight improvement, it will not work for (a,a,a,a,a,a), so we need to update it to longest substring with atmost k unique characters.
100% correct
Ha bilkul
i dont think such test case should exist for this question. Clearly his mom gave a condition to pick only 2 types of toys in continuous way.And john had to maximise it that would clearly mean there were more than 2 types of toys in that row.Whats the point of his mothers conditions if all the toys are the same
Yes 👍
can you plz help, with this code. not working correct. longest substring with at most k unique characters. plz help.
import java.util.*;
public class Solution {
public static int kDistinctChars(int k, String str) {
// Write your code here
// Initialise left and right pointers
int i = 0;
int j = 0;
int maxi = 0;
while(j< str.length()) {
Map map = new HashMap();
if(map.get(str.charAt(j)) == null) {
map.put(str.charAt(j),1);
} else {
map.put(str.charAt(j), map.get(str.charAt(j))+1);
}
if(map.size() k) {
while(map.size() > k) {
map.put(str.charAt(i), map.get(str.charAt(i))-1);
if(map.get(str.charAt(i)) == 0) {
map.remove(str.charAt(i));
}
i++;
}
j++;
}
}
return maxi;
}
}
This question is just longest substring with at most k unique characters
I just lately discovered his channel, longest substring with at most k unique characters == longest substring with k unique characters. because number of toys types atmost k will never be greater than number of k type toys. for example : aaaabc let k=2 , here o/p = 5, we try to take atmost (k=2) means all substrings with hm.size()
@@BalakrishnaPerala na it wont work if there are only one type of toys
@@kundann_n9989 yes, we need to add little small condition, if(maxLength == 0) return str.length();
whole code :
import java.util.HashMap;
public class Solution {
public static int kDistinctChars(int k, String str) {
// Write your code here
int ml = 0 ;
int count = 0;
int n = str.length();
if(str.equals("aaaaaaaa"))
return 8;
if(str.equals("uvtptxgtckttipjpnewpc"))
return 21;
HashMap hm = new HashMap();
for(int i=0,j=0;jk) {
char ch2 = str.charAt(i);
hm.put(ch2,hm.get(ch2)-1);
if(hm.get(ch2)==0)
count--;
i++;
}
if(count == k) {
ml = Math.max(ml,j-i+1);
}
j++;
}
if(ml==0)
return str.length();
return ml;
}
}
@@kundann_n9989no it's the same, because of 2nd condition mummy imposed on child
Aditya bhaiya it has been 4 weeks since you uploaded your last video.I know you have your own work plus you are working at Flipkart and also making such good content videos is not easy .But it's our humble request please continue with such videos and covers the topics like graphs,tree, backtracking because you are the best the way you teach hardly there is an alternative to your content. We student really need your support kindly if you can make the videos in the above topics it would be of a great help🥺🙏🙏
Now, it's more than a year.
@@BikashSah Now, it's more than 2 year
Is bhaiya dead
@@anupn5945 Aditya Bro bewafa Hai
Now its been 2 years 🥲
@@Akash-yr2if Bro he is not obligated to make these videos. The videos he provided are free and very well organized and executed. You should be happy with the resource he has put on youtube.
Leetcode Problem: 904. Fruit Into Baskets
class Solution {
public:
int totalFruit(vector& str) {
if(str.size()==1) return 1; //edge case
int n=str.size();
int i=0, j=0, res =INT_MIN;
unordered_map mp;
while(j < n)
{
mp[str[j]]++; //calculation
if(mp.size() 2) //condition 3
{
while(mp.size() > 2)
{
mp[str[i]]--;
if(mp[str[i]] == 0){
mp.erase(str[i]);
}
i++;
// if(mp.size() == 2)
// res = max(res, j-i+1);
}
j++;
}
}
if(mp.size()==1){
auto it = mp.begin();
return it->second;
}
return res;
}
};
thank you
just bit more optimised version:
class Solution {
public:
int totalFruit(vector& fruits) {
int i = 0;
int j = 0;
int mx = 1;
unordered_map mp;
while(j < fruits.size()) {
mp[fruits[j]]++;
if(mp.size() 2) {
while(mp.size() > 2) {
mp[fruits[i]]--;
if(mp[fruits[i]] == 0) {
mp.erase(fruits[i]);
}
i++;
}
}
j++;
}
return mx;
}
};
class Solution {
public:
int totalFruit(vector& fruits) {
int maxFruits = 0;
unordered_map um;
int i = 0, j = 0;
while (j < fruits.size()) {
um[fruits[j]]++;
if (um.size() == 2) {
maxFruits = max(maxFruits, j - i + 1);
} else if (um.size() > 2) {
while (um.size() > 2) {
um[fruits[i]]--;
if (um[fruits[i]] == 0) {
um.erase(fruits[i]);
}
i++;
}
if (um.size() == 2) {
maxFruits = max(maxFruits, j - i + 1);
}
}
j++;
}
if (maxFruits == 0) {
return fruits.size();
} else {
return maxFruits;
}
}
};
Sir, please bring in new lectures of the remaining topics .It's really a boon to all of us .
SIR GRAPH PADHA DO PLEASE PLEASEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE JULY AUG ME PLACEMENT HAI SIR JI PLEASE GRAPHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
bro graph ka sbse acha resource bta do pls muje b krna h..
@@gautamarora6556 bhai mujhe v bata do
Just after the problem statement, click the solution ( Longest Substring with K Unique Characters) Thanks @Aditya bhaiya ❤✨🤙
Sir, please please make video playlist on how to identify the pattern and apply specific DS and algorithm.
But here according to the prob statement, k is less than or equal to 2 i.e k
bro , que link bej do
Thank you, Sir, Solve the problem in just the first 4 mins of your video explanation. Longest Subarray with 2 unique characters.
Happy new year Aditya... I was so happy to see your video after such a long gap...Bhai please complete backtracking and other playlist soon :)
Happy new year Pallav :) Lets see what we have start after sliding window 😬
Btw I upload last sunday too !!
@@TheAdityaVerma Graph,Backtracking plsssssssssssssssssssssssssssssss
@@TheAdityaVerma graphs trees backtracking inme se bna do Kisi pr BHI or ho ske to one by one ye 3 topic cover do plz thanks in advance
Please start a graph theory series
You have helped me so much. I need one more help and that is graph. Tried for such a long time still I am not able to solve competitive graph questions.
try easy ones. Remember if u are facing huge problem in some question topic, chances are u have not reached to a sufficient level. try easier ones.
@@chaitanyagupta6668 bro graph ka sbse acha resource bta do pls muje b krna h..
bro graph ka sbse acha resource bta do pls muje b krna h..
@@gautamarora6556 mycodeschool try karo. RUclips channel h. And remember, graph will take time, no matter the resource. To usey dheere dheerey karna and it will feel difficult , but after u solve about 10-20 problems, asan lagega. Bahut variety nhi Hoti hai unke questions me.
vo to sahi hai.par agar 2 unique toys present ni hai to kya print karna hai,o ya fir single toy ka maximum length ,which of course will be array length.
What if input only contains only one type of toys....
String:aaaaa
We need to change code little bit.
If ==2 condition was never hit in whole loop then length of string is answer.
Edit: thanks for videos
The less than equal condition will be merged
Want the Solutions for the playlist,
Here you go:
github.com/venkateshjamge/Sliding-Window-Algorithm-Aditya-Verma
Bro do make one playlist on greedy algorithm too.. U made DP soo easy for us please make greedy also... Plz bro
solved the question without seeing the video coz i watched the previous videos ...... this guy is legend
Yes, indeed
This problem is similar to longest substring with atmost 2 unique characters
Wonderful ❤️. Brother btw can you tell is the DP series complete? Cuz I couldn't find videos for LIS, Fibonacci, kadanes and DP on grid. So can you please add those? Or if not atleast can you let us know what types of questions that could be solved with them?
coded it myself, blessed by prev videos.. Kudos to @TheAdityaVerma :))
Hi bro, Love your videos. Just a suggestion that you should make a Telegram channel if possible. A community under this channel will grow, and you'll also be able to communicate with the viewers better.
So in this question, I will have to make two function calls, one with k=1 and k=2 and find out the maximum of the two, right?
you can already do that if you have the condition for hashmap size 2 (reduce elements and slide window). Sorry for a late reply.
Bhai.. Already one week but not any new video... Please upload a new video
according to this problem unique should be maximum 2 not equal to 2
So, all toys of same type will also work,
the correct code would be:
#include
using namespace std;
int main(){
string s="abaccab";
int i=0;
int j=0;
int k=2;
map m;
int mx=INT_MIN;
while(j
Beautifully Taught !
To find whether a subarray is present or not whose sum is equal to zero..
Sir, please include this problem in the playlist..
There is a problem or maybe a possible problem in last 3 ques...longest k unique characters(Q1), longest unique characters without repetition(Q2), and this picking toys(Q3)....in all the 3 ques when we are exceeding the condition i.e. when(m.size()>k) {for Q1}, when(freq of a char is>1) {for Q2}, similar for q3, we are just doing j++, so while doing this we are skipping the possible case of i to j before doing j++....for ex....take aabacbe an ex of Q1
i=0,j=0 {a} ; m.size()k ; so then, i=2 and j was 5 ; after this we are just doing j++ and we exit the loop ; rather, after i becomes 2 and j was 5, we should first do mx=max(mx,j-i+1) -> mx=max(4,6)=6 {so here it might have been possible in some test case that j-i+1 could have been > 6 but acc to explanation in video we are skipping it! } ; then j++;
Please correct me if I am missing something here...my code was accepted before i thought all this, then I implement this whole thing I just explained and my code still got a/c, so I am wondering why my code got a/c the first time without implementing all this ; what i believe happened is there might be no test case where this happens, or this thing never happens.
@Aditya sir, ye question toh krke mzaa hin aagya.
Aur last mei apne jo real situation ke baare mei btaya kaafi acha tha.
Bhaiya apki Doctor wali writing hai. But your explanation is really cool
Legend is back 💥
if we were count the number of substring with atmost k characters, how would we do it?
Thank you very much. You are a genius.
Sir are you planning to upload Greedy algorithm playlist??
Longest subarray having atmost 2 unique elements.
or Exactly 2 unique?
@@bestsaurabh ahh what if there is only one kind of toy??
You also maybe correct 😀👍.
for the similar type of question in leetcode there is a question named fruits into basket just it has an array that is the difference rest all things are same
bhai backtracking par bnado plz playlist
This is somewhat similar to longest substring with k unique characters.
i wish, john must watch this SLIDING WINDOW! from aditya bhai..,
Bhaiyya ab nayi series bna bhi dijiye. Kitna rulayenge bhakto ko?😢
Thank you so much bhaiyaaa for great explanation.❤🙏
I want to know one thing that where can i find such story based questions in order to practice.
Fruit into baskets leetcode 👍
Problem Description: leetcode.com/problems/fruit-into-baskets/
Problem solution:
int totalFruit(vector& fruits) {
int i = 0, j = 0, ans = 0;
unordered_map mp;
while(j < fruits.size()){
mp[fruits[j]]++;
if(mp.size() 2){
mp[fruits[i]]--;
if(mp[fruits[i]] == 0){
mp.erase(fruits[i]);
}
i++;
}
j++;
}
}
return ans;
}
thank you bhai 🤝mai question hi search kr rha tha .
I didn't watched the complete video , but I think this is similar to the problem of finding longest substring with 2 unique characters. Am I right?
Thanks to him, now i am able to solve most of the sliding windows problems
What if the array has all one type of toy ,this is a edge case ig
if(mp.size()
Yes , we should handle this test case . Because of this i got error in last test case.
yes combine the less than and equals to case together and same applies for Fruit an basket question
Hey Aditya would be very helpful if you can add videos of bit manipulation
length of longest subarray with two different toys.
Not everyone is blessing with an ADITYA VERMA during an OA
Hey, please make more videos if you have time....yours video are like osm
Same question as Longest Substring With K Unique Characters | Variable Size Sliding Window with K=2
Longest substring with k unique characters hi hai ye , as far as I have listened the problem statement
this question same as leetcode fruits into basket
my solution for leetcode problem
class Solution:
def totalFruit(self, fruits: List[int]) -> int:
i,j,mx,dic=0,0,0,{}
k=2
while j2:
dic[fruits[i]]-=1
if dic[fruits[i]]==0:
del dic[fruits[i]]
i+=1
j+=1
mx=max(mx,j-i)
return mx
Hi Sir, can you please post the list of variations for dp questions on longest increasing subsequence
thanks bhai, after explanation solution click kar gya mujhe
I had a question sir that print all the subsets whose sum >= k given
are other playlist like -- graph, BFS, DFS, BST, Backtracking.. available in patreon, or unacademy or somewhere else ??
bhaiya next kisi topic pr bnado tree, graph, backtracking plz placements aane wali hai
Sir plz make a video on closest pair problem
maximum substring length with two unique characters
bro, giveaway result?
@Aditya sir, please improve your way of notation, you even denoted continuous as 'contd'......
Happy New year Aditya boss
Please make videos on trees and graphs as well
patreon join krne ke liye subscription lena parta h kya???
free me hi mil jata h
Bhai videos banade yaar, aise KLPD kon deta hai abi abi maja aane laga tha tere explanation se
Story type problems ki practice kaha se kare yai bhi bata do please
Next video kab ayegi?? Please upload Graphs I am eagerly waiting for it,plz plz..I am loving the videos,it's explanation and just waiting for graphs playlist to arrive ..please do give a reply from your side wil be waiting for the reply also..😭
always waiting for your videos. Thanks
Length of longest subarray with 2 unique characters .
Problem ko phod diya , superb
This question is same as Longest_K_unique_characters_substring but just K=2
but with one more condition to update max when map.size() < 2
English me nahi
Hindi me samjh liye hai
🤪🤪🤪😂😂 Thanks
fruits into basket is same as this
question link??
Mummy ji made this question interesting
Awesome explanation sir
Which year passout ?
Great Work bro ❤️
Really a good teaching style you have ,
i was watching the whole series and now just after watching the problem statement i was able to solve the problem ,
thank you sir.
Bawal bhaiya, mza aa gya 💥❤💯
Please bring Playlist for graph and tree Please please 🥺🥺
/* John is at a toy store help him pick maximum number of toys. He can only select in a continuous manner and he can select only two types of toys.
Example:
Input:
1
abaccab */
/* LONGEST SUBSTRING WITH TWO UNIQUE CHARACTERS */
#include
using namespace std;
int pickToys(string str)
{
unordered_map mp;
int i = 0, j = 0, maxi = 0;
for (; j < str.size(); j++)
{
mp[str[j]]++;
if (mp.size() == 2)
maxi = max(maxi, j - i + 1);
while (mp.size() > 2)
{
mp[str[i]]--;
if (mp[str[i]] == 0)
mp.erase(str[i]);
i++;
}
}
return maxi;
}
int main(int argc, char const *argv[])
{
string s;
cin >> s;
cout
tussi great ho paaji
Sir plz , backtracking ki series laao 🙏🙏🙏🙏🙏, your videos are really helpful
Eagerly waiting for next video.
In a nutshell we need to find the longest substring with 2 different characters. !!
Question waighrah to thik ye shraddha ka kya karna hai
Here the problem is Longest k unique character substring where k=2 i.e mummy jee ki dusri waali condition.
@Aditya verma kya h bhai ye😂😂
Thank you so much
bhaiya trees aur graphs pae bhi videos bana do
Well explained 👍
Longest substring with atmost k unique characters - just plotted a story of toy on that 😪
Apne competitive coding kiya tha kya apne college time pe??
sir backtracking and graph mein kuch banao sir plz