brain

tamnd's digital brain — notes, problems, research

42768 notes

LeetCode 142: Linked List Cycle II

Find the node where a linked list cycle begins using Floyd’s tortoise and hare algorithm with cycle entry mathematics.

leetcodemediumlinked-listtwo-pointersmath
LeetCode 117: Populating Next Right Pointers in Each Node II

A clear explanation of connecting next pointers in any binary tree using constant extra space.

leetcodetreebinary-treelinked-listbfs
LeetCode 91: Decode Ways

A detailed guide to solving Decode Ways with dynamic programming and careful handling of zeroes.

leetcodestringdynamic-programming
LeetCode 69: Sqrt(x)

A clear guide to computing the integer square root using binary search without built-in exponent functions.

leetcodemathbinary-search
LeetCode 168: Excel Sheet Column Title

A clear explanation of converting a positive integer into an Excel column title using bijective base 26.

leetcodemathstringbase-conversion
LeetCode 116: Populating Next Right Pointers in Each Node

A clear explanation of connecting next pointers in a perfect binary tree using constant extra space.

leetcodetreebinary-treebfslinked-list
LeetCode 167: Two Sum II - Input Array Is Sorted

A clear explanation of finding two numbers in a sorted array using two pointers and constant extra space.

leetcodearraytwo-pointersbinary-search
LeetCode 115: Distinct Subsequences

A clear explanation of counting distinct subsequences using dynamic programming.

leetcodedynamic-programmingstring
LeetCode 141: Linked List Cycle

Detect whether a linked list contains a cycle using Floyd’s tortoise and hare two-pointer algorithm.

leetcodeeasylinked-listtwo-pointers
LeetCode 114: Flatten Binary Tree to Linked List

A clear explanation of flattening a binary tree into a linked list in preorder traversal order using recursive depth-first search.

leetcodetreebinary-treelinked-listdfsrecursion
LeetCode 90: Subsets II

A detailed guide to solving Subsets II with sorting, backtracking, and duplicate skipping.

leetcodearraybacktrackingbit-manipulation
LeetCode 68: Text Justification

A clear guide to formatting text with greedy line packing and even space distribution.

leetcodearraystringsimulationgreedy
LeetCode 191: Number of 1 Bits

A clear explanation of counting set bits in an integer using bit manipulation and Brian Kernighan's algorithm.

leetcodebit-manipulationinteger
LeetCode 166: Fraction to Recurring Decimal

A clear explanation of converting a fraction into decimal form and detecting repeating fractional parts with a hash map.

leetcodehash-tablemathstring
LeetCode 113: Path Sum II

A clear explanation of finding all root-to-leaf paths whose values add up to a target sum using depth-first search and backtracking.

leetcodetreebinary-treedfsbacktrackingrecursion
LeetCode 67: Add Binary

A clear guide to adding two binary strings using two pointers and a carry.

leetcodestringmathsimulationbinary
LeetCode 89: Gray Code

A detailed guide to solving Gray Code using the binary-to-Gray-code formula.

leetcodemathbit-manipulationbacktracking
LeetCode 112: Path Sum

A clear explanation of checking whether a binary tree has a root-to-leaf path whose values add up to a target sum.

leetcodetreebinary-treedfsrecursion
LeetCode 140: Word Break II

Return all valid sentences formed by inserting spaces into a string so every word belongs to the dictionary, using DFS with memoization.

leetcodehardstringdynamic-programmingbacktrackingmemoizationhash-set
LeetCode 66: Plus One

A clear guide to adding one to a large integer represented as an array of digits.

leetcodearraymath
LeetCode 139: Word Break

Decide whether a string can be segmented into dictionary words using dynamic programming over prefixes.

leetcodemediumstringdynamic-programminghash-settrie
LeetCode 111: Minimum Depth of Binary Tree

A clear explanation of finding the minimum depth of a binary tree using breadth-first search.

leetcodetreebinary-treebfsqueue
LeetCode 88: Merge Sorted Array

A detailed guide to solving Merge Sorted Array in-place by merging from the back with three pointers.

leetcodearraytwo-pointerssorting
LeetCode 65: Valid Number

A clear guide to validating whether a string is a valid number using grammar rules and one left-to-right scan.

leetcodestringfinite-state-machineparsing
LeetCode 265: Paint House II

A clear explanation of the Paint House II problem using optimized dynamic programming with minimum and second minimum tracking.

