brain

tamnd's digital brain — notes, problems, research

43815 notes

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
LeetCode 250: Count Univalue Subtrees

A clear explanation of counting uni-value subtrees using post-order DFS.

leetcodebinary-treedfsrecursion
LeetCode 197: Rising Temperature

A clear explanation of the Rising Temperature SQL problem using a self join and date comparison.

leetcodesqlmysqldatabaseself-join
LeetCode 770: Basic Calculator IV

A clear explanation of simplifying algebraic expressions by parsing, substituting variables, and combining polynomial terms.

leetcodestringstackrecursionhash-tablemath
LeetCode 720: Longest Word in Dictionary

A clear explanation of finding the longest buildable word using sorting and a hash set.

leetcodestringhash-tablesortingtrie
LeetCode 747: Largest Number At Least Twice of Others

Find whether the maximum element is at least twice every other element using a single linear scan.

leetcodearray
LeetCode 794: Valid Tic-Tac-Toe State

A clear explanation of validating whether a Tic-Tac-Toe board can occur in a legal game.

leetcodearraymatrixsimulation
LeetCode 49: Group Anagrams

A clear explanation of Group Anagrams using a hash map keyed by each word's sorted character signature.

leetcodearrayhash-tablestringsorting
LeetCode 890: Find and Replace Pattern

A clear explanation of finding words that match a pattern using bijective character mapping.

leetcodearrayhash-tablestring
LeetCode 940: Distinct Subsequences II

A clear explanation of solving Distinct Subsequences II using dynamic programming and last occurrence tracking.

leetcodedynamic-programmingstringhash-map
LeetCode 769: Max Chunks To Make Sorted

A clear explanation of splitting a permutation into the maximum number of chunks using prefix maximums.

leetcodearraygreedysorting
LeetCode 793: Preimage Size of Factorial Zeroes Function

A clear explanation of finding how many integers have exactly k trailing zeroes in their factorial.

leetcodemathbinary-searchnumber-theory
LeetCode 746: Min Cost Climbing Stairs

Find the minimum cost to reach the top of the staircase using dynamic programming.

leetcodearraydynamic-programming
LeetCode 719: Find K-th Smallest Pair Distance

A clear explanation of finding the kth smallest pair distance using sorting, binary search on the answer, and a two-pointer count.

leetcodearraybinary-searchtwo-pointerssorting
LeetCode 249: Group Shifted Strings

A clear explanation of grouping strings by their shifting sequence using normalized hash keys.

leetcodearrayhash-mapstring
LeetCode 196: Delete Duplicate Emails

A clear explanation of the Delete Duplicate Emails SQL problem using DELETE with a self join.

leetcodesqlmysqldeleteself-join
LeetCode 48: Rotate Image

A clear explanation of Rotate Image using in-place matrix transpose and row reversal.

leetcodearraymatrixmath
LeetCode 248: Strobogrammatic Number III

A clear explanation of counting strobogrammatic numbers in a string range using recursive generation and range filtering.

leetcoderecursionstringdfs
LeetCode 247: Strobogrammatic Number II

A clear explanation of generating all strobogrammatic numbers of length n using recursion from the inside out.

leetcoderecursionarraystring
LeetCode 47: Permutations II

A clear explanation of Permutations II using sorting, depth-first search, and duplicate-skipping backtracking.

leetcodearraybacktrackingsorting
LeetCode 195: Tenth Line

A clear explanation of the Tenth Line shell problem using awk, sed, head, and tail.

leetcodeshellbashawksedheadtail
LeetCode 194: Transpose File

A clear explanation of the Transpose File shell problem using awk to transform rows into columns.

leetcodeshellbashawk
LeetCode 745: Prefix and Suffix Search

Support fast prefix and suffix queries by indexing every prefix-suffix combination with the largest word index.

leetcodestringhash-tabletriedesign
LeetCode 718: Maximum Length of Repeated Subarray

A clear explanation of finding the longest common contiguous subarray using dynamic programming.

leetcodearraydynamic-programming
LeetCode 46: Permutations

A clear explanation of Permutations using depth-first search and backtracking.

leetcodearraybacktrackingdfs
LeetCode 246: Strobogrammatic Number

A clear explanation of the Strobogrammatic Number problem using digit rotation rules and two pointers.

leetcodestringhash-maptwo-pointers
LeetCode 989: Add to Array-Form of Integer

A clear explanation of adding an integer to an array-form number using digit-by-digit simulation.

