Skip to content
  • Dashboard
  • Review
  • Go: plan & chat
  • Roadmap
  • Patterns & lessons49
  • Sheets
  • Problems1.5k
  • Ascend
  • Toolkit
  • Core CS + SQL
  • System Design
  • Machine Coding
  • Interview hub
  • Mock interview
  • Companies & OA
  • Leaderboard
  • Battles
  • College Cup
  • People

Keep your progress

Sync across devices with a free account.

Sign upSign in
Sheets
Sign inSign up
Sheets

365 problems · 18 topics · 46 of 49 patterns

The 365

Every pattern and its variants, plus the CSES classics and real company OA questions that OAs are built from.

0/365 solved122 days at 3 a dayThe 128 →
Start: Two Sum· Arrays & Hashing

Hash Map / Hash Set LookupHash map and set lookups
0/8
  • 1Two SumIn the 128 · Store what you've seen; look up the complement in one pass.Easy
  • 217Contains DuplicateA set answers "seen before?" as you go.Easy
  • 242Valid AnagramCount with a 26-slot array instead of a map.Easy
  • 49Group AnagramsIn the 128 · The sorted word, or its letter counts, is the key.Medium
  • 128Longest Consecutive SequenceIn the 128 · Only start counting from a run's first number, so it stays O(n).Medium
  • 4544Sum IISplit into two halves and meet in a hash map: n⁴ becomes n².Medium
  • Largest Outlier in an ArrayAmazon OA: total minus two candidates, checked against a count map.OAMedium
  • Count Pairs with Absolute Difference kSalesforce and Nutanix OA: for each x, count x + k.OAEasy
Boyer-Moore Majority VoteMajority vote
0/2
  • 169Majority ElementIn the 128 · Cancel pairs of different votes; the survivor is the majority.Easy
  • Majority Element IIKeep two candidates, then verify their counts.Medium
Kadane's Algorithmpart of 1D / Fibonacci-styleLearnit
0/3
  • 53Maximum SubarrayIn the 128 · Extend the running sum or restart at this element, whichever is bigger.Medium
  • 152Maximum Product SubarrayTrack the max and the min: a negative swaps them.Medium
  • Maximum Sum Circular SubarrayWrapping around = total minus the minimum subarray.Medium
Simulation & Matrix TraversalMatrix and in-place tricks
0/4
  • 48Rotate ImageTranspose, then reverse each row.Medium
  • 73Set Matrix ZeroesUse the first row and column as the markers: O(1) space.Medium
  • 54Spiral MatrixIn the 128 · Shrink four walls as you peel each layer.Medium
  • 31Next PermutationIn the 128 · Rightmost dip, swap with the next bigger to its right, reverse the tail.Medium
Cyclic SortValues 1..n: put each at its own indexLearnit
0/3
  • 268Missing NumberXOR (or sum) everything against 0..n.Easy
  • 287Find the Duplicate NumberIn the 128 · Values as next-pointers turn it into Floyd's cycle finding.Medium
  • 41First Missing PositiveIn the 128 · Swap each value home; the first misfit is the answer.Hard

Two PointersOpposite ends and read/write pointersLearnit
0/11
  • 125Valid PalindromeWalk inward from both ends, skipping what doesn't count.Easy
  • 167Two Sum II - Input Array Is SortedIn the 128 · Too small: move left up. Too big: move right down.Medium
  • 153SumIn the 128 · Fix one, two-pointer the rest, skip duplicates on every pointer.Medium
  • 11Container With Most WaterIn the 128 · Always move the shorter wall: keeping it can't do better.Medium
  • 42Trapping Rain WaterIn the 128 · The lower side's running max decides the water at that side.Hard
  • 75Sort ColorsIn the 128 · Dutch national flag: three regions, one pass.Medium
  • 283Move ZeroesA write pointer for the next non-zero.Easy
  • 26Remove Duplicates from Sorted ArrayRead and write pointers on sorted input.Easy
  • Count the Number of Fair PairsCount pairs ≤ upper, minus pairs < lower.Medium
  • Number of Subsequences That Satisfy the Given Sum ConditionSort; each valid (l, r) adds 2^(r − l) subsets.Medium
  • Count Removable Subarrays Leaving a Sorted ArrayDE Shaw OA: a sorted prefix meets a sorted suffix.OAHard