leetcodedynamic-programmingarrayoptimization
LeetCode 110: Balanced Binary Tree

A clear explanation of checking whether a binary tree is height-balanced using bottom-up depth-first search.

leetcodetreebinary-treedfsrecursion
LeetCode 138: Copy List with Random Pointer

Create a deep copy of a linked list with next and random pointers using hash maps or interleaved node cloning.

leetcodemediumlinked-listhash-map
LeetCode 165: Compare Version Numbers

A clear explanation of comparing version strings revision by revision while ignoring leading zeros.

leetcodestringtwo-pointers
LeetCode 40: Combination Sum II

A clear explanation of finding unique combinations that sum to a target when each array element may be used at most once.

leetcodearraybacktrackingsorting
LeetCode 212: Word Search II

A clear explanation of finding multiple words in a character board using a Trie and DFS backtracking.

leetcodetriedfsbacktrackingmatrix
LeetCode 412: Fizz Buzz

A clear explanation of the Fizz Buzz problem using direct simulation and divisibility checks.

leetcodemathstringsimulation
LeetCode 190: Reverse Bits

A clear explanation of reversing the bits of a 32-bit integer using bit manipulation.

leetcodebit-manipulationinteger
LeetCode 489: Robot Room Cleaner

A clear explanation of cleaning an unknown grid using DFS, relative coordinates, and physical backtracking.

leetcodedfsbacktrackingsimulationrobot
LeetCode 314: Binary Tree Vertical Order Traversal

A clear explanation of Binary Tree Vertical Order Traversal using BFS with column indices.

leetcodebinary-treebfshash-tabletree
LeetCode 463: Island Perimeter

A clear explanation of counting the perimeter of an island in a grid by adding land-cell edges and subtracting shared edges.

leetcodearraymatrixsimulationcounting
LeetCode 87: Scramble String

A detailed guide to solving Scramble String with recursive dynamic programming and memoization.

leetcodestringdynamic-programmingrecursionmemoization
LeetCode 343: Integer Break

A clear explanation of Integer Break using dynamic programming, with a note on the greedy math solution.

leetcodemathdynamic-programming
LeetCode 364: Nested List Weight Sum II

A clear explanation of computing inverse depth weighted sum using level-order traversal.

leetcodedfsbfsnested-listtree
LeetCode 389: Find the Difference

A clear explanation of finding the extra character added to a shuffled string using counting and XOR.

leetcodestringhash-tablebit-manipulation
LeetCode 64: Minimum Path Sum

A clear guide to finding the minimum path sum in a grid using dynamic programming.

leetcodedynamic-programmingmatrix
LeetCode 285: Inorder Successor in BST

A binary-search-style solution for finding the smallest node greater than p in a binary search tree.

leetcodebinary-search-treetreebinary-search
LeetCode 237: Delete Node in a Linked List

A clear explanation of deleting a node from a singly linked list when only that node is given.

leetcodelinked-listin-place
LeetCode 109: Convert Sorted List to Binary Search Tree

A clear explanation of converting a sorted linked list into a height-balanced binary search tree using slow and fast pointers.

leetcodelinked-listtreebinary-search-treedfsdivide-and-conquertwo-pointers
LeetCode 439: Ternary Expression Parser

Evaluate a nested ternary expression using a right-to-left stack parser.

leetcodestringstackparsing
LeetCode 264: Ugly Number II

A clear explanation of the Ugly Number II problem using dynamic programming with three pointers.

leetcodedynamic-programmingmaththree-pointers
LeetCode 137: Single Number II

Find the number that appears once when every other number appears three times using bit counting or finite-state bit manipulation.

leetcodemediumarraybit-manipulation
LeetCode 39: Combination Sum

A clear explanation of finding all unique combinations that sum to a target using backtracking.

leetcodearraybacktracking
LeetCode 211: Design Add and Search Words Data Structure

A clear explanation of designing a word dictionary with addWord and wildcard search using a Trie and DFS.

leetcodetriedfsbacktrackingdesign
LeetCode 411: Minimum Unique Word Abbreviation

A clear explanation of finding the shortest abbreviation that does not conflict with any dictionary word using bit masks.

leetcodebit-manipulationbacktrackingstringenumeration
LeetCode 189: Rotate Array

A clear explanation of rotating an array to the right by k steps using in-place reversal.

leetcodearraytwo-pointersin-place
LeetCode 164: Maximum Gap

