Blog/Patterns
🧩

Patterns

Deep dives into algorithm patterns like sliding window, two pointers, dynamic programming, and more.

58 articles

Two Pointer Patterns — Complete Guide

A complete guide to two-pointer patterns for LeetCode: opposite-direction converging, same-direction fast/slow, and fixed-gap — when each applies, how to avoid infinite loops, and a problem roadmap from easy to hard.

11 min read|

Union Find Patterns — Complete Guide

A complete guide to Union Find (Disjoint Set Union) patterns for LeetCode: path compression, union by rank, when to choose UF over BFS/DFS, weighted Union Find, and a full template in Python and Java.

11 min read|

Topological Sort — Complete LeetCode Guide

Master topological sort for LeetCode with Kahn's BFS and DFS post-order approaches. Learn cycle detection with in-degree tracking, apply both algorithms to Course Schedule, Alien Dictionary, and build-system dependency problems.

10 min read|

MST Patterns — Kruskal and Prim Guide

Master minimum spanning tree patterns for LeetCode with Kruskal's (sort + union-find) and Prim's (min-heap) algorithms. Learn when to use each, how Union-Find enables cycle detection, and recognize MST problems like connecting cities with minimum cost.

10 min read|

Backtracking Patterns — Complete Guide

A complete guide to backtracking on LeetCode: learn the universal template, apply it to permutations, combinations, subsets, and constraint satisfaction problems, and know when to use backtracking versus dynamic programming.

12 min read|

Graph BFS/DFS Patterns — Complete Guide

Master graph traversal with BFS and DFS. Learn when to use each, how multi-source BFS works, the bidirectional BFS speedup, and how DFS state tracking detects cycles.

12 min read|

Prefix Sum Patterns 2026 — Complete Guide

Master every prefix sum pattern for LeetCode: 1D range queries, 2D region sums, prefix XOR for range XOR queries, hashmap subarray counting for target sums, and difference arrays for batch range updates — all with templates and problem mappings.

14 min read|

Heap Patterns — Priority Queue Guide

A complete guide to heap and priority queue patterns on LeetCode: learn when to use heaps, the top-k, k-way merge, and two-heap median patterns, and the key differences between Python heapq and Java PriorityQueue.

11 min read|

LeetCode Concurrency Problems: A Complete Guide

A complete guide to LeetCode concurrency problems — mutex, semaphore, and thread-safe patterns tested at infrastructure-heavy companies like Uber, Netflix, and Apple.

10 min read|

LeetCode Design Patterns for OOP Interviews

Master the design patterns, SOLID principles, and class design questions that top companies test in OOP coding interviews.

10 min read|

Design a Parking Lot: The #1 OOP Design Interview Question

Master the most common OOP design interview question. Learn how to design a parking lot with clean class hierarchies, SOLID principles, and extensible architecture.

10 min read|

Trie vs Hash Set: When to Use Each in Coding Interviews

Learn when to use a trie vs hash set in coding interviews. A clear decision framework for word search, autocomplete, and dictionary problems.

8 min read|

Segment Tree LeetCode Guide: The Range Query Template You Need

Master the segment tree pattern for range query LeetCode problems with a clean interview template, classic problems, and lazy propagation explained.

10 min read|

LeetCode String Problems: 6 Patterns to Solve Any Question

Master the 6 essential string problem patterns for coding interviews: two pointers, sliding window, hash maps, string building, palindromes, and pattern matching.

10 min read|

DP Space Optimization: 3 Techniques for O(1) Space

Learn the 3 dp space optimization techniques that reduce O(n) to O(1) and O(n^2) to O(n). Master rolling arrays, two-variable compression, and row reduction for coding interviews.

10 min read|

Union Find LeetCode Pattern: The Complete Guide

Master the Union-Find data structure for LeetCode with path compression, union by rank, and the classic problems where it outperforms BFS and DFS.

10 min read|

Dijkstra's Algorithm for LeetCode: Shortest Path Guide

Master Dijkstra's algorithm for LeetCode — learn the priority queue template, when to use it vs BFS, and solve classic weighted graph interview problems.

10 min read|

The Two Pointer Template — A Universal Guide

Learn the 3 two pointer templates (opposite, same direction, fast/slow) that cover 30+ LeetCode problems. A universal guide with decision tables and practice strategy.

9 min read|

Matrix and Grid Problems: The Complete LeetCode Pattern Guide

Master grid traversal, matrix manipulation, and DP on grids. Learn to recognize that every leetcode matrix problem is a graph problem in disguise.

