brain

tamnd's digital brain — notes, problems, research

42766 notes

LeetCode 972: Equal Rational Numbers

A clear explanation of comparing rational numbers written as decimal strings with optional repeating parts.

leetcodemathstringfractions
LeetCode 847: Shortest Path Visiting All Nodes

A clear explanation of the Shortest Path Visiting All Nodes problem using multi-source BFS and bitmask state compression.

leetcodegraphbreadth-first-searchbitmaskdynamic-programming
LeetCode 924: Minimize Malware Spread

A clear explanation of minimizing malware spread by analyzing connected components with Union Find.

leetcodegraphunion-finddepth-first-searchbreadth-first-search
LeetCode 971: Flip Binary Tree To Match Preorder Traversal

A clear explanation of matching a binary tree preorder traversal by greedily flipping nodes.

leetcodetreebinary-treedepth-first-searchgreedy
LeetCode 846: Hand of Straights

A clear explanation of the Hand of Straights problem using sorting, frequency counting, and greedy grouping.

leetcodearrayhash-tablegreedysorting
LeetCode 923: 3Sum With Multiplicity

A clear explanation of counting index triplets with duplicate values using frequency counts and combinatorics.

leetcodearrayhash-tabletwo-pointerscombinatorics
LeetCode 900: RLE Iterator

A clear explanation of designing an iterator over a run-length encoded sequence without expanding it.

leetcodearraydesigniteratorsimulation
LeetCode 970: Powerful Integers

A clear explanation of generating all powerful integers using bounded powers and a set.

leetcodemathhash-tableenumeration
LeetCode 922: Sort Array By Parity II

A clear explanation of placing even numbers at even indices and odd numbers at odd indices using two pointers.

leetcodearraytwo-pointerssorting
LeetCode 845: Longest Mountain in Array

A clear explanation of the Longest Mountain in Array problem using peak detection and two-pointer expansion.

leetcodearraytwo-pointers
LeetCode 899: Orderly Queue

A clear explanation of finding the lexicographically smallest string after queue operations using rotation and sorting.

leetcodestringmathsorting
LeetCode 969: Pancake Sorting

A clear explanation of sorting an array using prefix reversals by repeatedly placing the largest remaining value.

leetcodearraysortinggreedy
LeetCode 1000: Minimum Cost to Merge Stones

A clear explanation of merging consecutive stone piles with minimum cost using interval dynamic programming.

leetcodearraydynamic-programminginterval-dpprefix-sum
LeetCode 875: Koko Eating Bananas

A clear explanation of finding the minimum banana-eating speed using binary search on the answer.

leetcodearraybinary-search
LeetCode 921: Minimum Add to Make Parentheses Valid

A clear explanation of making a parentheses string valid using greedy counting.

leetcodestringstackgreedycounting
LeetCode 844: Backspace String Compare

A clear explanation of the Backspace String Compare problem using stack simulation and an O(1) space two-pointer scan.

leetcodestringstacktwo-pointerssimulation
LeetCode 950: Reveal Cards In Increasing Order

A clear explanation of solving Reveal Cards In Increasing Order using sorting and queue simulation over indices.

leetcodearrayqueuesortingsimulation
LeetCode 825: Friends Of Appropriate Ages

A counting solution for computing how many directed friend requests are allowed by age rules.

leetcodearraycountingprefix-sum
LeetCode 898: Bitwise ORs of Subarrays

A clear explanation of counting distinct bitwise OR results from all non-empty subarrays using rolling sets.

leetcodearraydynamic-programmingbit-manipulationset
LeetCode 999: Available Captures for Rook

A clear explanation of counting how many pawns a rook can capture by scanning four directions on a chessboard.

leetcodearraymatrixsimulation
LeetCode 968: Binary Tree Cameras

A clear explanation of placing the minimum number of cameras in a binary tree using postorder DFS.

leetcodetreebinary-treedepth-first-searchgreedy
LeetCode 874: Walking Robot Simulation

A clear explanation of simulating robot movement on an infinite grid using direction vectors and obstacle lookup.

leetcodesimulationhash-setarray
LeetCode 949: Largest Time for Given Digits

A clear explanation of solving Largest Time for Given Digits by checking all permutations of four digits.

leetcodearraystringpermutationbrute-force
LeetCode 843: Guess the Word

A clear explanation of the Guess the Word interactive problem using candidate filtering and minimax-style guessing.

leetcodearraystringinteractivegame-theoryminimax
LeetCode 920: Number of Music Playlists