leetcodearraymathsimulation
LeetCode 815: Bus Routes

A BFS solution for finding the minimum number of buses needed to travel from a source stop to a target stop.

leetcodebfsgraphhash-map
LeetCode 865: Smallest Subtree with all the Deepest Nodes

A clear explanation of finding the smallest subtree that contains all deepest nodes using bottom-up DFS.

leetcodetreebinary-treedfsrecursion
LeetCode 792: Number of Matching Subsequences

A clear explanation of counting how many words are subsequences of a string using waiting queues.

leetcodestringhash-mapqueuesubsequence
LeetCode 768: Max Chunks To Make Sorted II

A clear explanation of splitting an array into the maximum number of chunks so sorting each chunk gives the fully sorted array.

leetcodearraysortingmonotonic-stackgreedy
LeetCode 744: Find Smallest Letter Greater Than Target

Use binary search to find the smallest character strictly greater than the target with wraparound handling.

leetcodearraybinary-search
LeetCode 717: 1-bit and 2-bit Characters

A clear explanation of determining whether the last character must be a one-bit character using greedy parsing.

leetcodearraygreedybit-manipulation
LeetCode 193: Valid Phone Numbers

A clear explanation of the Valid Phone Numbers shell problem using grep and regular expressions.

leetcodeshellbashgrepregex
LeetCode 192: Word Frequency

A clear explanation of the Word Frequency shell problem using Unix text-processing tools.

leetcodeshellbashsortuniqawk
LeetCode 45: Jump Game II

A clear explanation of Jump Game II using a greedy range expansion approach to find the minimum number of jumps.

leetcodearraygreedydynamic-programming
LeetCode 625: Minimum Factorization

A clear explanation of Minimum Factorization using greedy digit factors from 9 down to 2.

leetcodemathgreedyfactorization
LeetCode 245: Shortest Word Distance III

A clear explanation of the Shortest Word Distance III problem, including the special case where both target words are the same.

leetcodearraystring
LeetCode 44: Wildcard Matching

A clear explanation of Wildcard Matching using dynamic programming over string and pattern prefixes.

leetcodestringdynamic-programminggreedy
LeetCode 244: Shortest Word Distance II

A clear explanation of the Shortest Word Distance II problem using preprocessing and two pointers.

leetcodearrayhash-mapstringtwo-pointersdesign
LeetCode 43: Multiply Strings

A clear explanation of Multiply Strings using grade-school multiplication with digit arrays.

leetcodestringmathsimulation
LeetCode 624: Maximum Distance in Arrays

A clear explanation of Maximum Distance in Arrays using sorted endpoints and a greedy scan.

leetcodearraygreedysorting
LeetCode 243: Shortest Word Distance

A clear explanation of the Shortest Word Distance problem using one pass and the latest seen indices of both words.

leetcodearraystringtwo-pointers
LeetCode 791: Custom Sort String

A clear explanation of rearranging a string so that selected characters follow a custom order.

leetcodestringhash-mapcounting-sortsorting
LeetCode 767: Reorganize String

A clear explanation of rearranging characters so no two adjacent characters are equal using a greedy max heap.

leetcodestringgreedyheaphash-table
LeetCode 743: Network Delay Time

Find the time needed for a signal to reach all nodes in a directed weighted graph using Dijkstra's algorithm.

leetcodegraphheapshortest-pathdijkstra
LeetCode 716: Max Stack

A clear explanation of designing a stack that supports push, pop, top, peekMax, and popMax.

leetcodestackdesignlinked-listordered-map
LeetCode 42: Trapping Rain Water

A clear explanation of the Trapping Rain Water problem using left and right boundaries, then an optimized two-pointer solution.

leetcodearraytwo-pointersdynamic-programming
LeetCode 175: Combine Two Tables

A clear SQL guide for solving Combine Two Tables using LEFT JOIN.

leetcodesqldatabasejoinleft-join
LeetCode 623: Add One Row to Tree

A clear explanation of Add One Row to Tree using tree traversal and careful subtree reconnection.

leetcodebinary-treedfsbfstree
LeetCode 41: First Missing Positive

A clear explanation of the First Missing Positive problem using in-place index placement to achieve O(n) time and O(1) extra space.

leetcodearrayhash-tablecyclic-sort
LeetCode 622: Design Circular Queue

A clear explanation of Design Circular Queue using a fixed array, a front pointer, and a size counter.

leetcodearrayqueuedesignsimulation