Tree DP and Path Problems: Maximum Path Sum, Diameter, LCA, and Serialization (2025)
6 min read Tree DP Pattern Many tree problems require computing an answer that depends on both subtrees. The key pattern: define a […] Read article
// algorithms
Coding patterns with templates and walkthroughs: two pointers, sliding window, DP, graphs — and the problems each one unlocks.
6 min read Tree DP Pattern Many tree problems require computing an answer that depends on both subtrees. The key pattern: define a […] Read article
6 min read Palindrome Check A palindrome reads the same forward and backward. Brute force check: O(n). Two-pointer: left=0, right=n-1; while left < Read article
6 min read The String Matching Problem Given a text T of length n and a pattern P of length m, find all Read article
7 min read What Is a Minimum Spanning Tree? A Minimum Spanning Tree (MST) of a weighted undirected graph is a spanning tree Read article
6 min read Monotonic Stack Concept A monotonic stack maintains elements in strictly increasing or decreasing order. Elements that violate the order are Read article
6 min read What Is Amortized Analysis? Amortized analysis gives the average cost per operation over a sequence of operations, even when individual Read article
6 min read Why Randomized Algorithms? Randomized algorithms use random choices to achieve good expected performance, simplify implementation, or avoid worst-case inputs that Read article
7 min read When to Use DP on Graphs DP on graphs works when the graph has structure that prevents cycles in the Read article
7 min read Naive String Matching For each position i in text (0 to n-m): check if text[i:i+m] == pattern. O(n*m) in the Read article
7 min read Bellman-Ford Algorithm Finds shortest paths from a source to all nodes, handling negative edge weights. Algorithm: initialize dist[source]=0, dist[all others]=inf. Read article
7 min read Segment Tree A segment tree answers range queries (range sum, range minimum) in O(log n) and supports point or range Read article
6 min read When to Use 2D DP 2D DP uses a table dp[i][j] where i and j represent positions in two sequences, Read article
5 min read The Sliding Window Technique for Strings A sliding window maintains a contiguous substring without re-scanning from scratch. Two pointers (left Read article
5 min read Interval Problems: Core Insight Interval problems involve ranges [start, end]. The key operations: merge overlapping intervals, find non-overlapping sets, detect Read article
5 min read Interval Problem Fundamentals Interval problems involve ranges [start, end] and ask about overlaps, merges, insertions, or optimal scheduling. The key Read article
What's missing, wrong, or worth adding? One line helps.
Sent — thank you. We read every one.