Arrays Flashcards

1
Q

Search in rotated sorted array

A
  1. Binary search, compare start with mid to find ascending or descending
  2. Then check whether the target falls into the range
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Duplicate element in 0 - n -1 array

A
  1. Use tortoise and hare algo
  2. Find the cycle using do while and equality
  3. Set tortoise to start and iterate both by 1 and find the intersection
    Hashset and this algo are same time complexity, but this requires O(1) space complexity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Sliding window maximum

A
  1. Use queue to maintain the order of insertion (of indexes)
  2. Remove the out of index by i - k + 1 with peek value
  3. Remove the indexes with lower value than the current index
How well did you know this?
1
Not at all
2
3
4
5
Perfectly