Slinding Window Flashcards
What are 2 types of sliding windows
Fixed and variable
What is fixed sliding window
Usually the size of the window is k and you add elements to a set until you reach k then remove element to maintain fixed size and subsequently iterate on the array
The first pointer usually starts at 0 and the second pointer spans across the array when vast length increases from k you remove relents else you add
Contains duplicate in size k
1 start a pointer at 0 and a set that could contain upto k chars
2 if the size reaches k while iterating then check remove l value from set and increment l
2 iterate through the right pointer and check if the value is found in the set if it is return true
3 add r value in the set
4 return false
Number of sub array of size k and average greater that or equal to threshold
Concept is similar to fixed pointer keep on adding value once the set of value is k then check the average if average > or equal to value increment output counter by 1
This can also be done by sum and counter as a pointer as this is mathamatical
Variable sliding window
This case is when the size k is not fixed and you could expand or collapse window based on conditions
If the constraint is valid you keep on expanding window and soon as the constraint becomes. Invalid you collapse
The problems are usually asked I terms of find sizes of the array until condition is match
As here the unkown is k which is given in fixed size window
Minimum sliding window