brain

tamnd's digital brain — notes, problems, research

43815 notes

LeetCode 342: Power of Four

A clear explanation of Power of Four using bit manipulation and binary properties.

leetcodemathbit-manipulation
LeetCode 462: Minimum Moves to Equal Array Elements II

A clear explanation of why the median minimizes the number of moves needed to make all array elements equal.

leetcodearraymathsortingmedian
LeetCode 86: Partition List

A detailed guide to solving Partition List with two dummy lists while preserving relative order.

leetcodelinked-listtwo-pointers
LeetCode 363: Max Sum of Rectangle No Larger Than K

A clear explanation of reducing a 2D rectangle problem to a 1D prefix-sum problem with binary search.

leetcodearraymatrixprefix-sumbinary-searchordered-set
LeetCode 63: Unique Paths II

A clear guide to counting unique paths in a grid with obstacles using dynamic programming.

leetcodedynamic-programmingmatrix
LeetCode 284: Peeking Iterator

A wrapper iterator design that supports peeking at the next element without advancing the iterator.

leetcodedesigniteratorobject-oriented-programming
LeetCode 388: Longest Absolute File Path

A clear explanation of computing the longest absolute path to a file from a serialized file system string using path lengths by depth.

leetcodestringstackhash-table
LeetCode 108: Convert Sorted Array to Binary Search Tree

A clear explanation of building a height-balanced binary search tree from a sorted array using divide and conquer.

leetcodetreebinary-search-treedfsrecursiondivide-and-conquer
LeetCode 438: Find All Anagrams in a String

Find all starting indices where an anagram of p appears in s using a fixed-size sliding window.

leetcodehash-tablestringsliding-window
LeetCode 136: Single Number

Find the only number that appears once using the XOR operator, while every other number appears exactly twice.

leetcodeeasyarraybit-manipulationxor
LeetCode 263: Ugly Number

A clear explanation of the Ugly Number problem using repeated division by the only allowed prime factors.

leetcodemathnumber-theory
LeetCode 236: Lowest Common Ancestor of a Binary Tree

A clear explanation of finding the lowest common ancestor in a normal binary tree using recursive depth-first search.

leetcodetreebinary-treedfsrecursion
LeetCode 210: Course Schedule II

A clear explanation of finding a valid course ordering using topological sorting and cycle detection.

leetcodegraphtopological-sortbfsdfs
LeetCode 38: Count and Say

A clear explanation of generating the count-and-say sequence using run-length encoding.

leetcodestringsimulationrun-length-encoding
LeetCode 37: Sudoku Solver

A clear explanation of solving a Sudoku board using backtracking and constraint checking.

leetcodebacktrackingmatrixhash-table
LeetCode 410: Split Array Largest Sum

A clear explanation of minimizing the largest subarray sum using binary search on the answer and greedy validation.

leetcodearraybinary-searchgreedydynamic-programming
LeetCode 188: Best Time to Buy and Sell Stock IV

A clear explanation of maximizing stock trading profit with at most k transactions using dynamic programming.

leetcodearraydynamic-programmingstock
LeetCode 163: Missing Ranges

A clear explanation of finding all missing ranges inside an inclusive interval by scanning sorted unique numbers.

leetcodearraysimulation
LeetCode 312: Burst Balloons

A clear explanation of Burst Balloons using interval dynamic programming and the last-burst idea.

leetcodearraydynamic-programminginterval-dp
LeetCode 487: Max Consecutive Ones II

A clear explanation of finding the longest run of 1s after flipping at most one 0 using a sliding window.

leetcodearraysliding-windowtwo-pointers
LeetCode 341: Flatten Nested List Iterator

A clear explanation of Flatten Nested List Iterator using lazy stack-based flattening.

leetcodestackdfsiteratordesign
LeetCode 461: Hamming Distance

A clear explanation of computing the Hamming distance between two integers using XOR and bit counting.

leetcodebit-manipulation
LeetCode 283: Move Zeroes

A two-pointer in-place solution for moving all zeroes to the end while preserving the relative order of non-zero elements.

leetcodearraytwo-pointersin-place
LeetCode 62: Unique Paths

A clear guide to counting unique paths in a grid using dynamic programming.

leetcodedynamic-programmingmatrixcombinatorics
LeetCode 362: Design Hit Counter

A clear explanation of designing a hit counter for the last 5 minutes using a queue with compressed timestamps.

leetcodedesignqueuedata-stream
LeetCode 61: Rotate List