A clear explanation of counting valid music playlists using dynamic programming over playlist length and unique songs used.

leetcodedynamic-programmingcombinatoricsmath
LeetCode 824: Goat Latin

A string simulation solution for converting each word in a sentence into Goat Latin.

leetcodestringsimulation
LeetCode 967: Numbers With Same Consecutive Differences

A clear explanation of generating all n-digit numbers whose adjacent digits differ by k.

leetcodebacktrackingdepth-first-searchbreadth-first-search
LeetCode 998: Maximum Binary Tree II

A clear explanation of inserting a value into a maximum binary tree by following the right spine.

leetcodetreebinary-treerecursion
LeetCode 873: Length of Longest Fibonacci Subsequence

A clear explanation of finding the longest Fibonacci-like subsequence using dynamic programming and value-to-index lookup.

leetcodearraydynamic-programminghash-table
LeetCode 842: Split Array into Fibonacci Sequence

A clear explanation of the Split Array into Fibonacci Sequence problem using backtracking, leading-zero checks, and 32-bit integer limits.

leetcodestringbacktrackingdepth-first-search
LeetCode 919: Complete Binary Tree Inserter

A clear explanation of maintaining a complete binary tree inserter using level-order indexing.

leetcodetreebinary-treebreadth-first-searchdesign
LeetCode 823: Binary Trees With Factors

A dynamic programming solution for counting binary trees where every non-leaf node is the product of its children.

leetcodedynamic-programmingarrayhash-mapsorting
LeetCode 948: Bag of Tokens

A clear explanation of solving Bag of Tokens using sorting, greedy choices, and two pointers.

leetcodearraygreedysortingtwo-pointers
LeetCode 897: Increasing Order Search Tree

A clear explanation of rearranging a binary search tree into an increasing right-only tree using inorder traversal.

leetcodetreebinary-treebinary-search-treedfsinorder-traversal
LeetCode 966: Vowel Spellchecker

A clear explanation of implementing a spellchecker with exact, case-insensitive, and vowel-error matching.

leetcodearraystringhash-table
LeetCode 997: Find the Town Judge

A clear explanation of identifying the town judge using trust indegree and outdegree counts.

leetcodearraygraphcounting
LeetCode 918: Maximum Sum Circular Subarray

A clear explanation of finding the maximum circular subarray sum using Kadane's algorithm.

leetcodearraydynamic-programmingkadane-algorithm
LeetCode 841: Keys and Rooms

A clear explanation of the Keys and Rooms problem using graph traversal from room 0.

leetcodegraphdepth-first-searchbreadth-first-search
LeetCode 872: Leaf-Similar Trees

A clear explanation of comparing two binary trees by collecting their leaf value sequences with DFS.

leetcodetreebinary-treedfs
LeetCode 822: Card Flipping Game

A hash set solution for finding the smallest number that can be hidden from all front-facing cards.

leetcodearrayhash-set
LeetCode 947: Most Stones Removed with Same Row or Column

A clear explanation of solving Most Stones Removed with Same Row or Column using connected components and union-find.

leetcodegraphunion-finddepth-first-search
LeetCode 896: Monotonic Array

A clear explanation of checking whether an array is monotonic using one pass and direction flags.

leetcodearray
LeetCode 965: Univalued Binary Tree

A clear explanation of checking whether every node in a binary tree has the same value.

leetcodetreebinary-treedepth-first-searchrecursion
LeetCode 917: Reverse Only Letters

A clear explanation of reversing only English letters while keeping all non-letter characters fixed.

leetcodestringtwo-pointers
LeetCode 996: Number of Squareful Arrays

A clear explanation of counting unique permutations where every adjacent pair sums to a perfect square using backtracking.

leetcodearraybacktrackinggraphcounting
LeetCode 840: Magic Squares In Grid

A clear explanation of the Magic Squares In Grid problem using fixed-size subgrid validation.

leetcodearraymatrixsimulation
LeetCode 821: Shortest Distance to a Character

A two-pass solution for computing the shortest distance from each index to the nearest occurrence of a target character.

leetcodearraystringtwo-pointers
LeetCode 871: Minimum Number of Refueling Stops

A clear explanation of minimizing refueling stops using a greedy max heap over reachable stations.

leetcodegreedyheappriority-queuearray
LeetCode 964: Least Operators to Express Number

A clear explanation of expressing a target using the fewest operators with repeated uses of x.

leetcodemathdynamic-programmingdfsmemoization
LeetCode 946: Validate Stack Sequences

