brain

tamnd's digital brain — notes, problems, research

42768 notes

LeetCode 392: Is Subsequence

A clear explanation of checking whether one string is a subsequence of another using two pointers.

leetcodestringtwo-pointersdynamic-programming
LeetCode 367: Valid Perfect Square

A clear explanation of checking whether an integer is a perfect square using binary search without sqrt.

leetcodemathbinary-search
LeetCode 415: Add Strings

A clear explanation of adding two non-negative integer strings using manual digit-by-digit simulation.

leetcodemathstringsimulationtwo-pointers
LeetCode 317: Shortest Distance from All Buildings

A clear explanation of Shortest Distance from All Buildings using BFS from each building with distance and reach accumulation.

leetcodematrixbfsgraph
LeetCode 491: Non-decreasing Subsequences

A clear explanation of generating all distinct non-decreasing subsequences using DFS, backtracking, and per-level duplicate control.

leetcodearraybacktrackinghash-table
LeetCode 346: Moving Average from Data Stream

A clear explanation of Moving Average from Data Stream using a queue and rolling sum.

leetcodequeuedesignsliding-window
LeetCode 465: Optimal Account Balancing

A clear explanation of minimizing debt-settlement transactions using net balances, backtracking, and memoization-style pruning.

leetcodearrayhash-mapbacktrackingdfs
LeetCode 224: Basic Calculator

A clear explanation of evaluating an expression with plus, minus, spaces, and parentheses using a stack.

leetcodestringstackparser
LeetCode 296: Best Meeting Point

A median-based solution for minimizing total Manhattan distance in a grid.

leetcodemathsortingmatrixmedian
LeetCode 223: Rectangle Area

A clear explanation of computing the total covered area of two axis-aligned rectangles by subtracting their overlap.

leetcodemathgeometry
LeetCode 442: Find All Duplicates in an Array

Find all duplicated numbers in an array in O(n) time and O(1) extra space using index marking.

leetcodearrayhashingin-place
LeetCode 441: Arranging Coins

Find the maximum number of complete staircase rows that can be formed using binary search and triangular numbers.

leetcodemathbinary-search
LeetCode 414: Third Maximum Number

A clear explanation of finding the third distinct maximum number using one pass and constant space.

leetcodearraysortingset
LeetCode 345: Reverse Vowels of a String

A clear explanation of Reverse Vowels of a String using two pointers and selective swaps.

leetcodestringtwo-pointers
LeetCode 366: Find Leaves of Binary Tree

A clear explanation of grouping binary tree nodes by the round in which they become leaves using postorder DFS.

leetcodetreedfspostorderbinary-tree
LeetCode 316: Remove Duplicate Letters

A clear explanation of Remove Duplicate Letters using a greedy monotonic stack.

leetcodestringstackgreedymonotonic-stack
LeetCode 391: Perfect Rectangle

A clear explanation of checking whether many small axis-aligned rectangles form one exact rectangular cover using area and corner parity.

leetcodearrayhash-tablegeometry
LeetCode 275: H-Index II

A clear explanation of the H-Index II problem using binary search on a sorted citations array.

leetcodearraybinary-search
LeetCode 295: Find Median from Data Stream

A two-heap data structure for adding numbers from a stream and returning the current median in constant time.

leetcodeheappriority-queuedesigndata-stream
LeetCode 222: Count Complete Tree Nodes

A clear explanation of counting nodes in a complete binary tree faster than visiting every node.

leetcodebinary-treerecursionbinary-search
LeetCode 490: The Maze

A clear explanation of deciding whether a rolling ball can stop at the destination using BFS or DFS over stopping cells.

leetcodegraphbfsdfsmatrixmaze
LeetCode 344: Reverse String

A clear explanation of Reverse String using two pointers and in-place swaps.

leetcodestringtwo-pointers
LeetCode 413: Arithmetic Slices

A clear explanation of counting arithmetic subarrays using dynamic programming and consecutive differences.

leetcodearraydynamic-programmingmath
LeetCode 464: Can I Win

A clear explanation of solving the Can I Win game using minimax recursion, bitmask state compression, and memoization.

leetcodedynamic-programmingmemoizationbitmaskgame-theory
LeetCode 315: Count of Smaller Numbers After Self

A clear explanation of Count of Smaller Numbers After Self using coordinate compression and a Fenwick Tree.

leetcodearrayfenwick-treebinary-indexed-treemerge-sort
LeetCode 440: K-th Smallest in Lexicographical Order

