Skip to content

Blog

Guides on algorithm patterns and step-by-step LeetCode problem breakdowns.

XOR Cancellation: How Pairs Disappear Like Magic

easy

Understanding XOR from the ground up. How the cancellation property solves Single Number in O(n) time and O(1) space.

9 min
patterns

Search in Rotated Sorted Array: Modified Binary Search

medium

How to solve LeetCode Search in Rotated Sorted Array in O(log n). Identify the sorted half and search smartly.

8 min
binary-search

Remove Nth Node From End: Two Pointer Gap Technique

medium

How to solve LeetCode Remove Nth Node From End in one pass using the two-pointer gap technique.

6 min
linked-list

Longest Increasing Subsequence: DP and Binary Search

medium

How to solve LeetCode LIS in O(n^2) with DP or O(n log n) with patience sorting. Both approaches explained.

8 min
dynamic-programming

Letter Combinations of a Phone Number: Backtracking

medium

How to solve LeetCode Letter Combinations using backtracking. Build all combinations from digit-to-letter mapping.

9 min
backtracking

Combination Sum: Backtracking with Reuse

medium

How to solve LeetCode Combination Sum using backtracking with unlimited element reuse. Pruning explained visually.

10 min
backtracking

Word Search: Grid Backtracking

medium

How to solve LeetCode Word Search using DFS backtracking on a grid. The choose-explore-unchoose pattern.

10 min
backtracking

Validate BST: Range Checking vs Inorder

medium

How to solve LeetCode Validate BST with range bounds or inorder traversal. Two approaches compared.

7 min
trees

Valid Palindrome: Two Pointer String Check

easy

How to solve LeetCode Valid Palindrome with two pointers. Handle non-alphanumeric characters cleanly.

6 min
two-pointer

Top K Frequent Elements: Bucket Sort Trick

medium

How to solve LeetCode Top K Frequent Elements in O(n) with bucket sort. Faster than heap for this problem.

7 min
hash-map

Subsets: Backtracking Decision Tree

medium

How to solve LeetCode Subsets using backtracking. Generate all 2^n subsets with the include/exclude pattern.

9 min
backtracking

Spiral Matrix: Layer by Layer Traversal

medium

How to solve LeetCode Spiral Matrix with boundary tracking. The four-direction traversal pattern explained.

8 min
arrays

Serialize and Deserialize Binary Tree

hard

How to solve LeetCode Serialize/Deserialize Binary Tree with preorder DFS. Convert trees to strings and back.

8 min
trees

Permutations: Complete Backtracking Guide

medium

How to solve LeetCode Permutations using backtracking. Build all n! arrangements with the swap technique.

9 min
backtracking

Palindromic Substrings: Expand Around Center

medium

How to solve LeetCode Palindromic Substrings in O(n^2) using expand-from-center. Count all palindromes efficiently.

7 min
two-pointer

Min Stack: O(1) Minimum with Two Stacks

medium

How to implement LeetCode Min Stack with O(1) push, pop, and getMin. The auxiliary stack trick explained.

8 min
design

Merge Intervals: Sort and Sweep

medium

How to solve LeetCode Merge Intervals by sorting and merging overlapping ranges. The essential interval pattern.

7 min
arrays

Median of Two Sorted Arrays: Binary Search on Partitions

hard

How to solve LeetCode Median of Two Sorted Arrays in O(log(min(m,n))). The hardest binary search problem explained.

9 min
binary-search

LRU Cache: Hash Map + Doubly Linked List

medium

How to implement LeetCode LRU Cache with O(1) get and put. The classic design problem explained visually.

8 min
design

Lowest Common Ancestor: Post-Order Tree Logic

medium

How to solve LeetCode Lowest Common Ancestor using post-order DFS. The elegant recursive solution explained.

9 min
trees

Longest Palindromic Substring: Expand From Center

medium

How to solve LeetCode Longest Palindromic Substring in O(n^2). The expand-from-center technique explained visually.

7 min
two-pointer

Kth Largest Element: Heap vs Quickselect

medium

How to solve LeetCode Kth Largest Element with a min-heap or quickselect. Two O(n) approaches compared.

7 min
heap

House Robber: DP With a Twist

medium

How to solve LeetCode House Robber with dynamic programming. The rob-or-skip decision explained visually.

7 min
dynamic-programming

Decode Ways: DP String Decoding

medium

How to solve LeetCode Decode Ways with dynamic programming. Handle zeros and two-digit codes step by step.

9 min
dynamic-programming

Course Schedule: Cycle Detection with DFS

medium

How to solve LeetCode Course Schedule using topological sort and cycle detection. Graph DFS explained visually.

9 min
graphs

Coin Change: Classic Dynamic Programming

medium

How to solve LeetCode Coin Change with bottom-up DP. Visual table walkthrough for the unbounded knapsack pattern.

7 min
dynamic-programming

Valid Anagram: Frequency Counting Pattern

easy

How to solve LeetCode Valid Anagram using character frequency counting. Sort vs hash map approaches compared.

7 min
hash-map

3Sum: Sorting Plus Two Pointers

medium

How to solve LeetCode 3Sum in O(n^2) using sort and converging pointers. Handle duplicates cleanly.

8 min
two-pointer

Rotate Array: The Triple Reverse Trick

