brain

tamnd's digital brain — notes, problems, research

42768 notes

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 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 769: Max Chunks To Make Sorted

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

leetcodearraygreedysorting
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
LeetCode 742: Closest Leaf in a Binary Tree

Find the nearest leaf to a target node by converting the tree into an undirected graph and running breadth-first search.

leetcodetreegraphbreadth-first-searchdepth-first-search
LeetCode 766: Toeplitz Matrix

A clear explanation of checking whether every top-left to bottom-right diagonal in a matrix has the same value.

leetcodearraymatrix
LeetCode 790: Domino and Tromino Tiling

A clear explanation of counting tilings of a 2 x n board using dominoes and L-shaped trominoes with dynamic programming.

leetcodedynamic-programmingmathtiling
LeetCode 715: Range Module

A clear explanation of designing a range module that can add, query, and remove half-open intervals.

leetcodedesignintervalordered-listbinary-search
LeetCode 621: Task Scheduler

A clear explanation of Task Scheduler using frequency counting and the greedy block formula.

leetcodearrayhash-mapcountinggreedy
LeetCode 939: Minimum Area Rectangle

A clear explanation of solving Minimum Area Rectangle using diagonal point pairs and constant-time point lookup.

leetcodearrayhash-setgeometry
LeetCode 889: Construct Binary Tree from Preorder and Postorder Traversal

A clear explanation of reconstructing a binary tree from preorder and postorder traversals using recursion and index ranges.

leetcodearrayhash-tabletreebinary-treedivide-and-conquer
LeetCode 741: Cherry Pickup

Maximize cherries collected on a round trip by converting the problem into two simultaneous forward paths and solving with dynamic programming.

leetcodearraymatrixdynamic-programming
LeetCode 714: Best Time to Buy and Sell Stock with Transaction Fee

A clear explanation of maximizing stock trading profit with unlimited transactions and a fixed transaction fee using dynamic programming.

leetcodearraydynamic-programminggreedystock
LeetCode 962: Maximum Width Ramp

A clear explanation of finding the maximum width ramp using a monotonic decreasing stack.

leetcodearraymonotonic-stack
LeetCode 838: Push Dominoes

A clear explanation of the Push Dominoes problem using force propagation and a two-pass scan.

leetcodestringtwo-pointersdynamic-programming
LeetCode 765: Couples Holding Hands

A clear explanation of minimizing swaps so every couple sits together using greedy position tracking.

leetcodegreedyarrayhash-table
LeetCode 740: Delete and Earn

Transform the problem into House Robber dynamic programming by grouping equal values into total points.

leetcodearraydynamic-programminghash-table
LeetCode 789: Escape The Ghosts

A clear explanation of deciding whether escape is possible by comparing Manhattan distances to the target.

leetcodemathgeometrymanhattan-distance
LeetCode 914: X of a Kind in a Deck of Cards

A clear explanation of checking whether card counts share a common group size using the greatest common divisor.

leetcodearrayhash-tablemathnumber-theorygcd
LeetCode 988: Smallest String Starting From Leaf

A clear explanation of finding the lexicographically smallest leaf-to-root string in a binary tree using DFS.

leetcodetreebinary-treedepth-first-searchstring
LeetCode 864: Shortest Path to Get All Keys

A clear explanation of finding the minimum moves to collect all keys in a grid using BFS with key bitmasks.

leetcodebfsbitmaskmatrixshortest-path
LeetCode 814: Binary Tree Pruning

A postorder DFS solution for removing every binary tree subtree that does not contain a 1.

leetcodebinary-treedfsrecursion
LeetCode 961: N-Repeated Element in Size 2N Array

A clear explanation of finding the element repeated N times using a hash set.

leetcodearrayhash-table
LeetCode 888: Fair Candy Swap

A clear explanation of finding one candy box swap that makes Alice and Bob have equal total candies.

leetcodearrayhash-tablemath
LeetCode 938: Range Sum of BST

A clear explanation of solving Range Sum of BST using DFS with binary search tree pruning.

leetcodetreebinary-search-treedepth-first-search
LeetCode 788: Rotated Digits

A clear explanation of counting good numbers after rotating every digit by 180 degrees.

leetcodemathstringdigit-dp
LeetCode 739: Daily Temperatures

Find how many days each temperature must wait for a warmer future day using a monotonic stack.

leetcodearraystackmonotonic-stack
LeetCode 713: Subarray Product Less Than K

