brain
tamnd's digital brain — notes, problems, research
43815 notes
A clear explanation of Power of Four using bit manipulation and binary properties.
A clear explanation of why the median minimizes the number of moves needed to make all array elements equal.
A detailed guide to solving Partition List with two dummy lists while preserving relative order.
A clear explanation of reducing a 2D rectangle problem to a 1D prefix-sum problem with binary search.
A clear guide to counting unique paths in a grid with obstacles using dynamic programming.
A wrapper iterator design that supports peeking at the next element without advancing the iterator.
A clear explanation of computing the longest absolute path to a file from a serialized file system string using path lengths by depth.
A clear explanation of building a height-balanced binary search tree from a sorted array using divide and conquer.
Find all starting indices where an anagram of p appears in s using a fixed-size sliding window.
Find the only number that appears once using the XOR operator, while every other number appears exactly twice.
A clear explanation of the Ugly Number problem using repeated division by the only allowed prime factors.
A clear explanation of finding the lowest common ancestor in a normal binary tree using recursive depth-first search.
A clear explanation of finding a valid course ordering using topological sorting and cycle detection.
A clear explanation of generating the count-and-say sequence using run-length encoding.
A clear explanation of solving a Sudoku board using backtracking and constraint checking.
A clear explanation of minimizing the largest subarray sum using binary search on the answer and greedy validation.
A clear explanation of maximizing stock trading profit with at most k transactions using dynamic programming.
A clear explanation of finding all missing ranges inside an inclusive interval by scanning sorted unique numbers.
A clear explanation of Burst Balloons using interval dynamic programming and the last-burst idea.
A clear explanation of finding the longest run of 1s after flipping at most one 0 using a sliding window.
A clear explanation of Flatten Nested List Iterator using lazy stack-based flattening.
A clear explanation of computing the Hamming distance between two integers using XOR and bit counting.
A two-pointer in-place solution for moving all zeroes to the end while preserving the relative order of non-zero elements.
A clear guide to counting unique paths in a grid using dynamic programming.
A clear explanation of designing a hit counter for the last 5 minutes using a queue with compressed timestamps.
A clear guide to rotating a linked list to the right by k places using a circular list.
A clear explanation of finding the first non-repeating character in a string using character frequency counting.
A clear explanation of returning binary tree levels from bottom to top using breadth-first search.
Count downward paths in a binary tree whose values sum to targetSum using DFS and prefix sums.
A clear explanation of finding the lowest common ancestor in a binary search tree using BST ordering properties.
A detailed guide to solving Maximal Rectangle by converting each matrix row into a histogram and applying a monotonic stack.
A clear explanation of the Trips and Users SQL problem using joins, filtering, grouping, and conditional aggregation.
Compute the minimum candies needed using two greedy passes, one from the left and one from the right.
A clear explanation of finding the shortest contiguous subarray whose sum is at least target using a sliding window.
A clear explanation of finding repeated 10-letter DNA substrings using a fixed-size sliding window and hash sets.
A clear explanation of checking whether a partially filled Sudoku board is valid using hash sets.
A clear explanation of finding the longest palindrome length that can be built from given letters using character counts.
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 trapping rain water in a 2D elevation map using a min heap and boundary expansion.
A clear explanation of parsing a serialized nested integer string using a stack.
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.