Find the k-th integer in lexicographical order without generating all numbers, using prefix counting over a conceptual trie.

leetcodetrieprefixmathlexicographical-order
LeetCode 365: Water and Jug Problem

A clear explanation of solving the Water and Jug Problem using Bézout's identity and greatest common divisor.

leetcodemathgcdbreadth-first-searchnumber-theory
LeetCode 390: Elimination Game

A clear explanation of finding the last remaining number after alternating left-to-right and right-to-left eliminations.

leetcodemathrecursionsimulation
LeetCode 274: H-Index

A clear explanation of the H-Index problem using sorting, then an optimized counting approach.

leetcodearraysortingcounting-sort
LeetCode 294: Flip Game II

A recursive game theory solution with memoization for deciding whether the starting player can force a win.

leetcodebacktrackinggame-theorymemoizationstring
LeetCode 221: Maximal Square

A clear explanation of finding the largest square of 1s in a binary matrix using dynamic programming.

leetcodedynamic-programmingmatrix
LeetCode 293: Flip Game

A simple string scanning solution for generating every possible next state after flipping one consecutive ++ pair into --.

leetcodestringsimulation
LeetCode 273: Integer to English Words

A clear explanation of the Integer to English Words problem using three-digit chunks and scale words.

leetcodemathstringrecursion
LeetCode 292: Nim Game

A game theory solution for deciding whether the first player can win by using the losing-position pattern of multiples of four.

leetcodemathgame-theory
LeetCode 220: Contains Duplicate III

A clear explanation of checking nearby indices with nearby values using a sliding window and bucket hashing.

leetcodearrayhash-mapbucket-sortsliding-window
LeetCode 272: Closest Binary Search Tree Value II

A clear explanation of the Closest Binary Search Tree Value II problem using inorder traversal and a fixed-size sliding window.

leetcodetreebinary-search-treeinorder-traversaldeque
LeetCode 291: Word Pattern II

A backtracking solution for matching a pattern string to a target string using a bijective character-to-substring mapping.

leetcodebacktrackinghash-tablestring
LeetCode 219: Contains Duplicate II

A clear explanation of detecting whether equal values appear within distance k using a hash map or sliding window set.

leetcodearrayhash-maphash-setsliding-window
LeetCode 290: Word Pattern

A hash map solution for checking whether a pattern string and a space-separated word string form a bijection.

leetcodehash-tablestring
LeetCode 271: Encode and Decode Strings

A clear explanation of the Encode and Decode Strings problem using length-prefix encoding.

leetcodestringdesignencodingdecoding
LeetCode 289: Game of Life

An in-place matrix simulation for computing the next state of Conway's Game of Life using temporary encoded states.

leetcodematrixsimulationin-place
LeetCode 242: Valid Anagram

A clear explanation of checking whether two strings are anagrams using character frequency counting.

leetcodestringhash-tablecounting
LeetCode 270: Closest Binary Search Tree Value

A clear explanation of the Closest Binary Search Tree Value problem using the BST property to walk toward the target.

leetcodetreebinary-search-treedfsbinary-search
LeetCode 218: The Skyline Problem

A clear explanation of computing the skyline formed by buildings using sweep line and a max-heap.

leetcodeheapsweep-linegeometrypriority-queue
LeetCode 269: Alien Dictionary

A clear explanation of the Alien Dictionary problem using graph construction and topological sorting.

leetcodegraphtopological-sortbfsstring
LeetCode 217: Contains Duplicate

A clear explanation of detecting duplicates in an array using a hash set and sorting.

leetcodearrayhash-setsorting
LeetCode 241: Different Ways to Add Parentheses

A clear explanation of generating all possible results from different parenthesizations using divide and conquer recursion.

leetcodedivide-and-conquerrecursionmemoizationexpression-parsing
LeetCode 268: Missing Number

A clear explanation of the Missing Number problem using sum formula and XOR.

leetcodearraymathbit-manipulationxor
LeetCode 216: Combination Sum III

A clear explanation of finding k distinct numbers from 1 to 9 that sum to n using backtracking.

leetcodearraybacktrackingdfs
LeetCode 288: Unique Word Abbreviation

A hash map design for checking whether a word's abbreviation is unique in a dictionary.

leetcodehash-tablestringdesign
LeetCode 240: Search a 2D Matrix II

