brain
tamnd's digital brain — notes, problems, research
42734 notes
A clear explanation of maximizing uncrossed connecting lines between two arrays using longest common subsequence dynamic programming.
A clear explanation of counting numbers up to n with at least one repeated digit using digit DP and combinatorics.
A clear explanation of summing root-to-leaf binary numbers in a binary tree using DFS with accumulated values.
A clear explanation of checking divisibility of binary prefixes by 5 using running remainder tracking.
A clear explanation of efficiently querying a stream of characters against a word list using an Aho-Corasick trie.
A clear explanation of finding the maximum ancestor-node difference in a binary tree by tracking min and max along each root-to-leaf path.
A clear explanation of reconstructing a BST from its preorder traversal using value range bounds.
A clear explanation of finding the longest word chain where each word is formed by inserting one letter into the previous word, using dynamic programming.
A clear explanation of rearranging barcodes so no two adjacent barcodes are equal using a greedy max-heap approach.
A clear explanation of maximizing array sum by partitioning into subarrays of at most k elements, each filled with their maximum value, using dynamic programming.
A clear explanation of finding the minimum and maximum moves to make three stones consecutive by analyzing gap cases.
A clear explanation of checking if an array can be split into three contiguous parts with equal sum using a greedy two-pass approach.
A clear explanation of selecting the maximum sum subset under item and label count constraints using a greedy approach.
A clear explanation of finding the shortest path from top-left to bottom-right in a binary matrix using BFS.
A clear explanation of finding the lexicographically smallest equivalent string using Union-Find with canonical representatives.
A clear explanation of finding characters that appear in all words using minimum frequency counts.
A clear explanation of verifying that all paths from a source node lead to a destination using DFS with cycle detection.
A clear explanation of counting confusing numbers up to n using digit backtracking with rotation validation.
A clear explanation of converting a non-negative integer to its base negative-two representation.
A clear explanation of maximizing the sightseeing score by tracking the best left value seen so far in a single pass.
A clear explanation of checking if the digit sum of the array minimum is odd or even.
A clear explanation of maximizing satisfied customers by choosing the best window for the owner to not be grumpy using a sliding window.
A clear explanation of finding the longest substring that appears at least twice using binary search on length with rolling hash.
A clear explanation of finding a target in a mountain array using three binary searches on the interface API.
A clear explanation of checking whether a binary string contains all binary representations of integers from 1 to n.
A clear explanation of computing the average years of experience per project using JOIN and AVG aggregation.
A clear explanation of finding the shortest string containing both input strings as subsequences using LCS dynamic programming.
A clear explanation of finding the next greater value for each node in a linked list using a monotonic stack.
A clear explanation of counting all distinct non-empty sequences from a set of letter tiles using backtracking with frequency counting.
A clear explanation of finding books with fewer than 10 sales in the last year that were not sold in the last year using LEFT JOIN and GROUP BY.
A clear explanation of finding the maximum number of rows that can be made all-equal by flipping columns, using row pattern normalization.
A clear explanation of finding the minimum number of subsequences of source needed to form target using greedy two-pointer scanning.
A clear explanation of checking camelCase pattern matching by verifying uppercase consistency with a two-pointer approach.
A clear explanation of finding customers who purchased every product in the catalog using GROUP BY and HAVING with COUNT DISTINCT.
A clear explanation of finding the minimum total Manhattan distance to assign bikes to workers using bitmask dynamic programming.
A clear explanation of computing statistical measures (minimum, maximum, mean, median, mode) from a frequency count array.
A clear explanation of finding the project with the most employees using GROUP BY, COUNT, and a subquery for the maximum.
A clear explanation of converting a BST to a greater sum tree by accumulating values in reverse inorder traversal.
A clear explanation of computing each student's top-5 average score using sorting and grouping.
A clear explanation of checking if a number becomes a different valid number when rotated 180 degrees.
A clear explanation of counting students not in the expected height order by comparing the array to its sorted version.
A clear explanation of sorting matrix cells by Chebyshev distance from a given center cell using BFS.
A clear explanation of finding products sold only in the first quarter of 2019 using GROUP BY with date range conditions.
A clear explanation of greedily assigning bikes to workers based on Manhattan distance, prioritizing by distance then worker then bike index.
A clear explanation of adding two non-positive integers represented as arrays of digits.
A clear explanation of finding the smallest index where arr[i] equals i using binary search on a sorted distinct array.
A clear explanation of finding all index pairs where a word from the list appears in a text string using a trie.
A clear explanation of simulating stone smashing to find the last remaining weight using a max heap.
A clear explanation of coloring the border of a connected component in a grid using BFS.
A clear explanation of determining if a robot stays in a bounded circle by checking position and direction after one instruction cycle.
A clear explanation of eliminating adjacent duplicate character pairs from a string using a stack.
A clear explanation of simulating lamp illumination on a grid using hash maps for rows, columns, and diagonals.
A clear explanation of removing outermost parentheses from each primitive decomposition by tracking nesting depth.
A clear explanation of finding the longest subarray of ones by flipping at most k zeros using a sliding window.
A clear explanation of duplicating zeros in-place in an array without using extra space by working backwards.
A clear explanation of counting song pairs whose total duration is divisible by 60 using remainder frequency counting.
A clear explanation of reconstructing a binary tree from a depth-encoded preorder traversal string using a stack.
A clear explanation of finding the fraction of players retained the day after their first login using self-join and window functions.
A clear explanation of retrieving product names and their sale years using a JOIN between Sales and Product tables.
A clear explanation of finding the smallest repunit divisible by K by tracking remainders to detect cycles.
A clear explanation of finding the maximum sum of two numbers less than k using a two-pointer approach on a sorted array.
A clear explanation of checking if three points form a boomerang (non-collinear) using the cross product.
A clear explanation of counting submatrices with a given sum using 2D prefix sums combined with the subarray sum equals k technique.
A clear explanation of finding the complement of a number by XORing with a bitmask of the same bit length.
A clear explanation of finding the minimum ship capacity to deliver all packages within D days using binary search.
A clear explanation of finding minimum and maximum moves to make stones consecutive using a sliding window.
A clear explanation of finding the minimum number of video clips to cover a time range using a greedy interval covering approach.
A clear explanation of generating all strings from a brace expansion pattern in lexicographic order using backtracking.
A clear explanation of finding actor-director pairs with at least three collaborations using GROUP BY and HAVING.
A clear explanation of minimizing the last stone weight by splitting stones into two groups using 0/1 knapsack dynamic programming.
A clear explanation of counting subarrays where the leftmost element is not larger than any other element, using a monotonic stack.
A clear explanation of finding buyers who bought an iPhone but not an iPad using JOIN and NOT IN filtering.
A clear explanation of finding the first year each product was sold using a self-join or window function.
A clear explanation of assigning 4 flower types to garden nodes with no adjacent conflicts using greedy graph coloring.
A clear explanation of finding the lexicographically largest permutation smaller than the given array using at most one swap.
A clear explanation of finding minimum rotations to make all tops or bottoms equal using a greedy candidate check.
A clear explanation of finding the lexicographically smallest subsequence with all distinct characters using a greedy stack approach.
A clear explanation of finding the k-th missing number in a sorted array using binary search on the missing count.
A clear explanation of generating all strings from a brace expansion expression using recursive parsing and set union/concatenation.
A clear explanation of finding the best seller(s) by total price using GROUP BY, SUM, and a subquery for the maximum.
A clear explanation of finding the longest arithmetic subsequence in an array using dynamic programming with difference hash maps.
A clear explanation of maximizing array sum after exactly k negations using a greedy strategy.
A clear explanation of why Alice wins the divisor game if and only if n is even, proven by mathematical induction.
Zig gives you direct control over memory. That control is useful, but it also means you must follow clear rules.
Semantic analysis is the compiler stage that checks what a program means.
A debug build is a build made for finding mistakes.
WebAssembly, often shortened to Wasm, is a portable binary instruction format. It lets you compile code once and run it inside different hosts, such as web browsers, servers,...
Memory safety means using memory only while it is valid, only through the right type, and only inside the allowed range.
Allocation can fail.
@bitCast reinterprets the bits of one value as another type.
Static dispatch means the compiler decides which code to call before the program runs.
Type reflection means asking questions about a type while Zig is compiling the program.
Data-oriented design means you organize a program around the data it processes.
Efficient text processing means working with text without doing unnecessary allocation, copying, or decoding.
SIMD means Single Instruction, Multiple Data.
Embedded development means writing software for small computers inside devices.
Zig’s standard library is imported with:
A custom allocator is an allocator you design for a specific memory policy.
@ptrCast converts one pointer type into another pointer type.
A dangling pointer is a pointer that refers to memory that is no longer valid.