LeetCode
Hot100: Kth Smallest Element in a BST (Inorder Counting / Early Stop ACERS Guide)
Subtitle / Summary LeetCode 230 is not really about tree traversal mechanics alone. It is about turning BST order into a useful query. Once you see that the k-th smallest value is simply the k-th node visited in inorder traversal, the problem becomes a very stable counting task. Reading time: 11-14 min Tags: Hot100, binary tree, BST, inorder traversal, stack SEO keywords: Kth Smallest Element in a BST, BST, inorder traversal, stack, LeetCode 230 Meta description: Learn LeetCode 230 from BST inorder ordering, explicit-stack counting, and early-stop traversal, with runnable multi-language implementations. A — Algorithm Problem Restatement Given the root root of a binary search tree and an integer k, return the k-th smallest value in the tree. ...
Hot100: Add Two Numbers Linked-List Carry Simulation ACERS Guide
Subtitle / Summary LeetCode 2 is grade-school addition translated into a linked-list workflow. The only persistent state is the carry, and the only structural work is appending one new digit per round. Reading time: 12-15 min Tags: Hot100, linked list, carry, simulation SEO keywords: Add Two Numbers, linked-list carry, reverse order digits, LeetCode 2, Hot100 Meta description: A derivation-first ACERS guide to LeetCode 2 with carry propagation, dummy node construction, engineering mapping, and runnable multi-language code. A - Algorithm (Problem and Algorithm) Problem Restatement You are given two non-empty linked lists l1 and l2. Each list stores a non-negative integer in reverse order, and each node contains one digit. Add the two integers and return the sum as a linked list in the same reverse order. ...
Hot100: LRU Cache Hash Table + Doubly Linked List O(1) ACERS Guide
Subtitle / Summary LeetCode 146 is not a memorize-the-template problem. It is the core cache-design exercise: how to support fast lookup and fast recency updates at the same time. Reading time: 14-18 min Tags: Hot100, LRU, hash table, doubly linked list SEO keywords: LRU Cache, hash table + doubly linked list, O(1) get put, LeetCode 146, Hot100 Meta description: A derivation-first ACERS guide to LRU Cache using a hash table plus doubly linked list, with engineering scenarios, pitfalls, and runnable multi-language code. A - Algorithm (Problem and Algorithm) Problem Restatement Design a data structure LRUCache with: ...
Hot100: Remove Nth Node From End of List One-Pass Two-Pointer ACERS Guide
Subtitle / Summary The hard part of LeetCode 19 is not deleting a node. It is locating the predecessor of the n-th node from the end in a singly linked list without walking backward. Reading time: 12-15 min Tags: Hot100, linked list, two pointers, dummy node SEO keywords: Remove Nth Node From End of List, one-pass two pointers, dummy node, LeetCode 19, Hot100 Meta description: A derivation-first ACERS explanation of LeetCode 19 with fixed-gap two pointers, dummy node boundary handling, engineering mapping, and runnable multi-language implementations. A - Algorithm (Problem and Algorithm) Problem Restatement Given the head of a linked list, remove the n-th node from the end of the list and return the head of the modified list. ...
Hot100: Diameter of Binary Tree (Tree DP / Height Return ACERS Guide)
Subtitle / Summary The most common confusion in LeetCode 543 is deciding what the recursive function should return. It should return height, not diameter. The diameter is updated globally at each node using leftHeight + rightHeight. Once that separation is clear, the problem becomes a clean introduction to tree DP. Reading time: 10-13 min Tags: Hot100, binary tree, tree DP, DFS, postorder SEO keywords: Diameter of Binary Tree, tree DP, height return, DFS, LeetCode 543 Meta description: Learn LeetCode 543 from the postorder height-return pattern, with step-by-step derivation, engineering analogies, and runnable multi-language solutions. A — Algorithm Problem Restatement Given the root root of a binary tree, return the diameter of the tree. ...
Hot100: Lowest Common Ancestor of a Binary Tree (Postorder Return Semantics ACERS Guide)
Subtitle / Summary The real difficulty of LeetCode 236 is not memorizing an LCA template. It is defining what each recursive call should return. Once that return value becomes stable, the whole problem collapses into a short and very clean postorder recursion. Reading time: 11-14 min Tags: Hot100, binary tree, LCA, DFS, postorder SEO keywords: Lowest Common Ancestor of a Binary Tree, LCA, postorder, DFS, LeetCode 236 Meta description: Learn LeetCode 236 from the recursive return-value semantics, with step-by-step derivation, engineering mappings, and runnable multi-language implementations. A — Algorithm Problem Restatement Given a binary tree, find the lowest common ancestor (LCA) of two given nodes p and q. ...
Hot100: Validate Binary Search Tree (Range Constraints / Inorder ACERS Guide)
Subtitle / Summary The hardest part of LeetCode 98 is usually not recursion itself. It is realizing that checking a node against only its parent is not enough. A valid BST is constrained by all of its ancestors, so the stable solution is to pass a valid range downward. This guide explains that idea from scratch, then connects it to the equivalent inorder-sorted view. Reading time: 11-13 min Tags: Hot100, binary tree, BST, DFS, inorder traversal SEO keywords: Validate Binary Search Tree, BST, range constraints, inorder traversal, DFS, LeetCode 98 Meta description: Learn LeetCode 98 from the core invariant low < val < high, with step-by-step derivation, engineering mappings, and runnable multi-language implementations. A — Algorithm Problem Restatement Given the root root of a binary tree, determine whether it is a valid binary search tree (BST). ...
Hot100: N-Queens Incremental Build Tutorial
51. N-Queens is best learned by watching the code grow one small step at a time. This tutorial keeps only the teaching path: tiny example, first DFS skeleton, first correct version, column-only optimization, then full diagonal-state optimization. Problem The n-queens puzzle asks us to place n queens on an n x n chessboard so that no two queens attack each other. Given an integer n, return all distinct solutions. Each solution is represented as a list of strings where: ...
Hot100: Palindrome Partitioning (Backtracking / Palindrome Table ACERS Guide)
Subtitle / Summary 131. Palindrome Partitioning is not hard because of recursion alone. The real challenge is separating two concerns clearly: where the next cut starts, and whether the current substring is a valid palindrome. Reading time: 15-18 min Tags: Hot100, backtracking, string, palindrome, DP SEO keywords: Palindrome Partitioning, backtracking, palindrome DP, string partition, LeetCode 131 Meta description: Learn LeetCode 131 by building the solution from scratch, using suffix-based DFS plus a precomputed palindrome table. A — Algorithm Problem Restatement Given a string s, partition it so that every substring in the partition is a palindrome. Return all possible palindrome partitionings of s. ...
LeetCode 216: Combination Sum III (Backtracking / Fixed-Length Search ACERS Guide)
Subtitle / Summary 216. Combination Sum III is where backtracking adds one more important constraint: not only must the sum match, but the combination length must be exactly k. That turns the problem into a clean fixed-length combination search over the bounded range 1..9. Reading time: 12-15 min Tags: backtracking, fixed length, pruning, combination search SEO keywords: Combination Sum III, fixed-length backtracking, k numbers, pruning, LeetCode 216 Meta description: Build the stable solution for LeetCode 216 from scratch by understanding exact-length backtracking, sorted pruning, and the bounded candidate set 1..9. A — Algorithm Problem Restatement Find all valid combinations of k numbers that add up to n, subject to these rules: ...