A clear explanation of searching a row-sorted and column-sorted matrix using the top-right corner elimination method.

leetcodearraymatrixbinary-search
LeetCode 215: Kth Largest Element in an Array

A clear explanation of finding the kth largest element using sorting, a min-heap, and Quickselect.

leetcodearrayheapquickselectdivide-and-conquer
LeetCode 267: Palindrome Permutation II

A clear explanation of the Palindrome Permutation II problem using character counts and backtracking over half of the palindrome.

leetcodebacktrackingstringhash-tablepermutation
LeetCode 239: Sliding Window Maximum

A clear explanation of finding the maximum value in every sliding window using a monotonic deque.

leetcodearraysliding-windowdequemonotonic-queue
LeetCode 214: Shortest Palindrome

A clear explanation of building the shortest palindrome by finding the longest palindromic prefix using KMP.

leetcodestringkmppalindrome
LeetCode 287: Find the Duplicate Number

A Floyd cycle detection solution for finding the repeated number without modifying the array and using constant extra space.

leetcodearraytwo-pointerscycle-detectionfloyd
LeetCode 266: Palindrome Permutation

A clear explanation of the Palindrome Permutation problem using character parity counting.

leetcodehash-tablestringcounting
LeetCode 286: Walls and Gates

A multi-source BFS solution for filling each empty room with its shortest distance to the nearest gate.

leetcodebreadth-first-searchgraphmatrixqueue
LeetCode 238: Product of Array Except Self

A clear explanation of computing each product except self using prefix and suffix products without division.

leetcodearrayprefix-productsuffix-product
LeetCode 213: House Robber II

A clear explanation of maximizing robbed money from circularly arranged houses using dynamic programming.

leetcodedynamic-programmingarray
LeetCode 100: Same Tree

A detailed guide to solving Same Tree with recursive DFS and structural comparison.

leetcodetreebinary-treedepth-first-searchbreadth-first-search
LeetCode 99: Recover Binary Search Tree

A detailed guide to solving Recover Binary Search Tree with inorder traversal and two misplaced nodes.

leetcodetreebinary-search-treedepth-first-search
LeetCode 125: Valid Palindrome

A clear explanation of checking whether a string is a palindrome after ignoring non-alphanumeric characters and case.

leetcodestringtwo-pointers
LeetCode 98: Validate Binary Search Tree

A detailed guide to solving Validate Binary Search Tree with recursive lower and upper bounds.

leetcodetreebinary-search-treedepth-first-searchrecursion
LeetCode 150: Evaluate Reverse Polish Notation

Evaluate an arithmetic expression written in Reverse Polish Notation using a stack.

leetcodemediumstackmath
LeetCode 149: Max Points on a Line

Find the maximum number of points lying on the same straight line using slope counting and normalization.

leetcodehardgeometryhash-mapmath
LeetCode 124: Binary Tree Maximum Path Sum

A clear explanation of finding the maximum path sum in a binary tree using bottom-up depth-first search.

leetcodetreebinary-treedfsdynamic-programming
LeetCode 123: Best Time to Buy and Sell Stock III

A clear explanation of maximizing stock profit with at most two transactions using dynamic programming.

leetcodearraydynamic-programming
LeetCode 97: Interleaving String

A detailed guide to solving Interleaving String with two-dimensional dynamic programming.

leetcodestringdynamic-programming
LeetCode 122: Best Time to Buy and Sell Stock II

A clear explanation of maximizing stock profit with unlimited transactions using a greedy single-pass method.

leetcodearraygreedydynamic-programming
LeetCode 96: Unique Binary Search Trees

A detailed guide to solving Unique Binary Search Trees with dynamic programming and the Catalan recurrence.

leetcodetreebinary-search-treedynamic-programmingmath
LeetCode 75: Sort Colors

A clear guide to sorting an array of 0s, 1s, and 2s in place using the Dutch National Flag algorithm.

leetcodearraytwo-pointerssorting
LeetCode 148: Sort List

Sort a singly linked list in ascending order using merge sort with fast and slow pointers.

leetcodemediumlinked-listtwo-pointersdivide-and-conquermerge-sort
LeetCode 121: Best Time to Buy and Sell Stock

A clear explanation of finding the maximum profit from one stock transaction using a single pass.

leetcodearraydynamic-programming
LeetCode 174: Dungeon Game

A clear explanation of computing the minimum initial health needed to survive a dungeon using reverse dynamic programming.

