brain
tamnd's digital brain — notes, problems, research
42768 notes
A clear explanation of finding the smallest prime palindrome greater than or equal to n by generating odd-length palindromes and testing primality.
An enumeration solution for reconstructing all valid coordinate pairs after commas, spaces, and decimal points were removed.
A clear explanation of counting uni-value subtrees using post-order DFS.
A clear explanation of the Rising Temperature SQL problem using a self join and date comparison.
A clear explanation of simplifying algebraic expressions by parsing, substituting variables, and combining polynomial terms.
A clear explanation of finding the longest buildable word using sorting and a hash set.
Find whether the maximum element is at least twice every other element using a single linear scan.
A clear explanation of validating whether a Tic-Tac-Toe board can occur in a legal game.
A clear explanation of Group Anagrams using a hash map keyed by each word's sorted character signature.
A clear explanation of finding words that match a pattern using bijective character mapping.
A clear explanation of solving Distinct Subsequences II using dynamic programming and last occurrence tracking.
A clear explanation of finding how many integers have exactly k trailing zeroes in their factorial.
A clear explanation of splitting a permutation into the maximum number of chunks using prefix maximums.
Find the minimum cost to reach the top of the staircase using dynamic programming.
A clear explanation of finding the kth smallest pair distance using sorting, binary search on the answer, and a two-pointer count.
A clear explanation of grouping strings by their shifting sequence using normalized hash keys.
A clear explanation of the Delete Duplicate Emails SQL problem using DELETE with a self join.
A clear explanation of Rotate Image using in-place matrix transpose and row reversal.
A clear explanation of counting strobogrammatic numbers in a string range using recursive generation and range filtering.
A clear explanation of generating all strobogrammatic numbers of length n using recursion from the inside out.
A clear explanation of Permutations II using sorting, depth-first search, and duplicate-skipping backtracking.
A clear explanation of the Tenth Line shell problem using awk, sed, head, and tail.
A clear explanation of the Transpose File shell problem using awk to transform rows into columns.
Support fast prefix and suffix queries by indexing every prefix-suffix combination with the largest word index.
A clear explanation of finding the longest common contiguous subarray using dynamic programming.
A clear explanation of Permutations using depth-first search and backtracking.
A clear explanation of the Strobogrammatic Number problem using digit rotation rules and two pointers.
A clear explanation of adding an integer to an array-form number using digit-by-digit simulation.
A BFS solution for finding the minimum number of buses needed to travel from a source stop to a target stop.
A clear explanation of finding the smallest subtree that contains all deepest nodes using bottom-up DFS.
A clear explanation of counting how many words are subsequences of a string using waiting queues.
A clear explanation of splitting an array into the maximum number of chunks so sorting each chunk gives the fully sorted array.
Use binary search to find the smallest character strictly greater than the target with wraparound handling.
A clear explanation of determining whether the last character must be a one-bit character using greedy parsing.
A clear explanation of the Valid Phone Numbers shell problem using grep and regular expressions.
A clear explanation of the Word Frequency shell problem using Unix text-processing tools.
A clear explanation of Jump Game II using a greedy range expansion approach to find the minimum number of jumps.
A clear explanation of Minimum Factorization using greedy digit factors from 9 down to 2.
A clear explanation of the Shortest Word Distance III problem, including the special case where both target words are the same.
A clear explanation of Wildcard Matching using dynamic programming over string and pattern prefixes.
A clear explanation of the Shortest Word Distance II problem using preprocessing and two pointers.
A clear explanation of Multiply Strings using grade-school multiplication with digit arrays.
A clear explanation of Maximum Distance in Arrays using sorted endpoints and a greedy scan.
A clear explanation of the Shortest Word Distance problem using one pass and the latest seen indices of both words.
A clear explanation of rearranging a string so that selected characters follow a custom order.
A clear explanation of rearranging characters so no two adjacent characters are equal using a greedy max heap.
Find the time needed for a signal to reach all nodes in a directed weighted graph using Dijkstra's algorithm.
A clear explanation of designing a stack that supports push, pop, top, peekMax, and popMax.
A clear explanation of the Trapping Rain Water problem using left and right boundaries, then an optimized two-pointer solution.
A clear SQL guide for solving Combine Two Tables using LEFT JOIN.
A clear explanation of Add One Row to Tree using tree traversal and careful subtree reconnection.
A clear explanation of the First Missing Positive problem using in-place index placement to achieve O(n) time and O(1) extra space.
A clear explanation of Design Circular Queue using a fixed array, a front pointer, and a size counter.
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 checking whether every top-left to bottom-right diagonal in a matrix has the same value.
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 the Rectangle Overlap problem using axis projections and positive intersection area.
A clear explanation of solving Reorder Data in Log Files using custom sorting and stable handling of digit logs.
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.