Sliding WindowVariable and fixed windowsLearnit
0/14
  • 3Longest Substring Without Repeating CharactersIn the 128 · Grow right; shrink left while a character repeats.Medium
  • 424Longest Repeating Character ReplacementIn the 128 · The window is valid while length − maxFreq ≤ k.Medium
  • 567Permutation in StringIn the 128 · Fixed window of letter counts compared as it slides.Medium
  • Find All Anagrams in a StringThe same window, collecting every match.Medium
  • Max Consecutive Ones IIIIn the 128 · Longest window holding at most k zeros.Medium
  • Minimum Size Subarray SumShortest window reaching the target (positives only).Medium
  • Subarray Product Less Than KIn the 128 · Each valid window adds r − l + 1 new subarrays.Medium
  • 76Minimum Window SubstringIn the 128 · Expand until covered, shrink to the minimum, track how many needs are met.Hard
  • Binary Subarrays With SumExactly k = atMost(k) − atMost(k − 1).Medium
  • Subarrays with K Different IntegersExactly k distinct, by atMost twice.Hard
  • Number of Substrings Containing All Three CharactersOnce a window is valid, every longer end is too.Medium
  • Minimum Operations to Reduce X to ZeroFlip it: the longest middle window summing to total − x.Medium
  • Count Subarrays With Fixed BoundsRemember the last bad, last min and last max positions.Hard
  • Longest Same-Colour Wall Segment with k RepaintsUber OA: longest same-colour stretch with k repaints.OAMedium
Monotonic DequeWindow max and min with a dequeLearnit
0/3
  • 239Sliding Window MaximumIn the 128 · A deque of indices whose values only decrease.Hard
  • 1438Longest Continuous Subarray With Absolute Diff Less Than or Equal to LimitTwo deques: window max and window min.Medium
  • 862Shortest Subarray with Sum at Least KNegatives break the window; a deque over prefix sums fixes it.Hard

Prefix SumPrefix sums and prefix + hash mapLearnit
0/9
  • 303Range Sum Query - Immutablesum(l..r) = pre[r + 1] − pre[l].Easy
  • 724Find Pivot IndexLeft sum against total − left − a[i].Easy
  • 238Product of Array Except SelfIn the 128 · Products from the left times products from the right.Medium
  • 560Subarray Sum Equals KIn the 128 · Count earlier prefixes equal to pre − k.Medium
  • 525Contiguous ArrayIn the 128 · Turn 0 into −1: the longest zero-sum subarray.Medium
  • 974Subarray Sums Divisible by KCount equal remainders; fix negative mods.Medium
  • Find the Longest Substring Containing Vowels in Even CountsA parity bitmask is the prefix key.Medium
  • Subarray Sums IISubarray sums with negatives: the prefix + map version, under tight limits.CSESMedium
  • Items in ContainersAmazon OA: prefix counts plus the nearest wall on each side.OAMedium
2D Prefix Sumspart of Prefix SumLearnit
0/2
  • 304Range Sum Query 2D - ImmutableIn the 128 · Inclusion–exclusion on a 2D prefix.Medium
  • Number of Submatrices That Sum to TargetFix two rows, then it's subarray sum equals k.Hard
Difference Array & Line SweepDifference arrays and sweepsLearnit
0/3
  • 1094Car PoolingIn the 128 · +people at pickup, − at drop, then one sweep.Medium
  • 1109Corporate Flight BookingsRange add in O(1), one prefix pass at the end.Medium
  • Restaurant CustomersArrivals +1, departures −1, sorted: the max overlap (free Meeting Rooms II).CSESMedium
Contribution Technique (sum over all subarrays/pairs)Contribution technique
0/2
  • Total Appeal of A StringEach character counts for every substring that sees it first.Hard
  • Password Strength (Sum of Distinct Chars over Substrings)Amazon OA: each character's share is the gap to its last copy.OAMedium

Binary SearchOn a sorted arrayLearnit
0/10
  • 704Binary SearchThe template: lo ≤ hi, mid without overflow.Easy
  • 34Find First and Last Position of Element in Sorted ArrayIn the 128 · Two lower bounds.Medium
  • 33Search in Rotated Sorted ArrayIn the 128 · One half is always sorted; decide which.Medium
  • 153Find Minimum in Rotated Sorted ArrayIn the 128 · Compare mid with the right end.Medium
  • 540Single Element in a Sorted ArrayPairs flip parity after the single one.Medium
  • 162Find Peak ElementIn the 128 · Walk toward the bigger neighbour.Medium
  • 74Search a 2D MatrixTreat the matrix as one sorted array.Medium
  • Search a 2D Matrix IIStart top-right: every step drops a row or a column.Medium
  • Kth Missing Positive NumberMissing before index i = a[i] − i − 1.Easy
  • 4Median of Two Sorted ArraysIn the 128 · Binary-search the cut in the smaller array.Hard
