Core Interview Expectations
Interviewers evaluate
- Pattern recognition
- Time/space tradeoff awareness
- Edge-case handling
- Clean, readable logic
Universal Problem-Solving Steps
- Clarify
- Input size?
- Sorted or unsorted?
- Mutability allowed?
- Brute Force First
- State naive solution
- Time complexity
- Optimize
- Use data structures
- Recognize patterns
- Implement
- Clean variable naming
- Guard clauses
- Test
- Empty input
- Single element
- Extremes
TIME & SPACE COMPLEXITY MASTER SHEET
Common Time Complexities
| Pattern | Complexity |
|---|---|
| Single loop | O(n) |
| Nested loops | O(n²) |
| Divide & Conquer | O(n log n) |
| Hashing | O(1) avg |
| Binary Search | O(log n) |
| Sliding Window | O(n) |
| Two Pointers | O(n) |
Python-Specific Costs
- list append → O(1) amortized
- list insert(0) → O(n)
- dict lookup → O(1) avg
- heap push/pop → O(log n)
- set membership → O(1)
Common Algorithmic Patterns
Pattern 1: Frequency Counting
- Anagrams
- Duplicates
- Majority element
from collections import Counter
freq = Counter(nums)Pattern 2: Prefix Sums
- Subarray sum
- Range queries
prefix = [0]
for x in nums:
prefix.append(prefix[-1] + x)Pattern 3: Kadane’s Algorithm (Max Subarray)
cur = best = nums[0]
for x in nums[1:]:
cur = max(x, cur + x)
best = max(best, cur)TWO POINTERS PATTERN
When to Use
- Sorted arrays
- Pairs / triplets
- Palindromes
Basic Template
l, r = 0, len(arr) - 1
while l < r:
if condition:
l += 1
else:
r -= 1Common Problems
- Two Sum (sorted)
- Container With Most Water
- Remove duplicates
SLIDING WINDOW PATTERN
Fixed Window
window_sum = sum(arr[:k])
for i in range(k, len(arr)):
window_sum += arr[i] - arr[i-k]Variable Window
l = 0
for r in range(len(arr)):
while invalid_window:
l += 1Used For
- Longest substring
- Minimum window substring
- Subarray sums
HASHING & SET LOGIC
Why Hashing Works
- Converts lookup to O(1)
- Trades memory for speed
Classic Template
seen = set()
for x in arr:
if x in seen:
return True
seen.add(x)Common Uses
- Two Sum
- Cycle detection
- Duplicate detection
STACK PATTERNS
Monotonic Stack
- Used for:
- Next Greater Element
- Histogram area
- Daily Temperatures
Template (Increasing Stack)
stack = []
for i in range(len(nums)):
while stack and nums[stack[-1]] > nums[i]:
stack.pop()
stack.append(i)Valid Parentheses
stack = []
mapping = {')':'(', ']':'[', '}':'{'}QUEUE & DEQUE PATTERNS
Overview
Queue and deque patterns are commonly used for breadth-first search, sliding window problems, and efficient insertion and removal from both ends.
BFS Queue Template
from collections import deque
q = deque([start])
while q:
node = q.popleft()Sliding Window Max (Deque)
dq = deque()Used in
- Level order traversal
- Shortest path
- Window maximum
QUEUE & DEQUE PATTERNS
Overview
Queue and deque patterns are fundamental for breadth-first search and sliding window problems, enabling efficient FIFO operations and constant-time insertions and deletions at both ends.
BFS Queue Template
from collections import deque
q = deque([start])
while q:
node = q.popleft()Sliding Window Max (Deque)
dq = deque()Used in
- Level order traversal
- Shortest path
- Window maximum
LINKED LIST PATTERNS
Overview
Linked list patterns such as fast and slow pointers and in-place reversal are commonly used to detect cycles, find middle nodes, and manipulate list structure efficiently.
Fast & Slow Pointers
slow = fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.nextUsed for
- Cycle detection
- Middle node
Reverse Linked List
prev = None
cur = head
while cur:
nxt = cur.next
cur.next = prev
prev = cur
cur = nxtBINARY SEARCH PATTERNS
Overview
Binary search patterns are used to efficiently search sorted data or monotonic search spaces by repeatedly dividing the problem in half.
Standard Binary Search
l, r = 0, len(arr)-1
while l <= r:
mid = (l+r)//2Lower Bound Pattern
while l < r:
mid = (l+r)//2
if arr[mid] < target:
l = mid + 1
else:
r = midUsed in
- Rotated arrays
- First/last position
- Search space problems
RECURSION & BACKTRACKING
Overview
Recursion and backtracking patterns explore solution spaces by making choices and undoing them, commonly used for combinatorial problems.
General Backtracking Template
def backtrack(path):
if condition:
result.append(path[:])
return
for choice in choices:
path.append(choice)
backtrack(path)
path.pop()Used for
- Permutations
- Combinations
- Sudoku
- N-Queens
TREES: DFS & BFS
Overview
Tree traversal patterns such as DFS and BFS are used to explore nodes recursively or level by level.
DFS (Recursive)
def dfs(node):
if not node:
return
dfs(node.left)
dfs(node.right)BFS (Level Order)
from collections import dequeCommon Problems
- Diameter
- Path sum
- LCA
HEAPS & PRIORITY QUEUES
Overview
Heaps and priority queues efficiently retrieve minimum or maximum elements and are widely used in optimization problems.
Min Heap
import heapq
heapq.heappush(heap, x)
heapq.heappop(heap)Max Heap Trick
heapq.heappush(heap, -x)Used in
- Top K
- Median stream
- Scheduling
GRAPH PATTERNS
Overview
Graph traversal patterns explore nodes and edges using DFS or BFS to solve connectivity and path problems.
DFS Graph
def dfs(node):
for nei in graph[node]:
if nei not in visited:
dfs(nei)BFS Shortest Path
queue = deque([(start, 0)])Key Concepts
- Adjacency list
- Visited set
- Directed vs undirected
DYNAMIC PROGRAMMING (DP)
Overview
Dynamic programming breaks problems into overlapping subproblems and stores results to avoid recomputation.
DP Thought Process
- Define state
- Transition
- Base case
- Answer extraction
1D DP
dp = [0]*(n+1)2D DP
dp = [[0]*m for _ in range(n)]Common DP Problems
- Knapsack
- LIS
- Coin change
- Grid paths
FINAL INTERVIEW CHECKLIST
Overview
A concise checklist to ensure structured thinking, clean implementation, and correctness during technical interviews.
Before Coding
- Identify pattern
- State complexity
While Coding
- Clean loops
- No magic numbers
After Coding
- Edge cases
- Dry run example
TIME & SPACE COMPLEXITY MASTER SHEET
Overview
Common algorithmic patterns and their typical time complexities, frequently expected in interviews.
Common Time Complexities
| Pattern | Complexity |
|---|---|
| Single loop | O(n) |
| Nested loops | O(n²) |
| Divide & Conquer | O(n log n) |
| Hashing | O(1) avg |
| Binary Search | O(log n) |
| Sliding Window | O(n) |
| Two Pointers | O(n) |
ARRAYS / STRINGS
Overview
Core array and string problems that form the foundation of most coding interviews.
Patterns
| Problem | Pattern | |
|---|---|---|
| Two Sum (unsorted) | Hash Map | Store complement |
| Two Sum (sorted) | Two Pointers | Move inward |
| Maximum Subarray | Kadane | Carry or restart |
| Product Except Self | Prefix/Suffix | No division |
| Best Time to Buy/Sell | Greedy | Track min |
| Subarray Sum = K | Prefix Sum + Hash | Cumulative counts |
| Longest Consecutive | Hash Set | O(n) lookup |
| Anagram Check | Frequency Count | Character counts |
SLIDING WINDOW
Overview
Sliding window techniques optimize subarray and substring problems by maintaining a dynamic range.
Problems
| Problem | Pattern | |
|---|---|---|
| Longest Substring Without Repeat | Variable | Set / freq map |
| Longest Repeating Character | Variable | Max freq |
| Minimum Window Substring | Variable | Formed vs required |
| Max Sum Subarray (size k) | Fixed | Rolling sum |
TWO POINTERS
Overview
Two pointer techniques reduce time complexity by exploiting sorted data or symmetric traversal.
Problems
| Problem | Pattern |
|---|---|
| Container With Most Water | Move smaller |
| Remove Duplicates | Slow/Fast |
| 3Sum | Sort + inward |
| Palindrome Check | Ends inward |
STACK
Overview
Stack-based patterns are used for matching, monotonic sequences, and range queries.
Problems
| Problem | Pattern |
|---|---|
| Valid Parentheses | Matching |
| Daily Temperatures | Monotonic decreasing |
| Next Greater Element | Monotonic |
| Largest Rectangle Histogram | Monotonic |
LINKED LIST
Overview
Linked list problems focus on pointer manipulation and in-place transformations.
Problems
| Problem | Pattern |
|---|---|
| Detect Cycle | Fast & Slow |
| Reverse List | Iterative pointer swap |
| Merge Two Lists | Dummy node |
| Reorder List | Split + reverse |
BINARY SEARCH
Overview
Binary search applies to sorted data and monotonic answer spaces.
Problems
| Problem | Pattern |
|---|---|
| Sorted Array Search | Indices |
| Rotated Array | Modified mid |
| First/Last Position | Lower/Upper bound |
| Koko Eating Bananas | Answer space |
TREES
Overview
Tree problems test recursion, traversal strategies, and hierarchical reasoning.
Problems
| Problem | Pattern |
|---|---|
| Max Depth | DFS |
| Level Order | BFS |
| Diameter | Postorder |
| LCA | DFS recursion |
| Path Sum | DFS |
GRAPH
Overview
Graph problems emphasize traversal, connectivity, and dependency resolution.
Problems
| Problem | Pattern |
|---|---|
| Number of Islands | DFS/BFS |
| Clone Graph | DFS + map |
| Course Schedule | Topological sort |
| Shortest Path | BFS |
DYNAMIC PROGRAMMING
Overview
Dynamic programming evaluates optimal solutions using overlapping subproblems.
Problems
| Problem | Pattern |
|---|---|
| Climbing Stairs | 1D DP |
| House Robber | 1D DP |
| Coin Change | Unbounded knapsack |
| LIS | DP / Binary search |
| Unique Paths | Grid DP |
ARRAYS / STRINGS
Overview
Array and string problems form the core foundation of coding interviews and emphasize efficient traversal, hashing, and prefix techniques.
Problem Patterns
| Problem Type | Pattern | Key Insight |
|---|---|---|
| Two Sum (unsorted) | Hash Map | Store complement |
| Two Sum (sorted) | Two Pointers | Move inward |
| Maximum Subarray | Kadane | Carry or restart |
| Product Except Self | Prefix/Suffix | No division |
| Best Time to Buy/Sell | Greedy | Track min |
| Subarray Sum = K | Prefix Sum + Hash | Cumulative counts |
| Longest Consecutive | Hash Set | O(n) lookup |
| Anagram Check | Frequency Count | Character counts |
SLIDING WINDOW
Overview
Sliding window techniques optimize contiguous subarray or substring problems by maintaining a dynamic range.
Problems
| Problem Type | Window Typ | Key Variable |
|---|---|---|
| Longest Substring Without Repeat | Variable | Set / freq map |
| Longest Repeating Character | Variable | Max freq |
| Minimum Window Substring | Variable | Formed vs required |
| Max Sum Subarray (size k) | Fixed | Rolling sum |
TWO POINTERS
Overview
Two pointer techniques reduce complexity by scanning from multiple directions simultaneously.
Problems
| Problem | Pointer Movement |
|---|---|
| Container With Most Water | Move smaller |
| Remove Duplicates | Slow/Fast |
| 3Sum | Sort + inward |
| Palindrome Check | Ends inward |
STACK
Overview
Stack-based patterns are used for matching problems and monotonic ordering.
Problems
| Problem Type | Stack Type |
|---|---|
| Valid Parentheses | Matching |
| Daily Temperatures | Monotonic decreasing |
| Next Greater Element | Monotonic |
| Largest Rectangle Histogram | Monotonic |
LINKED LIST
Overview
Linked list problems focus on pointer manipulation and in-place transformations.
Problems
| Problem | Pattern |
|---|---|
| Detect Cycle | Fast & Slow |
| Reverse List | Iterative pointer swap |
| Merge Two Lists | Dummy node |
| Reorder List | Split + reverse |
BINARY SEARCH
Overview
Binary search applies to sorted data and monotonic answer spaces.
Problems
| Problem | Search Space |
|---|---|
| Sorted Array Search | Indices |
| Rotated Array | Modified mid |
| First/Last Position | Lower/Upper bound |
| Koko Eating Bananas | Answer space |
TREES
Overview
Tree problems emphasize recursion, traversal strategies, and hierarchical reasoning.
Problems
| Problem | Traversal |
|---|---|
| Max Depth | DFS |
| Level Order | BFS |
| Diameter | Postorder |
| LCA | DFS recursion |
| Path Sum | DFS |
GRAPH
Overview
Graph problems test traversal, connectivity, and dependency management.
Problems
| Problem | Pattern |
|---|---|
| Number of Islands | DFS/BFS |
| Clone Graph | DFS + map |
| Course Schedule | Topological sort |
| Shortest Path | BFS |
DYNAMIC PROGRAMMING
Overview
Dynamic programming solves optimization problems using overlapping subproblems and state transitions.
Problems
| Problem | DP Type |
|---|---|
| Climbing Stairs | 1D DP |
| House Robber | 1D DP |
| Coin Change | Unbounded knapsack |
| LIS | DP / Binary search |
| Unique Paths | Grid DP |
COMPANY-WISE PATTERN PRIORITY
Overview
Company-specific pattern focus based on real interview trends.
Company Focus
| Company Name | DSA Questions | Hints |
|---|---|---|
| Graphs, Trees, Binary Search on Answer, DP | Complex constraints, edge cases | |
| Meta (Facebook) | Sliding Window, Hashing, Two Pointers | Speed, clarity, communication |
| Amazon | Trees, Arrays, Sliding Window, BFS | Clean code, scalability |
| Microsoft | DP, Recursion, Graphs, Strings | Correctness, explanation |
| Apple | Arrays, Strings, Two Pointers | Elegant solutions |
| Netflix / Airbnb | Graphs, DFS, Design + DSA | Deep reasoning, tradeoffs |
