Slinding Window Flashcards

1
Q

What are 2 types of sliding windows

A

Fixed and variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is fixed sliding window

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Contains duplicate in size k

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Number of sub array of size k and average greater that or equal to threshold

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Variable sliding window

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Minimum sliding window

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly