Blog

In-depth guides on algorithms and data structures

47 posts

DP

Longest Bitonic Subsequence Explained - Forward + Backward LIS

Learn the Longest Bitonic Subsequence: the longest run that strictly rises then strictly falls. Combine a forward LIS and a backward LIS in O(n²) with interactive visualization.

BitonicLISDynamic ProgrammingCoding InterviewAlgoNote
Greedy

Gas Station (Circular Tour) Greedy - Find the Starting Point - AlgoNote

Learn how to find the start of a circular gas-station tour in O(n) with greedy. Understand diff accumulation and why moving the start forward is safe, with interactive visualization.

GreedyPrefix SumCircular ArrayCoding InterviewAlgoNote
Prefix Sum

Answering Range Sum Queries in O(1) with Prefix Sums - AlgoNote

Learn prefix sums through a neighborhood library visitor dataset. By precomputing a prefix sum array, any range [l, r] sum is answered in O(1) with a single subtraction prefix[r+1] - prefix[l]. See the full walkthrough in AlgoNote visualization.

Prefix SumRange SumPreprocessingCoding TestAlgoNote
Sorting

Multi-Key Coordinate Sorting Explained - Step by Step

Learn multi-key comparison sorting that orders (x, y) coordinates by x ascending, then y ascending on ties. See how to write the comparator and watch it run with AlgoNote visualization.

Multi-key SortCoordinate SortComparison SortAlgorithmAlgoNote
DP

Reduce a Number to 1 - Minimum Operations DP Explained

Find the minimum number of operations to reduce an integer X to 1 using ÷3, ÷2, and −1. Learn why greedy fails and how the dp[i]=1+min(...) recurrence guarantees the optimum, with an interactive visualization.

DPDynamic ProgrammingMin OperationsCoding InterviewAlgoNote
Graph

Minimum Transfer Route - BFS Shortest Moves Explained (AlgoNote)

Learn how to find the minimum number of moves (transfers) from start to destination on an unweighted route graph using BFS level traversal. See the queue and distance array in action with AlgoNote visualization.

BFSGraphShortest PathMinimum MovesAlgoNote
Searching

Cable Cutting - Parametric Binary Search Explained | AlgoNote

Find the maximum equal piece length that cuts cables of varying lengths into at least K pieces, using binary search on the answer plus a feasibility count. Follow it step by step with AlgoNote visualization.

Parametric SearchBinary SearchCable CuttingCoding InterviewAlgoNote
DP

2-by-n Tiling Recurrence Explained - Step by Step Guide

Learn how to count tilings of a 2-by-n strip with 1x2 and 2x1 tiles using the recurrence dp[i]=dp[i-1]+dp[i-2]. The same structure as Fibonacci, with interactive visualization on AlgoNote.

TilingDynamic ProgrammingDPRecurrenceAlgoNote
Data Structures

Bomb String Removal - Popping Patterns with a Stack - AlgoNote

Learn how to repeatedly remove a pattern from a string in O(n) using a stack. See the key idea of comparing only the tail with AlgoNote visualization.

StackStringSimulationCoding InterviewAlgoNote
Two Pointers

Closest Pair Sum to a Target - Solving It in O(n) with Two Pointers - AlgoNote

Find the pair whose sum is closest to a target in a sorted sequence, told through a duet pitch-matching story. Grasp the core idea of replacing the O(n²) all-pairs check with an O(n) two-pointer sweep. See the full solution in AlgoNote step-by-step visualization.

Two PointersSortingPair SumCoding TestAlgoNote
Searching

Cake Cutting - Parametric Search by Binary-Searching the Answer - AlgoNote

Learn parametric search through a dessert shop tasting-corner problem. Instead of picking where to cut, you binary-search the blade height (the answer) itself. See the full step-by-step solution in AlgoNote visualization.

Parametric SearchBinary SearchDecision ProblemCoding TestAlgoNote
Data Structures

Doubly Linked List Explained - Two Pointers, Both Directions

Learn what a doubly linked list is and how it differs from a singly linked list (reverse traversal, O(1) deletion). See the core approach to handling prev/next pointers with AlgoNote visualization.