A clear explanation of solving Validate Stack Sequences by simulating stack push and pop operations.

leetcodearraystacksimulation
LeetCode 895: Maximum Frequency Stack

A clear explanation of designing a stack that pops the most frequent value, breaking ties by most recent insertion.

leetcodehash-tablestackdesign
LeetCode 916: Word Subsets

A clear explanation of finding universal words by merging character frequency requirements from words2.

leetcodearraystringhash-tablecounting
LeetCode 800: Similar RGB Color

A clear explanation of finding the closest shorthand RGB color by rounding each color channel to the nearest repeated hexadecimal pair.

leetcodestringmathhexadecimal
LeetCode 775: Global and Local Inversions

A clear explanation of checking whether every global inversion is also a local inversion using distance constraints.

leetcodearraymathgreedy
LeetCode 725: Split Linked List in Parts

A clear explanation of splitting a linked list into k consecutive parts with sizes as equal as possible.

leetcodelinked-listsimulation
LeetCode 995: Minimum Number of K Consecutive Bit Flips

A clear explanation of making all bits equal to 1 using greedy left-to-right flips and a sliding window flip parity.

leetcodearraygreedysliding-windowbit-manipulation
LeetCode 820: Short Encoding of Words

A suffix-removal solution for finding the shortest reference string that can encode every word.

leetcodestringhash-settrie
LeetCode 870: Advantage Shuffle

A clear explanation of maximizing the advantage of one array over another using sorting, greedy matching, and two pointers.

leetcodearraygreedysortingtwo-pointers
LeetCode 839: Similar String Groups

A clear explanation of the Similar String Groups problem using graph connectivity and union-find.

leetcodestringgraphdepth-first-searchunion-find
LeetCode 963: Minimum Area Rectangle II

A clear explanation of finding the minimum-area rectangle from points when the rectangle may be rotated.

leetcodegeometryhash-tablemath
LeetCode 915: Partition Array into Disjoint Intervals

A clear explanation of finding the smallest left partition using prefix maximums and suffix minimums.

leetcodearrayprefixsuffix
LeetCode 894: All Possible Full Binary Trees

A clear explanation of generating all full binary trees with n nodes using recursion and memoization.

leetcodedynamic-programmingrecursiontreebinary-treememoization
LeetCode 945: Minimum Increment to Make Array Unique

A clear explanation of solving Minimum Increment to Make Array Unique by sorting and greedily assigning the next available value.

leetcodearraysortinggreedy
LeetCode 799: Champagne Tower

A clear explanation of simulating overflow in a champagne glass pyramid using dynamic programming.

leetcodedynamic-programmingsimulation
LeetCode 944: Delete Columns to Make Sorted

A clear explanation of solving Delete Columns to Make Sorted by checking each column independently.

leetcodearraystringmatrixgreedy
LeetCode 798: Smallest Rotation with Highest Score

A clear explanation of finding the smallest rotation with maximum score using a difference array.

leetcodearrayprefix-sumdifference-array
LeetCode 774: Minimize Max Distance to Gas Station

A clear explanation of minimizing the largest adjacent gas-station distance using binary search on the answer.

leetcodearraybinary-searchfloating-point
LeetCode 724: Find Pivot Index

A clear explanation of finding the leftmost pivot index using prefix sums and a running left sum.

leetcodearrayprefix-sum
LeetCode 994: Rotting Oranges

A clear explanation of finding the minimum time for all oranges to rot using multi-source BFS.

leetcodearraymatrixbreadth-first-searchgraph
LeetCode 993: Cousins in Binary Tree

A clear explanation of checking whether two binary tree nodes are cousins using BFS with parent tracking.

leetcodetreebinary-treebreadth-first-searchdepth-first-search
LeetCode 819: Most Common Word

A hash map and string parsing solution for finding the most frequent non-banned word in a paragraph.

leetcodehash-mapstringcounting
LeetCode 773: Sliding Puzzle

A clear explanation of solving the 2 x 3 sliding puzzle using breadth-first search over board states.

leetcodebfsgraphmatrixshortest-path
LeetCode 723: Candy Crush

A clear explanation of restoring a Candy Crush board to a stable state using repeated marking, crushing, and gravity simulation.

leetcodearraymatrixsimulationtwo-pointers
LeetCode 797: All Paths From Source to Target

A clear explanation of finding every path from node 0 to node n - 1 in a directed acyclic graph using DFS and backtracking.

leetcodegraphdfsbacktrackingdag
LeetCode 869: Reordered Power of 2

