brain

tamnd's digital brain — notes, problems, research

43815 notes

LeetCode 708: Insert into a Sorted Circular Linked List

A clear explanation of inserting a value into a sorted circular linked list while preserving the circular sorted order.

leetcodelinked-listcircular-linked-list
LeetCode 809: Expressive Words

A two-pointer group comparison solution for counting how many words can be stretched to match a target string.

leetcodestringtwo-pointers
LeetCode 859: Buddy Strings

A clear explanation of checking whether one swap in a string can make it equal to another string.

leetcodestringhash-table
LeetCode 759: Employee Free Time

A clear explanation of finding common free time by merging all employee busy intervals and returning the gaps.

leetcodearraysortingintervalsmerge-intervals
LeetCode 734: Sentence Similarity

Check whether two word arrays are sentence-similar using a hash set of symmetric similar word pairs.

leetcodearraystringhash-table
LeetCode 883: Projection Area of 3D Shapes

A clear explanation of computing the projection areas of stacked cubes from top, front, and side views.

leetcodematrixgeometrysimulation
LeetCode 933: Number of Recent Calls

A clear explanation of solving Number of Recent Calls using a queue as a sliding time window.

leetcodedesignqueuedata-streamsliding-window
LeetCode 983: Minimum Cost For Tickets

A clear explanation of finding the cheapest way to cover all travel days using dynamic programming.

leetcodearraydynamic-programming
LeetCode 908: Smallest Range I

A clear explanation of minimizing an array score after each value can move by at most k.

leetcodearraymath
LeetCode 956: Tallest Billboard

A clear explanation of solving Tallest Billboard using dynamic programming over height differences.

leetcodearraydynamic-programmingknapsack
LeetCode 783: Minimum Distance Between BST Nodes

A clear explanation of finding the minimum difference between any two nodes in a BST using inorder traversal.

leetcodetreebinary-search-treedfsinorder-traversal
LeetCode 832: Flipping an Image

A clear explanation of the Flipping an Image problem using row reversal, bit inversion, and an in-place two-pointer method.

leetcodearraymatrixtwo-pointersbit-manipulationsimulation
LeetCode 689: Maximum Sum of 3 Non-Overlapping Subarrays

Find three non-overlapping subarrays of length k with maximum total sum and return the lexicographically smallest starting indices.

leetcodearraydynamic-programmingsliding-window
LeetCode 670: Maximum Swap

A clear explanation of maximizing an integer by swapping at most two digits once.

leetcodegreedymathstring
LeetCode 641: Design Circular Deque

An array-based circular buffer solution for implementing a fixed-size double-ended queue.

leetcodedesignarrayqueuecircular-buffer
LeetCode 640: Solve the Equation

A string parsing solution for reducing a linear equation into coefficient and constant terms.

leetcodestringmathsimulationparsing
LeetCode 669: Trim a Binary Search Tree

A clear explanation of trimming a BST so that all remaining node values lie inside a given inclusive range.

leetcodetreebinary-treebinary-search-treedepth-first-searchrecursion
LeetCode 688: Knight Probability in Chessboard

Compute the probability that a knight remains on an n x n chessboard after exactly k random moves using dynamic programming.

leetcodedynamic-programmingprobabilitychessboard
LeetCode 639: Decode Ways II

A dynamic programming solution for counting decodings of a digit string with wildcard characters.

leetcodedynamic-programmingstringmodulo
LeetCode 687: Longest Univalue Path

Find the longest path in a binary tree where every node on the path has the same value using depth-first search.

leetcodetreebinary-treedfsrecursion
LeetCode 620: Not Boring Movies

A SQL guide for filtering movies with odd IDs and non-boring descriptions, then sorting by rating.

leetcodesqlfilteringorder-by
LeetCode 707: Design Linked List

A clear explanation of implementing a linked list from scratch using nodes, a dummy head, and a size counter.

leetcodelinked-listdesignsingly-linked-list
LeetCode 758: Bold Words in String

A clear explanation of marking matching substrings and merging overlapping bold ranges.

leetcodestringintervalssimulation
LeetCode 858: Mirror Reflection

A clear explanation of Mirror Reflection using room unfolding, least common multiples, and parity.

leetcodemathgeometrynumber-theory
LeetCode 808: Soup Servings

A probability dynamic programming solution for computing whether soup A empties before soup B, with an early return for large input.

leetcodedynamic-programmingprobabilitymemoization
LeetCode 932: Beautiful Array

