brain

tamnd's digital brain — notes, problems, research

42768 notes

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
LeetCode 854: K-Similar Strings

A clear explanation of finding the minimum number of swaps needed to transform one anagram string into another using BFS.

leetcodestringbfsgraphshortest-path
LeetCode 754: Reach a Number

A clear explanation of reaching a target on a number line using cumulative sums and parity.

leetcodemathgreedynumber-line
LeetCode 729: My Calendar I

Implement a calendar that accepts a booking only when it does not overlap with any existing booking.

leetcodedesignarrayintervals
LeetCode 703: Kth Largest Element in a Stream

A clear explanation of maintaining the kth largest element in a stream using a fixed-size min heap.

leetcodeheappriority-queuedesigndata-stream
LeetCode 679: 24 Game

Determine whether four numbers can be combined with arithmetic operations and parentheses to produce 24.

leetcodearraymathbacktracking
LeetCode 928: Minimize Malware Spread II

A clear explanation of solving Minimize Malware Spread II by removing each infected node and simulating the final malware spread.

leetcodegraphbreadth-first-searchdepth-first-searchsimulation
LeetCode 978: Longest Turbulent Subarray

A clear explanation of finding the longest subarray whose adjacent comparisons alternate between greater-than and less-than.

leetcodearraydynamic-programmingsliding-window
LeetCode 878: Nth Magical Number

A clear explanation of finding the nth magical number using binary search, greatest common divisor, least common multiple, and inclusion-exclusion.

leetcodemathbinary-searchnumber-theory
LeetCode 828: Count Unique Characters of All Substrings of a Given String

A clear explanation of Count Unique Characters of All Substrings using contribution counting with previous and next occurrences.

leetcodestringhash-mapdynamic-programmingcombinatorics
LeetCode 953: Verifying an Alien Dictionary

A clear explanation of checking whether words are sorted according to a custom alien alphabet order.

leetcodestringsortinghash-table
LeetCode 903: Valid Permutations for DI Sequence

A clear explanation of counting valid DI permutations using dynamic programming and prefix sums.

leetcodedynamic-programmingprefix-sumpermutation
LeetCode 661: Image Smoother

A clear explanation of averaging neighboring pixels in a matrix using direct simulation.

leetcodematrixsimulationarray
LeetCode 575: Distribute Candies

A clear explanation of Distribute Candies using a set to count candy types and a simple limit argument.

leetcodearrayhash-setgreedy
LeetCode 660: Remove 9

A clear explanation of finding the nth positive integer that does not contain the digit 9 using base-9 conversion.

leetcodemathbase-conversion
LeetCode 523: Continuous Subarray Sum

A clear explanation of detecting a subarray whose sum is a multiple of k using prefix sums and modular arithmetic.

leetcodearrayhash-mapprefix-summath
LeetCode 778: Swim in Rising Water

A clear explanation of finding the minimum time to reach the bottom-right cell using a priority queue and minimax path reasoning.

leetcodegraphheappriority-queuedijkstramatrix
LeetCode 611: Valid Triangle Number

A two-pointer guide for counting triplets that can form valid triangles after sorting the side lengths.

leetcodearraysortingtwo-pointersbinary-search
LeetCode 659: Split Array into Consecutive Subsequences

A clear explanation of deciding whether a sorted array can be split into consecutive subsequences of length at least three.

leetcodearrayhash-mapgreedy
LeetCode 610: Triangle Judgement

A SQL guide for checking whether three side lengths can form a valid triangle using the triangle inequality.

leetcodesqlcase-whenmathdatabase
LeetCode 550: Game Play Analysis IV

A clear explanation of calculating the fraction of players who logged in again the day after their first login.

leetcodesqldatabaseaggregationjoin
LeetCode 599: Minimum Index Sum of Two Lists

A clear hash map solution for finding common strings with the smallest index sum.

leetcodearrayhash-mapstring
LeetCode 658: Find K Closest Elements

A clear explanation of finding the k closest elements to a target using binary search and a sliding window.

leetcodearraybinary-searchtwo-pointerssliding-window
LeetCode 609: Find Duplicate File in System

A hash map guide for grouping file paths by identical file content and returning only duplicate groups.

leetcodearrayhash-tablestringparsing
LeetCode 549: Binary Tree Longest Consecutive Sequence II

