brain
tamnd's digital brain — notes, problems, research
42768 notes
Find the node where a linked list cycle begins using Floyd’s tortoise and hare algorithm with cycle entry mathematics.
A clear explanation of connecting next pointers in any binary tree using constant extra space.
A detailed guide to solving Decode Ways with dynamic programming and careful handling of zeroes.
A clear guide to computing the integer square root using binary search without built-in exponent functions.
A clear explanation of converting a positive integer into an Excel column title using bijective base 26.
A clear explanation of connecting next pointers in a perfect binary tree using constant extra space.
A clear explanation of finding two numbers in a sorted array using two pointers and constant extra space.
A clear explanation of counting distinct subsequences using dynamic programming.
Detect whether a linked list contains a cycle using Floyd’s tortoise and hare two-pointer algorithm.
A clear explanation of flattening a binary tree into a linked list in preorder traversal order using recursive depth-first search.
A detailed guide to solving Subsets II with sorting, backtracking, and duplicate skipping.
A clear guide to formatting text with greedy line packing and even space distribution.
A clear explanation of counting set bits in an integer using bit manipulation and Brian Kernighan's algorithm.
A clear explanation of converting a fraction into decimal form and detecting repeating fractional parts with a hash map.
A clear explanation of finding all root-to-leaf paths whose values add up to a target sum using depth-first search and backtracking.
A clear guide to adding two binary strings using two pointers and a carry.
A detailed guide to solving Gray Code using the binary-to-Gray-code formula.
A clear explanation of checking whether a binary tree has a root-to-leaf path whose values add up to a target sum.
Return all valid sentences formed by inserting spaces into a string so every word belongs to the dictionary, using DFS with memoization.
A clear guide to adding one to a large integer represented as an array of digits.
Decide whether a string can be segmented into dictionary words using dynamic programming over prefixes.
A clear explanation of finding the minimum depth of a binary tree using breadth-first search.
A detailed guide to solving Merge Sorted Array in-place by merging from the back with three pointers.
A clear guide to validating whether a string is a valid number using grammar rules and one left-to-right scan.
A clear explanation of the Paint House II problem using optimized dynamic programming with minimum and second minimum tracking.
A clear explanation of checking whether a binary tree is height-balanced using bottom-up depth-first search.
Create a deep copy of a linked list with next and random pointers using hash maps or interleaved node cloning.
A clear explanation of comparing version strings revision by revision while ignoring leading zeros.
A clear explanation of finding unique combinations that sum to a target when each array element may be used at most once.
A clear explanation of finding multiple words in a character board using a Trie and DFS backtracking.
A clear explanation of the Fizz Buzz problem using direct simulation and divisibility checks.
A clear explanation of reversing the bits of a 32-bit integer using bit manipulation.
A clear explanation of cleaning an unknown grid using DFS, relative coordinates, and physical backtracking.
A clear explanation of Binary Tree Vertical Order Traversal using BFS with column indices.
A clear explanation of counting the perimeter of an island in a grid by adding land-cell edges and subtracting shared edges.
A detailed guide to solving Scramble String with recursive dynamic programming and memoization.
A clear explanation of Integer Break using dynamic programming, with a note on the greedy math solution.
A clear explanation of computing inverse depth weighted sum using level-order traversal.
A clear explanation of finding the extra character added to a shuffled string using counting and XOR.
A clear guide to finding the minimum path sum in a grid using dynamic programming.
A binary-search-style solution for finding the smallest node greater than p in a binary search tree.
A clear explanation of deleting a node from a singly linked list when only that node is given.
A clear explanation of converting a sorted linked list into a height-balanced binary search tree using slow and fast pointers.
Evaluate a nested ternary expression using a right-to-left stack parser.
A clear explanation of the Ugly Number II problem using dynamic programming with three pointers.
Find the number that appears once when every other number appears three times using bit counting or finite-state bit manipulation.
A clear explanation of finding all unique combinations that sum to a target using backtracking.
A clear explanation of designing a word dictionary with addWord and wildcard search using a Trie and DFS.
A clear explanation of finding the shortest abbreviation that does not conflict with any dictionary word using bit masks.
A clear explanation of rotating an array to the right by k steps using in-place reversal.
A clear explanation of finding the maximum adjacent gap in sorted order using buckets and the pigeonhole principle.
A clear explanation of Super Ugly Number using dynamic programming with one pointer per prime.
A clear explanation of solving Zuma Game with DFS, memoization, and chain-removal simulation.
A clear explanation of Power of Four using bit manipulation and binary properties.
A clear explanation of why the median minimizes the number of moves needed to make all array elements equal.
A detailed guide to solving Partition List with two dummy lists while preserving relative order.
A clear explanation of reducing a 2D rectangle problem to a 1D prefix-sum problem with binary search.
A clear guide to counting unique paths in a grid with obstacles using dynamic programming.
A wrapper iterator design that supports peeking at the next element without advancing the iterator.
A clear explanation of computing the longest absolute path to a file from a serialized file system string using path lengths by depth.
A clear explanation of building a height-balanced binary search tree from a sorted array using divide and conquer.
Find all starting indices where an anagram of p appears in s using a fixed-size sliding window.
Find the only number that appears once using the XOR operator, while every other number appears exactly twice.
A clear explanation of the Ugly Number problem using repeated division by the only allowed prime factors.
A clear explanation of finding a valid course ordering using topological sorting and cycle detection.
A clear explanation of finding the lowest common ancestor in a normal binary tree using recursive depth-first search.
A clear explanation of generating the count-and-say sequence using run-length encoding.
A clear explanation of solving a Sudoku board using backtracking and constraint checking.
A clear explanation of minimizing the largest subarray sum using binary search on the answer and greedy validation.
A clear explanation of maximizing stock trading profit with at most k transactions using dynamic programming.
A clear explanation of finding all missing ranges inside an inclusive interval by scanning sorted unique numbers.
A clear explanation of Burst Balloons using interval dynamic programming and the last-burst idea.
A clear explanation of finding the longest run of 1s after flipping at most one 0 using a sliding window.
A clear explanation of Flatten Nested List Iterator using lazy stack-based flattening.
A clear explanation of computing the Hamming distance between two integers using XOR and bit counting.
A two-pointer in-place solution for moving all zeroes to the end while preserving the relative order of non-zero elements.
A clear guide to counting unique paths in a grid using dynamic programming.
A clear explanation of designing a hit counter for the last 5 minutes using a queue with compressed timestamps.
A clear guide to rotating a linked list to the right by k places using a circular list.
A clear explanation of finding the first non-repeating character in a string using character frequency counting.
A clear explanation of returning binary tree levels from bottom to top using breadth-first search.
Count downward paths in a binary tree whose values sum to targetSum using DFS and prefix sums.
A clear explanation of finding the lowest common ancestor in a binary search tree using BST ordering properties.
A detailed guide to solving Maximal Rectangle by converting each matrix row into a histogram and applying a monotonic stack.
A clear explanation of the Trips and Users SQL problem using joins, filtering, grouping, and conditional aggregation.
Compute the minimum candies needed using two greedy passes, one from the left and one from the right.
A clear explanation of finding the shortest contiguous subarray whose sum is at least target using a sliding window.
A clear explanation of finding repeated 10-letter DNA substrings using a fixed-size sliding window and hash sets.
A clear explanation of checking whether a partially filled Sudoku board is valid using hash sets.
A clear explanation of finding the longest palindrome length that can be built from given letters using character counts.
A clear explanation of finding any peak element using binary search on the slope of the array.
A clear explanation of Sparse Matrix Multiplication using non-zero entries to avoid wasted work.
A clear explanation of predicting whether Player 1 can win using minimax dynamic programming over score difference.
A clear explanation of Longest Substring with At Most K Distinct Characters using a sliding window and character counts.
A clear explanation of Nested List Weight Sum using depth-first search over a nested structure.
A clear explanation of Counting Bits using dynamic programming and bit manipulation.
A backtracking solution for inserting operators into a numeric string so the expression evaluates to a target value.
A clear explanation of designing an LFU cache with O(1) average get and put operations.
A clear explanation of checking whether a string can be built by repeating one of its proper substrings.
A clear guide to finding the kth permutation sequence using factorial blocks instead of generating all permutations.