A clear explanation of solving Beautiful Array using divide and conquer with odd and even transformations.

leetcodearraymathdivide-and-conquer
LeetCode 733: Flood Fill

Recolor the connected component containing the starting pixel using depth-first search.

leetcodearraymatrixdepth-first-searchbreadth-first-search
LeetCode 982: Triples with Bitwise AND Equal To Zero

A clear explanation of counting ordered triples whose bitwise AND is zero using pairwise AND counts.

leetcodearrayhash-tablebit-manipulationcounting
LeetCode 668: Kth Smallest Number in Multiplication Table

A clear explanation of finding the kth smallest value in an m by n multiplication table using binary search on answer.

leetcodebinary-searchmath
LeetCode 638: Shopping Offers

A DFS and memoization solution for finding the minimum cost to satisfy item needs using individual prices and reusable special offers.

leetcodedynamic-programmingdfsmemoizationbacktracking
LeetCode 619: Biggest Single Number

A SQL guide for finding the largest number that appears exactly once in a table.

leetcodesqlgroup-byhavingaggregation
LeetCode 686: Repeated String Match

Find the minimum number of times one string must be repeated so another string becomes a substring.

leetcodestringstring-matching
LeetCode 685: Redundant Connection II

Find the directed edge to remove so a graph becomes a rooted tree again, handling both cycles and nodes with two parents.

leetcodegraphunion-finddirected-graph
LeetCode 637: Average of Levels in Binary Tree

A breadth-first search solution for computing the average value of nodes at each level of a binary tree.

leetcodetreebinary-treebreadth-first-searchqueue
LeetCode 667: Beautiful Arrangement II

A clear explanation of constructing an array with exactly k distinct adjacent differences using a greedy pattern.

leetcodearraygreedyconstructive-algorithm
LeetCode 618: Students Report By Geography

A SQL guide for pivoting rows into columns using ranking and conditional aggregation.

leetcodesqlpivotrow-numbergroup-by
LeetCode 636: Exclusive Time of Functions

A stack-based solution for computing exclusive execution time from nested start and end logs.

leetcodestacksimulationstring
LeetCode 617: Merge Two Binary Trees

A recursive tree traversal guide for merging two binary trees node by node.

leetcodetreebinary-treerecursiondfs
LeetCode 882: Reachable Nodes In Subdivided Graph

A clear explanation of counting reachable original and subdivided nodes using Dijkstra's shortest path algorithm.

leetcodegraphdijkstrashortest-pathheap
LeetCode 907: Sum of Subarray Minimums

A clear explanation of summing subarray minimums using a monotonic stack and contribution counting.

leetcodearraystackmonotonic-stack
LeetCode 782: Transform to Chessboard

A clear explanation of transforming a binary board into a chessboard using feasibility checks and minimum row and column swaps.

leetcodematrixmathbit-manipulationgreedy
LeetCode 831: Masking Personal Information

A clear explanation of the Masking Personal Information problem using string parsing and format-specific masking rules.

leetcodestringsimulation
LeetCode 684: Redundant Connection

Find the extra edge in an undirected graph that creates a cycle using Union-Find.

leetcodegraphunion-finddisjoint-set
LeetCode 666: Path Sum IV

A clear explanation of computing all root-to-leaf path sums from a compact three-digit binary tree encoding.

leetcodetreebinary-treedepth-first-searchhash-map
LeetCode 616: Add Bold Tag in String

A string-marking guide for adding bold tags around all matched words while merging overlapping and adjacent bold regions.

leetcodestringhash-tablestring-matching
LeetCode 635: Design Log Storage System

A design solution for storing timestamped logs and retrieving IDs by inclusive time range at a chosen granularity.

leetcodedesignstringarraytimestamp
LeetCode 757: Set Intersection Size At Least Two

A clear explanation of solving interval intersection constraints using greedy sorting and minimal point selection.

leetcodegreedysortingintervals
LeetCode 706: Design HashMap

A clear explanation of designing a hash map without using built-in hash table libraries.

leetcodehash-tabledesignarraylinked-list
LeetCode 857: Minimum Cost to Hire K Workers

A clear explanation of hiring exactly k workers with minimum total cost using wage-to-quality ratios, sorting, and a max heap.

leetcodearraysortingheapgreedy
LeetCode 807: Max Increase to Keep City Skyline

A greedy solution for increasing building heights as much as possible while preserving every skyline view.

