brain
tamnd's digital brain — notes, problems, research
43815 notes
A clear explanation of finding the maximum value in every sliding window using a monotonic deque.
A clear explanation of building the shortest palindrome by finding the longest palindromic prefix using KMP.
A Floyd cycle detection solution for finding the repeated number without modifying the array and using constant extra space.
A clear explanation of the Palindrome Permutation problem using character parity counting.
A multi-source BFS solution for filling each empty room with its shortest distance to the nearest gate.
A clear explanation of computing each product except self using prefix and suffix products without division.
A clear explanation of maximizing robbed money from circularly arranged houses using dynamic programming.
A detailed guide to solving Same Tree with recursive DFS and structural comparison.
A detailed guide to solving Recover Binary Search Tree with inorder traversal and two misplaced nodes.
A clear explanation of checking whether a string is a palindrome after ignoring non-alphanumeric characters and case.
A detailed guide to solving Validate Binary Search Tree with recursive lower and upper bounds.
Evaluate an arithmetic expression written in Reverse Polish Notation using a stack.
Find the maximum number of points lying on the same straight line using slope counting and normalization.
A clear explanation of finding the maximum path sum in a binary tree using bottom-up depth-first search.
A clear explanation of maximizing stock profit with at most two transactions using dynamic programming.
A detailed guide to solving Interleaving String with two-dimensional dynamic programming.
A clear explanation of maximizing stock profit with unlimited transactions using a greedy single-pass method.
A detailed guide to solving Unique Binary Search Trees with dynamic programming and the Catalan recurrence.
A clear guide to sorting an array of 0s, 1s, and 2s in place using the Dutch National Flag algorithm.
Sort a singly linked list in ascending order using merge sort with fast and slow pointers.
A clear explanation of finding the maximum profit from one stock transaction using a single pass.
A clear explanation of computing the minimum initial health needed to survive a dungeon using reverse dynamic programming.
A clear guide to searching a sorted 2D matrix using binary search over a virtual one-dimensional array.
Sort a singly linked list using insertion sort by splicing each node into a growing sorted list.
A clear explanation of finding the minimum path sum in a triangle using bottom-up dynamic programming.
A clear explanation of designing an iterator over a BST using controlled inorder traversal with a stack.
A detailed guide to solving Unique Binary Search Trees II with recursive tree generation over value ranges.
Design an LRU cache with O(1) get and put operations using a hash map and doubly linked list.
A clear explanation of counting trailing zeroes in n! by counting factors of 5 instead of computing the factorial directly.
A clear guide to setting matrix rows and columns to zero in place using the first row and first column as markers.
A detailed guide to solving Binary Tree Inorder Traversal with recursion and an iterative stack.
Return the postorder traversal of a binary tree using recursion or an iterative stack-based approach.
A clear explanation of converting an Excel column title into its numeric index using base 26 accumulation.
A clear guide to computing the minimum number of insert, delete, and replace operations needed to convert one string into another.
Return the preorder traversal of a binary tree using recursion or an explicit stack.
A clear explanation of designing a data structure that supports add and find operations for pair sums.
A detailed guide to solving Restore IP Addresses with backtracking over four valid IP segments.
A clear guide to simplifying Unix-style file paths using a stack.
A clear explanation of generating a single row of Pascal's Triangle using in-place dynamic programming.
A clear explanation of counting connected groups of land cells in a grid using DFS or BFS.
A clear explanation of finding the element that appears more than half the time using Boyer-Moore voting.
Reorder a singly linked list in-place by finding the middle, reversing the second half, and merging the two halves alternately.
A clear explanation of generating Pascal's Triangle row by row using dynamic programming.
A detailed guide to solving Reverse Linked List II with a dummy node and in-place sublist reversal.
A clear guide to counting distinct ways to climb stairs using dynamic programming.
A clear explanation of returning the visible nodes from the right side of a binary tree using level-order traversal.
A clear explanation of maximizing robbery profit without robbing adjacent houses using dynamic programming.
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.