Skip to contentKEEP THE CRAFTTHE SANCTUARY

The Library

All 188 problems on one shelf, ten free to begin, or follow Blind 75 and NeetCode 150. Search also finds the lessons and skills; the roadmap waits on the map table.

The problem shelf

Difficulty
Kind

188 problems

  1. Contains DuplicateEasyInterviewFreeDecide whether any value appears twice by remembering every value you have already seen.
  2. Two SumEasyInterviewFreeFind two distinct indices whose values add to a target.
  3. Valid AnagramEasyInterviewFreeCheck whether two strings use exactly the same letters the same number of times.
  4. Group AnagramsMediumInterviewFreePut words that are anagrams of each other into the same group.
  5. Merge IntervalsMediumInterviewFreeSort intervals by start, then extend the last merged interval or start a new one.
  6. Best Non-Adjacent Sum for Every PrefixEasyPracticeFill the house-robber DP table: the best non-adjacent total from the first i values.
  7. Best Sum Ending at Each IndexEasyPracticeRecord Kadane's running value: the best sum of a run that ends exactly at each index.
  8. Build Prefix SumsEasyPracticeBuild the prefix sum list with a leading 0, so any range sum becomes one subtraction.
  9. Cancel Adjacent Equal PairsEasyPracticeRemove equal neighbors, including pairs created by earlier removals, with one stack pass.
  10. Clone Records with Random LinksEasyPracticeDeep-copy records that link to each other: make every copy first, then wire the links.
  11. Count VowelsEasyPracticeCount how many vowels a string contains, ignoring case.
  12. Count Word FrequenciesEasyPracticeTurn a list of words into a dictionary from each word to how many times it appears.
  13. Design HashMapEasyInterviewBuild a key-value map from an array of buckets, without a built-in dict.
  14. Design HashSetEasyInterviewBuild a set of integers from an array of buckets, without a built-in set or dict.
  15. Discard Pairs with Two PointersEasyPracticeCount pairs in a sorted list whose sum is below a limit, counting a whole block of partners at once.
  16. Distance to the Nearest SourceEasyPracticeFill a grid with each cell's distance to the nearest source, going around blocked cells.
  17. Extend a Path by One ChoiceEasyPracticePractise choose, record a copy, and un-choose on one level of a backtracking search.
  18. Find a Key in Hash BucketsEasyPracticeLook up a key in a hand-built hash table: hash to one bucket, then compare exact keys.
  19. Find the First True BoundaryEasyPracticeBinary search for the first True: if mid is True, save it and keep looking to the left.
  20. Find the Middle NodeEasyPracticeFind the middle node of an index-based linked list in one pass with slow and fast pointers.
  21. Follow Trie EdgesEasyPracticeBuild a trie and measure how far each query follows it from the root.
  22. Implement Stack Using QueuesEasyInterviewBuild a last-in, first-out stack out of a first-in, first-out queue.
  23. Keep the K Largest ValuesEasyPracticeKeep the k largest values with a min-heap of size k and return them in ascending order.
  24. Mark Seen IndicesEasyPracticeRecord which labels from 1 to n appear by sending label v to index v - 1.
  25. Merge Two Ordered RunsEasyPracticeMerge two sorted lists into one sorted list in a single pass.
  26. Normalize TextEasyPracticeLowercase a string and squeeze all of its whitespace down to single spaces.
  27. Partition Traversal RangesEasyPracticeList the index ranges you split when rebuilding a binary tree from its preorder and inorder traversals.
  28. Practice Deque OperationsEasyPracticeRun a list of add and remove commands on both ends of a collections.deque and report what each remove returns.
  29. Previous Smaller ElementEasyPracticeFor each value, find the nearest earlier value that is strictly smaller.
  30. Rank Top WordsEasyPracticeSort words by count, high to low, break ties alphabetically, and keep the first few.
  31. Reverse One Slice SegmentEasyPracticeReverse only text[start:end] by cutting the string into three slices and joining them back.
  32. Reverse Text with SlicingEasyPracticeReverse a string with one slice and learn why start and stop can be left out.
  33. Root-to-Leaf Path SumsEasyPracticeList the sum of every root-to-leaf path by carrying a running total down a DFS.
  34. Shrink Until the Window Is ValidEasyPracticeGrow the window on the right, shrink it from the left while the sum is too big, and keep the longest one.
  35. Simulate a Circular BufferEasyPracticeRun a fixed-size queue in a list with a head index, a count and wraparound.
  36. Slide a Fixed WindowEasyPracticeSlide a window of fixed width: add the value coming in, drop the value going out, record the sum.
  37. Smallest Square That FitsEasyPracticeBinary-search the smallest square side that can hold a given number of items.
  38. Sum Each Tree LevelEasyPracticeAdd up the values on each level of a tree, from the top level down.
  39. Tokenize WordsEasyPracticeSplit text into a list of lowercase words on any whitespace.
  40. Topological Sort in LayersEasyPracticeGroup the nodes of a directed graph into layers that respect every edge, or detect a cycle.
  41. Track Previously Seen ValuesEasyPracticeReport for each value whether it appeared earlier, using a set: look back first, then store.
  42. Unlink One Node from a Linked ListEasyPracticeSkip one node of an index-based linked list by pointing the node before it at the node after it.
  43. Visit Each Grid ComponentEasyPracticeMeasure every connected region of 1s in a grid, in scan order.
  44. Add Two NumbersMediumInterviewAdd two numbers stored as reversed digit lists, carrying just like column addition.
  45. Answer Connected Queries with Union-FindMediumPracticeMerge groups with union and answer connected queries with Union-Find.
  46. Answer Matrix Region SumsMediumPracticeBuild a 2D prefix-sum table once, then answer each rectangle sum from four corners.
  47. Apply Range AdditionsMediumPracticeMark each range update at its two ends, then recover every value with one running sum.
  48. Binary Search a Globally Sorted MatrixMediumInterviewSearch a matrix whose rows, read one after another, form a single sorted list.
  49. Binary Subarrays With SumMediumInterviewCount subarrays of 0s and 1s that add up to goal, using prefix sums and a dictionary of counts.
  50. Binary Tree Level OrderMediumInterviewReturn the values of a binary tree level by level, from left to right.
  51. Binary Tree Right Side ViewMediumInterviewReturn the value you would see at each level when looking at the tree from the right.
  52. Bottom-Up Level Order TraversalMediumInterviewList a tree's levels from the deepest one up to the root.
  53. Build a KMP Prefix TableMediumPracticeBuild the KMP longest-prefix-suffix (LPS) table in one pass, falling back to lps[j - 1] after a mismatch instead of starting over.
  54. Build a Unique AssignmentMediumPracticeGive every position a different allowed value, undoing choices that lead to a dead end.
  55. Build and Query a Binary Search TreeMediumPracticeInsert values into a binary search tree, read them back with an in-order traversal, and answer search queries by walking down one path.
  56. Build Graph RepresentationsMediumPracticeTurn an undirected edge list into a sorted adjacency list and an adjacency matrix.
  57. Build Tree from Inorder and PostorderMediumInterviewRebuild a binary tree from its inorder and postorder traversals.
  58. Build Tree from Preorder and InorderMediumInterviewRebuild a binary tree from its preorder and inorder traversals.
  59. Car FleetMediumInterviewCount how many groups of cars reach the target, scanning from the car closest to it.
  60. Choose Non-Adjacent Tree ValuesMediumPracticeReturn two answers from every subtree, with the node taken and with it skipped, and combine them at the parent.
  61. Coalesce Busy BlocksMediumPracticeMerge overlapping busy blocks with the sort-and-merge template, keeping touching half-open blocks apart.
  62. Compact Sorted ValuesMediumPracticeKeep one copy of each value in a sorted list with a read pointer and a write pointer.
  63. Compute All-Pairs Shortest PathsMediumPracticeFind the cheapest path between every pair of nodes by allowing one more middle stop per round (Floyd-Warshall).
  64. Compute GCD with EuclidMediumPracticeFind the greatest common divisor with Euclid's algorithm: replace (a, b) by (b, a % b) until b is 0.
  65. Compute Modular PowerMediumPracticeCompute base^exponent % modulus in O(log exponent) steps with fast exponentiation by squaring.
  66. Compute Nonnegative Shortest PathsMediumPracticeFind the cheapest distance from a source to every node of a weighted directed graph with the Dijkstra template.
  67. Copy a Random-Pointer ListMediumInterviewDeep-copy a list whose nodes also point at a random node, using a list of [value, random] records.
  68. Count Components with Union-FindMediumPracticeCount the connected components of an undirected graph with the union-find template.
  69. Count Good Nodes in a Binary TreeMediumInterviewCount the nodes that are at least as large as every node above them.
  70. Count Set BitsMediumPracticeCount the 1 bits of a nonnegative integer by clearing the lowest set bit until nothing is left.
  71. Count Subsequences by Minimum and MaximumMediumInterviewCount the subsequences whose smallest plus largest value is at most target.
  72. Course ScheduleMediumInterviewDecide whether every course can be taken by repeatedly taking courses with no unfinished prerequisites.
  73. Cutting RibbonsMediumInterviewFind the longest length you can cut at least k equal pieces of from a set of ribbons.
  74. Daily TemperaturesMediumInterviewFor each day, count the days until a warmer one with a monotonic stack of indices.
  75. Design a Task QueueMediumPracticeKeep tasks in arrival order with a deque, and return a sorted priority view without changing that order.
  76. Design Circular QueueMediumInterviewBuild a fixed-size first-in, first-out queue on a plain list whose free slots are reused by wrapping around.
  77. Detect a Directed CycleMediumPracticeFind a cycle in a directed graph with DFS and three node states: unvisited, on the current path, and finished.
  78. Diagonal Traverse IIMediumInterviewRead a jagged grid diagonal by diagonal, going from the bottom row up inside each diagonal.
  79. Encode and Decode StringsMediumInterviewTurn a list of strings into one string and back, even when the strings contain any character.
  80. Evaluate Reverse Polish NotationMediumInterviewEvaluate an arithmetic expression written in postfix order with a stack.
  81. Find a Linked-List Cycle EntranceMediumInterviewFind where a linked list's cycle begins with fast and slow pointers in O(1) extra space.
  82. Find a Peak ElementMediumInterviewReturn the index of any value that is bigger than both of its neighbors.
  83. Find All Duplicates in an ArrayMediumInterviewFind every value that appears twice, using the array itself as the seen-set.
  84. Find Every String MatchMediumPracticeSlide the pattern along the text, compare it character by character at each start, and record every start where it fully matches, overlaps included.
  85. Find K Closest ElementsMediumInterviewBinary search for where the best block of k neighbours of x starts in a sorted array.
  86. Find Peak Active SessionsMediumPracticeTurn sessions into start and end events, sort them, and track the largest running count.
  87. Find the Duplicate NumberMediumInterviewFind the one repeated value without changing the array or using extra memory.
  88. Find the First Matching IndexMediumPracticeScan a list once and return the index of the first value equal to the target.
  89. Find the Missing Number with Cyclic SortMediumPracticeSend every number to the index that matches its value, then find the empty seat.
  90. First and Last Target PositionMediumInterviewFind where a target's run of copies starts and ends in a sorted array.
  91. Friends of Appropriate AgesMediumInterviewCount one-way friend requests by counting people per age and checking the rules once for every pair of ages.
  92. Generate Balanced ParenthesesMediumInterviewList every balanced string made of n pairs of parentheses.
  93. Generate Primes with a SieveMediumPracticeList every prime up to a limit with the Sieve of Eratosthenes: cross out the multiples of each prime, starting at its square.
  94. Group Integers into Ordered BucketsMediumPracticeSplit integers into equal-width buckets, sort each bucket, and join the buckets in order.
  95. Grow a Spanning Tree with PrimMediumPracticeGrow a minimum spanning tree from node 0 with Prim's algorithm: a min-heap of edges leaving the tree.
  96. Heap SortMediumPracticeSort a list with heap sort: build a max-heap with sift_down, then move the largest value to the end again and again.
  97. House RobberMediumInterviewPick houses to rob so that no two are next to each other and the total is as large as possible.
  98. House Robber IIMediumInterviewRob houses arranged in a circle by solving the straight-street problem twice: once without the first house and once without the last.
  99. Implement TrieMediumInterviewStore words in a prefix tree so you can check whole words and prefixes in time proportional to their length.
  100. Insert GCD Nodes in a Linked ListMediumInterviewInsert a node holding the greatest common divisor between every pair of neighbors.
  101. Insert Into a Sorted Circular ListMediumInterviewInsert a value into a sorted circular list, including at the wrap from largest to smallest.
  102. K-Radius Subarray AveragesMediumInterviewFor each index, average the k values on each side of it, or return -1 when there are not enough.
  103. Keep the K Smallest Stream ValuesMediumPracticeKeep only k candidates in a heap while reading the values, then return the k smallest in order.
  104. Koko Eating BananasMediumInterviewBinary search the eating speed: find the slowest speed that still finishes every pile in time.
  105. Kruskal's Minimum Spanning TreeMediumPracticeConnect every node with the lightest set of edges by taking edges from lightest to heaviest and skipping any edge that would close a cycle.
  106. Kth Largest Element in an ArrayMediumInterviewFind the kth largest value by keeping only the k largest values in a min-heap.
  107. Kth Smallest in a BSTMediumInterviewFind the k-th smallest value in a binary search tree.
  108. Kth Smallest in a Sorted MatrixMediumInterviewMerge the sorted rows with a heap and stop at the kth value.
  109. Longest Consecutive SequenceMediumInterviewFind the length of the longest run of consecutive integers in an unsorted list.
  110. Longest Continuous Subarray Within LimitMediumInterviewFind the longest subarray whose largest and smallest values differ by at most limit.
  111. Longest Ones After Deleting One ElementMediumInterviewDelete exactly one element from a binary array and find the longest run of 1s that is left.
  112. Longest Repeating Character ReplacementMediumInterviewFind the longest substring that can become one repeated letter after at most k replacements.
  113. Longest Substring Without Repeating CharactersMediumInterviewFind the length of the longest contiguous part of a string with no repeated character.
  114. Lowest Common Ancestor in a BSTMediumInterviewFind the lowest common ancestor of two values in a binary search tree.
  115. LRU CacheMediumInterviewBuild a fixed-size cache that throws out the least recently used key, with O(1) get and put.
  116. Maintain Sliding-Window MaximumsMediumPracticeFind the maximum of every window as it slides, using a deque of indexes whose values decrease.
  117. Map Sum PairsMediumInterviewKeep a running total in each trie node so the sum of all keys with a given prefix is one walk away.
  118. Max Area of IslandMediumInterviewMeasure every island in the grid and return the largest area.
  119. Max Consecutive Ones IIIMediumInterviewFind the longest window of 0s and 1s that holds at most k zeros.
  120. Maximum Container AreaMediumInterviewPick two walls that hold the most water between them.
  121. Maximum Contiguous Subarray SumMediumInterviewFind the largest sum of any contiguous, nonempty part of an array.
  122. Maximum Sum of a Distinct Length-K SubarrayMediumInterviewFind the largest sum of k consecutive values that are all different.
  123. Maximum Unique String SplitMediumInterviewCut a string into as many pieces as possible while keeping every piece different.
  124. Measure a Minimum Spanning TreeMediumPracticeFind the weight of a minimum spanning tree with Kruskal's algorithm: sorted edges plus union-find.
  125. Memoize Grid PathsMediumPracticeCount down-and-right paths through a grid with blocked cells, caching each cell's answer.
  126. Merge Sorted RowsMediumPracticeMerge several sorted rows into one sorted list with a heap that holds one value per row.
  127. Min StackMediumInterviewDesign a stack that can also return its smallest value in constant time.
  128. Minimize Adjacent Merge CostMediumPracticeFill a table of the cheapest merge cost for every range, from short ranges to long ones.
  129. Minimum of a Rotated Sorted ArrayMediumInterviewFind the smallest value of a sorted array that has been rotated.
  130. Navigate a Grid with A*MediumPracticeFind the fewest moves across a grid with A*: a min-heap ordered by f = g + h, with Manhattan distance as h.
  131. Normalize Closed IntervalsMediumPracticeSort closed intervals and merge every pair that overlaps or touches.
  132. Number of IslandsMediumInterviewCount the islands of land cells joined up, down, left or right.
  133. Odd Even Linked ListMediumInterviewMove the nodes at odd positions in front of the nodes at even positions, keeping each group in order.
  134. Palindrome PartitioningMediumInterviewCut a string in every way that leaves only palindromes.
  135. Partition and Quick SortMediumPracticeSort a list with quick sort, using the Lomuto partition around the last value.
  136. Path Sum IIMediumInterviewList every root-to-leaf path whose values add up to a target.
  137. Peak Index in a Mountain ArrayMediumInterviewBinary search for the first downhill step of a mountain array.
  138. Permutation in StringMediumInterviewCheck whether some window of s2 holds exactly the same letters, in the same amounts, as s1.
  139. Permutations of Distinct ValuesMediumInterviewGenerate every ordering of a list of distinct integers.
  140. Phone Keypad Letter CombinationsMediumInterviewList every letter string a sequence of phone keypad digits can spell.
  141. Power Set of Distinct ValuesMediumInterviewReturn every subset of a list of distinct integers.
  142. Product Except SelfMediumInterviewFor each position, multiply every other number in the array, without division.
  143. Profile a Binary TreeMediumPracticeWalk a binary tree stored in a list level by level and report its node count, height and number of leaves.
  144. Recognize Three-Node Tree RotationsMediumPracticeSee what every AVL rotation case does to three inserted values: single or double, the median always ends up as the root.
  145. Relax Signed Edges with Bellman-FordMediumPracticeFind cheapest paths when weights can be negative by relaxing every edge in rounds, and detect a reachable negative cycle.
  146. Remove Nth Node From EndMediumInterviewRemove the nth node from the end of a linked list in one pass with two pointers and a dummy head.
  147. Reorder ListMediumInterviewRearrange a list as first, last, second, second-to-last, and so on, in place.
  148. Resolve a Weighted Random PickMediumInterviewTurn a random draw into an index, where each index is picked in proportion to its weight.
  149. Restore Valid IPv4 AddressesMediumInterviewPlace three dots in a digit string to form every valid IPv4 address.
  150. Reusable-Candidate Combination SumMediumInterviewFind every combination of candidates that adds up to target, using each candidate as often as you like.
  151. Roll a Window HashMediumPracticeCompute the polynomial hash of every fixed-size window, sliding from one window to the next in O(1) the way Rabin-Karp does.
  152. Rotting OrangesMediumInterviewFind how many minutes it takes for rot to reach every fresh orange.
  153. Search a Rotated Array With DuplicatesMediumInterviewSearch a rotated sorted array that may contain repeated values.
  154. Search a Rotated Sorted ArrayMediumInterviewFind a target in a sorted array that was rotated, still in O(log n) time.
  155. Search a Row-and-Column Sorted MatrixMediumInterviewSearch a matrix whose rows and columns are each sorted, by walking from the top-right corner.
  156. Seat Reservation ManagerMediumInterviewAlways hand out the smallest free seat, using a counter and a min-heap.
  157. Select the Kth Smallest ValueMediumPracticePartition around a pivot and keep only the side that holds the kth smallest value.
  158. Select the Most Non-Overlapping IntervalsMediumPracticeChoose as many non-overlapping intervals as possible by always keeping the one that ends first.
  159. Ship Packages Within D DaysMediumInterviewBinary search the ship's capacity: find the smallest one that ships every package, in order, within the given days.
  160. Shortest Subarray to Remove for Sorted OrderMediumInterviewRemove the shortest contiguous piece so that what is left is sorted.
  161. Shortest Subarray With OR at Least KMediumInterviewFind the shortest subarray whose bitwise OR is at least k.
  162. Simulate Fisher-Yates ShufflingMediumPracticeShuffle a copy of a list with Fisher-Yates: walk from the back and swap each position with a random earlier one, using given choices so the result can be checked.
  163. Simulate Reservoir SamplingMediumPracticeKeep a uniform sample of k items from a stream with Algorithm R, using given random numbers so the result can be checked.
  164. Single-Use Combination SumMediumInterviewList every unique combination that hits the target when each position can be used once and values may repeat.
  165. Sort a Bounded Integer RangeMediumPracticeSort integers from a small range by counting how often each value appears.
  166. Sort an ArrayMediumInterviewWrite merge sort: sort each half, then merge the two sorted halves.
  167. Sort Characters by FrequencyMediumInterviewRebuild a string so the most frequent characters come first, with each character's copies kept together.
  168. Sort Nonnegative Integers by DigitsMediumPracticeSort nonnegative integers one decimal digit at a time, from the ones digit up, with ten stable buckets per pass.
  169. Sorted List to Balanced BSTMediumInterviewTurn a sorted linked list into a height-balanced binary search tree.
  170. Split Linked List in PartsMediumInterviewCut a linked list into k consecutive parts whose sizes differ by at most one.
  171. Surrounded RegionsMediumInterviewFlip every region of 'O' cells that cannot reach the edge of the board.
  172. Tabulate Minimum Coin CountMediumPracticeFill a table of the fewest coins for every amount from 0 up to the target.
  173. Target SumMediumInterviewCount how many ways to put + or - in front of every number so the total equals the target.
  174. Time-Based Key-Value StoreMediumInterviewStore several timestamped values per key and return the latest one at or before a given time.
  175. Top K Frequent ElementsMediumInterviewCount each value, group values by how often they appear, and read the groups from most to least frequent.
  176. Track Stock State with a FeeMediumPracticeTrack two states each day, holding a share or not, and charge the fee when you sell.
  177. Unique Subsets With Duplicate InputsMediumInterviewReturn every subset exactly once when the input contains repeated values.
  178. Unique Zero-Sum TripletsMediumInterviewFind every distinct triplet of numbers that adds up to zero.
  179. Validate a Binary Search TreeMediumInterviewCheck that every node fits strictly inside the range its ancestors allow.
  180. Validate a Bipartite GraphMediumPracticeCheck whether an undirected graph can be painted with two colors by BFS coloring every part of it.
  181. Validate a Partial SudokuMediumInterviewCheck that no digit repeats in any row, column, or 3-by-3 box of a partly filled Sudoku board.
  182. Walls and GatesMediumInterviewFill every empty room with its distance to the nearest gate.
  183. Wildcard Word DictionaryMediumInterviewStore words in a trie and search them with patterns where a dot stands for any one letter.
  184. Word Search in a Character GridMediumInterviewDecide whether a word can be traced through neighbouring grid cells without reusing a cell.
  185. Zigzag Level Order TraversalMediumInterviewRead a tree level by level, switching direction on every level.
  186. Maintain Segment-Tree Range SumsHardPracticeAnswer inclusive range sums while single values change, using a segment tree stored in one array.
  187. Prefix and Range Sums with a Fenwick TreeHardPracticeKeep prefix and range sums up to date while numbers change, using a Fenwick tree.
  188. Word Search IIHardInterviewFind every dictionary word on a letter board by walking the board and a trie together.

Keep the craft