brain
tamnd's digital brain — notes, problems, research
42778 notes
A clear explanation of finding any peak element using binary search on the slope of the array.
A clear explanation of Sparse Matrix Multiplication using non-zero entries to avoid wasted work.
A clear explanation of predicting whether Player 1 can win using minimax dynamic programming over score difference.
A clear explanation of Longest Substring with At Most K Distinct Characters using a sliding window and character counts.
A clear explanation of Nested List Weight Sum using depth-first search over a nested structure.
A clear explanation of Counting Bits using dynamic programming and bit manipulation.
A backtracking solution for inserting operators into a numeric string so the expression evaluates to a target value.
A clear explanation of designing an LFU cache with O(1) average get and put operations.
A clear explanation of checking whether a string can be built by repeating one of its proper substrings.
A clear guide to finding the kth permutation sequence using factorial blocks instead of generating all permutations.
A clear explanation of finding the best bomb placement in a grid using cached row and column segment counts.
A clear explanation of sorting values after applying a quadratic function using two pointers.
A detailed guide to solving Largest Rectangle in Histogram with a monotonic increasing stack.
Find, for each interval, the interval with the smallest start point greater than or equal to its end point using sorting and binary search.
A clear explanation of the Graph Valid Tree problem using Union Find to detect cycles and verify connectivity.
A clear explanation of checking whether a singly linked list is a palindrome using fast and slow pointers plus in-place reversal.
Find the unique starting gas station index using a greedy scan with total fuel balance and current tank balance.
A clear explanation of implementing a Trie with insert, search, and startsWith operations.
A clear explanation of reversing the order of words in a character array in-place using two reversals.
A clear explanation of finding the index of a target, or where it should be inserted, using binary search.
A clear explanation of generating numbers from 1 to n in lexicographical order using an iterative DFS-style traversal.
A clear explanation of validating a word abbreviation using two pointers and number parsing.
A clear explanation of checking whether two strings are exactly one edit apart using a linear scan.
A clear explanation of finding the longest streak of 1s in a binary array with a single pass.
A clear explanation of Minimum Height Trees using leaf trimming to find the center of a tree.
A clear explanation of House Robber III using tree dynamic programming with rob and skip states.
A clear guide to generating an n x n matrix filled from 1 to n squared in spiral order.
A clear explanation of the Single Number III problem using XOR partitioning to isolate the two unique numbers.
A clear explanation of designing a logger that prints each message at most once every 10 seconds using a hash map.
A detailed explanation of counting how many times digit one appears from 0 to n using positional digit analysis.
A detailed guide to solving Remove Duplicates from Sorted List with one pointer and in-place linked list rewiring.
A queue-based iterator design for returning elements from two vectors in alternating order, with a clean extension to k vectors.
Remove the minimum number of intervals so the remaining intervals do not overlap, using greedy sorting by end time.
Count the number of word segments in a string by detecting transitions from spaces to non-space characters.
Create a deep copy of a connected undirected graph using DFS and a hash map from original nodes to cloned nodes.
A clear explanation of detecting cycles in a prerequisite graph using topological sorting and DFS.
A clear explanation of the combinatorics behind finding the minimum number of pigs needed to identify the poisonous bucket.
A clear explanation of finding the first and last index of a target in a sorted array using two binary searches.
A clear explanation of rebuilding a binary tree from inorder and postorder traversals using recursion and an index map.
A clear explanation of finding the node where two singly linked lists intersect using two pointers.
A clear explanation of constructing the lexicographically smallest permutation that matches an I and D pattern.
A clear explanation of Best Time to Buy and Sell Stock with Cooldown using dynamic programming states.
A clear explanation of the 3Sum Smaller problem using sorting and the two-pointer technique.
A clear guide to solving Length of Last Word by scanning the string from right to left.
A clear explanation of parsing a serialized nested integer string using a stack.
A clear explanation of trapping rain water in a 2D elevation map using a min heap and boundary expansion.
A detailed explanation of implementing a FIFO queue using two LIFO stacks with amortized constant time operations.
A clear SQL solution for finding employees whose salaries are in the top three unique salary levels within their department.
A clear explanation of rearranging a string so equal characters are at least k positions apart using a heap and cooldown queue.
A clear explanation of Palindrome Pairs using reversed-word lookup and palindrome split checks.
A clear explanation of reversing a singly linked list using iterative and recursive approaches.
A detailed guide to solving Remove Duplicates from Sorted List II with a dummy node and pointer rewiring.
Find the minimum number of cuts needed to split a string into palindromic substrings using palindrome precomputation and dynamic programming.
A greedy in-place solution for rearranging an array into a non-strict wiggle pattern.
Find the minimum number of valid one-character gene mutations using breadth-first search.
A detailed explanation of reversing linked-list nodes in groups of k using pointer manipulation and constant extra space.
A detailed explanation of swapping every two adjacent nodes in a linked list using pointer manipulation.
A detailed explanation of merging k sorted linked lists using a min heap.
A clear explanation of searching a rotated sorted array in logarithmic time using modified binary search.
A clear explanation of Range Sum Query 2D - Mutable using a 2D Fenwick Tree for efficient updates and rectangle sum queries.
A clear explanation of reconstructing a queue using greedy sorting and indexed insertion.
A clear explanation of the Add Digits problem using repeated digit sums first, then the digital root formula.
A clear explanation of finding the smallest base where n is written as all ones using geometric series and binary search.
A clear explanation of determining whether an integer is a power of two using binary properties and bit manipulation.
A clear explanation of rebuilding a binary tree from preorder and inorder traversals using recursion and an index map.
A clear explanation of detecting a valid cycle in a circular array using fast and slow pointers.
A clear explanation of finding the longest substring with at most two distinct characters using a sliding window.
A clear explanation of shuffling an array uniformly using the Fisher-Yates algorithm while supporting reset.
A clear explanation of checking whether two strings follow the same character mapping pattern.
A clear guide to solving Insert Interval with one linear scan over sorted, non-overlapping intervals.
A clear explanation of Self Crossing using constant-space checks for the only possible crossing patterns.
A clear explanation of finding the longest well-formed parentheses substring using a stack of indices.
A clear explanation of counting numbers with unique digits using combinatorics.
A clear SQL solution for finding every employee who earns the highest salary in their department.
A clear explanation of Range Sum Query - Mutable using a Fenwick Tree for efficient updates and range sums.
A detailed guide to solving Search in Rotated Sorted Array II with modified binary search and duplicate handling.
A clear explanation of converting integers to hexadecimal using bit manipulation and two's complement representation.
A detailed explanation of generating all well-formed parentheses strings using backtracking.
A detailed explanation of merging two sorted linked lists using a dummy node and pointer splicing.
A clear explanation of reformatting a license key by removing dashes, uppercasing characters, and grouping from the right.
A clear explanation of the Binary Tree Paths problem using DFS backtracking to collect every root-to-leaf path.
A clear explanation of finding the maximum depth of a binary tree using recursive depth-first search.
A clear explanation of finding the kth smallest value in a binary search tree using inorder traversal.
A clear explanation of checking whether one string can be constructed from another using character frequency counting.
A clear explanation of counting prime numbers less than n using the Sieve of Eratosthenes.
A clear guide to solving Merge Intervals by sorting intervals and merging them in one pass.
A dynamic programming solution for finding the least number of perfect square numbers that sum to n.
A clear explanation of implementing read with read4 when read may be called multiple times.
A clear explanation of Increasing Triplet Subsequence using greedy tracking of two minimum values.
Design a data structure that supports increment, decrement, get minimum key, and get maximum key in average O(1) time.
Generate all ways to split a string so that every piece is a palindrome, using backtracking with palindrome precomputation.
A clear SQL solution for finding customers who have no matching rows in the Orders table.
A clear explanation of detecting a 132 pattern using reverse traversal and a monotonic stack.
A clear explanation of checking whether 2D points are symmetric around a vertical line using min and max x-coordinates.
A clear explanation of finding the next lexicographically greater permutation in place using a right-to-left scan.
A detailed explanation of checking whether a bracket string is valid using a stack.
A clear explanation of Additive Number using split enumeration and deterministic checking.
A clear explanation of the Paint House problem using dynamic programming with constant space.
A clear explanation of constructing the magical string by using the string itself as run-length instructions.
A clear explanation of the Sum of Left Leaves problem using depth-first traversal of a binary tree.