A clear guide to rotating a linked list to the right by k places using a circular list.

leetcodelinked-listtwo-pointers
LeetCode 387: First Unique Character in a String

A clear explanation of finding the first non-repeating character in a string using character frequency counting.

leetcodestringhash-tablecounting
LeetCode 107: Binary Tree Level Order Traversal II

A clear explanation of returning binary tree levels from bottom to top using breadth-first search.

leetcodetreebinary-treebfsqueue
LeetCode 437: Path Sum III

Count downward paths in a binary tree whose values sum to targetSum using DFS and prefix sums.

leetcodetreebinary-treedfsprefix-sumhash-table
LeetCode 235: Lowest Common Ancestor of a Binary Search Tree

A clear explanation of finding the lowest common ancestor in a binary search tree using BST ordering properties.

leetcodetreebinary-search-treedfs
LeetCode 85: Maximal Rectangle

A detailed guide to solving Maximal Rectangle by converting each matrix row into a histogram and applying a monotonic stack.

leetcodearraydynamic-programmingstackmonotonic-stackmatrix
LeetCode 262: Trips and Users

A clear explanation of the Trips and Users SQL problem using joins, filtering, grouping, and conditional aggregation.

leetcodesqldatabasejoingroup-byaggregation
LeetCode 135: Candy

Compute the minimum candies needed using two greedy passes, one from the left and one from the right.

leetcodehardarraygreedy
LeetCode 209: Minimum Size Subarray Sum

A clear explanation of finding the shortest contiguous subarray whose sum is at least target using a sliding window.

leetcodearraysliding-windowtwo-pointers
LeetCode 187: Repeated DNA Sequences

A clear explanation of finding repeated 10-letter DNA substrings using a fixed-size sliding window and hash sets.

leetcodestringhash-tablesliding-windowrolling-hash
LeetCode 36: Valid Sudoku

A clear explanation of checking whether a partially filled Sudoku board is valid using hash sets.

leetcodearrayhash-tablematrix
LeetCode 409: Longest Palindrome

A clear explanation of finding the longest palindrome length that can be built from given letters using character counts.

leetcodehash-tablestringgreedycounting
LeetCode 162: Find Peak Element

A clear explanation of finding any peak element using binary search on the slope of the array.

leetcodearraybinary-search
LeetCode 311: Sparse Matrix Multiplication

A clear explanation of Sparse Matrix Multiplication using non-zero entries to avoid wasted work.

leetcodematrixhash-tablesimulation
LeetCode 486: Predict the Winner

A clear explanation of predicting whether Player 1 can win using minimax dynamic programming over score difference.

leetcodearraydynamic-programminggame-theoryrecursion
LeetCode 340: Longest Substring with At Most K Distinct Characters

A clear explanation of Longest Substring with At Most K Distinct Characters using a sliding window and character counts.

leetcodestringhash-tablesliding-window
LeetCode 339: Nested List Weight Sum

A clear explanation of Nested List Weight Sum using depth-first search over a nested structure.

leetcodedepth-first-searchbreadth-first-searchrecursion
LeetCode 338: Counting Bits

A clear explanation of Counting Bits using dynamic programming and bit manipulation.

leetcodedynamic-programmingbit-manipulation
LeetCode 282: Expression Add Operators

A backtracking solution for inserting operators into a numeric string so the expression evaluates to a target value.

leetcodebacktrackingdfsstringrecursion
LeetCode 460: LFU Cache

A clear explanation of designing an LFU cache with O(1) average get and put operations.

leetcodehash-maplinked-listdesignlfu-cache
LeetCode 459: Repeated Substring Pattern

A clear explanation of checking whether a string can be built by repeating one of its proper substrings.

leetcodestringstring-matching
LeetCode 60: Permutation Sequence

A clear guide to finding the kth permutation sequence using factorial blocks instead of generating all permutations.

leetcodemathrecursionpermutation
LeetCode 361: Bomb Enemy

A clear explanation of finding the best bomb placement in a grid using cached row and column segment counts.

leetcodedynamic-programmingmatrixgrid
LeetCode 360: Sort Transformed Array

A clear explanation of sorting values after applying a quadratic function using two pointers.

leetcodearraymathtwo-pointerssorting
LeetCode 84: Largest Rectangle in Histogram

A detailed guide to solving Largest Rectangle in Histogram with a monotonic increasing stack.

leetcodearraystackmonotonic-stack
LeetCode 436: Find Right Interval

