brain
tamnd's digital brain — notes, problems, research
43815 notes
A clear explanation of checking whether every top-left to bottom-right diagonal in a matrix has the same value.
Find the nearest leaf to a target node by converting the tree into an undirected graph and running breadth-first search.
A clear explanation of counting tilings of a 2 x n board using dominoes and L-shaped trominoes with dynamic programming.
A clear explanation of designing a range module that can add, query, and remove half-open intervals.
A clear explanation of Task Scheduler using frequency counting and the greedy block formula.
A clear explanation of solving Minimum Area Rectangle using diagonal point pairs and constant-time point lookup.
A clear explanation of reconstructing a binary tree from preorder and postorder traversals using recursion and index ranges.
Maximize cherries collected on a round trip by converting the problem into two simultaneous forward paths and solving with dynamic programming.
A clear explanation of maximizing stock trading profit with unlimited transactions and a fixed transaction fee using dynamic programming.
A clear explanation of finding the maximum width ramp using a monotonic decreasing stack.
A clear explanation of the Push Dominoes problem using force propagation and a two-pass scan.
A clear explanation of minimizing swaps so every couple sits together using greedy position tracking.
Transform the problem into House Robber dynamic programming by grouping equal values into total points.
A clear explanation of deciding whether escape is possible by comparing Manhattan distances to the target.
A clear explanation of checking whether card counts share a common group size using the greatest common divisor.
A clear explanation of finding the lexicographically smallest leaf-to-root string in a binary tree using DFS.
A clear explanation of finding the minimum moves to collect all keys in a grid using BFS with key bitmasks.
A postorder DFS solution for removing every binary tree subtree that does not contain a 1.
A clear explanation of finding the element repeated N times using a hash set.
A clear explanation of finding one candy box swap that makes Alice and Bob have equal total candies.
A clear explanation of solving Range Sum of BST using DFS with binary search tree pruning.
A clear explanation of counting good numbers after rotating every digit by 180 degrees.
Find how many days each temperature must wait for a warmer future day using a monotonic stack.
A clear explanation of counting contiguous subarrays whose product is less than k using a sliding window.
A clear explanation of finding the largest plus sign in a mined grid using four directional dynamic programming scans.
A clear explanation of the New 21 Game problem using probability dynamic programming and a sliding window sum.
Search for a target value in a binary search tree and return the subtree rooted at the matching node.
A clear explanation of Cat and Mouse using game states, reverse BFS, and topological propagation.
Simulate falling squares on a number line and track the maximum stack height after each placement.
A dynamic programming and prefix sum solution for partitioning an array into adjacent groups with maximum total average.
A clear explanation of vertical tree traversal using coordinates, DFS, sorting, and column grouping.
A clear explanation of finding all binary tree nodes at distance k from a target node by treating the tree as an undirected graph.
A clear explanation of using dynamic programming to minimize the ASCII cost of deletions needed to make two strings equal.
A clear explanation of deleting the minimum number of columns so every remaining row is individually sorted.
Find the largest number less than or equal to n whose digits are monotone increasing using a greedy digit adjustment.
A clear explanation of partitioning a string into the maximum number of parts so each character appears in at most one part.
A clear explanation of finding the minimum worst-case number of moves using dynamic programming over eggs and moves.
A clear explanation of solving Reorder Data in Log Files using custom sorting and stable handling of digit logs.
A clear explanation of the Rectangle Overlap problem using axis projections and positive intersection area.
A clear explanation of finding the cheapest flight route with at most k stops using bounded Bellman-Ford relaxation.
A clear explanation of sorting an array without built-in sorting using merge sort.
A dynamic programming and prime factorization solution for finding the minimum operations needed to produce n characters.
Decide whether an array can be divided into k non-empty subsets with equal sums using backtracking and pruning.
A queue-based simulation for predicting which party wins after senators ban opponents in turn order.
A clear explanation of counting distinct island shapes under rotation and reflection using normalization and geometric transformations.
A clear explanation of finding intersections between two sorted disjoint interval lists using two pointers.
A geometry solution for finding the largest triangle area by checking every triplet of points with the cross product formula.
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.