🧩 DSA & Coding

Pattern recognition + coding framework

Interview Framework (30 min)

1
Clarify 5 min

Inputs, outputs, edge cases, constraints

2
Examples 3 min

Walk through 2-3 examples by hand

3
Pattern 2 min

Identify pattern, state approach + complexity

4
Code 15 min

Write clean, correct code

5
Test 5 min

Trace through, edge cases, optimize

Big-O at a Glance

O(1) Constant Hash lookup
O(log n) Logarithmic Binary search
O(n) Linear Array scan
O(n log n) Linearithmic Merge sort
O(n²) Quadratic Nested loops
O(2ⁿ) Exponential Subsets
O(n!) Factorial Permutations

Core Data Structures

Array

Access O(1) · Search O(n) · Insert O(n)

Sequential data, index-based

HashMap

Get/Set/Delete O(1) avg

Count, lookup, dedup

Stack

Push/Pop O(1)

Undo, parsing, DFS

Queue / Deque

Enq/Deq O(1)

BFS, sliding window

Linked List

Insert/Delete O(1) at pointer

LRU cache, merge

Binary Tree / BST

Search/Insert O(log n)

Ordered data, ranges

Heap

Insert O(log n) · ExtractMin O(log n)

Top-K, median, priority

Graph

Depends on representation

Networks, paths, cycles

15 Essential Patterns

Two Pointers

O(n)

When: Sorted array, pair sum

Two Sum II, 3Sum

Sliding Window

O(n)

When: Subarray/substring with condition

Max Subarray, Min Window Sub

Fast & Slow

O(n)

When: Cycle detection, middle node

Linked List Cycle, Happy Number

Merge Intervals

O(n log n)

When: Overlapping ranges

Merge Intervals, Insert Interval

Binary Search

O(log n)

When: Sorted input, min/max answer

Search Rotated, Koko Bananas

BFS

O(V+E)

When: Shortest path, level order

Level Order, Rotten Oranges

DFS

O(V+E)

When: Explore all paths, connected comp

Number of Islands, Path Sum

Backtracking

O(2ⁿ)

When: All combinations/permutations

Subsets, N-Queens, Word Search

Topological Sort

O(V+E)

When: Dependencies, ordering

Course Schedule, Alien Dict

Union-Find

O(α(n))

When: Dynamic connectivity, groups

Connected Comp, Redundant Edge

Monotonic Stack

O(n)

When: Next greater/smaller element

Daily Temperatures, Histogram

Heap / Priority Queue

O(n log k)

When: Top-K, median, scheduling

Top K Frequent, Merge K Lists

Dynamic Programming

Varies

When: Overlapping subproblems, optimal

Coin Change, LCS, Knapsack

Greedy

O(n log n)

When: Local optimal → global optimal

Jump Game, Activity Selection

Trie

O(L)

When: Prefix matching, autocomplete

Word Search II, Implement Trie