Leetcode Flashcards

1
Q

Find duplicate number

A

use slow and fast pointer and where both meet is circular detection and that is duplicate number

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

search 2D

A

if it is sorted, then increment row or column based on the range. Like binary search

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

Find duplicates in two lists

A

use set and keep putting into set

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

Find the first and last position of element in sorted array

A

Use binary search and then keep incrementing and decrementing on that position

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

Merge sort

A

see which is one small and keep moving until 2one is bigger

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

Color sorting

A

as the range is small, use bucket or counter index, or use set to increment

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

Relative sort array

A

2N: FOR array 1 -> check exists in array 2 and put in dictionary with counter. Then run FOR loop on array 2 to print in that order

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

K-frequent numbers

A

First use bucket sort and then use frequnecy with MaxHeap and pop 3 times

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