Sliding Window Flashcards
What are the various approaches of Sliding Window ?
- Sliding Window with fixed Size 2. Sliding window with variable size 3. Sliding window with hashmap. 4. Sliding window with tracking of maxValue .
- Window with a substring function
- Window stored ina dequeue
- How can we detect sliding window ?
- Whenever we have Sequential Values
- Substring problems which is again sequential values.
- Longest sub array type of problems
- Contiguous elements in a linkedlist
- How to get the number of elements between 2 index
highindex - lowIndex +1
- What is the general format ?
Common errors in 2 pointer method ?
- While iterating you might miss an element when you do it while(left<right>
</right><li>last pointer should be in arr.length-1 not arr.length</li>
</right>
Whats the gotcha for sort in js ?
The sort is alphabetic , so we need to pass the function to make it sort properly
What does in-place replacement and constant space signify ?
It should immediately indicate swapping
Whenever we need to generate integer from strings , add (sum), multiply or have any integer operations. What is a potential pitfall
- Always think of max bytes .
- it could be individual numbers are integers but when you sum them , you get the bytes overflow
What are the properties of XOR ?
- taking XOR of a number with itself returns 0, e.g.,
1 ^ 1 = 0
29 ^ 29 = 0
Taking XOR of a number with 0 returns the same number, e.g.,
1 ^ 0 = 1
31 ^ 0 = 31
XOR is Associative & Commutative, which means:
(a ^ b) ^ c = a ^ (b ^ c)
a ^ b = b ^ a
How to invert bytes of a number ?
number ^ complement = all_bits_set
number ^ number ^ complement = number ^ all_bits_set
0 ^ complement = number ^ all_bits_set
complement = number ^ all_bits_set
How to store a binary tree ?
If parent is at i
LeftChild 2i
RIghtChild2i+1
Level order traversal , keep missing rows blank
If the height of the binary tree is h , how many element in full bionary tree ?
2^(h+1)-1
Whats hieght of a binary tree ?
log N
What should immeditaley come to mind when you see hash map and charachetrs
Hashmap of 26 charachters
Do you need repetitions ?
During DFS , whats the complexity?
, it is the size of the tree