Find, for each interval, the interval with the smallest start point greater than or equal to its end point using sorting and binary search.

leetcodearraybinary-searchsortingintervals
LeetCode 261: Graph Valid Tree

A clear explanation of the Graph Valid Tree problem using Union Find to detect cycles and verify connectivity.

leetcodegraphunion-finddfstree
LeetCode 234: Palindrome Linked List

A clear explanation of checking whether a singly linked list is a palindrome using fast and slow pointers plus in-place reversal.

leetcodelinked-listtwo-pointersrecursion
LeetCode 134: Gas Station

Find the unique starting gas station index using a greedy scan with total fuel balance and current tank balance.

leetcodemediumarraygreedy
LeetCode 208: Implement Trie Prefix Tree

A clear explanation of implementing a Trie with insert, search, and startsWith operations.

leetcodetrieprefix-treedesignstring
LeetCode 186: Reverse Words in a String II

A clear explanation of reversing the order of words in a character array in-place using two reversals.

leetcodestringarraytwo-pointersin-place
LeetCode 35: Search Insert Position

A clear explanation of finding the index of a target, or where it should be inserted, using binary search.

leetcodearraybinary-search
LeetCode 386: Lexicographical Numbers

A clear explanation of generating numbers from 1 to n in lexicographical order using an iterative DFS-style traversal.

leetcodedepth-first-searchtrieiteration
LeetCode 408: Valid Word Abbreviation

A clear explanation of validating a word abbreviation using two pointers and number parsing.

leetcodestringtwo-pointerssimulation
LeetCode 161: One Edit Distance

A clear explanation of checking whether two strings are exactly one edit apart using a linear scan.

leetcodestringtwo-pointers
LeetCode 485: Max Consecutive Ones

A clear explanation of finding the longest streak of 1s in a binary array with a single pass.

leetcodearraysimulation
LeetCode 310: Minimum Height Trees

A clear explanation of Minimum Height Trees using leaf trimming to find the center of a tree.

leetcodegraphtreebfstopological-sort
LeetCode 337: House Robber III

A clear explanation of House Robber III using tree dynamic programming with rob and skip states.

leetcodetreedfsdynamic-programmingbinary-tree
LeetCode 59: Spiral Matrix II

A clear guide to generating an n x n matrix filled from 1 to n squared in spiral order.

leetcodearraymatrixsimulation
LeetCode 260: Single Number III

A clear explanation of the Single Number III problem using XOR partitioning to isolate the two unique numbers.

leetcodebit-manipulationxor
LeetCode 359: Logger Rate Limiter

A clear explanation of designing a logger that prints each message at most once every 10 seconds using a hash map.

leetcodedesignhash-tabledata-stream
LeetCode 233: Number of Digit One

A detailed explanation of counting how many times digit one appears from 0 to n using positional digit analysis.

leetcodemathdigit-dpcounting
LeetCode 83: Remove Duplicates from Sorted List

A detailed guide to solving Remove Duplicates from Sorted List with one pointer and in-place linked list rewiring.

leetcodelinked-list
LeetCode 281: Zigzag Iterator

A queue-based iterator design for returning elements from two vectors in alternating order, with a clean extension to k vectors.

leetcodedesignqueueiteratorarray
LeetCode 435: Non-overlapping Intervals

Remove the minimum number of intervals so the remaining intervals do not overlap, using greedy sorting by end time.

leetcodearrayintervalsgreedysorting
LeetCode 434: Number of Segments in a String

Count the number of word segments in a string by detecting transitions from spaces to non-space characters.

leetcodestringsimulation
LeetCode 133: Clone Graph

Create a deep copy of a connected undirected graph using DFS and a hash map from original nodes to cloned nodes.

leetcodemediumgraphdfsbfshash-map
LeetCode 207: Course Schedule

A clear explanation of detecting cycles in a prerequisite graph using topological sorting and DFS.

leetcodegraphtopological-sortdfsbfs
LeetCode 458: Poor Pigs

A clear explanation of the combinatorics behind finding the minimum number of pigs needed to identify the poisonous bucket.

leetcodemathcombinatorics
LeetCode 34: Find First and Last Position of Element in Sorted Array

A clear explanation of finding the first and last index of a target in a sorted array using two binary searches.

leetcodearraybinary-search
LeetCode 106: Construct Binary Tree from Inorder and Postorder Traversal

