Medium Top Interview Flashcards

1
Q

Permutations of numbers

A

depth first search for each element

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

Generate parentheses

A

Back tracking and depth first search, two recursive calls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. Product of Array Except Self
A

Take leftside product and right side product and multiply them together.

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

Recursion and backtracking

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. 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.

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

4Sum II

A

hashtable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. Rotate Image
A

rotate a[i][j] = a[j][i] and then reverse the individual rows

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

Find duplicate element in the array

A

fast and slow method. However fast is basically a[a[fast]] instead of next next

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Top K Frequent elements
A

Create a dict, rev dict and a min heap.

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