Doubly Linked ListLinked ListData StructurePointerAlgoNote
Data Structures

Smartphone App Manager - The Core Idea of LRU That Keeps Only the N Most Recent - AlgoNote

The familiar rule "keep only a few recently used apps in memory" is actually an LRU cache. We grasp why an array or a hash map alone falls short, and why combining a hash map with a doubly linked list makes every operation O(1). See the full step-by-step solution in AlgoNote visualization.

LRUCacheHashMapDoublyLinkedListData StructureCoding TestAlgoNote
Data Structures

Segment Tree - Range-Sum Queries and Updates, Both in O(log n) - AlgoNote

Grasp the core idea of the segment tree for fast "range sums" on an array whose values change often. We explain why prefix sums fall short and why grouping ranges into a tree works. See the full step-by-step solution in AlgoNote visualization.

Segment TreeRange SumData StructureTreeCoding TestAlgoNote
Sorting

Make the Largest Number - Custom Comparator Sorting by Concatenation - AlgoNote

What is the largest number you can build from [3, 30, 34, 5, 9]? Ordering by numeric value is wrong. The key is the "a+b vs b+a" custom comparison. Grasp why we compare this way and how to approach it. See the full step-by-step solution in AlgoNote visualization.

Largest NumberSortingCustom ComparatorStringCoding TestAlgoNote
Data Structures

Next Warmer Day Alert - Solving in O(n) with a Monotonic Stack - AlgoNote

Grasp the core idea of solving "how many days until a warmer day?" in O(n) with a monotonic stack. We explain why a stack beats the O(n²) double loop. See the full step-by-step solution in AlgoNote visualization.

Monotonic StackStackData StructureCoding TestAlgoNote
Graph

Prim's Algorithm - Growing a Minimum Spanning Tree by Picking 'Edges' with a Priority Queue - AlgoNote

Grasp the core idea of the Minimum Spanning Tree (MST) through Prim's algorithm. Start from one node and use a priority queue to pick the cheapest connecting edge — and see how it differs from Dijkstra. Watch the full step-by-step trace in AlgoNote visualization.

PrimMinimum Spanning TreeMSTGraphPriority QueueAlgoNote
Graph

Tournament Rank Decision - Fixing Ranks from Partial Results with Floyd-Warshall - AlgoNote

Through an arm-wrestling tournament where only some results are known, learn a fresh use of Floyd-Warshall: how many players have a fully fixed rank? Instead of shortest distances, you fill a "win/loss reachability" matrix. See the full step-by-step solution in AlgoNote visualization.

Floyd-WarshallGraphTransitive ClosureReachabilityCoding TestAlgoNote
Greedy

Cafe Order Processing - Why Does Shortest-First Minimize Total Waiting Time? - AlgoNote

When customers rush a cafe all at once, which order should you make first to minimize everyone’s total wait? Grasp the intuition behind a greedy that boils down to one line of sorting. See the full step-by-step solution in AlgoNote visualization.

GreedySortingPrefix SumCoding TestAlgoNote
Sorting

Shell Sort - Speeding Up Insertion Sort by Adding a "Gap" - AlgoNote

Why is insertion sort sometimes slow? Shell sort fixes that weakness with the idea of a "gap" — ordering far-apart elements first. Grasp why a gap helps and how to approach it. See the full step-by-step solution in AlgoNote visualization.

Shell SortSortingInsertion SortCoding TestAlgoNote
Searching

EV Charger Placement - Intro to Parametric Search (Binary Search on the Answer) - AlgoNote

Grasp the core idea of parametric search through an EV charger placement problem. Instead of choosing positions, you binary-search the answer itself. See the full step-by-step solution in AlgoNote visualization.

Parametric SearchBinary SearchGreedyCoding TestAlgoNote
Sorting

Quick Sort - In-Place Sorting by Partitioning Around a Pivot - AlgoNote

Understand the partition step at the heart of quick sort and why it averages O(n log n) but can degrade to O(n²). See pivot choice and in-place sorting step by step with interactive visualization.

SortingDivide and ConquerQuick SortCoding InterviewAlgoNote
Sorting