A clear explanation of rebuilding a binary tree from inorder and postorder traversals using recursion and an index map.

leetcodetreebinary-treedfsrecursionhash-mapdivide-and-conquer
LeetCode 160: Intersection of Two Linked Lists

A clear explanation of finding the node where two singly linked lists intersect using two pointers.

leetcodelinked-listtwo-pointers
LeetCode 484: Find Permutation

A clear explanation of constructing the lexicographically smallest permutation that matches an I and D pattern.

leetcodearraystringstackgreedy
LeetCode 309: Best Time to Buy and Sell Stock with Cooldown

A clear explanation of Best Time to Buy and Sell Stock with Cooldown using dynamic programming states.

leetcodearraydynamic-programmingstock
LeetCode 259: 3Sum Smaller

A clear explanation of the 3Sum Smaller problem using sorting and the two-pointer technique.

leetcodearraytwo-pointerssorting
LeetCode 58: Length of Last Word

A clear guide to solving Length of Last Word by scanning the string from right to left.

leetcodestringtwo-pointers
LeetCode 407: Trapping Rain Water II

A clear explanation of trapping rain water in a 2D elevation map using a min heap and boundary expansion.

leetcodeheappriority-queuebfsmatrixgraph
LeetCode 385: Mini Parser

A clear explanation of parsing a serialized nested integer string using a stack.

leetcodestringstackparserdesign
LeetCode 232: Implement Queue using Stacks

A detailed explanation of implementing a FIFO queue using two LIFO stacks with amortized constant time operations.

leetcodestackqueuedesigndata-structure
LeetCode 185: Department Top Three Salaries

A clear SQL solution for finding employees whose salaries are in the top three unique salary levels within their department.

leetcodesqldatabasewindow-functiondense-rank
LeetCode 358: Rearrange String k Distance Apart

A clear explanation of rearranging a string so equal characters are at least k positions apart using a heap and cooldown queue.

leetcodestringgreedyheapqueue
LeetCode 336: Palindrome Pairs

A clear explanation of Palindrome Pairs using reversed-word lookup and palindrome split checks.

leetcodearrayhash-tablestringtrie
LeetCode 206: Reverse Linked List

A clear explanation of reversing a singly linked list using iterative and recursive approaches.

leetcodelinked-listrecursion
LeetCode 82: Remove Duplicates from Sorted List II

A detailed guide to solving Remove Duplicates from Sorted List II with a dummy node and pointer rewiring.

leetcodelinked-listtwo-pointers
LeetCode 132: Palindrome Partitioning II

Find the minimum number of cuts needed to split a string into palindromic substrings using palindrome precomputation and dynamic programming.

leetcodehardstringdynamic-programmingpalindrome
LeetCode 280: Wiggle Sort

A greedy in-place solution for rearranging an array into a non-strict wiggle pattern.

leetcodearraygreedysorting
LeetCode 433: Minimum Genetic Mutation

Find the minimum number of valid one-character gene mutations using breadth-first search.

leetcodebfshash-setstringshortest-path
LeetCode 25: Reverse Nodes in k-Group

A detailed explanation of reversing linked-list nodes in groups of k using pointer manipulation and constant extra space.

leetcodelinked-listrecursion
LeetCode 24: Swap Nodes in Pairs

A detailed explanation of swapping every two adjacent nodes in a linked list using pointer manipulation.

leetcodelinked-listrecursion
LeetCode 23: Merge k Sorted Lists

A detailed explanation of merging k sorted linked lists using a min heap.

leetcodelinked-listheappriority-queuedivide-and-conquer
LeetCode 33: Search in Rotated Sorted Array

A clear explanation of searching a rotated sorted array in logarithmic time using modified binary search.

leetcodearraybinary-search
LeetCode 308: Range Sum Query 2D - Mutable

A clear explanation of Range Sum Query 2D - Mutable using a 2D Fenwick Tree for efficient updates and rectangle sum queries.

leetcodematrixfenwick-treebinary-indexed-treedesign
LeetCode 406: Queue Reconstruction by Height

A clear explanation of reconstructing a queue using greedy sorting and indexed insertion.

leetcodegreedysortingarray
LeetCode 258: Add Digits

A clear explanation of the Add Digits problem using repeated digit sums first, then the digital root formula.

leetcodemathsimulationnumber-theory
LeetCode 483: Smallest Good Base

A clear explanation of finding the smallest base where n is written as all ones using geometric series and binary search.

leetcodemathbinary-searchgeometric-series