medium

How to solve LeetCode Rotate Array in O(n) time and O(1) space using three reversals.

7 min
arrays

Reverse Linked List: The Pointer Swap Technique

easy

How to solve LeetCode Reverse Linked List iteratively and recursively. Visual step-by-step pointer reversal guide.

6 min
linked-list

Product of Array Except Self: Two-Pass Prefix/Suffix

medium

How to solve LeetCode Product of Array Except Self in O(n) without division. Prefix and suffix product walkthrough.

6 min
greedy

Number of Islands: Grid DFS Pattern

medium

How to solve LeetCode Number of Islands using DFS flood fill. The essential grid traversal pattern explained.

10 min
graphs

Minimum Window Substring: Advanced Sliding Window

hard

How to solve LeetCode Minimum Window Substring with sliding window and frequency counting. O(n) solution.

9 min
sliding-window

Merge Sorted Array: The Backwards Trick

easy

How to solve LeetCode Merge Sorted Array in-place by filling from the end. O(n) two-pointer solution explained.

6 min
two-pointer

Maximum Depth of Binary Tree: Recursion Made Simple

easy

How to solve LeetCode Maximum Depth of Binary Tree with DFS recursion. Visual tree traversal walkthrough.

7 min
trees

Majority Element: Boyer-Moore Voting Algorithm

easy

How to solve LeetCode Majority Element in O(n) time and O(1) space with the Boyer-Moore voting algorithm.

7 min
arrays

Longest Substring Without Repeating Characters

medium

How to solve LeetCode Longest Substring Without Repeating Characters using sliding window and a set. O(n) solution.

7 min
sliding-window

Longest Consecutive Sequence: The Set Trick

medium

How to solve LeetCode Longest Consecutive Sequence in O(n) using a set. Why sorting is not needed.

7 min
hash-map

Linked List Cycle: Floyd's Tortoise and Hare

easy

How to detect a cycle in a linked list using O(1) space. Floyd's algorithm explained with visuals.

6 min
linked-list

Jump Game: Greedy Reachability

medium

How to solve LeetCode Jump Game in O(n) using greedy farthest-reach tracking. No DP needed.

9 min
greedy

Invert Binary Tree: The Famous Three-Line Solution

easy

How to solve LeetCode Invert Binary Tree with recursion. The problem that started a meme.

7 min
trees

Group Anagrams: Hash Map Grouping Pattern

medium

How to solve LeetCode Group Anagrams in O(n*k) using sorted keys. Step-by-step visual walkthrough.

7 min
hash-map

Daily Temperatures: Monotonic Stack Explained

medium

How to solve LeetCode Daily Temperatures using a monotonic stack. Visual walkthrough of the next-greater-element pattern.

8 min
stacks

Container With Most Water: Two Pointer Greedy

medium

How to solve LeetCode Container With Most Water in O(n) using two pointers. Why moving the shorter side is optimal.

7 min
two-pointer

Climbing Stairs: Your First Dynamic Programming Problem

easy

How to solve LeetCode Climbing Stairs with DP in O(n) time and O(1) space. The perfect intro to dynamic programming.

7 min
dynamic-programming

Binary Search (LeetCode 704): The Foundation

easy

How to implement binary search correctly. Avoid off-by-one errors with this clear visual walkthrough.

8 min
binary-search

Valid Parentheses: Stack Pattern Explained

easy

How to solve LeetCode Valid Parentheses using a stack. Visual step-by-step walkthrough with Python code.

7 min
stacks

Two Sum: The Classic Interview Starter

easy

How to solve LeetCode Two Sum in O(n) using a hash map complement lookup. Step-by-step walkthrough with visuals.

6 min
hash-map

Trapping Rain Water: Two Pointer Approach

hard

How to solve LeetCode Trapping Rain Water in O(n) time and O(1) space using two pointers. Visual step-by-step guide.

6 min
two-pointer

Contains Duplicate: Three Solutions Compared

easy

How to solve LeetCode Contains Duplicate using a set, sorting, or brute force. O(n) optimal solution explained.

6 min
hash-map

Best Time to Buy and Sell Stock: One Pass Solution

easy

How to solve LeetCode Best Time to Buy and Sell Stock in O(n) by tracking the running minimum. Visual walkthrough.

7 min
greedy

Binary Search: More Than Finding a Number

Learn binary search with visual walkthroughs, Python code, and the 'search on the answer space' variant that unlocks a whole class of interview problems.

9 min
patternssearching

Stack Patterns: Matching, Nesting, and More

Master stack patterns for coding interviews: bracket matching, monotonic stacks, and state save/restore. Visual walkthroughs with Python examples.

7 min
patternsstacks

Hash Map Patterns for Coding Interviews

Master the three core hash map patterns for coding interviews: frequency counting, complement lookup, and grouping. Python examples with O(1) lookups.

8 min
patternshash-maps

The Two Pointers Pattern: A Complete Guide

Master the two pointers technique for sorted array and linked list problems in O(n) time. Visual walkthrough with Python code and common variations.

8 min
patternsarrays

The Sliding Window Pattern: A Complete Guide

Learn the sliding window technique for solving subarray and substring problems in O(n) time. Step-by-step visual walkthrough with Python code examples.

8 min
patternsarrays