Merge Sort - Divide in Half, Sort, and Merge (Stable, O(n log n)) - AlgoNote

Learn how merge sort splits the array in half, sorts each part, and merges two sorted halves — why it guarantees O(n log n) and why it is stable. Watch the merge step with interactive visualization.

SortingDivide and ConquerMerge SortStable SortAlgoNote
String

KMP String Search - Finding a Pattern in O(n+m) with the Failure Function - AlgoNote

Learn how KMP reuses already-compared information via a failure function (partial-match table) to find a pattern in O(n+m) without ever rewinding the text pointer. See the difference from naive search with interactive visualization.

StringKMPPattern MatchingFailure FunctionAlgoNote
Data Structures

Heap - The Priority Queue That Pops Min/Max in O(log n) - AlgoNote

Learn how a heap represents a complete binary tree in an array to insert and remove the min (or max) in O(log n). See sift-up/down and priority-queue use with interactive visualization.

Data StructuresHeapPriority QueueBinary TreeAlgoNote
Data Structures

Queue - The FIFO Structure Where First In Comes First Out - AlgoNote

Learn how a queue works as FIFO and how a circular buffer makes enqueue/dequeue O(1). See the difference from a stack and its use in BFS with interactive visualization.

Data StructuresQueueFIFOCircular BufferAlgoNote
Backtracking

N-Queens - Placing Non-Attacking Queens with Backtracking - AlgoNote

Learn how N-Queens is solved by placing one queen per row in a safe column and backtracking when stuck, with pruning by column and diagonal usage. See the backtracking with interactive visualization.

BacktrackingN-QueensPruningRecursionAlgoNote
Data Structures

Hash Table - Average O(1) Lookup and How Collisions Are Handled - AlgoNote

Learn how a hash table maps keys to indices via a hash function for average O(1) operations, and how collisions are handled with chaining or open addressing. See load factor and rehashing with interactive visualization.

Data StructuresHashHash TableCollisionAlgoNote
Data Structures

Union-Find (Disjoint Set) - Merge Groups and Ask If Two Are Connected - AlgoNote

Learn how union-find manages groups of elements and runs union/find in near O(1) using path compression and union by rank. See both optimizations with interactive visualization.

Data StructuresUnion-FindDisjoint SetGraphAlgoNote
DP

Longest Increasing Subsequence (LIS) - Length in O(n log n) - AlgoNote

Learn that LIS finds the length of the longest increasing subsequence, with both the O(n²) DP and the binary-search O(n log n) approach (the tails array). See the difference with interactive visualization.

DPDynamic ProgrammingLISBinary SearchAlgoNote
DP

0/1 Knapsack - Solving Take-or-Leave with Dynamic Programming - AlgoNote

Learn how to solve 0/1 knapsack in O(nW) with the dp[i][w] state and a take/leave recurrence. See the 1D optimization and common pitfalls with interactive visualization.

DPDynamic ProgrammingKnapsackOptimizationAlgoNote
DP

Longest Common Subsequence (LCS) - Finding Shared Order with DP - AlgoNote

Learn how LCS finds the longest order-preserving common subsequence of two sequences in O(mn) with a dp[i][j] recurrence. See the difference from substrings and backtracking recovery with interactive visualization.

DPDynamic ProgrammingLCSStringAlgoNote
DP

Coin Change - Fewest Coins for an Amount with DP - AlgoNote

Learn why greedy fails on coin change and how the dp[a] = fewest coins for amount a recurrence solves it in O(amount × coins). See unreachable handling and common pitfalls with interactive visualization.

DPDynamic ProgrammingCoin ChangeOptimizationAlgoNote
Two Pointers

Sliding Window - Maintaining Window Values in O(n) by Sliding - AlgoNote

Learn how the sliding window slides a contiguous range one step at a time — adding the entering value and subtracting the leaving one — to maintain window sums/maxes in O(n). See fixed vs variable windows with interactive visualization.

Two PointersSliding WindowRange SumCoding InterviewAlgoNote
Two Pointers

Two Pointers - Scanning a Sorted Array in O(n) with Two Indices - AlgoNote

