brain
tamnd's digital brain — notes, problems, research
42768 notes
A clear explanation of finding the shortest non-empty subarray with sum at least k using prefix sums and a monotonic deque.
A clear explanation of counting numbers whose binary representation has a prime number of set bits.
A clear explanation of solving Stamping The Sequence using reverse simulation and BFS-style processing.
A clear explanation of counting regions formed by slashes using union find over four triangles per cell.
A clear explanation of checking whether people can be split into two groups using graph coloring and bipartite graph detection.
Check sentence similarity with transitive word relationships using union-find.
A clear explanation of the Image Overlap problem using translation vectors and frequency counting.
A clear explanation of finding the kth smallest fraction from a sorted array using a min-heap.
A clear explanation of Online Election using preprocessing and binary search over vote times.
Find the shortest contiguous subarray with the same degree as the whole array using frequency counts and first occurrence indices.
A trie-based solution for replacing each derivative word with the shortest matching root.
Count substrings with equal consecutive groups of 0s and 1s using run lengths.
A center expansion solution for counting every palindromic substring in a string.
Find the largest connected island area in a binary grid using depth-first search.
A clear explanation of selecting a uniformly random integer while excluding blacklisted values using remapping and hashing.
A clear explanation of maximizing a binary matrix score using greedy row and column flips.
A clear explanation of cutting trees in increasing height order using repeated BFS on a grid.
A hash map solution for accumulating visit counts across domains and all of their parent subdomains.
A greedy interval scheduling solution for finding the longest chain of valid pairs.
Count unique island shapes in a binary grid using DFS and relative coordinates.
A clear explanation of making a special binary string lexicographically largest using recursive decomposition and sorting.
Evaluate a Lisp-like expression with integers, variables, let bindings, addition, multiplication, and lexical scope.
A clear explanation of solving Knight Dialer using dynamic programming over the phone keypad graph.
A clear explanation of maintaining the sum of even numbers after each array update.
A clear explanation of generating grid coordinates in an outward clockwise spiral using simulation.
A clear explanation of checking whether a binary tree is complete using level-order traversal.
A clear explanation of minimizing the array range after adding either +k or -k to every element.
A clear explanation of checking whether an undirected graph can be split into two independent sets using graph coloring.
A clear explanation of the Sum of Distances in Tree problem using tree DP, subtree sizes, and rerooting.
A clear explanation of converting uppercase ASCII letters to lowercase by scanning the string once.
A math and bit manipulation solution for deciding whether Alice wins the XOR removal game.
A clear explanation of Lemonade Change using greedy simulation and bill counting.
A counting and math solution for finding the duplicated number and the missing number in a corrupted set.
A clear explanation of finding the longest strictly increasing contiguous subarray using a single scan.
Check whether every adjacent bit in a positive integer's binary representation is different.
A clear explanation of mapping each element in one array to a matching index in its anagram using a hash map.
Simulate asteroid collisions using a stack that keeps the surviving asteroids in order.
A clear explanation of solving Shortest Bridge using DFS to mark one island and BFS to expand toward the other island.
A clear explanation of finding uncommon words by counting word frequencies across both sentences.
A clear explanation of constructing a string with exact counts of a and b while avoiding three equal consecutive characters.
A clear explanation of simulating prison cell transitions efficiently using cycle detection.
A binary search solution for finding the maximum average of any contiguous subarray with length at least k.
Find the k most frequent words using frequency counting and custom sorting by count and lexicographical order.
A clear explanation of counting how many longest strictly increasing subsequences exist using dynamic programming.
A clear explanation of counting possible bulb states after pressing four toggle buttons exactly presses times.
Find the minimum number of stickers needed to form a target string using top-down dynamic programming with memoization.
A sliding window solution for finding the maximum average among all contiguous subarrays of fixed length k.
A clear explanation of Snakes and Ladders using breadth-first search over board squares.
Compute the total importance of an employee and all direct and indirect subordinates using a hash map and depth-first search.
A trie-based design for returning the top three historical sentences for a typed prefix.
A clear explanation of generating all strings formed by independently changing each letter to lowercase or uppercase.
A clear explanation of the Find And Replace in String problem using simultaneous replacement, source matching, and a replacement map.
A clear explanation of finding the second minimum value in a special binary tree using DFS.
A clear explanation of inserting a value into a sorted circular linked list while preserving the circular sorted order.
A two-pointer group comparison solution for counting how many words can be stretched to match a target string.
A clear explanation of checking whether one swap in a string can make it equal to another string.
A clear explanation of finding common free time by merging all employee busy intervals and returning the gaps.
Check whether two word arrays are sentence-similar using a hash set of symmetric similar word pairs.
A clear explanation of computing the projection areas of stacked cubes from top, front, and side views.
A clear explanation of solving Number of Recent Calls using a queue as a sliding time window.
A clear explanation of finding the cheapest way to cover all travel days using dynamic programming.
A clear explanation of minimizing an array score after each value can move by at most k.
A clear explanation of solving Tallest Billboard using dynamic programming over height differences.
A clear explanation of finding the minimum difference between any two nodes in a BST using inorder traversal.
A clear explanation of the Flipping an Image problem using row reversal, bit inversion, and an in-place two-pointer method.
Find three non-overlapping subarrays of length k with maximum total sum and return the lexicographically smallest starting indices.
A clear explanation of maximizing an integer by swapping at most two digits once.
An array-based circular buffer solution for implementing a fixed-size double-ended queue.
A string parsing solution for reducing a linear equation into coefficient and constant terms.
A clear explanation of trimming a BST so that all remaining node values lie inside a given inclusive range.
Compute the probability that a knight remains on an n x n chessboard after exactly k random moves using dynamic programming.
A dynamic programming solution for counting decodings of a digit string with wildcard characters.
Find the longest path in a binary tree where every node on the path has the same value using depth-first search.
A SQL guide for filtering movies with odd IDs and non-boring descriptions, then sorting by rating.
A clear explanation of implementing a linked list from scratch using nodes, a dummy head, and a size counter.
A clear explanation of marking matching substrings and merging overlapping bold ranges.
A clear explanation of Mirror Reflection using room unfolding, least common multiples, and parity.
A probability dynamic programming solution for computing whether soup A empties before soup B, with an early return for large input.
A clear explanation of solving Beautiful Array using divide and conquer with odd and even transformations.
Recolor the connected component containing the starting pixel using depth-first search.
A clear explanation of counting ordered triples whose bitwise AND is zero using pairwise AND counts.
A clear explanation of finding the kth smallest value in an m by n multiplication table using binary search on answer.
A DFS and memoization solution for finding the minimum cost to satisfy item needs using individual prices and reusable special offers.
A SQL guide for finding the largest number that appears exactly once in a table.
Find the minimum number of times one string must be repeated so another string becomes a substring.
Find the directed edge to remove so a graph becomes a rooted tree again, handling both cycles and nodes with two parents.
A breadth-first search solution for computing the average value of nodes at each level of a binary tree.
A clear explanation of constructing an array with exactly k distinct adjacent differences using a greedy pattern.
A SQL guide for pivoting rows into columns using ranking and conditional aggregation.
A stack-based solution for computing exclusive execution time from nested start and end logs.
A recursive tree traversal guide for merging two binary trees node by node.
A clear explanation of counting reachable original and subdivided nodes using Dijkstra's shortest path algorithm.
A clear explanation of summing subarray minimums using a monotonic stack and contribution counting.
A clear explanation of transforming a binary board into a chessboard using feasibility checks and minimum row and column swaps.
A clear explanation of the Masking Personal Information problem using string parsing and format-specific masking rules.
Find the extra edge in an undirected graph that creates a cycle using Union-Find.
A clear explanation of computing all root-to-leaf path sums from a compact three-digit binary tree encoding.
A string-marking guide for adding bold tags around all matched words while merging overlapping and adjacent bold regions.
A design solution for storing timestamped logs and retrieving IDs by inclusive time range at a chosen granularity.
A clear explanation of solving interval intersection constraints using greedy sorting and minimal point selection.