A clear explanation of checking whether the digits of a number can be reordered to form a power of two using digit frequency signatures.

leetcodemathhash-tabledigit-counting
LeetCode 992: Subarrays with K Different Integers

A clear explanation of counting subarrays with exactly k distinct integers using the at-most-k sliding window trick.

leetcodearrayhash-tablesliding-windowcounting
LeetCode 893: Groups of Special-Equivalent Strings

A clear explanation of counting special-equivalent string groups by building canonical signatures from even and odd positions.

leetcodearrayhash-tablestringsorting
LeetCode 750: Number Of Corner Rectangles

Count axis-aligned rectangles whose four corners are 1 using column-pair frequency counting.

leetcodearraymatrixhash-tablecounting
LeetCode 818: Race Car

A dynamic programming solution for finding the shortest instruction sequence that drives a race car to the target position.

leetcodedynamic-programmingbfsmath
LeetCode 943: Find the Shortest Superstring

A clear explanation of solving Find the Shortest Superstring using pairwise overlaps and bitmask dynamic programming.

leetcodestringdynamic-programmingbitmaskgraph
LeetCode 796: Rotate String

A clear explanation of checking whether one string can become another by repeated left rotations.

leetcodestringstring-matching
LeetCode 772: Basic Calculator III

A clear explanation of evaluating arithmetic expressions with parentheses, precedence, and integer division.

leetcodestringstackrecursionparser
LeetCode 722: Remove Comments

A clear explanation of removing line comments and block comments from source code using a state machine.

leetcodearraystringsimulationstate-machine
LeetCode 868: Binary Gap

A clear explanation of finding the maximum distance between adjacent set bits in a binary representation.

leetcodebit-manipulation
LeetCode 991: Broken Calculator

A clear explanation of finding the minimum operations by working backward from target to startValue.

leetcodemathgreedy
LeetCode 892: Surface Area of 3D Shapes

A clear explanation of computing the exposed surface area of stacked cubes by adding tower area and subtracting shared faces.

leetcodearraymatrixgeometrymath
LeetCode 749: Contain Virus

Simulate virus containment by repeatedly quarantining the most dangerous infected region and spreading the remaining regions.

leetcodearraymatrixsimulationdepth-first-searchbreadth-first-search
LeetCode 942: DI String Match

A clear explanation of solving DI String Match using a greedy two-pointer construction.

leetcodearraystringgreedytwo-pointers
LeetCode 817: Linked List Components

A hash set and linked list traversal solution for counting consecutive components whose values appear in nums.

leetcodelinked-listhash-setarray
LeetCode 867: Transpose Matrix

A clear explanation of transposing a matrix by swapping row and column indices.

leetcodearraymatrixsimulation
LeetCode 771: Jewels and Stones

A clear explanation of counting how many stones are jewels using a hash set for fast membership checks.

leetcodehash-tablestringset
LeetCode 795: Number of Subarrays with Bounded Maximum

A clear explanation of counting contiguous subarrays whose maximum value lies inside a given inclusive range.

leetcodearraytwo-pointerssliding-window
LeetCode 721: Accounts Merge

A clear explanation of merging accounts that share emails using union find and sorted email groups.

leetcodearrayhash-tablestringunion-findgraph
LeetCode 50: Pow(x, n)

A clear explanation of Pow(x, n) using binary exponentiation to compute powers in logarithmic time.

leetcodemathrecursionbinary-exponentiation
LeetCode 748: Shortest Completing Word

Find the shortest word that contains all required license plate letters using frequency counting.

leetcodestringhash-tablecounting
LeetCode 891: Sum of Subsequence Widths

A clear explanation of summing subsequence widths by sorting and counting each element as a maximum and minimum.

leetcodearraymathsortingcombinatorics
LeetCode 941: Valid Mountain Array

A clear explanation of solving Valid Mountain Array by walking up the increasing slope and then down the decreasing slope.

leetcodearraytwo-pointerssimulation
LeetCode 990: Satisfiability of Equality Equations

A clear explanation of checking equality and inequality constraints using union-find.

leetcodearraystringunion-findgraph
LeetCode 866: Prime Palindrome

A clear explanation of finding the smallest prime palindrome greater than or equal to n by generating odd-length palindromes and testing primality.

leetcodemathnumber-theorypalindrome
LeetCode 816: Ambiguous Coordinates

An enumeration solution for reconstructing all valid coordinate pairs after commas, spaces, and decimal points were removed.

leetcodestringenumerationbacktracking