leetcodearraymatrixgreedy
LeetCode 732: My Calendar III

Track the maximum number of overlapping calendar events using a sweep line difference map.

leetcodedesignintervalsordered-mapsweep-line
LeetCode 981: Time Based Key-Value Store

A clear explanation of designing a time-based key-value store using a hash map and binary search.

leetcodehash-tablebinary-searchdesignstring
LeetCode 931: Minimum Falling Path Sum

A clear explanation of solving Minimum Falling Path Sum using dynamic programming over matrix rows.

leetcodearraymatrixdynamic-programming
LeetCode 683: K Empty Slots

Find the earliest day when two turned-on bulbs have exactly k turned-off bulbs between them using a sliding window over bloom days.

leetcodearraysliding-window
LeetCode 665: Non-decreasing Array

A clear explanation of checking whether an array can become non-decreasing by modifying at most one element.

leetcodearraygreedy
LeetCode 634: Find the Derangement of An Array

A dynamic programming and combinatorics solution for counting permutations with no fixed positions.

leetcodedynamic-programmingmathcombinatorics
LeetCode 682: Baseball Game

Simulate a baseball scoring system using a stack to process operations and compute the final score.

leetcodearraystacksimulation
LeetCode 881: Boats to Save People

A clear explanation of minimizing rescue boats using sorting, greedy choice, and two pointers.

leetcodearraysortinggreedytwo-pointers
LeetCode 781: Rabbits in Forest

A clear explanation of finding the minimum possible number of rabbits using counting and greedy grouping.

leetcodearrayhash-mapgreedymath
LeetCode 906: Super Palindromes

A clear explanation of counting super-palindromes by generating palindromic roots and checking their squares.

leetcodemathpalindromeenumeration
LeetCode 830: Positions of Large Groups

A clear explanation of the Positions of Large Groups problem using a simple two-pointer scan.

leetcodestringtwo-pointers
LeetCode 615: Average Salary: Departments VS Company

A SQL guide for comparing each department's monthly average salary against the company's monthly average salary.

leetcodesqlwindow-functiongroup-bydatabase
LeetCode 633: Sum of Square Numbers

A two-pointer and number theory solution for checking whether an integer can be written as the sum of two square numbers.

leetcodemathtwo-pointersbinary-searchnumber-theory
LeetCode 664: Strange Printer

A clear explanation of minimizing printer turns using interval dynamic programming.

leetcodedynamic-programminginterval-dpstring
LeetCode 705: Design HashSet

A clear explanation of designing a hash set without using built-in hash table libraries.

leetcodehash-tabledesignarraylinked-list
LeetCode 756: Pyramid Transition Matrix

A clear explanation of solving Pyramid Transition Matrix using backtracking and memoization over pyramid rows.

leetcodebacktrackingdfsmemoizationhash-tablestring
LeetCode 856: Score of Parentheses

A clear explanation of scoring a balanced parentheses string using depth counting.

leetcodestringstackparentheses
LeetCode 806: Number of Lines To Write String

A simple simulation solution for counting how many 100-pixel lines are needed to write a string.

leetcodestringarraysimulation
LeetCode 731: My Calendar II

Allow double bookings but reject triple bookings using overlap interval tracking.

leetcodedesignintervalsarray
LeetCode 681: Next Closest Time

Find the next valid 24-hour time using only the digits from the current time.

leetcodestringsimulationenumeration
LeetCode 930: Binary Subarrays With Sum

A clear explanation of solving Binary Subarrays With Sum using prefix sums and a frequency map.

leetcodearrayhash-mapprefix-sumsliding-window
LeetCode 880: Decoded String at Index

A clear explanation of finding the kth character in a decoded string without building the full decoded string.

leetcodestringmathreverse-traversal
LeetCode 980: Unique Paths III

A clear explanation of counting all paths from start to end that visit every non-obstacle square exactly once using backtracking.

leetcodearraymatrixbacktrackingdepth-first-search
LeetCode 614: Second Degree Follower

A SQL guide for finding users who both follow someone and have followers, then counting how many followers they have.

leetcodesqlself-joingroup-bydatabase
LeetCode 905: Sort Array By Parity

A clear explanation of sorting an array by parity using a two-pointer partition method.

leetcodearraytwo-pointerspartition
LeetCode 663: Equal Tree Partition

A clear explanation of checking whether a binary tree can be split into two equal-sum trees by removing one edge.