Binary Search on the AnswerLearnit
0/10
  • 875Koko Eating BananasIn the 128 · Guess a speed, check it, halve the range.Medium
  • 1011Capacity To Ship Packages Within D DaysIn the 128 · The smallest capacity that fits in D days.Medium
  • Find the Smallest Divisor Given a ThresholdThe same template with ceiling sums.Medium
  • 1482Minimum Number of Days to Make m BouquetsFeasibility is monotone in days.Medium
  • 410Split Array Largest SumIn the 128 · Minimise the largest part (Allocate Books, Painter's Partition).Hard
  • Magnetic Force Between Two BallsIn the 128 · Maximise the minimum gap (Aggressive Cows).Medium
  • Minimum Time to Repair CarsIn time t a mechanic fixes ⌊√(t / r)⌋ cars.Medium
  • Factory MachinesMachines in parallel: total products made by time t.CSESMedium
  • Find K-th Smallest Pair DistanceCount pairs ≤ mid with two pointers.Hard
  • Minimum Time for n Cab TripsUber OA: the same check as the factory machines.OAMedium

String Matching (KMP / Z / Rabin-Karp)Parsing and matchingLearnit
0/9
  • 14Longest Common PrefixCompare column by column.Easy
  • 151Reverse Words in a StringIn the 128 · Split, reverse, join, or reverse twice in place.Medium
  • 8String to Integer (atoi)In the 128 · Spaces, sign, digits, overflow: in that order.Medium
  • Rotate Stringb is a rotation of a exactly when b is inside a + a.Easy
  • 43Multiply StringsGrade-school multiplication into a digit array.Medium
  • 28Find the Index of the First Occurrence in a StringIn the 128 · KMP's failure function.Easy
  • 214Shortest PalindromeKMP on s + "#" + reverse(s).Hard
  • Repeated DNA SequencesHash every window of length 10.Medium
  • IP Check (Validate IPv4 / IPv6)Sprinklr OA: the parsing round, every edge case.OAMedium
Palindromic SubstringsPalindromesLearnit
0/3
  • 5Longest Palindromic SubstringIn the 128 · Expand around all 2n − 1 centres.Medium
  • 647Palindromic SubstringsThe same expansion, counting instead.Medium
  • 680Valid Palindrome IIOn a mismatch, try skipping either side once.Easy

In-place ReversalReversal and rewiringLearnit
0/7
  • 206Reverse Linked ListIn the 128 · prev, curr, next: the three-pointer dance.Easy
  • 21Merge Two Sorted ListsIn the 128 · A dummy head, then splice the smaller node.Easy
  • 92Reverse Linked List IIReverse a sublist and stitch both ends.Medium
  • 25Reverse Nodes in k-GroupIn the 128 · Reverse k at a time; leave the short tail alone.Hard
  • 61Rotate ListClose it into a ring, cut at n − k.Medium
  • 2Add Two NumbersIn the 128 · Digit by digit with a carry.Medium
  • 138Copy List with Random PointerIn the 128 · Interleave the copies, set randoms, split.Medium
Fast & Slow PointersFast and slow pointersLearnit
0/8
  • 876Middle of the Linked ListSlow moves one, fast moves two.Easy
  • 141Linked List CycleThey meet if and only if there's a cycle.Easy
  • 142Linked List Cycle IIIn the 128 · Reset one to the head; they meet at the cycle's start.Medium
  • 19Remove Nth Node From End of ListIn the 128 · Keep a gap of n between two pointers.Medium
  • 234Palindrome Linked ListFind the middle, reverse the second half, compare.Easy
  • 143Reorder ListIn the 128 · Middle + reverse + merge: three patterns in one.Medium
  • 160Intersection of Two Linked ListsSwap heads at the end: both walk a + b.Easy
  • 148Sort ListSplit at the middle and merge sort.Medium

Stack for Matching & Expression ParsingStacks for parsing and simulation
0/8
  • 20Valid ParenthesesIn the 128 · Push openers, match closers.Easy
  • 155Min StackIn the 128 · Store the minimum alongside each value.Medium
  • 150Evaluate Reverse Polish NotationOperands wait on the stack for their operator.Medium
  • 394Decode StringIn the 128 · Stack of (count, string so far).Medium
  • 735Asteroid CollisionIn the 128 · Pop while the incoming asteroid wins.Medium
  • 1249Minimum Remove to Make Valid ParenthesesStack of unmatched indices.Medium
  • 227Basic Calculator IIApply × and ÷ at once; push + and − terms.Medium
  • Array BurstGoldman Sachs OA: a stack of (value, run length).OAMedium
Monotonic StackLearnit
0/10
  • 496Next Greater Element IPop everything smaller than the new element: they found their answer.Easy
  • 739Daily TemperaturesIn the 128 · A stack of days still waiting for a warmer one.Medium
  • 503Next Greater Element IIGo round twice for the circle.Medium
  • 901Online Stock SpanPop smaller prices and absorb their spans.Medium
  • 84Largest Rectangle in HistogramIn the 128 · Each bar's width runs to the next smaller bar on both sides.Hard
  • 85Maximal RectangleA histogram per row.Hard
  • 402Remove K DigitsIn the 128 · Keep the stack increasing; pop bigger digits while k lasts.Medium
  • 456132 PatternScan right to left keeping the best "2".Medium
  • 907Sum of Subarray MinimumsIn the 128 · Each element's share = left span × right span.Medium
  • 853Car FleetSort by position; arrival times form a monotone stack.Medium

Subsets / Permutations / CombinationsSubsets, permutations, combinationsLearnit
0/8
  • 78SubsetsIn the 128 · Take it or leave it at every index.Medium
  • 90Subsets IISort, skip a repeat at the same depth.Medium
  • 46PermutationsIn the 128 · A used[] array, or swap into place.Medium
  • Permutations IISkip a used duplicate at the same position.Medium
  • 39Combination SumIn the 128 · Reuse allowed: recurse on the same index.Medium
  • 40Combination Sum IIIn the 128 · Each once: skip equal neighbours.Medium
  • 17Letter Combinations of a Phone NumberOne level per digit.Medium
  • Apple DivisionTry every split of n ≤ 20 weights.CSESEasy
BacktrackingBacktracking with pruningLearnit
0/8
  • 22Generate ParenthesesIn the 128 · Open while you can, close while it stays valid.Medium
  • 79Word SearchIn the 128 · Mark the cell, recurse, unmark on the way back.Medium
  • 131Palindrome PartitioningCut only where the prefix is a palindrome.Medium
  • 51N-QueensIn the 128 · Sets for columns and both diagonals.Hard
  • 37Sudoku SolverRow, column and box sets; try digits in empty cells.Hard
  • 93Restore IP AddressesFour parts, each 0–255, no leading zeros.Medium
  • Word Break IIBacktracking with memo on the start index.Hard
  • Matchsticks to SquareFour sides, sort descending to prune early.Medium

Top-K ElementsTop K and greedy with a heapLearnit
0/9
  • 215Kth Largest Element in an ArrayIn the 128 · A min-heap of size k (or quickselect).Medium
  • 1046Last Stone WeightMax-heap simulation.Easy
  • 347Top K Frequent ElementsIn the 128 · Count, then a heap or buckets by frequency.Medium
  • 973K Closest Points to OriginA max-heap of size k on distance.Medium
  • 621Task SchedulerIn the 128 · The busiest task sets the frame; idle fills the gaps.Medium
  • 767Reorganize StringAlways place the most frequent letter that isn't the last one.Medium
  • 1642Furthest Building You Can ReachLadders on the biggest climbs: a min-heap of size L.Medium
  • 502IPOUnlock projects by capital, pick by profit: two heaps.Hard
  • Five Star SellersAmazon OA: a heap ordered by the marginal gain of one more review.OAMedium
Two HeapsLearnit
0/2
  • 295Find Median from Data StreamIn the 128 · Max-heap for the low half, min-heap for the high half.Hard
  • 480Sliding Window MedianTwo heaps with lazy deletion.Hard
K-way MergeLearnit
0/4
  • 23Merge k Sorted ListsIn the 128 · A heap of the k list heads.Hard
  • 378Kth Smallest Element in a Sorted MatrixRows are k sorted lists.Medium
  • 373Find K Pairs with Smallest SumsPush (i, j + 1) after popping (i, j).Medium
  • 632Smallest Range Covering Elements from K ListsHeap of k heads plus the current max.Hard

Merge IntervalsIntervalsLearnit
0/7
  • 56Merge IntervalsIn the 128 · Sort by start, extend or start a new block.Medium
  • 57Insert IntervalIn the 128 · Before, overlapping, after: three phases.Medium
  • 435Non-overlapping IntervalsIn the 128 · Sort by end; keep the earliest finisher.Medium
  • 452Minimum Number of Arrows to Burst BalloonsThe same sort by end, counting groups.Medium
  • 986Interval List IntersectionsTwo pointers; advance whichever ends first.Medium
  • Room AllocationRooms by a min-heap of end times (free Meeting Rooms II, with the assignment).CSESMedium
  • Movie FestivalInterval scheduling: the most non-overlapping movies.CSESMedium
GreedyGreedy choicesLearnit
0/13
  • 55Jump GameIn the 128 · Track the farthest reachable index.Medium
  • 45Jump Game IIIn the 128 · BFS by levels over the reach.Medium
  • 134Gas StationIn the 128 · If the total is ≥ 0, start just after the worst prefix.Medium
  • 763Partition LabelsIn the 128 · Cut when you reach the last occurrence of everything seen so far.Medium
  • 135CandyTwo passes: left neighbours, then right neighbours.Hard
  • 122Best Time to Buy and Sell Stock IITake every upward step.Medium
  • 846Hand of StraightsStart each group at the smallest card left.Medium
  • 678Valid Parenthesis StringKeep the range of possible open counts.Medium
  • 179Largest NumberSort by a + b against b + a.Medium
  • Minimum Number of Taps to Open to Water a GardenJump Game II on intervals.Hard
  • Tasks and DeadlinesShortest job first maximises the reward.CSESMedium
  • Missing Coin SumSorted coins: if the next coin > sum + 1, sum + 1 is unreachable.CSESMedium
  • Min Deletions to Make Letter Frequencies UniqueMicrosoft OA: sort frequencies, step each down to a free slot.OAMedium

Tree DFS (Paths & Recursion)DFS and recursion on treesLearnit
0/14
  • Binary Tree Inorder TraversalIn the 128 · Recursive first, then iterative with a stack.Easy
  • 104Maximum Depth of Binary TreeIn the 128 · 1 + max of the children.Easy
  • 100Same TreeCompare structure and values together.Easy
  • 226Invert Binary TreeIn the 128 · Swap children at every node.Easy
  • 101Symmetric TreeMirror-compare left against right.Easy
  • 110Balanced Binary TreeReturn the height, or −1 for unbalanced.Easy
  • 543Diameter of Binary TreeIn the 128 · Through each node: left height + right height.Easy
  • 113Path Sum IICarry the path; copy it at a leaf.Medium
  • Path Sum IIIPrefix sums on the root-to-node path.Medium
  • Count Complete Tree NodesEqual left and right heights mean a perfect tree: 2^h − 1.Medium
  • 236Lowest Common Ancestor of a Binary TreeIn the 128 · The node where both sides report a hit.Medium
  • 124Binary Tree Maximum Path SumIn the 128 · Return one branch up; update the answer with both.Hard
  • 863All Nodes Distance K in Binary TreeIn the 128 · Add parent links, then BFS from the target.Medium
  • Amount of Time for Binary Tree to Be InfectedThe same parent-link BFS.Medium
Tree BFS (Level Order)Level order (BFS)Learnit
0/5
  • 102Binary Tree Level Order TraversalIn the 128 · Queue, and the level size at the start of each round.Medium
  • 199Binary Tree Right Side ViewIn the 128 · The last node of each level.Medium
  • 103Binary Tree Zigzag Level Order TraversalFlip the direction each level.Medium
  • Maximum Width of Binary TreeIn the 128 · Number nodes 2i and 2i + 1; renumber per level.Medium
  • Vertical Order Traversal of a Binary TreeSort by (column, row, value).Hard
BST LogicBinary search treesLearnit
0/7
  • 98Validate Binary Search TreeIn the 128 · Pass (low, high) bounds down.Medium
  • 230Kth Smallest Element in a BSTIn the 128 · Inorder is sorted; stop at the k-th.Medium
  • 235Lowest Common Ancestor of a Binary Search TreeSplit point of the two values.Medium
  • 450Delete Node in a BSTReplace with the inorder successor.Medium
  • 108Convert Sorted Array to Binary Search TreeThe middle is the root, recursively.Easy
  • 173Binary Search Tree IteratorControlled inorder with a stack.Medium
  • 99Recover Binary Search TreeTwo inversions in the inorder sequence.Medium
Tree Construction & SerializationBuilding and serialising treesLearnit
0/3
  • 105Construct Binary Tree from Preorder and Inorder TraversalIn the 128 · Preorder gives the root; inorder splits the sides.Medium
  • 297Serialize and Deserialize Binary TreeIn the 128 · Preorder with null markers.Hard
  • 114Flatten Binary Tree to Linked ListReverse preorder, or Morris-style rewiring.Medium
DP on Treespart of Tree DFS (Paths & Recursion)Learnit
0/6
  • House Robber IIIReturn (rob, skip) from every node.Medium
  • Binary Tree CamerasThree states: covered, has camera, needs cover.Hard
  • SubordinatesSubtree sizes in one DFS.CSESMedium
  • Tree DiameterThe diameter by two BFS runs, or the best two child depths.CSESMedium
  • Sum of Distances in TreeRerooting: move the root, adjust the sum in O(1).Hard
  • Longest Path with Different Adjacent CharactersMicrosoft OA: the best two child chains.OAHard
Binary Lifting & LCABinary lifting and LCA
0/3
  • Kth Ancestor of a Tree NodeJump tables of 2^j ancestors.Hard
  • Company Queries IILCA by binary lifting.CSESMedium
  • Distance QueriesDistance = depth[a] + depth[b] − 2 · depth[lca].CSESMedium

Trie (Prefix Tree)Prefix treesLearnit
0/6
  • 208Implement Trie (Prefix Tree)In the 128 · Children plus an end-of-word flag.Medium
  • 211Design Add and Search Words Data StructureA "." branches into every child.Medium
  • 1268Search Suggestions SystemKeep the top three at each node, or sort and binary search.Medium
  • 212Word Search IIIn the 128 · Trie + backtracking; remove words once found.Hard
  • 421Maximum XOR of Two Numbers in an ArrayIn the 128 · A bit trie: always try the opposite bit.Medium
  • Command Autocomplete from HistoryUber OA: each trie node keeps its latest index.OAMedium

Graph BFS / DFSBFS and DFSLearnit
0/10
  • 733Flood FillDFS from one cell, recolour as you go.Easy
  • 200Number of IslandsIn the 128 · Count the DFS starts.Medium
  • 695Max Area of IslandDFS returns the size.Medium
  • 133Clone GraphIn the 128 · A map from old node to new node.Medium
  • 130Surrounded RegionsMark border-connected cells first; flip the rest.Medium
  • 417Pacific Atlantic Water FlowIn the 128 · Search uphill from each ocean, intersect.Medium
  • 399Evaluate DivisionA weighted graph; multiply along the path.Medium
  • Counting RoomsCount the rooms: number of islands at CSES size.CSESEasy
  • Maximal Network RankMicrosoft OA: degrees plus an adjacency check.OAMedium
  • Reorder Routes to Reach City 0Microsoft OA: DFS where each edge's direction costs 0 or 1.OAMedium
Multi-source BFSBFS shortest paths · part of Graph BFS / DFSLearnit
0/9
  • 994Rotting OrangesIn the 128 · Put every rotten orange in the queue first.Medium
  • 54201 MatrixMulti-source BFS from all zeros.Medium
  • 1091Shortest Path in Binary MatrixBFS in eight directions.Medium
  • 127Word LadderIn the 128 · Words are nodes; neighbours differ by one letter.Hard
  • Open the LockBFS over lock states, skipping deadends.Medium
  • Shortest Path with Alternating ColorsState = (node, colour of the last edge).Medium
  • 815Bus RoutesBFS over routes, not stops.Hard
  • MonstersTwo BFS runs: monsters first, then you.CSESMedium
  • Paths Avoiding Breach RadiusDE Shaw OA: multi-source BFS, then a grid DP.OAMedium
Bipartite Check / 2-ColouringBipartite check · part of Graph BFS / DFSLearnit
0/1
  • 785Is Graph Bipartite?In the 128 · 2-colour with BFS; a same-colour edge fails.Medium
Topological SortLearnit
0/6
  • 207Course ScheduleIn the 128 · Kahn's algorithm: if not every node comes out, there's a cycle.Medium
  • 210Course Schedule IIIn the 128 · The order Kahn's produces.Medium
  • Find Eventual Safe StatesReverse the edges and peel the sinks.Medium
  • 310Minimum Height TreesPeel leaves layer by layer.Medium
  • 329Longest Increasing Path in a MatrixA DAG in disguise: DFS with memo.Hard
  • Longest Flight RouteLongest path in a DAG: DP in topological order.CSESMedium
Union-Find (Disjoint Set)Union–Find (DSU)Learnit
0/8
  • 547Number of ProvincesUnion every edge; count the roots.Medium
  • 684Redundant ConnectionIn the 128 · The first edge joining two already-connected nodes.Medium
  • Number of Operations to Make Network ConnectedSpare edges against components − 1.Medium
  • 721Accounts MergeIn the 128 · Union by shared email.Medium
  • 947Most Stones Removed with Same Row or ColumnUnion rows with columns.Medium
  • Making A Large IslandLabel islands with sizes, try flipping each 0.Hard
  • Checking Existence of Edge Length Limited PathsOffline: sort queries and edges together.Hard
  • Existence of a Path with Edge LimitGoogle OA: the same offline DSU.OAMedium
Dijkstra (Weighted Shortest Path)DijkstraLearnit
0/7
  • 743Network Delay TimeIn the 128 · Dijkstra from one source; the answer is the max distance.Medium
  • 1631Path With Minimum EffortDijkstra on the max edge instead of the sum.Medium
  • 778Swim in Rising WaterMinimise the highest cell on the path.Hard
  • Number of Ways to Arrive at DestinationCount shortest paths as you relax.Medium
  • Minimum Obstacle Removal to Reach Corner0-1 BFS: 0-cost edges to the front of the deque.Hard
  • Shortest Routes IDijkstra at full CSES size: lazy deletion and 64-bit distances.CSESMedium
  • Flight DiscountState = (node, coupon used or not).CSESMedium
Bellman-FordBellman–FordLearnit
0/1
  • 787Cheapest Flights Within K StopsIn the 128 · k + 1 rounds of relaxation from a copy.Medium
Floyd-WarshallFloyd–WarshallLearnit
0/1
  • 1334Find the City With the Smallest Number of Neighbors at a Threshold DistanceIn the 128 · Every pair's distance, then count.Medium
Minimum Spanning TreeLearnit
0/2
  • 1584Min Cost to Connect All PointsIn the 128 · Prim's on a complete graph, or Kruskal's with DSU.Medium
  • Road ReparationKruskal's, and say when it's impossible.CSESMedium
Strongly Connected Components & CondensationBridges, SCCs and Euler paths
0/3
  • Critical Connections in a NetworkTarjan's low-link values.Hard
  • Flight Routes CheckStrong connectivity: DFS on the graph and its reverse.CSESMedium
  • 332Reconstruct ItineraryHierholzer's Euler path, smallest first.Hard

1D / Fibonacci-style1D DPLearnit
0/9
  • 70Climbing Stairsdp[i] = dp[i − 1] + dp[i − 2].Easy
  • 198House RobberIn the 128 · Rob i and skip i − 1, or skip i.Medium
  • 213House Robber IIIn the 128 · The circle: run it twice, without the first and without the last.Medium
  • Delete and EarnHouse Robber over values.Medium
  • 91Decode WaysIn the 128 · One digit or two, with zero rules.Medium
  • 139Word BreakIn the 128 · dp[i] = some dictionary word ends at i after a true dp[j].Medium
  • Dice CombinationsWays to make n with dice: the counting template.CSESEasy
  • Frog JumpState = (stone, last jump).Hard
  • Split a Digit String into PrimesSnowflake and Amazon OA: a sieve, then a linear DP.OAMedium
Grid / Matrix DPGrid DPLearnit
0/7
  • 62Unique PathsIn the 128 · From the top and from the left.Medium
  • 64Minimum Path SumIn the 128 · Min of top and left, plus the cell.Medium
  • 120TriangleBottom-up in one row of space.Medium
  • Minimum Falling Path SumThree parents per cell.Medium
  • 221Maximal Square1 + min of the three neighbours.Medium
  • 174Dungeon GameFill backwards from the princess.Hard
  • Cherry Pickup IITwo robots move together: state (row, c1, c2).Hard
0/1 KnapsackLearnit
0/5
  • 416Partition Equal Subset SumIn the 128 · Can a subset reach total / 2?Medium
  • 494Target SumIn the 128 · Count subsets summing to (total + target) / 2.Medium
  • 474Ones and ZeroesA knapsack with two capacities.Medium
  • Book ShopThe classic knapsack: price as weight, pages as value.CSESMedium
  • Max Value within Budget (0/1 Knapsack)DE Shaw and Snowflake OA: 1D table, loop backwards.OAMedium
Unbounded KnapsackLearnit
0/4
  • 322Coin ChangeIn the 128 · Fewest coins: min over coins of dp[a − c] + 1.Medium
  • 518Coin Change IIIn the 128 · Coins in the outer loop count combinations.Medium
  • 377Combination Sum IVAmount in the outer loop counts orderings.Medium
  • 279Perfect SquaresCoin Change with squares as coins.Medium
LCS / Two-SequenceTwo-string DPLearnit
0/8
  • 1143Longest Common SubsequenceIn the 128 · Match: diagonal + 1. Else: the max of top and left.Medium
  • 72Edit DistanceIn the 128 · Insert, delete, replace: the min of three neighbours.Medium
  • Maximum Length of Repeated SubarrayLongest common substring: reset to 0 on a mismatch.Medium
  • 115Distinct SubsequencesCount the ways, not the length.Hard
  • 97Interleaving Stringdp[i][j]: can the first i + j letters interleave?Medium
  • Wildcard Matching"*" takes zero or more: left or top.Hard
  • Regular Expression Matching"x*" means zero copies, or one more x.Hard
  • Shortest Common Supersequence Rebuild the string from the LCS table.Hard
Longest Increasing SubsequenceLearnit
0/5
  • 300Longest Increasing SubsequenceIn the 128 · O(n²) first, then tails + binary search.Medium
  • 368Largest Divisible SubsetSort, then LIS on divisibility, rebuilt.Medium
  • Longest String ChainSort by length; try deleting each letter.Medium
  • 354Russian Doll EnvelopesWidth up, height down, then LIS on heights.Hard
  • Increasing SubsequenceLIS at n = 2·10⁵: only the n log n version passes.CSESMedium
Palindromic SubstringsPalindrome DPLearnit
0/3
  • 516Longest Palindromic SubsequenceLCS of s and its reverse.Medium
  • Minimum Insertion Steps to Make a String PalindromeKeep the longest palindromic subsequence; insert the rest: n − LPS.Hard
  • 132Palindrome Partitioning IIA palindrome table, then a min-cuts DP.Hard
Interval DPLearnit
0/5
  • 312Burst BalloonsIn the 128 · Choose the last balloon to burst in (l, r).Hard
  • Minimum Score Triangulation of PolygonMatrix-chain multiplication in disguise.Medium
  • 1547Minimum Cost to Cut a StickSort the cuts; interval DP over cut indices.Hard
  • Removal GameTwo players take from the ends: the difference DP.CSESMedium
  • Strange PrinterMerge when the ends match.Hard
State Machine DP (Stocks)State machine DPLearnit
0/7
  • 121Best Time to Buy and Sell StockIn the 128 · Track the cheapest day so far.Easy
  • 309Best Time to Buy and Sell Stock with CooldownHold, sold, rest.Medium
  • 714Best Time to Buy and Sell Stock with Transaction FeeHold and free, pay on sale.Medium
  • 123Best Time to Buy and Sell Stock IIIFour states: two buys, two sells.Hard
  • Maximum Profit in Job SchedulingIn the 128 · Sort by end; take a job plus the best ending before it.Hard
  • Minimum Difficulty of a Job Scheduledp[day][i]: try every last-day block.Hard
  • Maximum Order Volume (Weighted Interval Scheduling)Snowflake OA: weighted interval scheduling again.OAHard
Bitmask DPLearnit
0/4
  • 698Partition to K Equal Sum Subsetsdp[mask] = the fill of the current bucket.Medium
  • 847Shortest Path Visiting All NodesBFS over (node, visited mask).Hard
  • Hamiltonian FlightsHamiltonian paths: dp[mask][last].CSESHard
  • Elevator RidesFewest rides: dp[mask] = (rides, weight in the last one).CSESMedium
Digit DPLearnit
0/3
  • Number of Digit OneCount per digit position.Hard
  • Numbers With Repeated DigitsCount numbers with all-distinct digits, subtract.Hard
  • Counting NumbersNo two adjacent digits equal: the full template.CSESMedium

Bit Tricks & BitmaskingBit manipulationLearnit
0/9
  • 136Single NumberIn the 128 · XOR everything; pairs cancel.Easy
  • 191Number of 1 Bitsn & (n − 1) removes the lowest set bit.Easy
  • 338Counting Bitsbits[i] = bits[i >> 1] + (i & 1).Easy
  • 137Single Number IICount each bit mod 3.Medium
  • 260Single Number IIIIn the 128 · Split the numbers on the lowest bit where the two differ.Medium
  • 371Sum of Two IntegersXOR is the sum, AND << 1 is the carry.Medium
  • 201Bitwise AND of Numbers RangeThe common prefix of the two ends.Medium
  • XOR Queries of a SubarrayPrefix XOR: the range is pre[r + 1] ^ pre[l].Medium
  • XOR World QueriesSprinklr OA: per-bit counts.OAMedium
Math / Number TheoryMath and number theoryLearnit
0/6
  • Greatest Common Divisor of Stringsgcd of the lengths, if a + b = b + a.Easy
  • 204Count PrimesIn the 128 · Sieve of Eratosthenes.Medium
  • 50Pow(x, n)In the 128 · Fast power: square and halve; careful with negative n.Medium
  • ExponentiationModular fast power.CSESMedium
  • Counting DivisorsDivisors by trial division up to √x.CSESMedium
  • Binomial CoefficientsnCr mod p with factorials and inverses.CSESMedium

System / DS DesignData-structure designLearnit
0/9
  • 146LRU CacheIn the 128 · Hash map + doubly linked list.Medium
  • 380Insert Delete GetRandom O(1)In the 128 · Array + index map; delete by swapping with the last.Medium
  • 981Time Based Key-Value StoreIn the 128 · Per-key sorted timestamps + binary search.Medium
  • 232Implement Queue using StacksTwo stacks, amortised O(1).Easy
  • 355Design TwitterPer-user lists, merged with a heap.Medium
  • Design Underground SystemTwo maps: open check-ins and route totals.Medium
  • Snapshot ArrayPer-index history + binary search on snap id.Medium
  • 460LFU CacheFrequency buckets of linked lists, plus a min-frequency pointer.Hard
  • In-Memory Database (CodeSignal ICF, 4 levels)Meta's CodeSignal OA: four levels of one growing design.OAMedium

Segment Tree / Fenwick (BIT)Fenwick and segment treesLearnit
0/9
  • 307Range Sum Query - MutableA Fenwick tree: update and prefix in O(log n).Medium
  • Dynamic Range Minimum QueriesRange minimum with point updates: a segment tree.CSESMedium
  • Static Range Minimum QueriesStatic range minimum: a sparse table.CSESMedium
  • Range Update QueriesRange add, point read: a Fenwick tree over differences.CSESMedium
  • Hotel QueriesSegment tree descent: the first hotel with enough rooms.CSESMedium
  • 315Count of Smaller Numbers After SelfFenwick over compressed values, scanning right to left.Hard
  • 493Reverse PairsMerge sort counting, or a Fenwick tree.Hard
  • Inversions of Length 3Goldman Sachs OA: left-greater × right-smaller with a Fenwick tree.OAMedium
  • 218The Skyline ProblemSweep events with a max-heap of heights.Hard
TodayReviewPatternsProblems