This is an overview of 75+ LeetCode questions that will prepare you for coding interviews - including explanations of common patterns/ways to use to solve these problems.
The key is for you to change my explanations to yours - in a way that allows you to remember how you solved it.
💡 Code on Github: https://github.com/tobiadey/LeetCode-Questions
Youtube Channels: LeetCode & Back To Back SWE
Common Coding Interview Patterns
Common Coding Interview Patterns:
- HashMap:
- A data structure that stores key-value pairs.
- Recursion: Time O(n),Space O(n)
- A function that calls itself.
- **Depth First Search(DFS): Time O(|v|+|e|),Space O(|v|)**
- A searching algorithm that favours depth over breadth. Implemented using a stack user-defined stack or the call stack from using recursion.
- Uses cases include backtracking, and exhausting possible paths.
- **Breath First Search(BFS): Time O(|v|+|e|),Space O(|v|)**
- A searching algorithm that favours breadth over depth. Uses a queue. Implemented iteratively.
- Uses cases include: checking if a path exists between 2 nodes
- Binary Search: Time O(logn),Space O(1)
- Searching algorithm for sorted data structures.
- Sliding Window
- A problem-solving technique that involves using pointers and moving them across an array in order to solve the problem
- Heaps:
- A tree-based Data structure that is a complete binary tree. e.g include Max & Min heap.
Array - [1,2,3,4,5]
- Two Sum - Stores each value in a hashMap. Before hashing check, if the difference has already been hashed.
- Best Time to Buy and Sell Stock - Find local min and search for local max, sliding window;
- Contains Duplicate - Use sets operation then compare lengths
- Product of Array Except Self - make two passes, first in order, second in reverse, to compute products. (you will need the prefix & suffix to compute these values)
- Maximum Subarray - Pattern: prev subarray can't be negative, dynamic programming: compute max sum for each prefix