Medium Top Interview Flashcards
1
Q
Permutations of numbers
A
depth first search for each element
2
Q
Generate parentheses
A
Back tracking and depth first search, two recursive calls
3
Q
- Product of Array Except Self
A
Take leftside product and right side product and multiply them together.
4
Q
- Subsets
A
Recursion and backtracking
5
Q
- Kth Smallest Element in a BST
A
Keep a stack. Push all left elements, if k is zero, return, else decrement k and go right.
6
Q
4Sum II
A
hashtable
7
Q
- Rotate Image
A
rotate a[i][j] = a[j][i] and then reverse the individual rows
8
Q
Find duplicate element in the array
A
fast and slow method. However fast is basically a[a[fast]] instead of next next
9
Q
- Top K Frequent elements
A
Create a dict, rev dict and a min heap.