Variable Size Sliding Window General Format

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


In this video we will discussion how fix size and variable size sliding window are different and Will discuss the general format for Variable Size Sliding Window.

The things that we gonna generalise in this video will help us tremendously in solving the upcoming problems.

Next Video: 20th Dec 2020 .
------------------------------------------------------------------------------------------
Here are some of the gears that I use almost everyday:

PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.
Рекомендации по теме
Комментарии
Автор

11th - 12th :- HC VERMA
AFTER 12th :- ADITYA VERMA 🔥❤️

shlokhinge
Автор

its only your videos which improved my coding skills unexceptionally specially DP, please add more DP problems, do make videos on trees and graphs, cuz most companies are asking for these, this placement session is going harder a bit.
LOTS OF LOVE FOR NITA guy

rajkrishna
Автор

Amazing and lucid explanations. 1 week back I feared these problems now i solve it easily .. your are truly inspirational man

vaibhavsingh
Автор

Hey @Aditya Verma!
Actually The Problem Minimum size Subarray with Sum K doesn't follow the generic pattern mentioned here as it is bit different use cases.
Tha actual Code which gives me proper answer is:

public int minSubArrayLen(int target, int[] nums) {
int i = 0, j = 0, answer = Integer.MAX_VALUE, currWinSize = answer;
long currSum = 0;

while (j < nums.length) {
//Calculating the sum for jth Elemnets
currSum += nums[j];
if (currSum < target) {
j++; // Waiting for the condition to be met.
} else if (currSum == target) {
currWinSize = j - i + 1; //Retrieving the Answer as the condition already met
answer = Math.min(answer, currWinSize);
j++;
} else if (currSum > target) {
while (currSum > target) {
currWinSize = j - i + 1; //Retrieving the Answer again
answer = Math.min(answer, currWinSize);
currSum = currSum - nums[i];
i++;
}
if (currSum == target) {
currWinSize = j - i + 1; //Retrieving the Answer as the condition already met
answer = Math.min(answer, currWinSize);
}
j++;
}
}
if (answer == Integer.MAX_VALUE) {
return 0;
}
return answer;
}

prathamsinghal
Автор

Was solving a problem on Leetcode,
Came here to understand SW concept, and this video made it buttery-easy.
Thanks man!

wasifirshad
Автор

In variable size, while removing calculation of i, there is also a possible candidate of answer which is missing here.

gyanendraverma-jc
Автор

is there anyone else who likes Aditya sir's video before it starts and then start watching?

samirsaurabh
Автор

@Aditya Sir Sir, I think one thing not handled in this general format... if(condn>K) ->after coming out from while loop ...what if we got( condn==k)...then we should have taken this candidate in ans variable or not??.
Please check

ManishKumar-uxun
Автор

Hi Aditya, your way of teaching is really good, it is helping out so many people who are having difficulty learning DSA, and I am eagerly looking foward to more such video

prachitanaik
Автор

Hi everyone,
Firstly, I appreciate aditya's effort.. he is a fantastic teacher.

Cheak this test case-4 1 2 1 2 3 5 for k=5
the code will give wrong output as 2 but the answer is 3. This is because 1 2 1 2 sum become 6 and the code remove first 1 and then added j=j+1. This skips the candidate "2 1 2".
So, We can avoid this by writing sum==k statement before sum+=array[j]. This will only add 1 iteration. Thanks

aryan_sharma
Автор

Bhai yr sach me sach me END kr diya tum ne
Ye lo dil rakh lo mera 💁🏻‍♂️♥️

unknown-cjgv
Автор

Aap jb btana shuru krte ho na toh lgta h bass sunte video kbi khtm hi na ho, itta smoothly concepts gain hote h 💖 ♥ 💥💥

roushanraj
Автор

Sir in this format, if we are doing J++ every time why not write in last and not include cond <k as we only do j++ in that condition so there's no need for that i think.

DhrutiSahoo
Автор

Good evening bhaiya we are waiting for Backtracking and greedy algorithm

gorakhkumargupta
Автор

so nice explanation bhai...thank you so ji..chaaaa gayeee....guru...

pranaypatadiya
Автор

Please make Playlist for graph and tree, please please 🙏

roushanraj
Автор

Bhaiya i think that the above approach will only work when array has only positives and zero and not in the case when array has negative elements also.

nilmani
Автор

if(condition<k)
j++;

is this condition is really required if we are incrementing j at last.

ShivamSharma-isep
Автор

@Aditya sir aapka jyada duration of video aasan sa, less important cheez smjhane mei jaata hai....aur more important hard things less touched rh jaata baar aap apna video dekhna aap ko smjh mei aa jayega meri baat.

ManishKumar-uxun
Автор

a better format could be this:
int start = 0;
int end = 0;
while (end < size) {

// calculations

if (....== k) {
// conditions/calculations
} else if (... > k) {
while (... > k && start < end) {
// do something
start++;
}
}
end++;
}

// return something

bliss_anand