// practice
Practice
Problems and design prompts with explanations that connect the idea to how software runs — then try the exercise yourself.
- 01dsaDesign a skip listImplement search, add and erase on a skip list with probabilistic heights, handle duplicates correctly, and measure how close average searches stay to log2 n.hardLeetCodeOct 7, 2026
- 02dsaDesign a bounded blocking queueBuild a thread-safe queue with a fixed capacity: enqueue blocks when full, dequeue blocks when empty, and no call busy-waits.mediumLeetCodeOct 7, 2026
- 03dsaRange sum query: immutableAnswer many range-sum queries on a fixed array in O(1) each with a prefix-sum array.easyLeetCodeOct 5, 2026
- 04dsaRunning sum of an arrayReturn the running totals of an array, and see why recomputing each total from scratch is quadratic.easyLeetCodeOct 5, 2026
- 05dsaCapacity to ship packages within D daysFind the smallest ship capacity that delivers packages in order within D days, by binary searching capacities with a greedy check.mediumLeetCodeOct 5, 2026
- 06dsaPow(x, n)Compute x to the power n with O(log n) multiplications by halving the exponent, including negative exponents.mediumLeetCodeOct 5, 2026
- 07dsaSearch a 2D matrix IISearch a matrix whose rows and columns are sorted independently, in O(m + n), with a staircase walk from the top-right corner.mediumLeetCodeOct 5, 2026
- 08dsaMissing numberAn array holds every number from 0 to n except one. Find it four ways and compare their time and space.easyLeetCodeOct 5, 2026
- 09dsaUTF-8 validationGiven a list of byte values, decide whether they form valid UTF-8, using the leading bits of each byte.mediumLeetCodeOct 5, 2026
- 10dsaMy calendar IAccept a booking only if it overlaps no existing one, by checking its neighbors in an ordered map.mediumLeetCodeOct 5, 2026
- 11dsaRange moduleTrack a set of half-open ranges under additions, removals and coverage queries, keeping disjoint intervals sorted.hardLeetCodeOct 5, 2026
- 12dsaStock price fluctuationHandle out-of-order and corrected price updates while reporting the latest, highest and lowest prices, with a hash map plus an ordered structure.mediumLeetCodeOct 5, 2026
- 13dsaFibonacci numberCompute the nth Fibonacci number recursively, measure the calls, then fix it with memoization and with a loop.easyLeetCodeOct 5, 2026
- 14dsaShortest common supersequenceBuild the shortest string containing both inputs as subsequences by walking back through an LCS table.hardLeetCodeOct 5, 2026
- 15dsaAccounts mergeMerge user accounts that share any email address, by unioning emails and grouping them by root.mediumLeetCodeOct 5, 2026
- 16dsaFind critical and pseudo-critical edges in a minimum spanning treeClassify each edge as in every minimum spanning tree, in some, or in none, by rerunning Kruskal with the edge removed or forced in.hardLeetCodeOct 5, 2026
- 17dsaFind eventual safe statesFind the vertices of a directed graph from which every path ends at a terminal vertex, using three-color DFS.mediumLeetCodeOct 5, 2026
- 18dsaFind if path exists in graphBuild adjacency lists from an edge list and decide whether two vertices are connected with BFS or DFS.easyLeetCodeOct 5, 2026
- 19dsaFind the city with the smallest number of neighbors at a threshold distanceCompute all-pairs distances with Floyd-Warshall, then count each city's neighbors within a distance limit.mediumLeetCodeOct 5, 2026
- 20dsaNumber of provincesCount the groups of cities connected directly or indirectly, given an adjacency matrix, with union-find.mediumLeetCodeOct 5, 2026
- 21dsaPath with minimum effortFind the route across a height grid whose largest single climb is as small as possible, with Dijkstra on bottleneck costs.mediumLeetCodeOct 5, 2026
- 22dsaSatisfiability of equality equationsDecide whether a set of equalities and inequalities between variables can all hold, by unioning the equalities first.mediumLeetCodeOct 5, 2026
- 23dsaSliding puzzleSolve a 2 × 3 sliding-tile puzzle in the fewest moves by searching the graph of board states, with BFS or A*.hardLeetCodeOct 5, 2026
- 24dsaContains duplicate IIIFind two values close in position and in value, with a ceiling query on an ordered window.hardLeetCodeOct 5, 2026
- 25dsaRandom pick with blacklistPick uniformly from 0 to n − 1 excluding a blacklist, with one random call per pick, by remapping blacklisted values through a hash map.hardLeetCodeOct 5, 2026
- 26dsaSubarray sum equals KCount the subarrays whose sum is exactly k, even with negative numbers, using prefix sums and a hash map.mediumLeetCodeOct 5, 2026
- 27dsaKth largest element in a streamReport the kth largest value after each insertion into a stream, with a min-heap that never holds more than k values.easyLeetCodeOct 5, 2026
- 28dsaMinimum cost to connect sticksJoin sticks into one, paying the sum of the two lengths each time, at minimum total cost, by always joining the two shortest.mediumLeetCodeOct 5, 2026
- 29dsaSliding window medianReport the median of every window of size k, with an ordered multiset or two heaps with lazy deletion.hardLeetCodeOct 5, 2026
- 30dsaMinimum number of arrows to burst balloonsShoot the fewest arrows to burst every horizontal balloon, shooting at the earliest end each time.mediumLeetCodeOct 5, 2026
- 31dsaDesign linked listImplement a linked list with get, add at head, add at tail, add at index and delete at index, handling every edge case.mediumLeetCodeOct 5, 2026
- 32dsaInsertion sort listSort a singly linked list with insertion sort, splicing each node into a growing sorted list behind a dummy head.mediumLeetCodeOct 5, 2026
- 33dsaLinked list random nodePick a uniformly random node from a linked list in one pass with O(1) extra memory, using reservoir sampling.mediumLeetCodeOct 5, 2026
- 34dsaMerge k sorted listsMerge k sorted linked lists into one, in O(N log k), with a min-heap of the current list heads.hardLeetCodeOct 5, 2026
- 35dsaSort listSort a linked list in O(n log n) time with merge sort, splitting at the middle with fast and slow pointers and merging by rewiring nodes.mediumLeetCodeOct 5, 2026
- 36dsaCount primesCount the primes below n, first by testing each number and then with the sieve of Eratosthenes, and compare how the two grow.mediumLeetCodeOct 5, 2026
- 37dsaShuffle an arrayReturn uniformly random permutations of an array with the Fisher-Yates shuffle, and restore the original on demand.mediumLeetCodeOct 5, 2026
- 38dsaShortest path in binary matrixFind the shortest clear path from the top-left to the bottom-right of a grid, moving in eight directions, with BFS.mediumLeetCodeOct 5, 2026
- 39dsaLargest numberArrange numbers so their concatenation is as large as possible, using a custom comparator that defines a valid total order.mediumLeetCodeOct 5, 2026
- 40dsaMaximum gapFind the largest difference between consecutive values in sorted order, in linear time, without a comparison sort.mediumLeetCodeOct 5, 2026
- 41dsaSort an arraySort an array of integers in O(n log n) without the built-in sort: implement merge sort, then quick sort with a random pivot, and compare.mediumLeetCodeOct 5, 2026
- 42dsaSort array by increasing frequencySort values by how often they occur, breaking ties by value in decreasing order, with a composite sort key.easyLeetCodeOct 5, 2026
- 43dsaDecode stringExpand an encoded string such as 3[a2[c]] into accaccacc, first recursively and then with an explicit stack.mediumLeetCodeOct 5, 2026
- 44dsaDesign a stack with increment operationSupport push, pop and adding a value to the bottom k elements, all in O(1), by recording increments lazily and passing them down on pop.mediumLeetCodeOct 5, 2026
- 45dsaDesign circular queueImplement a fixed-size queue on a ring buffer, with every operation in O(1) and correct full and empty checks.mediumLeetCodeOct 5, 2026
- 46dsaImplement queue using stacksBuild a FIFO queue from two LIFO stacks, and show that each operation is O(1) amortized.easyLeetCodeOct 5, 2026
- 47dsaOnline stock spanReport, for each new price, how many consecutive days up to today had a price at most today's, with a monotonic stack that is O(1) amortized per call.mediumLeetCodeOct 5, 2026
- 48dsaEncode and decode a list of stringsPack a list of arbitrary strings into a single contiguous byte buffer with length prefixes and decode it back without delimiter collisions.mediumLeetCodeOct 5, 2026
- 49dsaFind the first occurrence in a stringReturn the first index where a pattern occurs in a text, with Rabin-Karp or KMP in linear time.easyLeetCodeOct 5, 2026
- 50dsaRepeated DNA sequencesFind every 10-letter sequence that occurs more than once in a DNA string, by hashing a rolling window.mediumLeetCodeOct 5, 2026
- 51dsaShortest palindromeAdd the fewest characters to the front of a string to make it a palindrome, by finding its longest palindromic prefix with the prefix function.hardLeetCodeOct 5, 2026
- 52dsaBalance a binary search treeTurn any binary search tree into a balanced one with the same keys, by flattening it in order and rebuilding.mediumLeetCodeOct 5, 2026
- 53dsaBinary tree inorder traversalReturn the inorder traversal of a binary tree, first recursively and then iteratively with an explicit stack.easyLeetCodeOct 5, 2026
- 54dsaBinary tree maximum path sumFind the path with the largest sum of values anywhere in the tree, returning the best downward branch and recording the best turning path.hardLeetCodeOct 5, 2026
- 55dsaConvert sorted array to binary search treeBuild a height-balanced binary search tree from sorted values by making the middle value the root, recursively.easyLeetCodeOct 5, 2026
- 56dsaDelete node in a BSTDelete a key from a binary search tree, handling nodes with zero, one and two children.mediumLeetCodeOct 5, 2026
- 57dsaFlatten nested list iteratorIterate over the integers of an arbitrarily nested list lazily, keeping your place with an explicit stack instead of recursion.mediumLeetCodeOct 5, 2026
- 58dsaInsert into a binary search treeInsert a value into a binary search tree by searching for its empty spot and attaching a new leaf.mediumLeetCodeOct 5, 2026
- 59dsaLongest duplicate substringFind the longest substring that occurs at least twice, with a suffix array and LCP array, or binary search over rolling hashes.hardLeetCodeOct 5, 2026
- 60dsaMinimum depth of binary treeFind the depth of the shallowest leaf, stopping a level-order traversal at the first leaf it meets.easyLeetCodeOct 5, 2026
- 61dsaRepeated substring patternDecide whether a string is a shorter block repeated several times, using its smallest period from the prefix function.easyLeetCodeOct 5, 2026
- 62dsaMove zeroesMove every 0 in an array to the end while keeping the other elements in order, in place and in one pass.easyLeetCodeOct 5, 2026
- 63dsaDesign a hash mapBuild put, get and remove for a hash map from scratch, without using your language's built-in hash table.easyLeetCodeOct 3, 2026
- 64dsaContains duplicateReturn true if any value appears at least twice in an array of integers, and false if every value is distinct.easyLeetCodeOct 3, 2026
- 65dsaGroup anagramsGroup the words in a list that are anagrams of each other, using a key that every anagram of a word shares.mediumLeetCodeOct 3, 2026
- 66dsaTwo sumReturn the indices of the two numbers in an array that add up to a target value.easyLeetCodeOct 3, 2026
- 67system designDesign a Rate LimiterImplement a token bucket or fixed-window counter that allows bursts but enforces a steady request rate across many service instances.mediumLeetCodeSep 26, 2026
- 68dsaBest Time to Buy and Sell StockChoose one buy day and a later sell day to maximize positive profit; return zero if no profitable trade exists.easyLeetCodeSep 25, 2026
- 69dsaMajority elementFind the value that fills more than half of an array, and compare a hash map, sorting, a random guess and the Boyer-Moore vote.easyLeetCodeSep 25, 2026
- 70dsaProduct of array except selfReturn, for each index, the product of all other elements, with prefix and suffix products and no division.mediumLeetCodeSep 25, 2026
- 71dsaCombination sum IIFind every unique combination that sums to a target when each candidate may be used once and the input contains duplicates.mediumLeetCodeSep 25, 2026
- 72dsaCombination sumFind every combination of candidates, each usable any number of times, that adds up to a target, pruning once the sum is too large.mediumLeetCodeSep 25, 2026
- 73dsaGenerate parenthesesGenerate every well-formed string of n pairs of parentheses, never building an invalid prefix.mediumLeetCodeSep 25, 2026
- 74dsaN-queensPlace n queens on an n × n board so that no two attack each other, and return every solution, pruning by column and diagonal.hardLeetCodeSep 25, 2026
- 75dsaPalindrome partitioningSplit a string into pieces that are all palindromes, in every possible way.mediumLeetCodeSep 25, 2026
- 76dsaPermutationsReturn every ordering of an array of distinct integers, tracking which elements are already used.mediumLeetCodeSep 25, 2026
- 77dsaSubsetsReturn every subset of a set of distinct integers, using backtracking with a start index.mediumLeetCodeSep 25, 2026
- 78dsaBinary searchFind a target in a sorted array in O(log n), with a half-open range and an invariant that makes every boundary obvious.easyLeetCodeSep 25, 2026
- 79dsaFind the duplicate numberAn array of n + 1 numbers from 1 to n contains one repeated value. Find it without modifying the array and with O(1) extra space, by treating the array as a linked list with a cycle.mediumLeetCodeSep 25, 2026
- 80dsaFind first and last position of element in sorted arrayReturn the first and last index of a target in a sorted array with duplicates, using lower and upper bounds.mediumLeetCodeSep 25, 2026
- 81dsaFind minimum in rotated sorted arrayFind the smallest element of a rotated sorted array in O(log n) by comparing the middle with the right end.mediumLeetCodeSep 25, 2026
- 82dsaKoko eating bananasFind the slowest eating speed that finishes all piles within h hours, by binary searching over speeds with a feasibility check.mediumLeetCodeSep 25, 2026
- 83dsaMedian of two sorted arraysFind the median of two sorted arrays in O(log min(m, n)) by binary searching for the cut that splits all elements in half.hardLeetCodeSep 25, 2026
- 84dsaSearch a 2D matrixSearch a matrix whose rows continue each other in sorted order, as one flat sorted array of m × n elements.mediumLeetCodeSep 25, 2026
- 85dsaSearch insert positionReturn the index of a target in a sorted array, or where it would be inserted: the lower bound.easyLeetCodeSep 25, 2026
- 86dsaSearch in rotated sorted arrayFind a target in a sorted array that has been rotated, in O(log n), by identifying the sorted half at each step.mediumLeetCodeSep 25, 2026
- 87dsaCounting bitsFor every integer from 0 to n, return how many 1 bits it has, in a single pass.easyLeetCodeSep 25, 2026
- 88dsaNumber of 1 bitsCount how many bits are set in the binary form of a 32-bit unsigned integer.easyLeetCodeSep 25, 2026
- 89dsaSingle numberEvery value in an array appears twice except one. Find it in linear time and constant extra memory.easyLeetCodeSep 25, 2026
- 90dsaDesign add and search wordsStore words in a trie and search patterns in which a dot matches any letter, branching only where the pattern has a dot.mediumLeetCodeSep 25, 2026
- 91dsaLRU cacheBuild a fixed-capacity cache with O(1) get and put that evicts the least recently used key, using a hash map and a doubly linked list.mediumLeetCodeSep 25, 2026
- 92dsaTime based key-value storeStore values with timestamps and answer 'value as of time t' queries with an upper-bound search per key.mediumLeetCodeSep 25, 2026
- 93dsaBurst balloonsMaximize the coins from bursting balloons with an interval DP over which balloon in each range bursts last.hardLeetCodeSep 25, 2026
- 94dsaClimbing stairsCount the ways to climb n stairs one or two steps at a time, first with memoized recursion and then with two variables.easyLeetCodeSep 25, 2026
- 95dsaCoin changeFind the fewest coins that make an amount, with unlimited copies of each coin, using an unbounded knapsack table.mediumLeetCodeSep 25, 2026
- 96dsaCombination sum IVCount the ordered sequences of numbers that sum to a target, and see how the loop order decides whether orderings are counted.mediumLeetCodeSep 25, 2026
- 97dsaDecode waysCount the ways to decode a digit string into letters, adding the counts for one-digit and two-digit last letters.mediumLeetCodeSep 25, 2026
- 98dsaDistinct subsequencesCount how many times t appears as a subsequence of s with a two-string counting DP.hardLeetCodeSep 25, 2026
- 99dsaEdit distanceFind the fewest insertions, deletions and replacements to turn one word into another, with a table over prefixes, then in two rows.mediumLeetCodeSep 25, 2026
- 100dsaHouse robber IIRob houses arranged in a circle by solving the straight-line problem twice, once without the first house and once without the last.mediumLeetCodeSep 25, 2026
- 101dsaHouse robberMaximize the loot from houses on a street without robbing two neighbors, with a take-or-skip recurrence.mediumLeetCodeSep 25, 2026
- 102dsaLongest common subsequenceFind the length of the longest subsequence shared by two strings with a table over their prefixes.mediumLeetCodeSep 25, 2026
- 103dsaLongest increasing subsequenceFind the length of the longest strictly increasing subsequence, in O(n²) with DP and in O(n log n) with patience tails.mediumLeetCodeSep 25, 2026
- 104dsaLongest palindromic subsequenceFind the longest subsequence of a string that reads the same backward, with an interval DP on the string's two ends.mediumLeetCodeSep 25, 2026
- 105dsaMaximum subarrayFind the largest sum of a contiguous subarray in O(n) with Kadane's best-ending-here recurrence.mediumLeetCodeSep 25, 2026
- 106dsaMin cost climbing stairsFind the cheapest way to the top of a staircase where each step has a cost, filling a table from the bottom up.easyLeetCodeSep 25, 2026
- 107dsaPartition equal subset sumDecide whether an array can be split into two equal-sum halves, as a subset-sum table with a downward loop.mediumLeetCodeSep 25, 2026
- 108dsaRegular expression matchingMatch a string against a pattern with . and * using a table over string and pattern prefixes.hardLeetCodeSep 25, 2026
- 109dsaTarget sumCount the ways to assign + and − signs to reach a target, by transforming it into counting subsets with a given sum.mediumLeetCodeSep 25, 2026
- 110dsaUnique paths IICount right-and-down paths through a grid with obstacles, setting blocked cells to zero.mediumLeetCodeSep 25, 2026
- 111dsaUnique pathsCount the paths from the top-left to the bottom-right of a grid moving only right or down, with a grid DP.mediumLeetCodeSep 25, 2026
- 112dsaWord breakDecide whether a string can be split into dictionary words with a DP over prefixes.mediumLeetCodeSep 25, 2026
- 113dsaCheapest flights within K stopsFind the cheapest route with at most k stops by running k + 1 Bellman-Ford rounds over a copy of the previous round.mediumLeetCodeSep 25, 2026
- 114dsaClone graphDeep-copy a connected undirected graph, mapping each original vertex to its copy so that cycles are copied once.mediumLeetCodeSep 25, 2026
- 115dsaCourse schedule IIReturn an order in which all courses can be taken, or an empty list if the prerequisites form a cycle.mediumLeetCodeSep 25, 2026
- 116dsaCourse scheduleDecide whether all courses can be finished given their prerequisites, by checking the prerequisite graph for a cycle.mediumLeetCodeSep 25, 2026
- 117dsaMax area of islandFind the largest island in a grid by having each flood fill return the number of cells it marked.mediumLeetCodeSep 25, 2026
- 118dsaMin cost to connect all pointsConnect every point at the lowest total Manhattan distance, with the O(n²) array version of Prim's algorithm.mediumLeetCodeSep 25, 2026
- 119dsaNetwork delay timeFind how long a signal takes to reach every node of a weighted directed network, with Dijkstra from the source.mediumLeetCodeSep 25, 2026
- 120dsaNumber of connected components in an undirected graphCount the connected components of a graph by starting a search from every vertex not yet visited.mediumLeetCodeSep 25, 2026
- 121dsaNumber of islandsCount the islands in a grid of land and water, flooding each one with DFS or BFS the first time you step on it.mediumLeetCodeSep 25, 2026
- 122dsaPacific Atlantic water flowFind the cells whose water can reach both oceans by searching uphill from each ocean's border and intersecting the results.mediumLeetCodeSep 25, 2026
- 123dsaReconstruct itineraryUse every flight ticket exactly once, starting from JFK and preferring alphabetical order, with a DFS that adds airports after their tickets run out.hardLeetCodeSep 25, 2026
- 124dsaRedundant connectionFind the edge that closes the only cycle in a graph that was a tree plus one extra edge, with union-find.mediumLeetCodeSep 25, 2026
- 125dsaRotting orangesFind how many minutes it takes rot to spread from every rotten orange to all fresh ones, with a multi-source BFS.mediumLeetCodeSep 25, 2026
- 126dsaSurrounded regionsCapture regions of O cells that don't touch the border, by first marking every O reachable from the border.mediumLeetCodeSep 25, 2026
- 127dsaSwim in rising waterFind the earliest time you can swim across a grid as water rises, by minimizing the highest cell on the path with Dijkstra.hardLeetCodeSep 25, 2026
- 128dsaWord ladderFind the length of the shortest chain of one-letter changes from one word to another through a dictionary, with BFS over an implicit graph.hardLeetCodeSep 25, 2026
- 129dsaWord search IIFind every dictionary word that can be traced through adjacent grid cells, with one depth-first search guided by a trie of all the words.hardLeetCodeSep 25, 2026
- 130dsaWord searchDecide whether a word can be traced through adjacent cells of a letter grid, marking cells as used and unmarking them on the way back.mediumLeetCodeSep 25, 2026
- 131dsaGas stationFind the starting station for a circular route in one pass, using the total balance and the running tank.mediumLeetCodeSep 25, 2026
- 132dsaJump gameDecide whether the last index is reachable by tracking the farthest index reachable so far.mediumLeetCodeSep 25, 2026
- 133dsaMerge triplets to form target tripletDecide whether element-wise maximums of some triplets can equal a target, by merging only the triplets that never exceed it.mediumLeetCodeSep 25, 2026
- 134dsaHand of straightsSplit a hand into groups of consecutive cards by always starting a group at the smallest remaining card.mediumLeetCodeSep 25, 2026
- 135dsaInsert delete getrandom O(1)Design a set that inserts, removes and returns a uniformly random element, each in O(1) on average.mediumLeetCodeSep 25, 2026
- 136dsaLongest consecutive sequenceFind the length of the longest run of consecutive integers in an unsorted array in O(n), using a hash set and starting only at the beginning of each run.mediumLeetCodeSep 25, 2026
- 137dsaValid SudokuCheck whether a partly filled 9 × 9 Sudoku board breaks any rule, using the box-number formula.mediumLeetCodeSep 25, 2026
- 138dsaFind median from data streamMaintain the median of a growing stream with a max-heap for the lower half and a min-heap for the upper half.hardLeetCodeSep 25, 2026
- 139dsaK closest points to originReturn the k points nearest the origin with a max-heap of size k keyed by squared distance.mediumLeetCodeSep 25, 2026
- 140dsaFind k pairs with smallest sumsGenerate the k pairs with the smallest sums from two sorted arrays, treating each row of pairs as a sorted stream to merge.mediumLeetCodeSep 25, 2026
- 141dsaKth largest element in an arrayFind the kth largest value in an unsorted array with a size-k heap or with quickselect, without fully sorting it.mediumLeetCodeSep 25, 2026
- 142dsaLast stone weightRepeatedly smash the two heaviest stones together, using a max-heap to find them in O(log n).easyLeetCodeSep 25, 2026
- 143dsaSingle-threaded CPUSimulate a CPU that always runs the shortest available task, with a heap of tasks that have arrived.mediumLeetCodeSep 25, 2026
- 144dsaSliding Window MaximumReturn the maximum value for every contiguous window of width k.hardLeetCodeSep 25, 2026
- 145dsaTask schedulerFind the minimum time to run tasks when equal tasks need n idle intervals between them, by always running the most frequent remaining task.mediumLeetCodeSep 25, 2026
- 146dsaTop k frequent elementsReturn the k most frequent values, by counting with a hash map and keeping a size-k heap of counts.mediumLeetCodeSep 25, 2026
- 147dsaInsert intervalInsert a new interval into a sorted, non-overlapping list, merging where needed, in O(n).mediumLeetCodeSep 25, 2026
- 148dsaMerge intervalsMerge all overlapping intervals after sorting them by start, in one pass.mediumLeetCodeSep 25, 2026
- 149dsaMinimum interval to include each queryFor each query point, find the length of the shortest interval containing it, by sweeping sorted queries and keeping a heap of active intervals.hardLeetCodeSep 25, 2026
- 150dsaNon-overlapping intervalsFind the fewest intervals to remove so the rest don't overlap, by keeping as many as possible with the earliest-end rule.mediumLeetCodeSep 25, 2026
- 151dsaAdd two numbersAdd two numbers stored as linked lists of digits in reverse order, building the result list with a dummy head and a carry.mediumLeetCodeSep 25, 2026
- 152dsaCopy list with random pointerDeep-copy a linked list whose nodes also have a random pointer to any node, so that the copy's pointers lead only to copy nodes.mediumLeetCodeSep 25, 2026
- 153dsaDesign browser historyImplement a browser's visit, back and forward with two stacks, or with an array and a cursor.mediumLeetCodeSep 25, 2026
- 154dsaLinked list cycleDecide whether a linked list loops back on itself, in O(n) time and O(1) memory, with fast and slow pointers.easyLeetCodeSep 25, 2026
- 155dsaMerge two sorted listsSplice the nodes of two sorted linked lists into one sorted list, using a dummy head and a tail pointer.easyLeetCodeSep 25, 2026
- 156dsaRemove nth node from end of listRemove the node n positions from the end of a linked list in one pass, using two pointers a fixed gap apart.mediumLeetCodeSep 25, 2026
- 157dsaReorder listRearrange L0 → L1 → … → Ln into L0 → Ln → L1 → Ln−1 → … in place, by finding the middle, reversing the second half and merging.mediumLeetCodeSep 25, 2026
- 158dsaReverse linked listReverse a singly linked list in place by turning every next pointer around, iteratively and then recursively.easyLeetCodeSep 25, 2026
- 159dsaLongest increasing path in a matrixFind the longest strictly increasing path between neighboring cells of a grid with a memoized depth-first search.hardLeetCodeSep 25, 2026
- 160dsaRotate imageRotate an n × n matrix by 90 degrees clockwise, in place, using index arithmetic.mediumLeetCodeSep 25, 2026
- 161dsaSet matrix zeroesZero every row and column that contains a 0, first with O(m + n) extra memory and then with O(1).mediumLeetCodeSep 25, 2026
- 162dsaSpiral matrixReturn the elements of an m × n matrix in clockwise spiral order, keeping four boundaries straight.mediumLeetCodeSep 25, 2026
- 163dsaCar fleetCount how many groups of cars arrive at a destination, by sorting by position and stacking arrival times.mediumLeetCodeSep 25, 2026
- 164dsaDaily temperaturesFor each day, count the days until a warmer one, in a single pass with a monotonic stack.mediumLeetCodeSep 25, 2026
- 165dsaEvaluate reverse Polish notationEvaluate an arithmetic expression written in postfix order with a single stack of operands.mediumLeetCodeSep 25, 2026
- 166dsaLargest rectangle in histogramFind the largest rectangle under a histogram in O(n), using an increasing stack to find each bar's previous and next smaller bars.hardLeetCodeSep 25, 2026
- 167dsaLongest valid parenthesesFind the length of the longest well-formed run of parentheses, using a stack of indexes instead of characters.hardLeetCodeSep 25, 2026
- 168dsaMin stackDesign a stack that also returns its minimum element in O(1), even after pops, by storing the running minimum with each item.mediumLeetCodeSep 25, 2026
- 169dsaValid parenthesesDecide whether a string of (), [] and curly brackets is balanced, with each closer matching the most recent unclosed opener.easyLeetCodeSep 25, 2026
- 170dsaLetter combinations of a phone numberReturn every string a sequence of phone digits could spell, one letter per digit.mediumLeetCodeSep 25, 2026
- 171dsaLongest Repeating Character ReplacementFind the longest substring that can be made uniform by replacing at most k characters.mediumLeetCodeSep 25, 2026
- 172dsaLongest Substring Without Repeating CharactersFind the maximum length of a contiguous substring containing no repeated characters.mediumLeetCodeSep 25, 2026
- 173dsaMinimum Window SubstringFind the shortest substring of s containing every required character in t with at least its required multiplicity.hardLeetCodeSep 25, 2026
- 174dsaPartition labelsSplit a string into as many pieces as possible so each letter appears in only one piece, using each letter's last position.mediumLeetCodeSep 25, 2026
- 175dsaPermutation in StringDetermine whether any contiguous window in the second string is a permutation of the first string.mediumLeetCodeSep 25, 2026
- 176dsaReverse words in a stringReverse the order of the words in a string, collapsing extra spaces, with two-pointer reversals.mediumLeetCodeSep 25, 2026
- 177dsaValid anagramDecide whether two strings are anagrams by counting letters instead of sorting, in O(n) time.easyLeetCodeSep 25, 2026
- 178dsaValid palindromeDecide whether a string reads the same forward and backward after ignoring case and non-alphanumeric characters, in O(1) extra space.easyLeetCodeSep 25, 2026
- 179dsaBalanced binary treeDecide whether every node's subtrees differ in height by at most one, in a single O(n) pass.easyLeetCodeSep 25, 2026
- 180dsaBinary tree level order traversalReturn a tree's values level by level, using a queue and the length of the queue at the start of each level.mediumLeetCodeSep 25, 2026
- 181dsaBinary tree right side viewReturn the values visible from the right side of a tree: the last node of each level.mediumLeetCodeSep 25, 2026
- 182dsaConstruct binary tree from preorder and inorder traversalRebuild a binary tree from its preorder and inorder traversals, using the root from preorder to split the inorder list.mediumLeetCodeSep 25, 2026
- 183dsaDiameter of binary treeFind the longest path between any two nodes by returning heights and recording the best path through each node.easyLeetCodeSep 25, 2026
- 184dsaCount good nodes in binary treeCount nodes that are at least as large as every node on the path from the root, passing the running maximum down.mediumLeetCodeSep 25, 2026
- 185dsaInvert binary treeMirror a binary tree by swapping every node's left and right children.easyLeetCodeSep 25, 2026
- 186dsaKth smallest element in a BSTFind the kth smallest key in a binary search tree with an inorder traversal that stops early.mediumLeetCodeSep 25, 2026
- 187dsaLowest common ancestor of a binary search treeFind the lowest node that has both p and q as descendants, by walking down from the root until the two keys split.mediumLeetCodeSep 25, 2026
- 188dsaMaximum depth of binary treeReturn the number of nodes on the longest root-to-leaf path, recursively and with a level-order traversal.easyLeetCodeSep 25, 2026
- 189dsaSame treeDecide whether two binary trees have the same shape and the same values, by recursing on both at once.easyLeetCodeSep 25, 2026
- 190dsaSubtree of another treeDecide whether one tree appears as a subtree of another, by running a same-tree check from every node.easyLeetCodeSep 25, 2026
- 191dsaValidate binary search treeDecide whether a binary tree is a valid binary search tree by passing down the range each subtree must lie in.mediumLeetCodeSep 25, 2026
- 192dsaImplement a trieBuild a prefix tree with insert, exact search and prefix search, each in time proportional to the word's length.mediumLeetCodeSep 25, 2026
- 193dsaContainer with most waterFind two lines that hold the most water, moving the pointer at the shorter line inward each step.mediumLeetCodeSep 25, 2026
- 194dsaMerge sorted arrayMerge a sorted array into another sorted array that has empty space at its end, in place, by filling from the back.easyLeetCodeSep 25, 2026
- 195dsaSort colorsSort an array of 0s, 1s and 2s in one pass and in place, with a three-way (Dutch national flag) partition.mediumLeetCodeSep 25, 2026
- 196dsa3SumFind every unique triple that sums to zero by fixing one value and running a two-pointer scan on the rest.mediumLeetCodeSep 25, 2026
- 197dsaTrapping rain waterCompute the water trapped between bars after rain, with two pointers and running maximums from each side.hardLeetCodeSep 25, 2026
- 198dsaTwo sum II: input array is sortedFind two numbers in a sorted array that add up to a target, in O(n) time and O(1) space, with converging pointers.mediumLeetCodeSep 25, 2026
- 199system designDesign a Short-Link ServiceDesign short-link creation and redirection from traffic assumptions through identifier generation, storage, cache, and abuse controls.mediumLeetCodeSep 25, 2026
- 200system designImplement a Time-Based Logger Rate LimiterTrack the last accepted timestamp for each message and reason about state growth, ordering, and concurrent requests.easyLeetCodeSep 25, 2026