Forem

Thesius Code
Thesius Code

Posted on • Originally published at datanest-stores.pages.dev

Coding Patterns Quick Reference

Coding Patterns Quick Reference

15 essential coding interview patterns with Python and JavaScript solutions, visual explanations, complexity analysis, and pattern-recognition decision trees. Stop memorizing 500 LeetCode problems — learn 15 patterns and solve anything.

Key Features

  • 15 fundamental patterns covering 90%+ of coding interview questions
  • 45 solved problems (3 per pattern: easy, medium, hard) in Python and JavaScript
  • Pattern recognition decision tree — identify the right pattern in 30 seconds
  • Complexity cheatsheet for every pattern and solution
  • Common mistakes guide — pitfalls that cause silent wrong answers
  • Spaced repetition schedule for long-term retention

The 15 Patterns

# Pattern Key Problems When to Use
1 Sliding Window Max subarray, longest substring Contiguous subarray/substring optimization
2 Two Pointers Two sum (sorted), container with most water Sorted arrays, pair finding
3 Fast & Slow Pointers Linked list cycle, find middle Cycle detection, linked lists
4 Merge Intervals Insert interval, meeting rooms Overlapping intervals
5 Cyclic Sort Find missing number, find duplicate Arrays with values in [1, n] range
6 In-Place Linked List Reversal Reverse sublist, reverse k-group Reversing without extra memory
7 BFS Level order traversal, shortest path Level-by-level tree/graph traversal
8 DFS Path sum, island count Exhaustive tree/graph exploration
9 Two Heaps Find median, sliding window median Track median or top/bottom elements
10 Subsets / Backtracking Permutations, combination sum Generate all combinations
11 Modified Binary Search Search rotated array, find peak Sorted or semi-sorted search
12 Top K Elements K largest, k frequent elements Selection from large datasets
13 K-Way Merge Merge k sorted lists Multiple sorted inputs
14 Dynamic Programming Coin change, longest subsequence Optimal substructure + overlapping subproblems
15 Monotonic Stack Next greater element, largest rectangle Next greater/smaller element problems

Sample Content

Pattern 1: Sliding Window

When to use: You need to find/calculate something among contiguous subarrays or substrings of a given size.

Template (Python):

def sliding_window(arr: list[int], k: int) -> int:
    """Find maximum sum of any contiguous subarray of size k."""
    window_sum = sum(arr[:k])
    max_sum = window_sum

    for i in range(k, len(arr)):
        window_sum += arr[i] - arr[i - k]  # slide: add right, remove left
        max_sum = max(max_sum, window_sum)

    return max_sum

# Example: sliding_window([2, 1, 5, 1, 3, 2], 3) → 9 (subarray [5, 1, 3])
Enter fullscreen mode Exit fullscreen mode

Template (JavaScript):

function slidingWindow(arr, k) {
  let windowSum = arr.slice(0, k).reduce((a, b) => a + b, 0);
  let maxSum = windowSum;

  for (let i = k; i < arr.length; i++) {
    windowSum += arr[i] - arr[i - k];
    maxSum = Math.max(maxSum, windowSum);
  }
  return maxSum;
}
Enter fullscreen mode Exit fullscreen mode

Pattern Recognition Decision Tree

Is the input sorted or can it be sorted?
├── YES → Are you looking for a pair/triplet?
│         ├── YES → Two Pointers (#2)
│         └── NO  → Are you searching for a value?
│                   ├── YES → Modified Binary Search (#11)
│                   └── NO  → Merge Intervals (#4)
├── NO  → Is it a tree or graph?
│         ├── YES → Need level-by-level?
│         │         ├── YES → BFS (#7)
│         │         └── NO  → DFS (#8)
│         └── NO  → Is it a subarray/substring problem?
│                   ├── YES → Sliding Window (#1)
│                   └── NO  → Does it have optimal substructure?
│                             ├── YES → Dynamic Programming (#14)
│                             └── NO  → Subsets / Backtracking (#10)
Enter fullscreen mode Exit fullscreen mode

Study Plan

Week Patterns Problems/Day
1 Sliding Window, Two Pointers, Fast & Slow 2
2 Merge Intervals, Cyclic Sort, Linked List Reversal 2
3 BFS, DFS, Two Heaps 2
4 Subsets, Binary Search, Top K 2
5 K-Way Merge, DP, Monotonic Stack 2
6 Mixed practice — random pattern selection 3

Practice Tips

  1. Learn the pattern, then solve problems. Read the template first, then attempt the easy problem without looking.
  2. Always state the pattern before coding. In interviews, say "This looks like a sliding window problem because..."
  3. Track your weak patterns. If you struggle with DP, spend 2x time there.
  4. Time yourself. Easy: 15 min. Medium: 25 min. Hard: 40 min.
  5. Review solutions the next day. Spaced repetition beats grinding.

Contents

  • src/ — All 15 patterns with templates in Python and JavaScript
  • examples/ — 45 solved problems with step-by-step walkthroughs
  • docs/ — Decision tree poster (printable), complexity cheatsheet

This is 1 of 11 resources in the Interview Prep Pro toolkit. Get the complete [Coding Patterns Quick Reference] with all files, templates, and documentation for $29.

Get the Full Kit →

Or grab the entire Interview Prep Pro bundle (11 products) for $199 — save 30%.

Get the Complete Bundle →


Related Articles

Top comments (0)