10 min read|

Memoization vs Tabulation: Choosing the Right DP Approach

A practical guide to choosing between memoization (top-down) and tabulation (bottom-up) for dynamic programming interview problems.

10 min read|

Topological Sort LeetCode Pattern Guide

Master topological sort for coding interviews with Kahn's algorithm, DFS-based sorting, cycle detection, and the most common LeetCode dependency problems.

10 min read|

Dynamic Programming: A Framework That Works

Dynamic programming trips up even experienced engineers. Learn the two-step framework — identify overlapping subproblems, write a recurrence relation — and you'll be able to tackle any DP problem on LeetCode.

10 min read|

Binary Search on Answer Space: Hards Feel Like Mediums

Learn the binary search on answer space pattern — the template that turns Hard LeetCode problems into predictable solves with a simple feasibility check.

10 min read|

Trees and Graph Traversal: The Complete LeetCode Guide

Trees and graphs appear in over a third of coding interviews. Learn the BFS and DFS patterns, templates, and classic problems you need to solve them confidently.

9 min read|

Graph Algorithm Patterns — Complete Guide

Learn the 6 graph algorithm patterns that cover nearly every coding interview graph problem — BFS, DFS, topological sort, union-find, and more with real LeetCode examples.

10 min read|

Sliding Window LeetCode Pattern: The Complete Deep Dive

Master the sliding window technique with fixed and variable window templates that solve 15+ LeetCode problems. Includes the universal template and classic problem walkthroughs.

10 min read|

Two Pointers & Sliding Window: LeetCode Pattern Guide

Two pointers and sliding window solve 20+ common LeetCode problems. Learn the mental models, see the classic problems, and drill the patterns with spaced repetition.

9 min read|

Quicksort Partition Pattern: Lomuto, Hoare & Dutch National Flag

Master the quicksort partition pattern for LeetCode interviews. Learn Lomuto, Hoare, and Dutch National Flag partitioning with practice problems.

10 min read|

Bit Manipulation Patterns for LeetCode Interviews

Master the 5 essential bit manipulation tricks that solve LeetCode problems in O(1) space — XOR, bitmasks, and the bitwise operators interviewers love to see.

10 min read|

Subarray vs Subsequence Patterns: The LeetCode Decision Framework

Learn the critical difference between subarray and subsequence problems on LeetCode. Master sliding window, prefix sum, and DP patterns with a clear decision framework.

10 min read|

LeetCode Patterns: 15 Templates for 80% of Problems

Most LeetCode grinders memorize solutions. The engineers who get hired recognize patterns. Here are the 15 core leetcode patterns that show up again and again in coding interviews.

9 min read|

BFS vs DFS: When to Use Each in Coding Interviews

A clear decision framework for choosing between BFS and DFS in coding interviews, with side-by-side comparisons and real LeetCode examples.

10 min read|

LeetCode Interval Problems: 3 Patterns That Solve Every Question

Master the 3 core interval patterns — merge, insert, and schedule — to confidently solve any interval problem on LeetCode and in coding interviews.

10 min read|

Monotonic Stack Pattern: Solve Next Greater Element in O(n)

Learn the monotonic stack pattern to solve next greater element, daily temperatures, and histogram problems in O(n) time.

10 min read|

Hash Map Deep Dive — Beyond Two Sum: 6 Patterns for LeetCode

Go beyond Two Sum with 6 hash map patterns that cover frequency counting, grouping, prefix sums, and more — the complete hash map interview toolkit.

10 min read|

Prefix Sum LeetCode Pattern Guide

Learn the prefix sum pattern that turns O(n) range queries into O(1) lookups. Covers the template, hash map combo, and classic LeetCode problems like Subarray Sum Equals K.

10 min read|

Trie Data Structure Pattern Guide for LeetCode

Master the trie data structure pattern for LeetCode — from basic implementation to Word Search II, with templates and strategy.

9 min read|

Stack & Queue Patterns for Coding Interviews

Stacks and queues appear in more coding interviews than most people expect. This guide covers parentheses matching, monotonic stacks, queue patterns, and the key problems you need to know.

9 min read|

Binary Tree LeetCode Problems: The Complete Pattern Guide

Master every binary tree pattern for coding interviews — DFS, BFS, BST tricks, and advanced path problems with reusable recursion templates.

10 min read|

Heap Priority Queue LeetCode Guide: Patterns You Need

Master heap and priority queue patterns for coding interviews. From top K elements to merging K sorted lists, these are the patterns that separate good candidates from great ones.