A clear explanation of finding the maximum adjacent gap in sorted order using buckets and the pigeonhole principle.

leetcodearraybucket-sortradix-sortsorting
LeetCode 313: Super Ugly Number

A clear explanation of Super Ugly Number using dynamic programming with one pointer per prime.

leetcodedynamic-programmingmathheap
LeetCode 488: Zuma Game

A clear explanation of solving Zuma Game with DFS, memoization, and chain-removal simulation.

leetcodestringdfsmemoizationbacktracking
LeetCode 342: Power of Four

A clear explanation of Power of Four using bit manipulation and binary properties.

leetcodemathbit-manipulation
LeetCode 462: Minimum Moves to Equal Array Elements II

A clear explanation of why the median minimizes the number of moves needed to make all array elements equal.

leetcodearraymathsortingmedian
LeetCode 86: Partition List

A detailed guide to solving Partition List with two dummy lists while preserving relative order.

leetcodelinked-listtwo-pointers
LeetCode 363: Max Sum of Rectangle No Larger Than K

A clear explanation of reducing a 2D rectangle problem to a 1D prefix-sum problem with binary search.

leetcodearraymatrixprefix-sumbinary-searchordered-set
LeetCode 63: Unique Paths II

A clear guide to counting unique paths in a grid with obstacles using dynamic programming.

leetcodedynamic-programmingmatrix
LeetCode 284: Peeking Iterator

A wrapper iterator design that supports peeking at the next element without advancing the iterator.

leetcodedesigniteratorobject-oriented-programming
LeetCode 388: Longest Absolute File Path

A clear explanation of computing the longest absolute path to a file from a serialized file system string using path lengths by depth.

leetcodestringstackhash-table
LeetCode 108: Convert Sorted Array to Binary Search Tree

A clear explanation of building a height-balanced binary search tree from a sorted array using divide and conquer.

leetcodetreebinary-search-treedfsrecursiondivide-and-conquer
LeetCode 438: Find All Anagrams in a String

Find all starting indices where an anagram of p appears in s using a fixed-size sliding window.

leetcodehash-tablestringsliding-window
LeetCode 136: Single Number

Find the only number that appears once using the XOR operator, while every other number appears exactly twice.

leetcodeeasyarraybit-manipulationxor
LeetCode 263: Ugly Number

A clear explanation of the Ugly Number problem using repeated division by the only allowed prime factors.

leetcodemathnumber-theory
LeetCode 210: Course Schedule II

A clear explanation of finding a valid course ordering using topological sorting and cycle detection.

leetcodegraphtopological-sortbfsdfs
LeetCode 236: Lowest Common Ancestor of a Binary Tree

A clear explanation of finding the lowest common ancestor in a normal binary tree using recursive depth-first search.

leetcodetreebinary-treedfsrecursion
LeetCode 38: Count and Say

A clear explanation of generating the count-and-say sequence using run-length encoding.

leetcodestringsimulationrun-length-encoding
LeetCode 37: Sudoku Solver

A clear explanation of solving a Sudoku board using backtracking and constraint checking.

leetcodebacktrackingmatrixhash-table
LeetCode 410: Split Array Largest Sum

A clear explanation of minimizing the largest subarray sum using binary search on the answer and greedy validation.

leetcodearraybinary-searchgreedydynamic-programming
LeetCode 188: Best Time to Buy and Sell Stock IV

A clear explanation of maximizing stock trading profit with at most k transactions using dynamic programming.

leetcodearraydynamic-programmingstock
LeetCode 163: Missing Ranges

A clear explanation of finding all missing ranges inside an inclusive interval by scanning sorted unique numbers.

leetcodearraysimulation
LeetCode 312: Burst Balloons

A clear explanation of Burst Balloons using interval dynamic programming and the last-burst idea.

leetcodearraydynamic-programminginterval-dp
LeetCode 487: Max Consecutive Ones II

A clear explanation of finding the longest run of 1s after flipping at most one 0 using a sliding window.

leetcodearraysliding-windowtwo-pointers
LeetCode 341: Flatten Nested List Iterator

A clear explanation of Flatten Nested List Iterator using lazy stack-based flattening.

leetcodestackdfsiteratordesign
LeetCode 461: Hamming Distance

A clear explanation of computing the Hamming distance between two integers using XOR and bit counting.

leetcodebit-manipulation
LeetCode 283: Move Zeroes