A clear explanation of finding the longest increasing or decreasing consecutive path in a binary tree using DFS.

leetcodetreebinary-treedepth-first-searchdynamic-programming
LeetCode 608: Tree Node

A SQL guide for classifying binary tree nodes as Root, Inner, or Leaf based on parent-child relationships.

leetcodesqlcase-whenself-referencedatabase
LeetCode 657: Robot Return to Origin

A clear explanation of determining whether a robot returns to the origin after executing movement instructions.

leetcodesimulationstring
LeetCode 598: Range Addition II

A clear math solution for counting the maximum values after repeated top-left matrix increment operations.

leetcodearraymathmatrix
LeetCode 574: Winning Candidate

A clear explanation of Winning Candidate using SQL aggregation to count votes and return the candidate with the most votes.

leetcodesqldatabasegroup-byjoin
LeetCode 548: Split Array with Equal Sum

A clear explanation of splitting an array into four equal-sum parts using prefix sums and set-based search.

leetcodearrayprefix-sumhash-set
LeetCode 522: Longest Uncommon Subsequence II

A clear explanation of finding the longest uncommon subsequence among many strings using subsequence checks.

leetcodearraystringtwo-pointerssorting
LeetCode 521: Longest Uncommon Subsequence I

A clear explanation of finding the longest uncommon subsequence between two strings using simple case analysis.

leetcodestring
LeetCode 607: Sales Person

A SQL guide for finding salespeople who never had an order related to the company named RED.

leetcodesqlanti-joinnot-existsdatabase
LeetCode 630: Course Schedule III

A greedy heap solution for taking the maximum number of courses before their deadlines.

leetcodearraygreedyheapsorting
LeetCode 656: Coin Path

A clear explanation of finding the minimum-cost path with bounded jumps, blocked cells, and lexicographic tie-breaking.

leetcodedynamic-programmingpatharray
LeetCode 606: Construct String from Binary Tree

A recursive guide for converting a binary tree into a preorder parenthesized string while preserving the one-to-one mapping between the tree and the string.

leetcodetreebinary-treerecursionstring
LeetCode 547: Number of Provinces

A clear explanation of counting connected components in an undirected graph represented by an adjacency matrix.

leetcodegraphdepth-first-searchbreadth-first-searchunion-find
LeetCode 597: Friend Requests I: Overall Acceptance Rate

A clear SQL guide for computing the overall friend request acceptance rate with duplicate pairs counted once.

leetcodesqlaggregationdistinctround
LeetCode 573: Squirrel Simulation

A clear explanation of Squirrel Simulation using Manhattan distance and the special first trip.

leetcodemathgreedysimulation
LeetCode 520: Detect Capital

A clear explanation of checking whether a word uses capital letters correctly by counting uppercase letters.

leetcodestring
LeetCode 572: Subtree of Another Tree

A clear explanation of Subtree of Another Tree using recursive tree matching and DFS.

leetcodetreebinary-treedepth-first-searchrecursion
LeetCode 519: Random Flip Matrix

A clear explanation of randomly flipping zero cells in a matrix without repetition using hash mapping and virtual swapping.

leetcoderandomizationhash-mapmatrix
LeetCode 596: Classes With at Least 5 Students

A clear SQL guide for finding classes that have at least five students.

leetcodesqlgroup-byhavingaggregation
LeetCode 571: Find Median Given Frequency of Numbers

A clear explanation of Find Median Given Frequency of Numbers using cumulative frequency and SQL window functions.

leetcodesqldatabasewindow-functionprefix-sum
LeetCode 518: Coin Change II

A clear explanation of counting coin-change combinations using dynamic programming.

leetcodedynamic-programmingarraycoin-changeunbounded-knapsack
LeetCode 546: Remove Boxes

A clear explanation of maximizing remove-box scores using interval dynamic programming with memoization.

leetcodedynamic-programminginterval-dpmemoizationrecursion
LeetCode 570: Managers with at Least 5 Direct Reports

A clear explanation of Managers with at Least 5 Direct Reports using grouping and a self join.

leetcodesqldatabasegroup-byself-join
LeetCode 545: Boundary of Binary Tree

A clear explanation of collecting the boundary of a binary tree using separate left boundary, leaves, and right boundary traversals.

leetcodetreebinary-treedepth-first-search