Learn how two pointers move two indices over a sorted array to solve problems like two-sum in O(n), and why monotonicity guarantees no answer is missed. See it with interactive visualization.

Two PointersSortingTwo SumCoding InterviewAlgoNote
Math

Sieve of Eratosthenes - Finding All Primes up to N at Once - AlgoNote

Learn how the Sieve of Eratosthenes finds all primes up to N in O(N log log N) by crossing out multiples. See why you start at p² and stop at √N with interactive visualization.

MathPrimeSieve of EratosthenesNumber TheoryAlgoNote
Graph

Topological Sort - Ordering Tasks with Dependencies - AlgoNote

Learn how topological sort orders vertices of a DAG so every edge u→v has u before v, using the in-degree-based Kahn’s algorithm. See cycle detection with interactive visualization.

GraphTopological SortDAGIn-degreeAlgoNote
Graph

Depth-First Search (DFS) - Go Deep, Then Backtrack - AlgoNote

Learn how DFS dives deep then backtracks, how to implement it with a stack or recursion, and how it differs from BFS. See why marking visited matters with interactive visualization.

GraphDFSDepth-First SearchBacktrackingAlgoNote
Tree

Binary Tree Traversal - Preorder, Inorder, Postorder, Level - AlgoNote

Learn that preorder, inorder, and postorder differ only in "when you visit the root," why inorder gives ascending order on a BST, and how level-order (BFS) works. See it with interactive visualization.

TreeTraversalPreorder Inorder PostorderBinary TreeAlgoNote
Math

GCD and the Euclidean Algorithm - Plus LCM in O(log) - AlgoNote

Learn how the Euclidean algorithm computes the GCD in O(log) via gcd(a,b)=gcd(b, a mod b), why it works, and how to get the LCM from the GCD. See the remainder shrink step by step with interactive visualization.

MathGCDEuclidean AlgorithmNumber TheoryAlgoNote
Sorting

Heap Sort - Repeatedly Extract the Max from a Max-Heap - AlgoNote

Learn how heap sort builds a max-heap and repeatedly moves the root (max) to the end. Understand heapify and why it is always O(n log n) and in-place, with interactive visualization.

SortingHeapHeap SortPriority QueueAlgoNote
Sorting

Sorting Algorithms Compared - Complete Guide to 7 Essential Sorts

Compare the principles and time complexities of 7 major sorting algorithms, from Bubble Sort to Counting Sort. Experience each algorithm with interactive visualizations.

SortingAlgorithmTime ComplexityCoding Interview
Searching

Binary Search Algorithm Explained - Step by Step Guide

Learn how binary search works, its implementation, and O(log n) time complexity. A must-know algorithm for coding interviews with interactive visualization.

Binary SearchAlgorithmCoding InterviewO(log n)AlgoNote
Graph

BFS Algorithm Explained - Breadth-First Search with Visualization

Understand how BFS (Breadth-First Search) works, its queue-based implementation, and differences from DFS. Master this essential graph algorithm for shortest path problems with interactive visualization.

BFSBreadth-First SearchGraphShortest PathAlgoNote
Graph

Dijkstra's Algorithm Explained - Shortest Path Made Simple

Learn how Dijkstra's algorithm finds the shortest path in weighted graphs. Understand priority queue implementation, time complexity, and common interview patterns with step-by-step visualization.

DijkstraShortest PathGraph AlgorithmPriority QueueAlgoNote
DP

Dynamic Programming for Beginners - Learn DP with Fibonacci

Understand dynamic programming through the Fibonacci sequence. Learn memoization vs tabulation, how DP reduces time complexity from O(2^n) to O(n), with interactive visualization.

Dynamic ProgrammingDPFibonacciMemoizationAlgoNote
Data Structures

Stack Data Structure Explained - Operations, Uses & Interview Tips

Master the Stack data structure: LIFO principle, push/pop operations, and real-world applications. From parentheses matching to browser history — learn with interactive visualization.

StackData StructureLIFOCoding InterviewAlgoNote
Blog | Algorithm Learning Guides | AlgoNote