A two-pointer in-place solution for moving all zeroes to the end while preserving the relative order of non-zero elements.

leetcodearraytwo-pointersin-place
LeetCode 62: Unique Paths

A clear guide to counting unique paths in a grid using dynamic programming.

leetcodedynamic-programmingmatrixcombinatorics
LeetCode 362: Design Hit Counter

A clear explanation of designing a hit counter for the last 5 minutes using a queue with compressed timestamps.

leetcodedesignqueuedata-stream
LeetCode 61: Rotate List

A clear guide to rotating a linked list to the right by k places using a circular list.

leetcodelinked-listtwo-pointers
LeetCode 387: First Unique Character in a String

A clear explanation of finding the first non-repeating character in a string using character frequency counting.

leetcodestringhash-tablecounting
LeetCode 107: Binary Tree Level Order Traversal II

A clear explanation of returning binary tree levels from bottom to top using breadth-first search.

leetcodetreebinary-treebfsqueue
LeetCode 437: Path Sum III

Count downward paths in a binary tree whose values sum to targetSum using DFS and prefix sums.

leetcodetreebinary-treedfsprefix-sumhash-table
LeetCode 235: Lowest Common Ancestor of a Binary Search Tree

A clear explanation of finding the lowest common ancestor in a binary search tree using BST ordering properties.

leetcodetreebinary-search-treedfs
LeetCode 85: Maximal Rectangle

A detailed guide to solving Maximal Rectangle by converting each matrix row into a histogram and applying a monotonic stack.

leetcodearraydynamic-programmingstackmonotonic-stackmatrix
LeetCode 262: Trips and Users

A clear explanation of the Trips and Users SQL problem using joins, filtering, grouping, and conditional aggregation.

leetcodesqldatabasejoingroup-byaggregation
LeetCode 135: Candy

Compute the minimum candies needed using two greedy passes, one from the left and one from the right.

leetcodehardarraygreedy
LeetCode 209: Minimum Size Subarray Sum

A clear explanation of finding the shortest contiguous subarray whose sum is at least target using a sliding window.

leetcodearraysliding-windowtwo-pointers
LeetCode 187: Repeated DNA Sequences

A clear explanation of finding repeated 10-letter DNA substrings using a fixed-size sliding window and hash sets.

leetcodestringhash-tablesliding-windowrolling-hash
LeetCode 36: Valid Sudoku

A clear explanation of checking whether a partially filled Sudoku board is valid using hash sets.

leetcodearrayhash-tablematrix
LeetCode 409: Longest Palindrome

A clear explanation of finding the longest palindrome length that can be built from given letters using character counts.

leetcodehash-tablestringgreedycounting
LeetCode 162: Find Peak Element

A clear explanation of finding any peak element using binary search on the slope of the array.

leetcodearraybinary-search
LeetCode 311: Sparse Matrix Multiplication

A clear explanation of Sparse Matrix Multiplication using non-zero entries to avoid wasted work.

leetcodematrixhash-tablesimulation
LeetCode 486: Predict the Winner

A clear explanation of predicting whether Player 1 can win using minimax dynamic programming over score difference.

leetcodearraydynamic-programminggame-theoryrecursion
LeetCode 340: Longest Substring with At Most K Distinct Characters

A clear explanation of Longest Substring with At Most K Distinct Characters using a sliding window and character counts.

leetcodestringhash-tablesliding-window
LeetCode 339: Nested List Weight Sum

A clear explanation of Nested List Weight Sum using depth-first search over a nested structure.

leetcodedepth-first-searchbreadth-first-searchrecursion
LeetCode 338: Counting Bits

A clear explanation of Counting Bits using dynamic programming and bit manipulation.

leetcodedynamic-programmingbit-manipulation
LeetCode 282: Expression Add Operators

A backtracking solution for inserting operators into a numeric string so the expression evaluates to a target value.

leetcodebacktrackingdfsstringrecursion
LeetCode 460: LFU Cache

A clear explanation of designing an LFU cache with O(1) average get and put operations.

leetcodehash-maplinked-listdesignlfu-cache
LeetCode 459: Repeated Substring Pattern

A clear explanation of checking whether a string can be built by repeating one of its proper substrings.

leetcodestringstring-matching
LeetCode 60: Permutation Sequence

A clear guide to finding the kth permutation sequence using factorial blocks instead of generating all permutations.

leetcodemathrecursionpermutation