A clear explanation of counting contiguous subarrays whose product is less than k using a sliding window.

leetcodearraysliding-windowtwo-pointers
LeetCode 764: Largest Plus Sign

A clear explanation of finding the largest plus sign in a mined grid using four directional dynamic programming scans.

leetcodedynamic-programmingmatrixgrid
LeetCode 837: New 21 Game

A clear explanation of the New 21 Game problem using probability dynamic programming and a sliding window sum.

leetcodemathdynamic-programmingsliding-windowprobability
LeetCode 700: Search in a Binary Search Tree

Search for a target value in a binary search tree and return the subtree rooted at the matching node.

leetcodetreebinary-search-treedfs
LeetCode 913: Cat and Mouse

A clear explanation of Cat and Mouse using game states, reverse BFS, and topological propagation.

leetcodegraphgame-theorybreadth-first-searchtopological-sort
LeetCode 699: Falling Squares

Simulate falling squares on a number line and track the maximum stack height after each placement.

leetcodeintervalssimulationsegment-treecoordinate-compression
LeetCode 813: Largest Sum of Averages

A dynamic programming and prefix sum solution for partitioning an array into adjacent groups with maximum total average.

leetcodedynamic-programmingprefix-sumarray
LeetCode 987: Vertical Order Traversal of a Binary Tree

A clear explanation of vertical tree traversal using coordinates, DFS, sorting, and column grouping.

leetcodetreebinary-treedepth-first-searchbreadth-first-searchsorting
LeetCode 863: All Nodes Distance K in Binary Tree

A clear explanation of finding all binary tree nodes at distance k from a target node by treating the tree as an undirected graph.

leetcodebinary-treegraphdfsbfs
LeetCode 712: Minimum ASCII Delete Sum for Two Strings

A clear explanation of using dynamic programming to minimize the ASCII cost of deletions needed to make two strings equal.

leetcodestringdynamic-programming
LeetCode 960: Delete Columns to Make Sorted III

A clear explanation of deleting the minimum number of columns so every remaining row is individually sorted.

leetcodestringdynamic-programminglongest-increasing-subsequence
LeetCode 738: Monotone Increasing Digits

Find the largest number less than or equal to n whose digits are monotone increasing using a greedy digit adjustment.

leetcodemathgreedy
LeetCode 763: Partition Labels

A clear explanation of partitioning a string into the maximum number of parts so each character appears in at most one part.

leetcodestringgreedyhash-tabletwo-pointers
LeetCode 887: Super Egg Drop

A clear explanation of finding the minimum worst-case number of moves using dynamic programming over eggs and moves.

leetcodedynamic-programmingmathbinary-search
LeetCode 836: Rectangle Overlap

A clear explanation of the Rectangle Overlap problem using axis projections and positive intersection area.

leetcodemathgeometry
LeetCode 937: Reorder Data in Log Files

A clear explanation of solving Reorder Data in Log Files using custom sorting and stable handling of digit logs.

leetcodestringsortingcustom-sort
LeetCode 787: Cheapest Flights Within K Stops

A clear explanation of finding the cheapest flight route with at most k stops using bounded Bellman-Ford relaxation.

leetcodegraphdynamic-programmingbellman-fordshortest-path
LeetCode 912: Sort an Array

A clear explanation of sorting an array without built-in sorting using merge sort.

leetcodearraysortingmerge-sortdivide-and-conquer
LeetCode 650: 2 Keys Keyboard

A dynamic programming and prime factorization solution for finding the minimum operations needed to produce n characters.

leetcodedynamic-programmingmathprime-factorization
LeetCode 698: Partition to K Equal Sum Subsets

Decide whether an array can be divided into k non-empty subsets with equal sums using backtracking and pruning.

leetcodearraybacktrackingdynamic-programmingbitmask
LeetCode 649: Dota2 Senate

A queue-based simulation for predicting which party wins after senators ban opponents in turn order.

leetcodestringqueuegreedysimulation
LeetCode 711: Number of Distinct Islands II

A clear explanation of counting distinct island shapes under rotation and reflection using normalization and geometric transformations.

leetcodegriddfsgeometryhashing
LeetCode 986: Interval List Intersections

A clear explanation of finding intersections between two sorted disjoint interval lists using two pointers.

leetcodearraytwo-pointersintervals
LeetCode 812: Largest Triangle Area

A geometry solution for finding the largest triangle area by checking every triplet of points with the cross product formula.

leetcodemathgeometryarray