10 min read|

Binary Search Patterns for LeetCode Interviews

Binary search goes far beyond sorted arrays. Learn the template variations for rotated arrays, answer space problems, and the off-by-one traps that trip up even experienced engineers.

10 min read|

Array & Hashing Patterns for LeetCode Interviews

Arrays and hash maps are the most-tested category in coding interviews. Learn the core patterns — frequency counting, two-sum, grouping, and prefix sums — that turn brute-force into elegant O(n) solutions.

9 min read|

Linked List Patterns for LeetCode Interviews

Master the 5 core linked list patterns — reversal, fast & slow pointers, merge, dummy heads, and edge case handling — to crack any linked list interview problem.

10 min read|

Backtracking Problems Guide for LeetCode Interviews

Master the backtracking algorithm template that solves permutations, combinations, subsets, N-Queens, and more. Learn when to use backtracking and how to prune for optimal performance.

11 min read|

LeetCode Design Problems — The Complete Category Guide

LeetCode Design category guide: LRU Cache, Min Stack, LFU Cache, Design Twitter — master data structure composition for FAANG interviews.

11 min read|

Anagram Problems on LeetCode — The Complete Pattern Guide

All anagram problems — from Valid Anagram to Group Anagrams to Find All Anagrams — reduce to one insight: comparing character frequency maps. Master the four techniques that cover every variant on LeetCode.

10 min read|

Dijkstra's Algorithm on LeetCode — Problems, Patterns, and Implementation

Dijkstra's algorithm is the standard shortest-path solution for weighted graphs and appears across 10+ LeetCode problems under different names. Learn the 5-step min-heap pattern, recognize signal words like 'minimum cost' and 'network delay', and know when to use Bellman-Ford instead.

10 min read|

LLD / OOP Design for LeetCode Interviews — Parking Lot, Elevator, and More

LLD interviews are distinct from system design — they test object-oriented modeling of a single system. Master the 5-step OOP framework and the three canonical problems: parking lot, elevator, and TinyURL.

13 min read|

Bellman-Ford Algorithm — When Dijkstra Fails

Master the Bellman-Ford algorithm for LeetCode: negative edge weights, negative cycle detection, and the key problems — Cheapest Flights Within K Stops (#787), Network Delay Time (#743), and Find the City (#1334).

11 min read|

Simulation Problems on LeetCode — Tic Tac Toe, Candy Crush, and Beyond

Learn how to approach simulation problems on LeetCode: board games like Design Tic-Tac-Toe (#348), grid cascades like Candy Crush (#723), and state machines like Snake Game (#353). The pattern that trips up even strong coders.

12 min read|

Fibonacci and Dynamic Programming — The Gateway DP Problem for leetcode fibonacci

Master leetcode fibonacci by solving #509 four ways: naive recursion, memoization, tabulation, and space-optimized O(1). Then see how the same recurrence powers Climbing Stairs, House Robber, and Decode Ways.

11 min read|

Lowest Common Ancestor (LCA) — Complete LeetCode Guide

LCA appears in Meta's top 10, Blind 75, and FAANG interview rotations. The recursive insight clicks fast — but the variants will trip you up without a clear mental model.

11 min read|

LeetCode Greedy Algorithm Patterns — When Greedy Beats DP

Greedy algorithms make the locally optimal choice at each step. The hard part is recognizing when that strategy is provably correct — and when it will blow up.

12 min read|

Sorting Algorithms for LeetCode — The Interview-Relevant Subset

Stop memorizing every sort. In LeetCode interviews, sorting is a setup step that unlocks two pointers, greedy, and binary search — learn the 4 that actually matter.

10 min read|

BFS Leetcode and DFS Patterns — When to Use Each in Interviews

Master bfs leetcode and dfs leetcode patterns. Learn the 5-question decision framework that tells you which traversal to use before writing a single line of code.

12 min read|

LeetCode Palindrome Problems — Complete Pattern Guide

Master every leetcode palindrome pattern: two pointers, expand-around-center, DP for subsequences, and backtracking for partitioning.

11 min read|

Kadane's Algorithm — Maximum Subarray and Beyond

Kadane's Algorithm solves Maximum Subarray in O(n) with one elegant DP insight. Learn why it works, how to implement it, and which LeetCode problems use it.

10 min read|

Greedy Algorithm Patterns for LeetCode Interviews

Learn when greedy algorithms work, when they fail, and how to prove your approach is correct. Covers Jump Game, Gas Station, interval scheduling, and the greedy vs DP decision framework.

10 min read|