Lesson 25/25 ยท ๐ฏ Interview Patterns
๐ฏ Interview PatternsLesson 25/25
Phase 9 ยท Interview Patterns30 min
Top Interview Patterns
The 5 pattern recognition skills that unlock 80% of coding interview problems
The secret to coding interviews isn't memorizing solutions, it's pattern recognition. When you see a problem, you identify which pattern applies, then adapt the template.
The 5 most common patterns:1. Two Pointers, sorted array, pairs, palindromes2. Sliding Window, subarrays, substrings3. Fast & Slow Pointers, cycle detection, middle of list4. BFS/DFS, trees, graphs, islands5. Dynamic Programming, optimal value, count ways
The 5 most common patterns:1. Two Pointers, sorted array, pairs, palindromes2. Sliding Window, subarrays, substrings3. Fast & Slow Pointers, cycle detection, middle of list4. BFS/DFS, trees, graphs, islands5. Dynamic Programming, optimal value, count ways
Fast & Slow Pointers, detect cycle in linked listpython
class Node:
def __init__(self, val): self.val = val; self.next = None
def has_cycle(head):
"""Floyd's algorithm: slow moves 1 step, fast moves 2."""
slow = fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow is fast: # They met, there's a cycle
return True
return False # Fast reached end, no cycle
# Build a cycle: 1โ2โ3โ4โ2 (4 points back to 2)
nodes = [Node(i) for i in range(1, 5)]
for i in range(3): nodes[i].next = nodes[i+1]
nodes[3].next = nodes[1] # Cycle
print(has_cycle(nodes[0])) # โ TruePattern Recognition Cheat Sheet:
| You seeโฆ | Thinkโฆ ||----------|--------|| Sorted array + find pair | Two Pointers || Subarray/substring of size k | Fixed Sliding Window || Longest/shortest subarray with condition | Variable Sliding Window || Tree/graph traversal, shortest path | BFS || Tree/graph: all paths, cycle detection | DFS || "How many ways", "minimum cost" | Dynamic Programming || "Linked list cycle", "find middle" | Fast & Slow Pointers || "Top k", "kth largest" | Heap || Key-value lookups, frequencies | Hash Map |
| You seeโฆ | Thinkโฆ ||----------|--------|| Sorted array + find pair | Two Pointers || Subarray/substring of size k | Fixed Sliding Window || Longest/shortest subarray with condition | Variable Sliding Window || Tree/graph traversal, shortest path | BFS || Tree/graph: all paths, cycle detection | DFS || "How many ways", "minimum cost" | Dynamic Programming || "Linked list cycle", "find middle" | Fast & Slow Pointers || "Top k", "kth largest" | Heap || Key-value lookups, frequencies | Hash Map |
๐ฌIn the Real World...
In real interviews, communicating your pattern recognition is as important as the solution: "I see a subarray problem with a sum condition, this looks like a variable sliding window. Let me think about the expand/contract conditions."
๐คQuick Check
A problem asks: "Find all unique triplets in an array that sum to zero." Which pattern?
๐ฏ
Phase Complete!
Interview Patterns
You've completed the DSA & Algorithms track! You understand complexity, every major data structure, and the top interview patterns. You're interview-ready. Keep practicing!
0/500
Practice Exercises
0/2 solvedExercise 1 of 2hard
โฑ 00:00Three Sum
Find all unique triplets that sum to zero. Use sort + two pointers.
Expected output:
Expected output:
[[-1, -1, 2], [-1, 0, 1]]solution.py
1 / 2
Exercise 2 of 2medium
โฑ 00:00Word Break
Given a string and a word dictionary, can the string be segmented into dictionary words?
Expected output:
Expected output:
Truesolution.py
2 / 2
Solve all 2 exercises to unlock completion