brain
tamnd's digital brain — notes, problems, research
42791 notes
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.
A clear explanation of zigzag level order traversal using breadth-first search and alternating level direction.
A detailed guide to solving Remove Duplicates from Sorted Array II with an in-place two-pointer method.
A clear explanation of finding all elements that appear more than n/3 times using the extended Boyer-Moore voting algorithm.
A clear explanation of finding all starting indices where a substring is formed by concatenating every word exactly once.
A clear guide to solving Jump Game with greedy reachability.
A clear explanation of removing all linked list nodes with a target value using iteration and a dummy node.
A binary search solution for finding the first bad version while minimizing calls to the isBadVersion API.
A clear explanation of implementing read using the given read4 API and copying only the needed characters.
A clear explanation of Largest BST Subtree using postorder traversal and subtree state propagation.
A clear explanation of selecting a random linked list node with equal probability using reservoir sampling.
Convert an N-ary tree into a binary tree and reconstruct it using the left-child right-sibling representation.
A detailed explanation of removing the nth node from the end of a singly linked list using two pointers and a dummy node.
A clear explanation of Reconstruct Itinerary using a directed graph and Hierholzer's algorithm.
A clear explanation of flipping a binary tree upside down by rewiring pointers from the left spine.
Capture surrounded O regions by marking border-connected O cells first, then flipping the remaining O cells.
A clear explanation of designing a randomized multiset with average O(1) insert, remove, and getRandom operations.
A clear SQL solution for reporting email values that appear more than once in the Person table.
A detailed explanation of finding all unique quadruplets that sum to a target using sorting and two pointers.
A clear explanation of verifying preorder serialization using slot counting without reconstructing the tree.
A clear explanation of the greedy two-pointer solution for maximizing the number of content children.
A clear SQL solution for finding employees whose salary is greater than their manager's salary using a self join.
Flatten a multilevel doubly linked list in-place using depth-first traversal and pointer splicing.
A detailed explanation of generating all possible phone keypad letter combinations using backtracking.
A clear explanation of Number of Islands II using Union-Find to dynamically merge connected land cells.
A clear explanation of implementing a simplified Twitter using hash maps, sets, timestamps, and a heap.
A clear explanation of Patching Array using a greedy smallest-missing-sum invariant.
Compute the sum of all numbers formed by root-to-leaf paths using depth-first search and decimal accumulation.
Traverse an N-ary tree level by level using breadth-first search.
A clear explanation of designing a randomized set with average O(1) insert, remove, and getRandom operations.
A clear explanation of maintaining the median of each fixed-size window using two heaps and lazy deletion.
A clear explanation of designing a stack that can return the current minimum element in constant time.
A clear SQL solution for finding numbers that appear at least three times consecutively in the Logs table.
A clear explanation of Range Sum Query 2D - Immutable using a 2D prefix sum matrix for constant-time rectangle queries.
A clear explanation of the Verify Preorder Sequence in Binary Search Tree problem using a monotonic stack and lower bound tracking.
A clear explanation of solving Russian Doll Envelopes using sorting and longest increasing subsequence.
A clear explanation of counting zero-sum tuples across four arrays using pair sums and a hash map.
A detailed explanation of finding the sum of three integers closest to a target using sorting and two pointers.
A clear explanation of Longest Increasing Path in a Matrix using DFS with memoization.
A clear explanation of designing a phone directory that can allocate, check, and release numbers efficiently.
Find the longest run of consecutive integers in an unsorted array using a hash set and sequence-start detection.
A clear explanation of arranging non-negative integers to form the largest possible concatenated number using a custom sort order.
A clear explanation of finding the largest palindrome made from the product of two n-digit numbers by generating palindrome candidates directly.
A clear explanation of finding the minimum element in a rotated sorted array that may contain duplicates.
A clear explanation of the Factor Combinations problem using DFS backtracking with non-decreasing factors.
A clear explanation of the math behind making all array elements equal by incrementing n - 1 elements at a time.
Serialize an N-ary tree into a string and reconstruct the same tree using preorder traversal with child counts.
A clear explanation of Range Sum Query - Immutable using prefix sums for constant-time range queries.
A clear explanation of implementing Snake Game with a deque for body order and a set for constant-time collision checks.
A detailed explanation of finding all unique triplets that sum to zero using sorting and two pointers.
Use breadth-first search to find the shortest transformation sequence length between two words.
A clear explanation of binary tree level order traversal using breadth-first search and a queue.
A clear explanation of the Frog Jump problem using dynamic programming with reachable jump sizes.
A clear explanation of Odd Even Linked List using in-place pointer rewiring.
A clear explanation of finding the kth smallest value in a row-sorted and column-sorted matrix using binary search on values.
A clear SQL solution for ranking scores with dense ranking, where ties share the same rank and no rank numbers are skipped.
A clear explanation of generating uniformly random points inside a circle using polar coordinates.
A clear explanation of the Meeting Rooms II problem using a min heap to track active meeting end times.
A clear explanation of summarizing a sorted unique integer array into compact consecutive ranges.
A detailed guide to solving Word Search with depth-first search and backtracking on a grid.
A clear explanation of finding the minimum element in a rotated sorted array using binary search.
A clear explanation of integer division without using multiplication, division, or modulo, using repeated doubling with bit shifts.
A detailed explanation of finding the longest common prefix among an array of strings by comparing characters column by column.
A clear guide to reading a matrix in spiral order using shrinking boundaries.
A clear explanation of the greedy interval solution for finding the minimum number of arrows needed to burst all balloons.
Build a quad tree from a binary square grid using recursive divide and conquer.
A clear explanation of the Remove K Digits problem using a greedy monotonic stack.
A clear explanation of Combination Sum IV using dynamic programming to count ordered combinations that sum to a target.
A clear explanation of maintaining disjoint sorted intervals from a stream using insertion and merging.
A clear explanation of Count of Range Sum using prefix sums and merge sort counting.
A clear explanation of Smallest Rectangle Enclosing Black Pixels using binary search on rows and columns.
A two-pass solution for finding a celebrity using the knows API with O(n) calls and O(1) extra space.
A clear explanation of detecting whether repeated digit-square sums eventually reach 1.
A clear SQL solution for finding the nth highest distinct salary from the Employee table.
A clear explanation of the Meeting Rooms problem using interval sorting to detect overlaps.
A detailed explanation of evaluating arithmetic expressions with stack-based parsing and operator precedence.
A detailed explanation of tracking both maximum and minimum products while scanning the array.
A detailed guide to solving Subsets with backtracking and the include-or-skip recursion idea.
A clear explanation of finding the first occurrence of one string inside another using direct string matching.
A clear guide to solving Maximum Subarray with brute force first, then Kadane's dynamic programming algorithm.
A detailed explanation of converting a Roman numeral string into an integer using symbol values and the subtraction rule.
A clear explanation of computing the total Hamming distance across all pairs by counting different bits column by column.
A clear explanation of finding the bitwise complement of a positive integer using a binary mask.
A clear explanation of sorting characters by decreasing frequency using a hash map and sorting.
Convert a BST into a sorted circular doubly linked list in-place using inorder traversal.
A clear explanation of the Binary Watch problem using bit counting over all valid times.
A clear explanation of the Wiggle Subsequence problem using dynamic programming intuition and an optimized greedy solution.
A clear explanation of Android Unlock Patterns using backtracking, a jump table, and symmetry optimization.