brain
tamnd's digital brain — notes, problems, research
42768 notes
A clear SQL guide for finding countries with either large area or large population.
A clear explanation of Median Employee Salary using SQL window functions to rank employees inside each company.
A clear explanation of balancing dresses across washing machines using greedy prefix flow.
A clear explanation of building the final tournament bracket by repeatedly pairing strongest and weakest teams.
A clear hash map solution for finding the longest subsequence whose maximum and minimum differ by exactly one.
A clear explanation of finding the length of the longest palindromic subsequence using interval dynamic programming.
A clear explanation of finding the longest path between any two nodes in a binary tree using DFS height computation.
A clear explanation of Maximum Vacation Days using dynamic programming over weeks and cities.
A clear explanation of finding the maximum value at every depth of a binary tree using level-order traversal.
A clear geometry solution for checking whether four unordered points form a valid square.
A clear explanation of Permutation in String using a fixed-size sliding window and character frequency counts.
A clear explanation of computing the distance to the nearest zero in a binary matrix using multi-source BFS.
A clear explanation of finding the minimum steps to spell a key on a circular ring using dynamic programming and memoized DFS.
A clear parsing and math solution for evaluating fraction addition and subtraction expressions.
A clear stack-based parser for validating nested XML-like tags with CDATA sections.
A clear explanation of Reshape the Matrix using index mapping from the original matrix to the reshaped matrix.
A clear explanation of finding the leftmost value in the deepest row of a binary tree using level-order traversal.
A clear explanation of finding the first device used by each player using SQL aggregation and a join.
A clear explanation of finding each player's first login date using SQL aggregation.
A clear DFS solution for returning the postorder traversal of an N-ary tree.
A clear explanation of Array Nesting using cycle detection over a permutation.
A clear explanation of reversing the first k characters in every 2k block of a string.
A clear explanation of finding the inorder successor in a binary search tree when nodes contain parent pointers.
A clear explanation of computing Fibonacci numbers using dynamic programming and iterative state transitions.
A clear explanation of finding the most frequent subtree sum in a binary tree using postorder DFS and a frequency map.
A dynamic programming solution for counting permutations of 1 to n with exactly k inverse pairs.
A clear explanation of formatting a binary tree into a 2D string matrix using tree height and recursive placement.
A greedy guide for determining whether a given number of flowers can be planted without violating the no-adjacent-flowers rule.
A clear DFS solution for returning the preorder traversal of an N-ary tree.
A clear explanation of Find the Closest Palindrome using prefix mirroring and a small candidate set.
A clear explanation of finding the only non-duplicate element in a sorted array using binary search.
A clear explanation of checking whether a number equals the sum of its positive divisors excluding itself.
A clear explanation of counting car fleets by sorting cars by position and tracking arrival times.
A reverse simulation and union-find solution for counting how many bricks fall after each hit.
A clear explanation of Cracking the Safe using a de Bruijn sequence and depth-first search over password states.
Check each number in a range by extracting its digits and testing whether every digit divides the original number.
A clear explanation of searching in a sorted array when the array length is hidden behind an ArrayReader interface.
A clear explanation of assigning athlete ranks from scores using sorting while preserving original indices.
Check whether a string containing parentheses and wildcard stars can be made valid using a greedy range of possible open counts.
A clear explanation of finding the minimum difference between 24-hour clock times using minute conversion and sorting.
A guide to implementing a lazy iterator over a run-length encoded string without fully decompressing it.
A clear explanation of Binary Tree Tilt using postorder DFS to compute subtree sums and accumulate tilt.
A clear explanation of constructing a maximum binary tree recursively using divide and conquer.
A clear design guide for implementing an in-memory file system with directory listing, directory creation, file append, and file read operations.
A clear explanation of finding the largest product of three numbers using sorting or constant-space tracking.
A clear explanation of finding the shortest rolling distance in a maze using Dijkstra’s algorithm.
Design a map that supports key-value insertion and prefix-sum queries using a hash map and trie.
A clear explanation of Longest Line of Consecutive One in Matrix using dynamic programming over four directions.
A SQL guide for finding all cinema seats that are free and adjacent to at least one other free seat.
A clear explanation of finding whether two different nodes in a binary search tree sum to a target value.
A clear convex hull solution for returning all trees that lie on the fence boundary.
A SQL update solution for swapping all m and f values in the Salary table using a single statement.
A clear explanation of converting a BST into a greater tree using reverse inorder traversal and a running sum.
A clear explanation of converting an integer into its base 7 string representation using repeated division.
A clear explanation of finding the next greater element in a circular array using a monotonic stack.
A clear explanation of solving Three Equal Parts by counting ones, locating the three binary patterns, and comparing them in one pass.
A clear explanation of sorting squared values from a sorted array using two pointers.
A clear explanation of solving Largest Component Size by Common Factor using prime factorization and union find.
A clear explanation of the Stone Game problem using game theory and interval dynamic programming.
A clear explanation of counting numbers less than or equal to N using digit-by-digit construction and combinatorics.
A clear explanation of finding the peak index in a mountain array using binary search.
A clear explanation of the Making A Large Island problem using connected component labeling and island size lookup.
A graph traversal solution for finding all nodes that cannot reach a directed cycle.
A clear explanation of validating string transformation using two pointers and movement constraints.
A clear explanation of solving Open the Lock using breadth-first search over lock states.
Find the shortest substring of s1 that contains s2 as a subsequence using dynamic programming.
A clear explanation of finding the largest valid triangle perimeter using sorting and a greedy scan.
A clear explanation of checking whether two binary trees are equivalent after swapping left and right children at any number of nodes.
A clear explanation of solving Flip String to Monotone Increasing with a one-pass dynamic programming approach.
A clear explanation of Online Stock Span using a monotonic decreasing stack with accumulated spans.
A clear explanation of finding the middle node of a singly linked list using slow and fast pointers.
A clear explanation of Loud and Rich using graph traversal, DFS, and memoization.
A clear explanation of the Most Profit Assigning Work problem using sorting, greedy choice, and two pointers.
A dynamic programming solution for finding the minimum number of same-index swaps needed to make two arrays strictly increasing.
A clear explanation of splitting a binary search tree into two BSTs using recursion and pointer rewiring.
A clear explanation of converting a range of IPv4 addresses into the shortest list of CIDR blocks using greedy bit manipulation.
Parse a chemical formula with nested parentheses, atom names, and multipliers using recursive descent.
A clear explanation of inserting a value into a binary search tree using recursive and iterative traversal.
Design a dictionary that can check whether a word can match a stored word after changing exactly one character.
A clear explanation of finding duplicate binary tree subtrees using postorder traversal, serialization, and a hash map.
A SQL guide for counting friendships from both requester and accepter sides, then returning the user with the most friends.
A clear explanation of maximizing capital by selecting at most k projects using sorting and a max heap.
A clear explanation of multiplying complex numbers represented as strings using algebraic expansion.
A clear SQL guide for finding the customer who placed the most orders.
A clear explanation of Array Partition using sorting and adjacent pairing to maximize the sum of pair minimums.
A dynamic programming solution for maximizing the number of A characters printed with a limited number of keyboard operations.
A SQL solution for swapping every pair of adjacent student seats while leaving the final seat unchanged when the row count is odd.
A SQL guide for finding stadium records that belong to runs of at least three consecutive ids where each row has at least 100 people.
A clear explanation of finding the most frequent value or values in a binary search tree using inorder traversal.
A clear explanation of parsing a parenthesized string recursively to construct a binary tree.
A clear SQL guide for summing 2016 investments for policies with repeated 2015 investment values and unique locations.
A clear explanation of Subarray Sum Equals K using prefix sums and a hash map to count matching subarrays in linear time.
A clear explanation of designing a simple URL encoder and decoder using a hash map and generated keys.
A clear explanation of computing cumulative games played per player and date using SQL window functions.
A clear SQL guide for selecting customers who were not referred by customer 2, including customers with no referee.
A clear explanation of Maximum Depth of N-ary Tree using recursive depth-first search.
A clear dynamic programming solution for finding the minimum deletions needed to make two strings equal.
A clear explanation of merging two quad-trees using recursive logical OR operations.
A clear explanation of counting black lonely pixels using row counts, column counts, and duplicate row patterns.
A clear explanation of Reverse Words in a String III using two-pointer scanning and string reversal.