I haven't included the code of this problem in this video and not uploading it right now (although I have it ready): for two reason: 1) Video was getting too long. 2) I want you guys to do it by yourself, since this will be last video in this series and this is the "BAAP" problem of sliding window, if you can do it, I can assure you will be able to do almost any sliding window problem. Try it by yourself, I will upload soon :)
Thank you so much, Aditya. Pleaseee upload BFS & DFS (i am having trouble with imp questions like number of islands etc) your videos have been very helpful :)
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
I tried to find your social media link but couldn't find it, because of you only got placed in VMware Interview mei pucha mrese ki node to node max sum path ka value nikalna h aur hm yeh thumb nail mei dekhe the yaad tha qstn but soln nii aata tha ab hmko smjh nii aara tree mei dp kaise lgega kahe ki yeh dp playlist mei h aur interviewer smjh gya ki hmko yeh qstn aata nii h kahe ki hm bhot cross qstn krre end mei solve huaa aur vo next Interviewer ko itna aacha review diye ki baapre kisi ne reject nii krra aur mreko hr mei bola gya face mei ki I got selected for intern + fte Bhai sir literally bow to your expertise ❤️❤️ aur stack ko sort krne v bola recursively vo v bna diye hm uska v video h apka playlist mei bhai bnate rhiye aisa video bhot help hota h ❤️❤️
Idea behind iterating Given String length can thought as : 1) Iterate thru string S till the count [map size from String T characters] variable reaches to 0. 2) Once counter is 0, try to move the start pointer towards end pointer to minimize the length of the found substring. If character at start pointer matches with string T increment the count variable. Loop thru till count variable is 0. // String s = "timetopractice"; String t = "toct"; int sLen = s.length(); int tLen = t.length(); if(tLen > sLen) System.out.println("Invalid Input"); HashMap countMap = new HashMap(); for (char c: t.toCharArray() ) { countMap.put(c,countMap.getOrDefault(c,0) + 1); } int start = 0; int end = 0; int maxLen = Integer.MAX_VALUE; int maxStart = 0; // to track Start index of substring int maxEnd = 0; // to track End index of substring int count = countMap.size(); while (end < sLen){ char tempCharEnd = s.charAt(end); if(countMap.containsKey(tempCharEnd)){ countMap.put(tempCharEnd,countMap.get(tempCharEnd) - 1); if(countMap.get(tempCharEnd) == 0){ count--; } } while (count == 0) { if(maxLen > end - start + 1) { maxLen = end - start + 1; maxStart = start; maxEnd = end + 1; } char tempCharStart = s.charAt(start); if (countMap.containsKey(tempCharStart)) { countMap.put(tempCharStart, countMap.get(tempCharStart) + 1); if (countMap.get(tempCharStart) > 0) { count++; } } start++; } end++; } System.out.println(maxLen); System.out.println("Start Index : " + maxStart +" End Index :" + maxEnd + ": "+ s.substring(maxStart,maxEnd));
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
@@adityajain5101 Try this one, it passes all the test cases. In your code it should be if(mp[s[i]] > 0) count++; My code :- string result=""; unordered_map mp;
The condition - if (countMap.get(tempCharStart) > 0) { count++; } is wrong coz here count represents the count of distinct characters, not the count of all characters. It should be -: if (countMap.get(tempCharStart) =1) { count++; }
Bhaiyya we really need more content! You have spoiled us so much that we cannot settle for anyone else! Please consider doing a series on graphs and/or backtracking.
Aditya bhaai, please upload your videos more frequent like before... I'm preparing for interviews and need your styled videos on backtracking and greedy algorithms. You are my favourite teacher.
This one was a bit trickier than the rest but managed to code it after a few attempts. Amazing playlist, I have personally seen a lot of question based on the limited patterns covered in this playlist! Very helpful!
I am in 4th year and I feared coding from 1st year but YOU HAVE REMOVED MY FEAR!! God bless you, love you bhai...please cover all the topics like graphs and trees as well
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
Subscribed. Hands down best content on youtube. I recently stumbled upon a problem I couldn't solve. Take a look into this mate might even be an addition to the playlist. the question - Given a string s and an integer k, return the length of the longest substring of s such that the frequency of each character in this substring is greater than or equal to k. Input: s = "aaabb", k = 3 Output: 3 Explanation: The longest substring is "aaa", as 'a' is repeated 3 times. Input: s = "ababbc", k = 2 Output: 5 Explanation: The longest substring is "ababb", as 'a' is repeated 2 times and 'b' is repeated 3 times.
working code in C++ According to Aditya Bhai's Explanation Hope this help!!!! #include using namespace std; int main() { string s="totmtaptat"; string s1="tta"; // Making the Map unordered_map mp; for(int i=0 ; i
I solved almost all of the string based sliding window questions using count of distinct numbers technique in one way or another... It's such an OP trick
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
@@akankshasinha3352 search tuf , striver has covered variety of problems on trees, first get a basic idea of how recursion works, then trees will be a cakewalk for you. Linkedlist are easy dude. it will come along with some practice.
I don't know why subscriber are less at this Channel...No one can Compare to Aditya Bhaiya...He is amazing to make people understood what he teach... Lots of love to your effort and your way of teaching.
Bhai tu best h Plss saare concepts pe video banado. I have enrolled in Coding blocks, Simplilearn and now HEYCOACH cohort fot DSA. Prr conecpts strong sirf teri videos se hote hai. Please saare concepts pe video banao bhai, IN THE SAME FORMAT PLease. Apna way of teaching and format constant rakhna bas. I always recomment you to everyone, who needs DSA!! U r best bro. Keep it up
Tried implementing in Python.. def minimumSubstringWindow(strng, t): count_map = dict() n = len(strng) for ch in t: if ch in count_map: count_map[ch] += 1 else: count_map[ch] = 1
start = 0 end = 0 map_size = len(count_map) min_window_len = 1000000007 maxStart = 0 maxend = 0 while end < n: if strng[end] in count_map: count_map[strng[end]] -= 1 if count_map[strng[end]] == 0: map_size -= 1 while map_size == 0: min_window_len = min(min_window_len, (end - start + 1)) maxStart = start #substring start index maxend = end+1 #substring end index ch_start = strng[start] if ch_start in count_map: count_map[ch_start] += 1 if count_map[ch_start] > 0: map_size += 1 start += 1 end += 1 print("substring start index {} and end index {}".format(maxStart, maxend)) return min_window_len
A)Java soltuion for this video: as well as modified for leetcode in part B) public class minimum_window_substring { public static void main(String[] args) { String s = "timetopractice", t = "toc"; HashMap map=new HashMap(); for(int x=0;x
Here is the c++ implementation string minWindow(string s, string t) { int i=0,j=0,MinL=INT_MAX,start=0; unordered_map mp; for(auto it:t) mp[it]++; int count=mp.size();
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
after watching this playlist, i finally can say that i can solve almost every problem of sliding window, really this is the best explanation for sliding window technique. Thanks a lot
C++ Code for the explanation and also made the addition for LC Question as it needs us to return the actual substring : my solution is not the most optimal but this is what i came up with based on my current understanding. string minSubstrWindow(string s, string t) { if(t.length()>s.length()) { return ""; } int res = INT_MAX; // we calc the freq of each char in the map unordered_map map; unordered_map mapS;
idea behind returning string as out answer : we use an ans variable since we know we are trying to find the smallest substring we can use that to our advantage and use the minimum window size. So whenever after changing the count to 1 we check if our stored ans length is > then the window if yes than store the string in the window as our answer
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
@@akankshasinha3352 You can check other channels related to coding as Leadcode by fraz and pepcoding(they have great playlists regarding different problems)
@@akankshasinha3352 first of all see mycodeschool DSA playlist make notes then all playlist of Aditya Verma starting from heap, stacks, sliding window, binary search, recursion except dp .....and make sure to make notes of all these topics. Then watch striver recursion playlist and dp playlist and make notes . Then solve striver sde sheet of 180 question it might be difficult for uhh to solve every problems by own so try to see video solution.....nd I guarantee this is enough for anybody to get good placement nd for girls it is enough to get very good placement ☕☕🌚
@@prathamrajbhattnit-allahab4108 haan Bhai notes h thik thak bane hue bass mei jada decorated nhi krta hu notes I mean only use one pen ...aur concept pakda aur code rough type se likh diya ache se samajh mei aa jayega kisiko v mere notes 👍
Sir what happened to you.Hope you are kepping well the last video was uploaded 4 months ago we really want your help many are eagerly waiting for your videos. Please come back soon.
Here is the most easy to understand solution, I hereby conclude that I have completed this series and I am confident that I can identify and tackle the sliding window problems. Thanks Aditya Bhaiya ur teaching gave mine lost confidence back 🔥🔥❤❤ Code: class Solution { public: string minWindow(string s, string t) { unordered_map mp; for (char c : t) mp[c]++; int count = t.size(); int i = 0, j = 0; int ans = INT_MAX; int start = 0; while (j < s.size()) { if (mp[s[j]] > 0) count--; mp[s[j]]--; j++; while (count == 0) { if (j - i < ans) { ans = j - i; start = i; } mp[s[i]]++; if (mp[s[i]] > 0) count++; i++; } } if (ans == INT_MAX) return ""; return s.substr(start, ans); } };
C++ solution along with explanation to few condition I have taken into account string minWindow(string s, string t) { // base case if length of s in smaller than j if(s.size() < t.size()) return ""; // initialize the map to store character ocurring in t along with their count unordered_map map; for (char c : t) map[c]++; // define i and j and n = s.size() along with count int i = 0; int j = 0; int count = map.size(); int n = s.size(); int minSize = INT_MAX; //I am using pair to store the index of smallest resultant substring pair res{-1,-1}; while( j < n){ if(map.find(s[j]) != map.end()){ map[s[j]]--; if(map[s[j]] == 0)count--; } cout
If you want to find the smallest string: string minWindow(string s, string t) { int starti=0; int endi=-1; int slen = s.length(); int tlen = t.length(); unordered_map mp; for(int i=0;i
Sir please make videos on Back-Tracking and Graph !!! It will be very helpful for us who cannot afford such quality and expensive courses on other plateform. Keep up the good work sir!!!😇
I am following your DP playlist. I have seen comments of your every video, Everybody request you to make trees & graph tutorial. These topics are tougher to understand? If yes then I am also requesting you to make videos on them. Thanks
//declare window variables int i=0,j=0; int len=INT_MAX; //to store the length of minimum window int startIdx = 0; string result;//finally return s.substr(startIdx,len)
//create freq. map unordered_map mp; for(int i=0 ; i
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
Thnx bro for not showing us the exact code but only explaining the logic , As, after doing the code without error after using with Video's logic, Is great feeling :)
Bhiya poora graph aur tree pe daalo videos plz. Btw aapka dp seris bhut mast tha😊😊😊😊😊. Bhiya dp ka playlist mein kuch missing h kyaa?? Yaa complete h woh?
Sir , My friend requested ur channel. I am a non Hindhi speaker. But somewhat I can understand ur video....It will be more better if u add subtitiles....Autogenerating Subtitles are not good.Thank you for the great content .
In this video condition is explained but "what to compare the condition to?" is not well explained, I tried "if count > 0: j++" and "else if count == 0: ...result and slide window". I then tried another approach. Below is the Python3 code for another approach: S = list("ADOBECODEBANC") T = list("ABC") freqT = {} for c in T: freqT[c] = freqT.get(c, 0) + 1 i = 0 j = 0 m = len(S) n = len(T) freqS = {} output = [] matchCount = 0 while i < m: # Acquire while i < m and matchCount < n: c = S[i] freqS[c] = freqS.get(c, 0) + 1 if freqS.get(c, 0)
Sir your way of teaching is really magical. Even hard questions of leetcode seem easy. This and upcoming generations are really blessed to have your lectures. Sir just a request please make graph also easy. You can make any topic a cakewalk.
Concise code for the problem:
string minWindow(string s, string t) {
unordered_map mp;
int minlen=INT_MAX, start=0;
for(auto ch:t){
mp[ch]++;
}
int i=0,j=0,count=mp.size();
while(j
commenting for better reach ( according to the explanation) great
CFBR
CFBR
Please note that instead if(mp[s[i]]==1) it will be if(mp[s[i]] > 0)
good
I haven't included the code of this problem in this video and not uploading it right now (although I have it ready): for two reason:
1) Video was getting too long.
2) I want you guys to do it by yourself, since this will be last video in this series and this is the "BAAP" problem of sliding window, if you can do it, I can assure you will be able to do almost any sliding window problem.
Try it by yourself, I will upload soon :)
Thank you so much, Aditya. Pleaseee upload BFS & DFS (i am having trouble with imp questions like number of islands etc)
your videos have been very helpful :)
Hello, I tried to write its code, but getting few errors. Can you please upload the code on github or in another video?
Bhai you are great your videos are very helpful, plz make videos on backtracking plz🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏
upload nhi kiye
Kindly add subtitles..so it Will be useful for everyone
Hello Sir, I never thought coding could be this enjoyable before watching ur videos, eagerly waiting for your series of GRAPHS and TREES.☺️
yes graph and all the other remaining topics🙈.
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
Keep waiting 😂😂😂
@@akankshasinha3352 u may refer to other channel take u forward / striver / techdose
@iblis take u forward
Vote for backtracking series.
@Aditya verma what does it mean?
@@Jadon09 It's a traveling fake salesman problem
definetly intrested,
This is his last uploaded video
I tried to find your social media link but couldn't find it, because of you only got placed in VMware Interview mei pucha mrese ki node to node max sum path ka value nikalna h aur hm yeh thumb nail mei dekhe the yaad tha qstn but soln nii aata tha ab hmko smjh nii aara tree mei dp kaise lgega kahe ki yeh dp playlist mei h aur interviewer smjh gya ki hmko yeh qstn aata nii h kahe ki hm bhot cross qstn krre end mei solve huaa aur vo next Interviewer ko itna aacha review diye ki baapre kisi ne reject nii krra aur mreko hr mei bola gya face mei ki I got selected for intern + fte Bhai sir literally bow to your expertise ❤️❤️ aur stack ko sort krne v bola recursively vo v bna diye hm uska v video h apka playlist mei bhai bnate rhiye aisa video bhot help hota h ❤️❤️
Idea behind iterating Given String length can thought as :
1) Iterate thru string S till the count [map size from String T characters] variable reaches to 0.
2) Once counter is 0, try to move the start pointer towards end pointer to minimize the length of the found substring. If character at start pointer matches with string T increment the count variable. Loop thru till count variable is 0.
//
String s = "timetopractice";
String t = "toct";
int sLen = s.length();
int tLen = t.length();
if(tLen > sLen)
System.out.println("Invalid Input");
HashMap countMap = new HashMap();
for (char c: t.toCharArray()
) {
countMap.put(c,countMap.getOrDefault(c,0) + 1);
}
int start = 0;
int end = 0;
int maxLen = Integer.MAX_VALUE;
int maxStart = 0; // to track Start index of substring
int maxEnd = 0; // to track End index of substring
int count = countMap.size();
while (end < sLen){
char tempCharEnd = s.charAt(end);
if(countMap.containsKey(tempCharEnd)){
countMap.put(tempCharEnd,countMap.get(tempCharEnd) - 1);
if(countMap.get(tempCharEnd) == 0){
count--;
}
}
while (count == 0) {
if(maxLen > end - start + 1) {
maxLen = end - start + 1;
maxStart = start;
maxEnd = end + 1;
}
char tempCharStart = s.charAt(start);
if (countMap.containsKey(tempCharStart)) {
countMap.put(tempCharStart, countMap.get(tempCharStart) + 1);
if (countMap.get(tempCharStart) > 0) {
count++;
}
}
start++;
}
end++;
}
System.out.println(maxLen);
System.out.println("Start Index : " + maxStart +" End Index :" + maxEnd + ": "+ s.substring(maxStart,maxEnd));
string result="";
unordered_map mp;
for(int m=0;m
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
@@adityajain5101 Try this one, it passes all the test cases. In your code it should be
if(mp[s[i]] > 0)
count++;
My code :-
string result="";
unordered_map mp;
for(int m=0;m
you don't need maxEnd if you've already found the min lngth i.e. s.substring(maxStart, maxStart + maxLen+1)
The condition -
if (countMap.get(tempCharStart) > 0) {
count++;
}
is wrong coz here count represents the count of distinct characters, not the count of all characters.
It should be -:
if (countMap.get(tempCharStart) =1) {
count++;
}
WOW aditya bhayia, kitna badia samjhaya hai aapne , khud se code pass karvane ki jo khushi hoti hai na kya hi batau , thanks a lot
Bhaiyya we really need more content! You have spoiled us so much that we cannot settle for anyone else! Please consider doing a series on graphs and/or backtracking.
Bruh
Aditya bhaai, please upload your videos more frequent like before... I'm preparing for interviews and need your styled videos on backtracking and greedy algorithms. You are my favourite teacher.
This one was a bit trickier than the rest but managed to code it after a few attempts. Amazing playlist, I have personally seen a lot of question based on the limited patterns covered in this playlist! Very helpful!
Please start a series on trees and graphs.
Please make a Series on Backtracking, Graph, Tree, Hashing & Number System
Aditya bhai , sari playlist ka security tight krva lo . Its PURE GOLD 🔥. Thanks for great approach
Thanks a lot for this awesome playlist . just completed and pretty much confident to solve most of the sliding window problems now
Bro can u pls help in the leetcode 1838 frequency of most frequent element question???
Using Aditya Sir approach
I am in 4th year and I feared coding from 1st year but YOU HAVE REMOVED MY FEAR!! God bless you, love you bhai...please cover all the topics like graphs and trees as well
already covered by striver
Then why are you here! lol
@@vivekswami2182
This has been an awesome series. Thanks a lot! Please cover more topics!
Please make a series on tree and graphs ... Please!
finally after so many tries of dry run. Here is the Js approach.
function minimumWindowSubstring(s, k) {
let [start, end, count, ans] = [0, 0, 0, Infinity];
let ansString = "";
const obj = {};
for (let i = 0; i < k.length; i++) {
obj[k[i]] = (obj[k[i]] || 0) + 1;
}
count = Object.keys(obj).length;
while (end < s.length) {
if (count !== 0) {
if (obj.hasOwnProperty(s[end])) {
obj[s[end]]--;
}
if (obj[s[end]] === 0) {
count--;
}
if (count !== 0) {
end++;
}
}
if (count === 0) {
if (ans > Math.min(ans, end - start + 1)) {
ans = Math.min(ans, end - start + 1);
ansString = s.slice(start, end + 1);
}
if (obj.hasOwnProperty([s[start]])) {
obj[s[start]]++;
}
if (obj[s[start]] == 1) {
count++;
end++;
start++;
continue;
}
start++;
if (ans > Math.min(ans, end - start + 1)) {
ans = Math.min(ans, end - start + 1);
ansString = s.slice(start, end + 1);
}
}
}
return ans === Infinity ? "" : ansString;
}
Placement season has started. Please upload videos on graphs and backtracking. And possibly add more videos on DP.
Thanks!
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
@@akankshasinha3352 you can check out take U forward youtube channel.
@@akankshasinha3352 check out take u forward. And love babbars dsa cracker sheet.
Subscribed.
Hands down best content on youtube.
I recently stumbled upon a problem I couldn't solve. Take a look into this mate
might even be an addition to the playlist.
the question -
Given a string s and an integer k, return the length of the longest
substring of s such that the frequency of each character
in this substring is greater than or equal to k.
Input: s = "aaabb", k = 3
Output: 3
Explanation: The longest substring is "aaa", as 'a' is repeated
3 times.
Input: s = "ababbc", k = 2
Output: 5
Explanation: The longest substring is "ababb", as 'a' is repeated
2 times and 'b' is repeated 3 times.
string minWindow(string s, string t) {
int size=t.length();
int size1=s.length();
if(size>size1) return "";
string ANS = "";
mapm;
for(int i = 0; i < size; i++){
m[t[i]]++;
}
int i=0,j=0,ans=INT_MAX;
int count=m.size();
while(j
@@payaljain4015
string smallestWindow (string s, string p){
vector umap(128,0);
for(int i=0;i 0){
counter++;
}
i++;
}
}
return minLength == INT_MAX ? "-1" : s.substr(minStart,minLength);
}
working code in C++ According to Aditya Bhai's Explanation
Hope this help!!!!
#include
using namespace std;
int main()
{
string s="totmtaptat";
string s1="tta";
// Making the Map
unordered_map mp;
for(int i=0 ; i
Thanks Man !
,🔥🔥❤️
int minWindowSubstring(string s, string t)
{
int i = 0;
int j = 0;
int ans = INT_MAX;
int n = s.length();
unordered_map mp;
int count = 0;
for (char c : t)
{
if (mp.find(c) == mp.end())
mp[c] = 0;
mp[c]++;
}
count = mp.size();
while (j < n)
{
if (mp.find(s[j]) != mp.end())
{
mp[s[j]]--;
if (!mp[s[j]])
count--;
}
if (count > 0)
j++;
else if (count == 0)
{
while (count == 0)
{
ans = min(ans, j - i + 1);
if(mp.find(s[i]) != mp.end()){
mp[s[i]]++;
if(mp[s[i]] == 1)
count++;
}
i++;
}
j++;
}
}
return ans;
}
I solved almost all of the string based sliding window questions using count of distinct numbers technique in one way or another... It's such an OP trick
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
@@akankshasinha3352 search tuf , striver has covered variety of problems on trees, first get a basic idea of how recursion works, then trees will be a cakewalk for you. Linkedlist are easy dude. it will come along with some practice.
@@vishalgupta957 thankyouuuuu 😋😋 i
Sir, never stop doing this, gold content
Why have you stopped making videos?...Your content is just awesome.
Bro can u pls help in the leetcode 1838 frequency of most frequent element question???
Using Aditya Sir approach
Start uploading again, please. We need you. Jaldi aao.
Sir, please bring in new lectures on remaining topics . Your observations has really been a boon to all of us .
I don't know why subscriber are less at this Channel...No one can Compare to Aditya Bhaiya...He is amazing to make people understood what he teach... Lots of love to your effort and your way of teaching.
completed the whole playlist sir thankyou for such an effort of yours to explain this topic in such depth.
Bhaiya aapki puri playlist dekhi. Best playlist on youtube for sliding window technique👌. Voting for backtracking series
thanks sir!! you explained the sliding window concept in amazing depth , amazing playlist
solved by my own, thank you for the concepts
The most awaited video of the most amazing teacher.
Bas ab ek hi cheez bachi hai zindagi me aur wo hai aapke charan sparsh karna.
Arreyy Nhi bhai, hmara aashirvaad aese hi sath h tumhare 🖐😬😬
Thank you so much for all this hard work sir, coding has never been this easy.
Completely agree brother. I am so fortunate ki mujhe ye channel Mila.
Very well illustrated! Thanks
I was stucked in this problem for last 3 hrs but after watching your video I was able to code in single run 😃
Bhai tu best h
Plss saare concepts pe video banado. I have enrolled in Coding blocks, Simplilearn and now HEYCOACH cohort fot DSA. Prr conecpts strong sirf teri videos se hote hai. Please saare concepts pe video banao bhai, IN THE SAME FORMAT PLease. Apna way of teaching and format constant rakhna bas. I always recomment you to everyone, who needs DSA!! U r best bro. Keep it up
Tried implementing in Python..
def minimumSubstringWindow(strng, t):
count_map = dict()
n = len(strng)
for ch in t:
if ch in count_map:
count_map[ch] += 1
else:
count_map[ch] = 1
start = 0
end = 0
map_size = len(count_map)
min_window_len = 1000000007
maxStart = 0
maxend = 0
while end < n:
if strng[end] in count_map:
count_map[strng[end]] -= 1
if count_map[strng[end]] == 0:
map_size -= 1
while map_size == 0:
min_window_len = min(min_window_len, (end - start + 1))
maxStart = start #substring start index
maxend = end+1 #substring end index
ch_start = strng[start]
if ch_start in count_map:
count_map[ch_start] += 1
if count_map[ch_start] > 0:
map_size += 1
start += 1
end += 1
print("substring start index {} and end index {}".format(maxStart, maxend))
return min_window_len
Thanks Aditya.
Below is the java solution based on this explaination.
Java Solution :
class Solution {
public String minWindow(String s, String t) {
String ans="";
int i=0,j=0;
int min=Integer.MAX_VALUE;
HashMap map=new HashMap();
for(int k=0;k0)
count++;
i++;
}
if(count==0)
{
if(min>j-i+1)
{
ans=s.substring(i,j+1);
min=j-i+1;
}
}
}
}
j++;
}
return ans;
}
}
Here is bit improved code
class Solution {
public String minWindow(String s, String t) {
String ans="";
int i=0,j=0;
int min=Integer.MAX_VALUE;
HashMap map=new HashMap();
for(int k=0;k0)
count++;
}
i++;
}
}
}
return ans;
}
}
A)Java soltuion for this video: as well as modified for leetcode in part B)
public class minimum_window_substring {
public static void main(String[] args) {
String s = "timetopractice", t = "toc";
HashMap map=new HashMap();
for(int x=0;x
Bro can u pls help in the leetcode 1838 frequency of most frequent element question???
Using Aditya Sir approach
Aditya shocked to see your face on recommended video😮😮
Good Job!
SSMV ka naam roshan kar diya👍
Here is the c++ implementation
string minWindow(string s, string t) {
int i=0,j=0,MinL=INT_MAX,start=0;
unordered_map mp;
for(auto it:t)
mp[it]++;
int count=mp.size();
if(mp.find(s[j])!=mp.end()){
mp[s[j]]--;
if(mp[s[j]]==0)
count--;
}
while(j0){
j++;
if(mp.find(s[j])!=mp.end()){
mp[s[j]]--;
if(mp[s[j]]==0)
count--;
}
}
else if(count==0){
// MinL=min(MinL,j-i+1);
if(MinL>j-i+1){
MinL=j-i+1;
start=i;
}
while(count==0){
if(mp.find(s[i])!=mp.end()){
mp[s[i]]++;
if(mp[s[i]]==1){
count++;
// MinL=min(MinL,j-i+1);
if(MinL>j-i+1){
MinL=j-i+1;
start=i;
}
}
i++;
}
else
i++;
}
}
}
string str="";
if(MinL!=INT_MAX)
return str.append(s.substr(start,MinL));
else
return str;
}
Runtime: 44 ms
Memory Usage: 7.8 MB
Pretty Awesome code man.
Thank you!!
Why you have checked the first value before the while loop(j
@@kanishkraj5640 i guess coz he is incrementing j bfr use in while loop, either move it to end of if block or start j with -1 to avoid it
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
Bhai kaha gaye the yaar... I just waited, waited and again I waited...
after watching this playlist, i finally can say that i can solve almost every problem of sliding window, really this is the best explanation for sliding window technique. Thanks a lot
can't thank you enough, had fun sliding through the playlist
Very nice video. Clarity of your thought process is awesome.
C++ Code for the explanation and also made the addition for LC Question as it needs us to return the actual substring : my solution is not the most optimal but this is what i came up with based on my current understanding.
string minSubstrWindow(string s, string t)
{
if(t.length()>s.length())
{
return "";
}
int res = INT_MAX;
// we calc the freq of each char in the map
unordered_map map;
unordered_map mapS;
for(int i=0; i
idea behind returning string as out answer : we use an ans variable since we know we are trying to find the smallest substring we can use that to our advantage and use the minimum window size. So whenever after changing the count to 1 we check if our stored ans length is > then the window if yes than store the string in the window as our answer
I am glad previous approach provided help me to solve this problem , without looking at this videos
I'm also from MANIT CSE. Please please make a series on Trees and graphs. Much needed. Placement season is approaching.
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
@@akankshasinha3352 You can check other channels related to coding as Leadcode by fraz and pepcoding(they have great playlists regarding different problems)
@@akankshasinha3352 first of all see mycodeschool DSA playlist make notes then all playlist of Aditya Verma starting from heap, stacks, sliding window, binary search, recursion except dp .....and make sure to make notes of all these topics. Then watch striver recursion playlist and dp playlist and make notes . Then solve striver sde sheet of 180 question it might be difficult for uhh to solve every problems by own so try to see video solution.....nd I guarantee this is enough for anybody to get good placement nd for girls it is enough to get very good placement ☕☕🌚
@@hrithikkumar9648 hello bro kya tmne insabka notes bna rkha hai proper?
@@prathamrajbhattnit-allahab4108 haan Bhai notes h thik thak bane hue bass mei jada decorated nhi krta hu notes I mean only use one pen ...aur concept pakda aur code rough type se likh diya ache se samajh mei aa jayega kisiko v mere notes 👍
Sir what happened to you.Hope you are kepping well the last video was uploaded 4 months ago we really want your help many are eagerly waiting for your videos. Please come back soon.
bro, really nice explanation...!! found it very useful.
wonderful explaination 🫡
Very Very good explanation
Here is the most easy to understand solution, I hereby conclude that I have completed this series and I am confident that I can identify and tackle the sliding window problems. Thanks Aditya Bhaiya ur teaching gave mine lost confidence back 🔥🔥❤❤
Code:
class Solution {
public:
string minWindow(string s, string t) {
unordered_map mp;
for (char c : t) mp[c]++;
int count = t.size();
int i = 0, j = 0;
int ans = INT_MAX;
int start = 0;
while (j < s.size()) {
if (mp[s[j]] > 0) count--;
mp[s[j]]--;
j++;
while (count == 0) {
if (j - i < ans) {
ans = j - i;
start = i;
}
mp[s[i]]++;
if (mp[s[i]] > 0) count++;
i++;
}
}
if (ans == INT_MAX) return "";
return s.substr(start, ans);
}
};
Thank you
Please continue uploading videos seriously u teach very well and it is very much understandable
This playlist of sliding window is like God gifted for everyone😊😊😊
Great Explanation :)
Coded after watching the video with a wrong attempt...
Sep'27, 2023 11:10 pm
Epic Level Explanation...Thanks !!
After listening problem explanation able to solve by myself ,thank you for the series bhai
Thanks sir for this best or more useful playlist ❤❤❤
thankyou bhai saari video dekhi maza aaya
C++ solution along with explanation to few condition I have taken into account
string minWindow(string s, string t) {
// base case if length of s in smaller than j
if(s.size() < t.size()) return "";
// initialize the map to store character ocurring in t along with their count
unordered_map map;
for (char c : t)
map[c]++;
// define i and j and n = s.size() along with count
int i = 0;
int j = 0;
int count = map.size();
int n = s.size();
int minSize = INT_MAX;
//I am using pair to store the index of smallest resultant substring
pair res{-1,-1};
while( j < n){
if(map.find(s[j]) != map.end()){
map[s[j]]--;
if(map[s[j]] == 0)count--;
}
cout
22:49 for the actuall solution and explaination
If you want to find the smallest string:
string minWindow(string s, string t) {
int starti=0;
int endi=-1;
int slen = s.length();
int tlen = t.length();
unordered_map mp;
for(int i=0;i
stucked at an edge case in gfg
Thank you.
This helped a lot.
can you please do video on bitmask dp & dp on grid
Sir please make videos on Back-Tracking and Graph !!!
It will be very helpful for us who cannot afford such quality and expensive courses on other plateform.
Keep up the good work sir!!!😇
I am following your DP playlist. I have seen comments of your every video, Everybody request you to make trees & graph tutorial. These topics are tougher to understand? If yes then I am also requesting you to make videos on them. Thanks
SIR, Ye toh Gold hai👏👏👏👏
*C++ Implementation* :
string minWindow(string s, string t) {
//declare window variables
int i=0,j=0;
int len=INT_MAX; //to store the length of minimum window
int startIdx = 0;
string result;//finally return s.substr(startIdx,len)
//create freq. map
unordered_map mp;
for(int i=0 ; i
Hi … please tell , how to build concept for rest of the linkedlist and trees kind of problem? Cz everything is not covered on this channel ! 🥺😔 gimme some ideas
Nice
thank you so much bhai ...
Thank you so much sir ,just loved the series
Finally i Completed the whole playlists of the "appar gyan bhandar".......thanks thanks a lot*infinity Sir❤❤❤❤
Thank You !
Please make playlist for backtracking and queue ds
Great dedication "Likh hi deta hu"!!!
wonderful explanation!!!!!!!!!!!!!!!
Thnx bro for not showing us the exact code but only explaining the logic , As, after doing the code without error after using with Video's logic, Is great feeling :)
Hey brother, can you provide your code?? My code is not working .
doing MTECH in iit doesnt count so remove that iit madras from your profile name
@@TuringTested01 It counts very well.
loved this video..will share your videos with all my friends..Top work..keep it up!
Bhiya poora graph aur tree pe daalo videos plz. Btw aapka dp seris bhut mast tha😊😊😊😊😊.
Bhiya dp ka playlist mein kuch missing h kyaa?? Yaa complete h woh?
misiing he
Sir , My friend requested ur channel. I am a non Hindhi speaker. But somewhat I can understand ur video....It will be more better if u add subtitiles....Autogenerating Subtitles are not good.Thank you for the great content .
Thank you very much. You are a genius.
You are great man
Bhaiya graph ki series bhi upload kr do please 🙏
Sir please make a dedicated series on backtracking, it is really needed.
Want the Solutions for the playlist,
Here you go:
github.com/venkateshjamge/Sliding-Window-Algorithm-Aditya-Verma
thanks for this series
Best explanation
No word to say thanks to you... Thanx
best lecture ever... loved it...
Sir please start greedy Algo too
Hi Aditya ,Please make more videos
NEVER THOUGHT OF DOING SUCH QUESTION BY MY OWN . THANKS FOR THE CONCEPT
Bro can u pls help in the leetcode 1838 frequency of most frequent element question???
Using Aditya Sir approach
Thanks so much, Aditya, for creating such videos.
Very very helpful thanks alot❤
In this video condition is explained but "what to compare the condition to?" is not well explained, I tried "if count > 0: j++" and "else if count == 0: ...result and slide window". I then tried another approach. Below is the Python3 code for another approach:
S = list("ADOBECODEBANC")
T = list("ABC")
freqT = {}
for c in T:
freqT[c] = freqT.get(c, 0) + 1
i = 0
j = 0
m = len(S)
n = len(T)
freqS = {}
output = []
matchCount = 0
while i < m:
# Acquire
while i < m and matchCount < n:
c = S[i]
freqS[c] = freqS.get(c, 0) + 1
if freqS.get(c, 0)
Thank you so much bhaiya ❤️
Now I am able to solve LeetCode medium problems based on sliding window 💯✅
Your videos are so amazing. Please make a playlist of system design. we don't see any good system design videos especially in hindi.
Thanks Aaditya bhai!! Completed DP and SLiding window playlist! Can you please upload video related to Backtracking and greedy algo
amazing content
Sir your way of teaching is really magical. Even hard questions of leetcode seem easy. This and upcoming generations are really blessed to have your lectures. Sir just a request please make graph also easy. You can make any topic a cakewalk.
Sir please complete the DP series. There is no content comparable to yours.