brain
tamnd's digital brain — notes, problems, research
43815 notes
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 minimizing the last stone weight by splitting stones into two groups using 0/1 knapsack dynamic programming.
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 project with the most employees using GROUP BY, COUNT, and a subquery for the maximum.
A clear explanation of counting students not in the expected height order by comparing the array to its sorted version.
A clear explanation of counting numbers up to n with at least one repeated digit using digit DP and combinatorics.
A clear explanation of finding the longest arithmetic subsequence in an array using dynamic programming with difference hash maps.
A clear explanation of removing outermost parentheses from each primitive decomposition by tracking nesting depth.
A clear explanation of simulating stone smashing to find the last remaining weight using a max heap.
A clear explanation of finding minimum rotations to make all tops or bottoms equal using a greedy candidate check.
A clear explanation of counting song pairs whose total duration is divisible by 60 using remainder frequency counting.
A clear explanation of counting substrings of length k with all unique characters using a sliding window.
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 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 finding the first year each product was sold using a self-join or window function.
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 summing root-to-leaf binary numbers in a binary tree using DFS with accumulated values.
A clear explanation of determining if a car can transport all passengers using a difference array for passenger count tracking.
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 selecting the maximum sum subset under item and label count constraints using a greedy approach.
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 computing each student's top-5 average score using sorting and grouping.
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 finding the minimum ship capacity to deliver all packages within D days using binary search.
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 counting confusing numbers up to n using digit backtracking with rotation validation.
A clear explanation of reconstructing a BST from its preorder traversal using value range bounds.
A clear explanation of checking if three points form a boomerang (non-collinear) using the cross product.
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 finding the smallest repunit divisible by K by tracking remainders to detect cycles.
A clear explanation of minimizing the total score of triangulating a polygon using interval dynamic programming.
A clear explanation of computing statistical measures (minimum, maximum, mean, median, mode) from a frequency count array.
A clear explanation of maximizing array sum after exactly k negations using a greedy strategy.
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 the minimum and maximum moves to make three stones consecutive by analyzing gap cases.
A clear explanation of finding the most experienced employee(s) for each project using a window function or correlated subquery.
A clear explanation of finding minimum and maximum moves to make stones consecutive using a sliding window.
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 efficiently querying a stream of characters against a word list using an Aho-Corasick trie.
A clear explanation of finding the longest subarray of ones by flipping at most k zeros using a sliding window.
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 if the digit sum of the array minimum is odd or even.
A clear explanation of assigning 4 flower types to garden nodes with no adjacent conflicts using greedy graph coloring.
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 computing the average years of experience per project using JOIN and AVG aggregation.
A clear explanation of why Alice wins the divisor game if and only if n is even, proven by mathematical induction.
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 simulating lamp illumination on a grid using hash maps for rows, columns, and diagonals.
A clear explanation of finding the longest duplicate substring using binary search on length combined with Rabin-Karp rolling hash.
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 all index pairs where a word from the list appears in a text string using a trie.
A clear explanation of finding two non-overlapping subarrays with maximum combined sum using prefix sums and running maximums.
A clear explanation of computing the clumsy factorial by simulating cyclic operators with a stack.
A clear explanation of finding the lexicographically smallest equivalent string using Union-Find with canonical representatives.
A clear explanation of counting the occurrences of a specific digit in all numbers from 1 to n using digit dynamic programming.
A clear explanation of generating all strings from a brace expansion pattern in lexicographic order using backtracking.
A clear explanation of maximizing uncrossed connecting lines between two arrays using longest common subsequence dynamic programming.
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 verifying that all paths from a source node lead to a destination using DFS with cycle detection.
A clear explanation of rearranging barcodes so no two adjacent barcodes are equal using a greedy max-heap approach.
A clear explanation of checking camelCase pattern matching by verifying uppercase consistency with a two-pointer approach.
A clear explanation of finding the lexicographically largest permutation smaller than the given array using at most one swap.
A clear explanation of finding the next greater value for each node in a linked list using a monotonic stack.
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.
A generic data structure is a data structure that works with more than one element type.
Type coercion means Zig converts a value from one type to another when the conversion is safe and well-defined.
A state machine is a simple way to describe a program that moves between fixed states.
A dynamic string is text whose length is not fixed ahead of time.
A build option is a value passed from the command line into build.zig.
Queues and stacks are two simple ways to organize a collection of items.
The page allocator asks the operating system for memory directly.
@typeInfo asks the compiler for structured information about a type.
Reflection means inspecting a type as data.
An error union is a value that can contain either:
A union stores one active field at a time.
Zig string data is usually stored as UTF-8 bytes.
Zig programs use memory in different places. The two most important places are the stack and the heap.
Terminal programming means writing programs that interact with the command line as more than simple text output.
A static file server is a program that reads files from a directory and sends them to a browser over HTTP.
@Type builds a type from compile-time type information.
Generating code at compile time means using Zig code to create specialized program behavior before the final executable is built.
anytype means the function parameter can accept many different types.
A tagged union is a type that can store one value from several possible shapes.