brain
tamnd's digital brain — notes, problems, research
43815 notes
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.
A clear explanation of the Power of Three problem using repeated division and integer arithmetic.
A clear explanation of Remove Invalid Parentheses using BFS to guarantee the minimum number of removals.
A dynamic programming solution for counting ways to paint fence posts with no more than two adjacent posts sharing the same color.
A clear explanation of the Flatten 2D Vector problem using row and column pointers to implement an iterator.
A clear explanation of inverting a binary tree using recursive depth-first traversal.
A clear explanation of finding the bitwise AND of every number in an inclusive range using the common binary prefix.
A clear SQL solution for finding the second highest distinct salary from the Employee table.
A detailed guide to solving Combinations with backtracking and pruning.
A clear guide to solving N-Queens II by counting valid queen placements with backtracking.
A clear explanation of removing all occurrences of a value from an array in place using a write pointer.
A detailed explanation of converting an integer into a Roman numeral using a fixed value-symbol table and greedy subtraction.
A detailed explanation of finding the maximum water container area using two pointers.
A detailed explanation of matching a full string against a simplified regular expression with dot and star using dynamic programming.
A detailed explanation of checking whether an integer is a palindrome using digit operations without converting it to a string.
A detailed explanation of parsing a string into a 32-bit signed integer with whitespace, sign, digit reading, and clamping rules.
A detailed explanation of reversing a signed 32-bit integer while handling overflow correctly.
A detailed explanation of converting a string into a zigzag pattern using row simulation.
A detailed explanation of finding the longest palindromic substring using expand-around-center.
A clear explanation of reversing word order while removing extra spaces.
Find all shortest word transformation sequences using BFS to build shortest-path parents, then backtracking to reconstruct every answer.
A clear explanation of checking whether a binary tree is symmetric using mirror recursion.
A detailed guide to solving Minimum Window Substring with a sliding window and frequency counters.
A clear guide to solving N-Queens with backtracking, row-by-row placement, and constant-time conflict checks.
A detailed explanation of finding the median of two sorted arrays using binary search over partitions.
A clear explanation of removing duplicates from a sorted array in place using two pointers.
A clear explanation of the longest substring problem using sliding window and a hash set.
A detailed explanation of the Add Two Numbers linked list problem, including digit-by-digit addition, carry handling, and linked list construction.
A clear explanation of the Two Sum problem using brute force first, then an optimized hash map solution.
Browse notes by date
Prove that any comparison-based sorting algorithm requires Ω(n log n) comparisons in the worst case using a decision tree argument.
Count pairs of elements in the wrong relative order to measure how far an array is from sorted, using a modified merge sort in O(n log n) time.
Verify both the ordering and permutation properties of sorting implementations using randomized, edge-case, and adversarial test strategies.
Distribute sorting work across multiple processors to reduce wall-clock time, with analysis of total work, span, communication, and synchronization.
Select the appropriate sorting algorithm based on input size, data characteristics, memory constraints, and required guarantees such as stability or worst-case bounds.
Identify boundary errors, broken invariants, and comparator mistakes that cause sorting implementations to fail on edge cases or duplicate-heavy inputs.
Replace large or sparse keys with small dense ranks that preserve order, making range-based and indexed structures practical on wide-valued data.
Produce only the smallest k elements in sorted order rather than sorting the entire array, reducing unnecessary work when the full order is not needed.
Find the middle value of a collection in linear time using selection algorithms, without the overhead of a full sort.
Find the largest or smallest k elements without sorting the full input, using a heap or partition-based approach.
Sort datasets that exceed main memory by organizing the algorithm around sequential disk access, merge passes, and minimizing I/O operations.
Sort structured values by one or more fields while moving the full record, with attention to key extraction, stability, and multi-key ordering.
Exploit near-sorted structure in inputs like append-only logs or incremental updates to sort in linear or near-linear time.
Define correct comparison relations for user-defined types and non-trivial orderings — consistency requirements that sorting correctness depends on.
Find the element at a given rank using quicksort's partition step but recursing into only one side, achieving expected linear time.
Sort integer keys from a small range in linear time by counting occurrences and reconstructing the output from those counts.
Build a sorted prefix one element at a time by inserting each new element into its correct position within the already-sorted portion.
Build a max-heap in place, then repeatedly extract the maximum to produce a sorted array in O(n log n) worst-case time.
Divide the input into halves, recursively sort each half, then merge them — combining local order into global order in O(n log n) time.
Distribute elements into buckets by value range, sort each bucket, then concatenate — achieving linear expected time on uniformly distributed input.
Partition around a pivot so smaller elements go left and larger go right, then recursively sort each partition in expected O(n log n) time.
A stable sort preserves the original relative order of equal keys — an extra guarantee required when sorting by secondary fields or compound criteria.
Sort keys digit by digit using a stable subroutine, achieving linear time for fixed-width integers without any key comparisons.
Sort by repeatedly selecting the minimum element from the unsorted suffix and placing it into the next output position.
A sorting algorithm is correct only when its output is both ordered and a permutation of the input — two properties every implementation must preserve.
Distribute keys across a dynamic set of nodes so that adding or removing nodes moves only a minimal fraction of keys.
Verify correctness, stability, and performance of hash-based structures through randomized and adversarial test strategies.
Defend hash tables against adversarial inputs that force worst-case collision behavior using randomized hashing.
Produce stable hash values that remain consistent across program runs, machines, builds, and language runtimes.
Combine hash tables with other data structures to handle skewed distributions, heavy deletions, and mixed workloads.
Design hash table layouts that minimize cache misses and align memory access patterns with hardware behavior.
Join two collections by key using a hash table to reduce the cost from quadratic to linear expected time.
Examine hash-based structures in complete systems: streaming pipelines, graph algorithms, caches, and distributed workflows.
Understand how memory hierarchy effects cause hash table performance to deviate from asymptotic expectations.
Remove duplicate entries from a dataset or stream efficiently using hash sets for membership tracking.
Approximate frequency counting for large key streams using a compact probabilistic data structure with bounded error.
Choose and implement hash tables that perform reliably under mixed key types, uneven access patterns, and adversarial input.
Achieve predictable worst-case bounds for hash-based structures rather than relying solely on average-case expectations.
Hash and compare multi-field keys correctly by combining all fields that participate in equality into the hash function.
Implement a hash-based set for fast membership testing, insertion, and deletion without associated values.
Compute hash values for sliding windows over a sequence in constant time by incrementally updating rather than recomputing.
Build a hash-based map that associates keys with values and supports insert, lookup, delete, and update in expected constant time.
Track frequency counts for keys using a hash map that increments a counter on each insertion of an existing key.
Test set membership approximately using a compact bit array and multiple hash functions, with no false negatives and bounded false positives.
Partition a collection into groups by key using a hash map that accumulates values into per-key lists or sets.
Resolve hash collisions using separate chaining or open addressing, with trade-offs in memory, locality, and load tolerance.
Control hash table performance by monitoring the load factor and growing the bucket array before collisions accumulate.