brain
tamnd's digital brain — notes, problems, research
42768 notes
A clear explanation of checking whether one string is a subsequence of another using two pointers.
A clear explanation of checking whether an integer is a perfect square using binary search without sqrt.
A clear explanation of adding two non-negative integer strings using manual digit-by-digit simulation.
A clear explanation of Shortest Distance from All Buildings using BFS from each building with distance and reach accumulation.
A clear explanation of generating all distinct non-decreasing subsequences using DFS, backtracking, and per-level duplicate control.
A clear explanation of Moving Average from Data Stream using a queue and rolling sum.
A clear explanation of minimizing debt-settlement transactions using net balances, backtracking, and memoization-style pruning.
A clear explanation of evaluating an expression with plus, minus, spaces, and parentheses using a stack.
A median-based solution for minimizing total Manhattan distance in a grid.
A clear explanation of computing the total covered area of two axis-aligned rectangles by subtracting their overlap.
Find all duplicated numbers in an array in O(n) time and O(1) extra space using index marking.
Find the maximum number of complete staircase rows that can be formed using binary search and triangular numbers.
A clear explanation of finding the third distinct maximum number using one pass and constant space.
A clear explanation of Reverse Vowels of a String using two pointers and selective swaps.
A clear explanation of grouping binary tree nodes by the round in which they become leaves using postorder DFS.
A clear explanation of Remove Duplicate Letters using a greedy monotonic stack.
A clear explanation of checking whether many small axis-aligned rectangles form one exact rectangular cover using area and corner parity.
A clear explanation of the H-Index II problem using binary search on a sorted citations array.
A two-heap data structure for adding numbers from a stream and returning the current median in constant time.
A clear explanation of counting nodes in a complete binary tree faster than visiting every node.
A clear explanation of deciding whether a rolling ball can stop at the destination using BFS or DFS over stopping cells.
A clear explanation of Reverse String using two pointers and in-place swaps.
A clear explanation of counting arithmetic subarrays using dynamic programming and consecutive differences.
A clear explanation of solving the Can I Win game using minimax recursion, bitmask state compression, and memoization.
A clear explanation of Count of Smaller Numbers After Self using coordinate compression and a Fenwick Tree.
Find the k-th integer in lexicographical order without generating all numbers, using prefix counting over a conceptual trie.
A clear explanation of solving the Water and Jug Problem using Bézout's identity and greatest common divisor.
A clear explanation of finding the last remaining number after alternating left-to-right and right-to-left eliminations.
A clear explanation of the H-Index problem using sorting, then an optimized counting approach.
A recursive game theory solution with memoization for deciding whether the starting player can force a win.
A clear explanation of finding the largest square of 1s in a binary matrix using dynamic programming.
A simple string scanning solution for generating every possible next state after flipping one consecutive ++ pair into --.
A clear explanation of the Integer to English Words problem using three-digit chunks and scale words.
A game theory solution for deciding whether the first player can win by using the losing-position pattern of multiples of four.
A clear explanation of checking nearby indices with nearby values using a sliding window and bucket hashing.
A clear explanation of the Closest Binary Search Tree Value II problem using inorder traversal and a fixed-size sliding window.
A backtracking solution for matching a pattern string to a target string using a bijective character-to-substring mapping.
A clear explanation of detecting whether equal values appear within distance k using a hash map or sliding window set.
A hash map solution for checking whether a pattern string and a space-separated word string form a bijection.
A clear explanation of the Encode and Decode Strings problem using length-prefix encoding.
An in-place matrix simulation for computing the next state of Conway's Game of Life using temporary encoded states.
A clear explanation of checking whether two strings are anagrams using character frequency counting.
A clear explanation of the Closest Binary Search Tree Value problem using the BST property to walk toward the target.
A clear explanation of computing the skyline formed by buildings using sweep line and a max-heap.
A clear explanation of the Alien Dictionary problem using graph construction and topological sorting.
A clear explanation of detecting duplicates in an array using a hash set and sorting.
A clear explanation of generating all possible results from different parenthesizations using divide and conquer recursion.
A clear explanation of the Missing Number problem using sum formula and XOR.
A clear explanation of finding k distinct numbers from 1 to 9 that sum to n using backtracking.
A hash map design for checking whether a word's abbreviation is unique in a dictionary.
A clear explanation of searching a row-sorted and column-sorted matrix using the top-right corner elimination method.
A clear explanation of finding the kth largest element using sorting, a min-heap, and Quickselect.
A clear explanation of the Palindrome Permutation II problem using character counts and backtracking over half of the palindrome.
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.
A clear explanation of finding the minimum path sum in a triangle using bottom-up dynamic programming.
Sort a singly linked list using insertion sort by splicing each node into a growing sorted list.
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.