leetcodetreebinary-treedepth-first-searchhash-set
LeetCode 780: Reaching Points

A clear explanation of checking whether one point can reach another by working backward with modulo.

leetcodemathmodulonumber-theory
LeetCode 632: Smallest Range Covering Elements from K Lists

A heap-based solution for finding the smallest range that contains at least one number from each sorted list.

leetcodearrayheappriority-queuesliding-window
LeetCode 829: Consecutive Numbers Sum

A clear explanation of the Consecutive Numbers Sum problem using arithmetic series formulas and divisibility analysis.

leetcodemathnumber-theoryprefix-sumarithmetic-series
LeetCode 704: Binary Search

A clear explanation of searching for a target in a sorted array using binary search.

leetcodearraybinary-search
LeetCode 755: Pour Water

A clear explanation of simulating water droplets over an elevation map by checking left first, then right.

leetcodearraysimulation
LeetCode 855: Exam Room

A clear explanation of simulating an exam room by maintaining occupied seats in sorted order.

leetcodedesignordered-setbinary-searchsimulation
LeetCode 805: Split Array With Same Average

A dynamic programming solution for deciding whether an array can be split into two non-empty groups with the same average.

leetcodedynamic-programmingsubset-summath
LeetCode 730: Count Different Palindromic Subsequences

Count distinct non-empty palindromic subsequences using interval dynamic programming and duplicate handling.

leetcodestringdynamic-programmingpalindrome
LeetCode 680: Valid Palindrome II

Check whether a string can become a palindrome after deleting at most one character using two pointers.

leetcodestringtwo-pointersgreedy
LeetCode 929: Unique Email Addresses

A clear explanation of solving Unique Email Addresses using string normalization and a hash set.

leetcodestringhash-setsimulation
LeetCode 979: Distribute Coins in Binary Tree

A clear explanation of balancing coins in a binary tree using postorder DFS and subtree coin balance.

leetcodetreebinary-treedepth-first-searchpostorder
LeetCode 879: Profitable Schemes

A clear explanation of counting profitable crime schemes using 0/1 knapsack dynamic programming with members and profit states.

leetcodedynamic-programmingknapsackarray
LeetCode 613: Shortest Distance in a Line

A SQL guide for finding the minimum distance between any two unique points on the X-axis.

leetcodesqlself-joinwindow-functiondatabase
LeetCode 525: Contiguous Array

A clear explanation of finding the longest contiguous subarray with equal numbers of 0 and 1 using prefix sums and a hash map.

leetcodearrayhash-mapprefix-sum
LeetCode 955: Delete Columns to Make Sorted II

A clear explanation of deleting the minimum number of columns so rows become lexicographically sorted.

leetcodestringgreedyarray
LeetCode 954: Array of Doubled Pairs

A clear explanation of checking whether an array can be reordered into pairs where one number is double the other.

leetcodearraygreedyhash-tablesorting
LeetCode 904: Fruit Into Baskets

A clear explanation of Fruit Into Baskets using a sliding window with at most two distinct fruit types.

leetcodearrayhash-tablesliding-window
LeetCode 662: Maximum Width of Binary Tree

A clear explanation of computing the maximum width of a binary tree using level-order traversal and complete-tree indices.

leetcodetreebinary-treebreadth-first-searchqueue
LeetCode 779: K-th Symbol in Grammar

A clear explanation of finding the kth symbol in the grammar sequence using recursion and the parent-child relationship.

leetcoderecursionmathbit-manipulation
LeetCode 524: Longest Word in Dictionary through Deleting

A clear explanation of finding the longest dictionary word obtainable as a subsequence using two pointers and sorting rules.

leetcodestringtwo-pointerssorting
LeetCode 612: Shortest Distance in a Plane

A SQL guide for finding the minimum Euclidean distance between any two points in a 2D plane.

leetcodesqlgeometryself-joinmathdatabase
LeetCode 631: Design Excel Sum Formula

A design solution for a small Excel-like spreadsheet that supports set, get, and dynamic sum formulas.

leetcodedesignmatrixhash-maprecursion
LeetCode 600: Non-negative Integers without Consecutive Ones

A clear digit dynamic programming solution for counting numbers whose binary representation does not contain consecutive ones.

leetcodedynamic-programmingdigit-dpbit-manipulation
LeetCode 804: Unique Morse Code Words

A set-based solution for counting how many different Morse code transformations appear among a list of words.

leetcodehash-setstringarray