leetcodedynamic-programmingmatrix
LeetCode 74: Search a 2D Matrix

A clear guide to searching a sorted 2D matrix using binary search over a virtual one-dimensional array.

leetcodearraymatrixbinary-search
LeetCode 120: Triangle

A clear explanation of finding the minimum path sum in a triangle using bottom-up dynamic programming.

leetcodedynamic-programmingarray
LeetCode 147: Insertion Sort List

Sort a singly linked list using insertion sort by splicing each node into a growing sorted list.

leetcodemediumlinked-listsortinginsertion-sort
LeetCode 173: Binary Search Tree Iterator

A clear explanation of designing an iterator over a BST using controlled inorder traversal with a stack.

leetcodestacktreedesignbinary-search-treeiterator
LeetCode 95: Unique Binary Search Trees II

A detailed guide to solving Unique Binary Search Trees II with recursive tree generation over value ranges.

leetcodetreebinary-search-treedynamic-programmingbacktrackingrecursion
LeetCode 146: LRU Cache

Design an LRU cache with O(1) get and put operations using a hash map and doubly linked list.

leetcodemediumdesignhash-maplinked-list
LeetCode 172: Factorial Trailing Zeroes

A clear explanation of counting trailing zeroes in n! by counting factors of 5 instead of computing the factorial directly.

leetcodemath
LeetCode 73: Set Matrix Zeroes

A clear guide to setting matrix rows and columns to zero in place using the first row and first column as markers.

leetcodearraymatrixin-place
LeetCode 94: Binary Tree Inorder Traversal

A detailed guide to solving Binary Tree Inorder Traversal with recursion and an iterative stack.

leetcodebinary-treedepth-first-searchstackrecursion
LeetCode 145: Binary Tree Postorder Traversal

Return the postorder traversal of a binary tree using recursion or an iterative stack-based approach.

leetcodeeasytreebinary-treedfsstack
LeetCode 171: Excel Sheet Column Number

A clear explanation of converting an Excel column title into its numeric index using base 26 accumulation.

leetcodemathstringbase-conversion
LeetCode 72: Edit Distance

A clear guide to computing the minimum number of insert, delete, and replace operations needed to convert one string into another.

leetcodedynamic-programmingstring
LeetCode 144: Binary Tree Preorder Traversal

Return the preorder traversal of a binary tree using recursion or an explicit stack.

leetcodeeasytreebinary-treedfsstack
LeetCode 170: Two Sum III - Data Structure Design

A clear explanation of designing a data structure that supports add and find operations for pair sums.

leetcodehash-tabledesign
LeetCode 93: Restore IP Addresses

A detailed guide to solving Restore IP Addresses with backtracking over four valid IP segments.

leetcodestringbacktracking
LeetCode 71: Simplify Path

A clear guide to simplifying Unix-style file paths using a stack.

leetcodestringstack
LeetCode 119: Pascal's Triangle II

A clear explanation of generating a single row of Pascal's Triangle using in-place dynamic programming.

leetcodearraydynamic-programmingmath
LeetCode 200: Number of Islands

A clear explanation of counting connected groups of land cells in a grid using DFS or BFS.

leetcodematrixgraphdepth-first-searchbreadth-first-search
LeetCode 169: Majority Element

A clear explanation of finding the element that appears more than half the time using Boyer-Moore voting.

leetcodearrayhash-tabledivide-and-conquersortingcounting
LeetCode 143: Reorder List

Reorder a singly linked list in-place by finding the middle, reversing the second half, and merging the two halves alternately.

leetcodemediumlinked-listtwo-pointers
LeetCode 118: Pascal's Triangle

A clear explanation of generating Pascal's Triangle row by row using dynamic programming.

leetcodearraydynamic-programmingmath
LeetCode 92: Reverse Linked List II

A detailed guide to solving Reverse Linked List II with a dummy node and in-place sublist reversal.

leetcodelinked-list
LeetCode 70: Climbing Stairs

A clear guide to counting distinct ways to climb stairs using dynamic programming.

leetcodedynamic-programmingmathfibonacci
LeetCode 199: Binary Tree Right Side View

A clear explanation of returning the visible nodes from the right side of a binary tree using level-order traversal.

leetcodebinary-treebreadth-first-searchdepth-first-search
LeetCode 198: House Robber

A clear explanation of maximizing robbery profit without robbing adjacent houses using dynamic programming.

leetcodedynamic-programmingarray