10 Must-Know Time Complexity Patterns for Interviews:
1. ๐๐๐ฌ๐ก ๐๐จ๐จ๐ค๐ฎ๐ฉ - ๐(1) ๐๐ฏ๐๐ซ๐๐ ๐
A lookup usually takes constant time, regardless of input size. In the worst case, it can degrade to O(n).
2. ๐๐๐ฅ๐ฏ๐ข๐ง๐ ๐๐จ๐จ๐ฉ - ๐(๐ฅ๐จ๐ ๐ง)
The input size is divided by a constant factor in every step, such as in binary search.
3. ๐๐ข๐ง๐ ๐ฅ๐ ๐๐จ๐จ๐ฉ - ๐(๐ง)
Each element is processed once.
4. ๐๐๐ช๐ฎ๐๐ง๐ญ๐ข๐๐ฅ ๐๐จ๐จ๐ฉ๐ฌ - ๐(๐ง + ๐ฆ)
You iterate over two separate inputs one after another, not with one loop nested inside the other.
5. ๐๐จ๐จ๐ฉ + ๐๐ข๐ง๐๐ซ๐ฒ ๐๐๐๐ซ๐๐ก - ๐(๐ง ๐ฅ๐จ๐ ๐ง)
A loop runs n times, and each iteration performs O(log n) work.
6. ๐๐ข๐ฏ๐ข๐๐ & ๐๐จ๐ง๐ช๐ฎ๐๐ซ - ๐(๐ง ๐ฅ๐จ๐ ๐ง)
The problem is divided across roughly log n levels, with O(n) total work at each level. Merge sort is a common example.
7. ๐๐๐ฌ๐ญ๐๐ ๐๐จ๐จ๐ฉ๐ฌ - ๐(๐งยฒ)
For every element, you iterate over all elements again.
8. ๐๐ซ๐ข๐๐ง๐ ๐ฎ๐ฅ๐๐ซ ๐๐จ๐จ๐ฉ - ๐(๐งยฒ)
The inner loop performs fewer iterations each time, but the total is still roughly n(n โ 1) / 2, which is quadratic.
9. ๐๐ซ๐๐ง๐๐ก๐ข๐ง๐ ๐๐๐๐ฎ๐ซ๐ฌ๐ข๐จ๐ง - ๐๐ฑ๐ฉ๐จ๐ง๐๐ง๐ญ๐ข๐๐ฅ ๐๐ข๐ฆ๐
When each recursive call creates multiple new calls, the work can grow exponentially.
10. ๐๐๐ซ๐ฆ๐ฎ๐ญ๐๐ญ๐ข๐จ๐ง๐ฌ - ๐(๐ง!)
There are n! possible orderings, and producing or copying each complete permutation can take O(n) time.
โป๏ธ Repost to help others in your network.
If you want to learn Big O and time complexity in more detail, click here: algomaster.io/learn/dsa/big-โฆ
14 Must-Know Data Structures for Coding Interviews:
1. Array
2. Queue
3. Deque
4. Matrix
5. Stack
6. Binary Tree
7. Linked List
8. Doubly Linked List
9. HashMap
10. Binary Search Tree (BST)
11. Heap (Priority Queue)
12. Trie
13. Graph
14. Union Find
โป๏ธ Repost to help others in your network
7 Must-Know Big-O Complexities for Interviews:
1. ๐(1) - ๐๐จ๐ง๐ฌ๐ญ๐๐ง๐ญ ๐ญ๐ข๐ฆ๐
- The runtime doesn't change regardless of the input size.
- Example: Accessing an element in an array by its index.
2. ๐(๐ฅ๐จ๐ ๐ง) - ๐๐จ๐ ๐๐ซ๐ข๐ญ๐ก๐ฆ๐ข๐ ๐ญ๐ข๐ฆ๐
- The runtime grows slowly as the input size increases. Typically seen in algorithms that divide the problem in half with each step.
- Example: Binary search in a sorted array.
3. ๐(๐ง) - ๐๐ข๐ง๐๐๐ซ ๐ญ๐ข๐ฆ๐
- The runtime grows linearly with the input size.
- Example: Finding an element in an array by iterating through each element.
4. ๐(๐ง ๐ฅ๐จ๐ ๐ง) - ๐๐ข๐ง๐๐๐ซ๐ข๐ญ๐ก๐ฆ๐ข๐ ๐ญ๐ข๐ฆ๐
- The runtime grows slightly faster than linear time. It involves a logarithmic number of operations for each element in the input.
- Example: Sorting an array using quick sort or merge sort.
5. ๐(๐ง^2) - ๐๐ฎ๐๐๐ซ๐๐ญ๐ข๐ ๐ญ๐ข๐ฆ๐
- The runtime grows proportionally to the square of the input size.
- Example: Bubble sort algorithm which compares and potentially swaps every pair of elements.
6. ๐(2^๐ง) - ๐๐ฑ๐ฉ๐จ๐ง๐๐ง๐ญ๐ข๐๐ฅ ๐ญ๐ข๐ฆ๐
- The runtime doubles with each addition to the input. These algorithms become impractical for larger input sizes.
- Example: Generating all subsets of a set.
7. ๐(๐ง!) - ๐
๐๐๐ญ๐จ๐ซ๐ข๐๐ฅ ๐ญ๐ข๐ฆ๐
- Runtime is proportional to the factorial of the input size.
- Example: Generating all permutations of a set.
โป๏ธ Repost to help others learn this
10 Must-Know Graph Algorithms for Coding Interviews:
1. DFS (Depth-First Search)
2. BFS (Breadth-First Search)
3. Topological Sort
4. Union Find (Disjoint Set)
5. Cycle Detection
6. Connected Components
7. Bipartite Check
8. Flood Fill
9. Minimum Spanning Tree
10. Shortest Path (Dijkstra)
โป๏ธ Repost to help others in your network
๐ If you want to master all important algorithms and patterns for coding interviews checkout algomaster.io
Basic OOP Concepts Explained with Clear Examples:
1. ๐๐ง๐๐๐ฉ๐ฌ๐ฎ๐ฅ๐๐ญ๐ข๐จ๐ง
Hide internal data behind public methods.
- Example: A BankAccount class keeps balance and pin private. The only way to interact with it is through deposit() and getBalance().
2. ๐๐๐ฌ๐ญ๐ซ๐๐๐ญ๐ข๐จ๐ง
Expose a simple interface, hide the complexity behind it.
- Example: An EmailService class gives you sendEmail(to, body). Internally, it handles SMTP connections, authentication, and retry logic. The caller doesn't need to know any of that. They just call one method and it works.
3. ๐๐ง๐ก๐๐ซ๐ข๐ญ๐๐ง๐๐
Let child classes reuse and override behavior from a parent class.
- Example: An Animal class defines speak(). Dog extends it and returns "Woof!", Cat extends it and returns "Meow!". Shared logic lives in one place, and each subclass customizes what it needs.
4. ๐๐จ๐ฅ๐ฒ๐ฆ๐จ๐ซ๐ฉ๐ก๐ข๐ฌ๐ฆ
Write code that works with multiple types through a common interface.
- Example: Define a Shape interface with a draw() method. Now Circle, Rectangle, and Triangle each implement draw() their own way. A single drawShape(Shape s) method works with all of them.
โป๏ธ Repost to help others learn this
AlgoMaster.io retweeted
๐๐จ๐ฐ ๐ญ๐จ ๐
๐ข๐ง๐ ๐ ๐๐ฒ๐๐ฅ๐ ๐ข๐ง ๐ ๐๐ข๐ง๐ค๐๐ ๐๐ข๐ฌ๐ญ
Use Floydโs Cycle Detection Algorithm, also known as the slow and fast pointer technique.
Start two pointers at the head:
- slow moves one step at a time
- fast moves two steps at a time
If the linked list has no cycle, fast will eventually reach the end.
If there is a cycle, fast will eventually catch up with slow inside the loop.
Why does this work?
Think of two runners on a circular track. If one runs faster than the other, they are guaranteed to meet eventually.
Time Complexity: O(n)
Space Complexity: O(1)
๐๐จ๐ฐ ๐ญ๐จ ๐
๐ข๐ง๐ ๐ ๐๐ฒ๐๐ฅ๐ ๐ข๐ง ๐ ๐๐ข๐ง๐ค๐๐ ๐๐ข๐ฌ๐ญ
Use Floydโs Cycle Detection Algorithm, also known as the slow and fast pointer technique.
Start two pointers at the head:
- slow moves one step at a time
- fast moves two steps at a time
If the linked list has no cycle, fast will eventually reach the end.
If there is a cycle, fast will eventually catch up with slow inside the loop.
Why does this work?
Think of two runners on a circular track. If one runs faster than the other, they are guaranteed to meet eventually.
Time Complexity: O(n)
Space Complexity: O(1)
15 Must-Know Software Design Patterns:
1. Singleton
2. Factory Method
3. Builder
4. Adapter
5. Decorator
6. Facade
7. Proxy
8. Composite
9. Observer
10. Strategy
11. Command
12. Iterator
13. State
14. Template Method
15. Chain of Responsibility
โป๏ธ Repost to help others in your network
20 must-know DSA patterns for coding interviews:
1. Prefix Sum
2. Two Pointers
3. Sliding Window
4. Fast & Slow Pointers
5. LinkedList In-place Reversal
6. Frequency Counting
7. Monotonic Stack
8. Bit Manipulation
9. Top โKโ Elements
10. Overlapping Intervals
11. Binary Search Variants
12. Binary Tree Traversal
13. Depth-First Search (DFS)
14. Breadth-First Search (BFS)
15. Shortest Path
16. Matrix Traversal
17. Backtracking
18. Prefix Search (Trie)
19. Greedy
20. Dynamic Programming Patterns
โป๏ธ Repost to help others master coding interviews
๐ Checkout the full list of patterns with detailed explanations and problems at algomaster.io
7 Must-Know Big-O Complexities for Coding Interviews:
1. ๐(1) - ๐๐จ๐ง๐ฌ๐ญ๐๐ง๐ญ ๐ญ๐ข๐ฆ๐
- The runtime doesn't change regardless of the input size.
- Example: Accessing an element in an array by its index.
2. ๐(๐ฅ๐จ๐ ๐ง) - ๐๐จ๐ ๐๐ซ๐ข๐ญ๐ก๐ฆ๐ข๐ ๐ญ๐ข๐ฆ๐
- The runtime grows slowly as the input size increases. Typically seen in algorithms that divide the problem in half with each step.
- Example: Binary search in a sorted array.
3. ๐(๐ง) - ๐๐ข๐ง๐๐๐ซ ๐ญ๐ข๐ฆ๐
- The runtime grows linearly with the input size.
- Example: Finding an element in an array by iterating through each element.
4. ๐(๐ง ๐ฅ๐จ๐ ๐ง) - ๐๐ข๐ง๐๐๐ซ๐ข๐ญ๐ก๐ฆ๐ข๐ ๐ญ๐ข๐ฆ๐
- The runtime grows slightly faster than linear time. It involves a logarithmic number of operations for each element in the input.
- Example: Sorting an array using quick sort or merge sort.
5. ๐(๐ง^2) - ๐๐ฎ๐๐๐ซ๐๐ญ๐ข๐ ๐ญ๐ข๐ฆ๐
- The runtime grows proportionally to the square of the input size.
- Example: Bubble sort algorithm which compares and potentially swaps every pair of elements.
6. ๐(2^๐ง) - ๐๐ฑ๐ฉ๐จ๐ง๐๐ง๐ญ๐ข๐๐ฅ ๐ญ๐ข๐ฆ๐
- The runtime doubles with each addition to the input. These algorithms become impractical for larger input sizes.
- Example: Generating all subsets of a set.
7. ๐(๐ง!) - ๐
๐๐๐ญ๐จ๐ซ๐ข๐๐ฅ ๐ญ๐ข๐ฆ๐
- Runtime is proportional to the factorial of the input size.
- Example: Generating all permutations of a set.
โป๏ธ Repost to help others learn this
๐๐จ๐ฐ ๐๐๐ซ๐ ๐ ๐๐จ๐ซ๐ญ ๐๐จ๐ซ๐ค๐ฌ
Merge Sort is a classic Divide & Conquer algorithm.
Hereโs the idea:
- Divide โ Split the array into two halves
- Conquer โ Recursively sort both halves
- Combine โ Merge the sorted halves into one sorted array
The magic lies in the merge step, where two sorted arrays are combined efficiently in linear time.
Time Complexity: O(n log n) (always)
Quick example:
[5, 2, 4, 1] โ [5, 2] + [4, 1] โ [2, 5] + [1, 4] โ [1, 2, 4, 5]
โป๏ธ Repost to help others in your network
14 must-know Data Structures for coding interviews:
1. Array
2. Queue
3. Deque
4. Matrix
5. Stack
6. Binary Tree
7. Linked List
8. Doubly Linked List
9. HashMap
10. Binary Search Tree (BST)
11. Heap (Priority Queue)
12. Trie
13. Graph
14. Union Find
โป๏ธ Repost to help others in your network
10 must-know Array patterns for coding interviews:
1. Two Pointers
2. Sliding Window
3. Prefix Sum
4. Kadane's Algorithm
5. Binary Search
6. Cyclic Sort
7. Merge Intervals
8. Monotonic Stack
9. Hash Map Lookup
10. Sorting + Greedy
โป๏ธ Repost to help others in your network
If you want to master dynamic programming for coding interviews, learn these 20 patterns:
1. Fibonacci Numbers
2. 0/1 Knapsack
3. Unbounded Knapsack
4. Longest Common Subsequence
5. Longest Increasing Subsequence
6. Palindromic Subsequence
7. Matrix Chain
8. Edit Distance
9. Coin Change
10. Kadane's Algorithm
11. Grid Paths
12. Subset Sum
13. Rod Cutting
14. Climbing Stairs
15. House Robber
16. Interval DP
17. State Machine DP
18. Tree DP
19. Bitmask DP
20. Digit DP
โป๏ธ Repost to help others in your network
๐ For more coding interview patterns checkout algomaster.io









