Leetcode Flashcards
Find duplicate number
use slow and fast pointer and where both meet is circular detection and that is duplicate number
search 2D
if it is sorted, then increment row or column based on the range. Like binary search
Find duplicates in two lists
use set and keep putting into set
Find the first and last position of element in sorted array
Use binary search and then keep incrementing and decrementing on that position
Merge sort
see which is one small and keep moving until 2one is bigger
Color sorting
as the range is small, use bucket or counter index, or use set to increment
Relative sort array
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
K-frequent numbers
First use bucket sort and then use frequnecy with MaxHeap and pop 3 times