- BFS
- find shortest path in grid
- print node values in specific order
- traversal patterns: level order traversal (no preorder/inorder/postorder)
questions:
- DFS
- find longest path in tree
- uses last in first out concept
- common data structures: stack [], double ended queue, collections.deque([])
- traversal patterns: preorder (node, left, right), inorder (left, node, right), postorder (left, right, node)
- ** inorder traversal always give you elements in ascending sorted order
questions:
- Stack
- delete from end of the list frequently
- Hashmaps
- lookup with O(n)
- count number/character occurence
questions:
- Two pointer/Binary search
- traverse an array
questions:
- Min/Max Heap
- find Kth element
questions:
- Sliding Window
- use 2 pointer approach
- normally left and right pointer start on the same index, right pointer moves forward, hits a condition and stops, then left pointer will move to meet right pointer and then right pointer will increment by one index and repeat the same process
questions: max consecutive ones
- subarray sum equals K/divisible by K/multiple of K is solved by using prefix sum
- prefix sum is the accumulative sum of each numbers as you go along the array
- commonly used with a hashmap to track historical seen sums
- if the current sum is being seen before, it means K existed
- speak out thoughts when solving leetcode questions
- write down bullet points of how to solve a question
- think about edge cases first before solution
- show interviewer you have weigh the pros & cons of every solution
- reverse traverse list with
for i in range(len(list) -1, -1, -1): list[i]...
- traverse a list with index and value at the same time with enumerate
eg: for index, value in enumerate(list): ...
- list should not be the key of a dictionary in python because list is mutable, only immutable data structures are valid for python dictionary keys, use tuple instead
- return the values in a dictionary using dict.values()
- Space complexity for binary search trees is dependent on whether the nodes are balanced or skewed on one side
- pre order runs the body of the node first and then the body of the left children and then the body of the right children
- if you are able to simplify the question we wont have to think about the cases (ex: insert into sorted circular linked list)
- calculate the ascii letter difference between two alphabets by using ord('a') - ord('b') = -1
- Read question carefully
- Internalize implementation steps in your mind
- Verify if steps works with sample input
- Verify again if steps covered edge cases
- Write down internalized steps in bullet points
- Modify any gaps that you didn't cover
- Start coding