brain
tamnd's digital brain — notes, problems, research
43815 notes
A clear explanation of determining whether an integer is a power of two using binary properties and bit manipulation.
A clear explanation of rebuilding a binary tree from preorder and inorder traversals using recursion and an index map.
A clear explanation of detecting a valid cycle in a circular array using fast and slow pointers.
A clear explanation of finding the longest substring with at most two distinct characters using a sliding window.
A clear explanation of shuffling an array uniformly using the Fisher-Yates algorithm while supporting reset.
A clear explanation of checking whether two strings follow the same character mapping pattern.
A clear guide to solving Insert Interval with one linear scan over sorted, non-overlapping intervals.
A clear explanation of Self Crossing using constant-space checks for the only possible crossing patterns.
A clear explanation of finding the longest well-formed parentheses substring using a stack of indices.
A clear explanation of counting numbers with unique digits using combinatorics.
A clear SQL solution for finding every employee who earns the highest salary in their department.
A clear explanation of Range Sum Query - Mutable using a Fenwick Tree for efficient updates and range sums.
A detailed guide to solving Search in Rotated Sorted Array II with modified binary search and duplicate handling.
A clear explanation of converting integers to hexadecimal using bit manipulation and two's complement representation.
A detailed explanation of generating all well-formed parentheses strings using backtracking.
A detailed explanation of merging two sorted linked lists using a dummy node and pointer splicing.
A clear explanation of reformatting a license key by removing dashes, uppercasing characters, and grouping from the right.
A clear explanation of the Binary Tree Paths problem using DFS backtracking to collect every root-to-leaf path.
A clear explanation of finding the maximum depth of a binary tree using recursive depth-first search.
A clear explanation of finding the kth smallest value in a binary search tree using inorder traversal.
A clear explanation of checking whether one string can be constructed from another using character frequency counting.
A clear explanation of counting prime numbers less than n using the Sieve of Eratosthenes.
A clear guide to solving Merge Intervals by sorting intervals and merging them in one pass.
A dynamic programming solution for finding the least number of perfect square numbers that sum to n.
A clear explanation of implementing read with read4 when read may be called multiple times.
Design a data structure that supports increment, decrement, get minimum key, and get maximum key in average O(1) time.
A clear explanation of Increasing Triplet Subsequence using greedy tracking of two minimum values.
Generate all ways to split a string so that every piece is a palindrome, using backtracking with palindrome precomputation.
A clear SQL solution for finding customers who have no matching rows in the Orders table.
A clear explanation of detecting a 132 pattern using reverse traversal and a monotonic stack.
A clear explanation of checking whether 2D points are symmetric around a vertical line using min and max x-coordinates.
A clear explanation of finding the next lexicographically greater permutation in place using a right-to-left scan.
A detailed explanation of checking whether a bracket string is valid using a stack.
A clear explanation of Additive Number using split enumeration and deterministic checking.
A clear explanation of the Paint House problem using dynamic programming with constant space.
A clear explanation of constructing the magical string by using the string itself as run-length instructions.
A clear explanation of the Sum of Left Leaves problem using depth-first traversal of a binary tree.
A clear explanation of zigzag level order traversal using breadth-first search and alternating level direction.
A detailed guide to solving Remove Duplicates from Sorted Array II with an in-place two-pointer method.
A clear explanation of finding all elements that appear more than n/3 times using the extended Boyer-Moore voting algorithm.
A clear explanation of finding all starting indices where a substring is formed by concatenating every word exactly once.
A clear guide to solving Jump Game with greedy reachability.
A clear explanation of removing all linked list nodes with a target value using iteration and a dummy node.
A binary search solution for finding the first bad version while minimizing calls to the isBadVersion API.
A clear explanation of implementing read using the given read4 API and copying only the needed characters.
A clear explanation of Largest BST Subtree using postorder traversal and subtree state propagation.
A clear explanation of selecting a random linked list node with equal probability using reservoir sampling.
Convert an N-ary tree into a binary tree and reconstruct it using the left-child right-sibling representation.
A detailed explanation of removing the nth node from the end of a singly linked list using two pointers and a dummy node.
A clear explanation of Reconstruct Itinerary using a directed graph and Hierholzer's algorithm.
A clear explanation of flipping a binary tree upside down by rewiring pointers from the left spine.
Capture surrounded O regions by marking border-connected O cells first, then flipping the remaining O cells.
A clear explanation of designing a randomized multiset with average O(1) insert, remove, and getRandom operations.
A clear SQL solution for reporting email values that appear more than once in the Person table.
A detailed explanation of finding all unique quadruplets that sum to a target using sorting and two pointers.
A clear explanation of verifying preorder serialization using slot counting without reconstructing the tree.
A clear explanation of the greedy two-pointer solution for maximizing the number of content children.
A clear SQL solution for finding employees whose salary is greater than their manager's salary using a self join.
Flatten a multilevel doubly linked list in-place using depth-first traversal and pointer splicing.
A detailed explanation of generating all possible phone keypad letter combinations using backtracking.
A clear explanation of Number of Islands II using Union-Find to dynamically merge connected land cells.
A clear explanation of implementing a simplified Twitter using hash maps, sets, timestamps, and a heap.
A clear explanation of Patching Array using a greedy smallest-missing-sum invariant.
Compute the sum of all numbers formed by root-to-leaf paths using depth-first search and decimal accumulation.
Traverse an N-ary tree level by level using breadth-first search.
A clear explanation of designing a randomized set with average O(1) insert, remove, and getRandom operations.
A clear explanation of maintaining the median of each fixed-size window using two heaps and lazy deletion.
A clear explanation of designing a stack that can return the current minimum element in constant time.
A clear SQL solution for finding numbers that appear at least three times consecutively in the Logs table.
A clear explanation of Range Sum Query 2D - Immutable using a 2D prefix sum matrix for constant-time rectangle queries.
A clear explanation of the Verify Preorder Sequence in Binary Search Tree problem using a monotonic stack and lower bound tracking.
A clear explanation of solving Russian Doll Envelopes using sorting and longest increasing subsequence.
A clear explanation of counting zero-sum tuples across four arrays using pair sums and a hash map.
A detailed explanation of finding the sum of three integers closest to a target using sorting and two pointers.
A clear explanation of Longest Increasing Path in a Matrix using DFS with memoization.
A clear explanation of designing a phone directory that can allocate, check, and release numbers efficiently.
Find the longest run of consecutive integers in an unsorted array using a hash set and sequence-start detection.
A clear explanation of arranging non-negative integers to form the largest possible concatenated number using a custom sort order.
A clear explanation of finding the largest palindrome made from the product of two n-digit numbers by generating palindrome candidates directly.
A clear explanation of finding the minimum element in a rotated sorted array that may contain duplicates.
A clear explanation of the Factor Combinations problem using DFS backtracking with non-decreasing factors.
A clear explanation of the math behind making all array elements equal by incrementing n - 1 elements at a time.
Serialize an N-ary tree into a string and reconstruct the same tree using preorder traversal with child counts.
A clear explanation of Range Sum Query - Immutable using prefix sums for constant-time range queries.
A clear explanation of implementing Snake Game with a deque for body order and a set for constant-time collision checks.
A detailed explanation of finding all unique triplets that sum to zero using sorting and two pointers.
A clear explanation of binary tree level order traversal using breadth-first search and a queue.
Use breadth-first search to find the shortest transformation sequence length between two words.
A clear explanation of the Frog Jump problem using dynamic programming with reachable jump sizes.
A clear explanation of Odd Even Linked List using in-place pointer rewiring.
A clear explanation of finding the kth smallest value in a row-sorted and column-sorted matrix using binary search on values.
A clear SQL solution for ranking scores with dense ranking, where ties share the same rank and no rank numbers are skipped.
A clear explanation of generating uniformly random points inside a circle using polar coordinates.
A clear explanation of the Meeting Rooms II problem using a min heap to track active meeting end times.
A clear explanation of summarizing a sorted unique integer array into compact consecutive ranges.
A detailed guide to solving Word Search with depth-first search and backtracking on a grid.
A clear explanation of finding the minimum element in a rotated sorted array using binary search.
A clear explanation of integer division without using multiplication, division, or modulo, using repeated doubling with bit shifts.
A detailed explanation of finding the longest common prefix among an array of strings by comparing characters column by column.
A clear guide to reading a matrix in spiral order using shrinking boundaries.