brain
tamnd's digital brain — notes, problems, research
43815 notes
A clear explanation of finding the minimum number of swaps needed to transform one anagram string into another using BFS.
A clear explanation of reaching a target on a number line using cumulative sums and parity.
Implement a calendar that accepts a booking only when it does not overlap with any existing booking.
A clear explanation of maintaining the kth largest element in a stream using a fixed-size min heap.
Determine whether four numbers can be combined with arithmetic operations and parentheses to produce 24.
A clear explanation of solving Minimize Malware Spread II by removing each infected node and simulating the final malware spread.
A clear explanation of finding the longest subarray whose adjacent comparisons alternate between greater-than and less-than.
A clear explanation of finding the nth magical number using binary search, greatest common divisor, least common multiple, and inclusion-exclusion.
A clear explanation of checking whether words are sorted according to a custom alien alphabet order.
A clear explanation of Count Unique Characters of All Substrings using contribution counting with previous and next occurrences.
A clear explanation of counting valid DI permutations using dynamic programming and prefix sums.
A clear explanation of averaging neighboring pixels in a matrix using direct simulation.
A clear explanation of finding the nth positive integer that does not contain the digit 9 using base-9 conversion.
A clear explanation of Distribute Candies using a set to count candy types and a simple limit argument.
A clear explanation of detecting a subarray whose sum is a multiple of k using prefix sums and modular arithmetic.
A clear explanation of finding the minimum time to reach the bottom-right cell using a priority queue and minimax path reasoning.
A two-pointer guide for counting triplets that can form valid triangles after sorting the side lengths.
A clear explanation of deciding whether a sorted array can be split into consecutive subsequences of length at least three.
A SQL guide for checking whether three side lengths can form a valid triangle using the triangle inequality.
A clear explanation of calculating the fraction of players who logged in again the day after their first login.
A clear hash map solution for finding common strings with the smallest index sum.
A clear explanation of finding the k closest elements to a target using binary search and a sliding window.
A hash map guide for grouping file paths by identical file content and returning only duplicate groups.
A clear explanation of finding the longest increasing or decreasing consecutive path in a binary tree using DFS.
A SQL guide for classifying binary tree nodes as Root, Inner, or Leaf based on parent-child relationships.
A clear explanation of determining whether a robot returns to the origin after executing movement instructions.
A clear math solution for counting the maximum values after repeated top-left matrix increment operations.
A clear explanation of Winning Candidate using SQL aggregation to count votes and return the candidate with the most votes.
A clear explanation of splitting an array into four equal-sum parts using prefix sums and set-based search.
A clear explanation of finding the longest uncommon subsequence among many strings using subsequence checks.
A clear explanation of finding the longest uncommon subsequence between two strings using simple case analysis.
A SQL guide for finding salespeople who never had an order related to the company named RED.
A greedy heap solution for taking the maximum number of courses before their deadlines.
A clear explanation of finding the minimum-cost path with bounded jumps, blocked cells, and lexicographic tie-breaking.
A recursive guide for converting a binary tree into a preorder parenthesized string while preserving the one-to-one mapping between the tree and the string.
A clear explanation of counting connected components in an undirected graph represented by an adjacency matrix.
A clear SQL guide for computing the overall friend request acceptance rate with duplicate pairs counted once.
A clear explanation of Squirrel Simulation using Manhattan distance and the special first trip.
A clear explanation of checking whether a word uses capital letters correctly by counting uppercase letters.
A clear explanation of Subtree of Another Tree using recursive tree matching and DFS.
A clear explanation of randomly flipping zero cells in a matrix without repetition using hash mapping and virtual swapping.
A clear SQL guide for finding classes that have at least five students.
A clear explanation of Find Median Given Frequency of Numbers using cumulative frequency and SQL window functions.
A clear explanation of counting coin-change combinations using dynamic programming.
A clear explanation of maximizing remove-box scores using interval dynamic programming with memoization.
A clear explanation of Managers with at Least 5 Direct Reports using grouping and a self join.
A clear explanation of collecting the boundary of a binary tree using separate left boundary, leaves, and right boundary traversals.
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.