Practice
370 problems across 27 topics. Hints come one at a time and the solution stays shut until you ask.
370 problems
Topic · Arrays
0 / 20 completed- EasySingle Stock Trade#single-pass#running-minimumO(n) timeO(1) space15 minInput: prices = [8, 3, 6, 1, 9, 4]Output: 8Start
- EasyDrop Sorted Duplicates#two-pointers#in-placeO(n) timeO(1) space15 minInput: nums = [1, 1, 2, 3, 3, 3]Output: 3, and nums begins with [1, 2, 3]Start
- MediumProduct Of Others#prefix-products#two-passO(n) timeO(n) spaceSign in25 minInput: nums = [2, 3, 4, 5]Output: [60, 40, 30, 24]Start
- MediumLongest Distinct Run#sliding-window#hash-mapO(n) timeO(n) spaceSign in25 minInput: items = [1, 2, 3, 2, 4, 5]Output: 4Start
- HardWindow Maximums#sliding-window#monotonic-dequeO(n) timeO(n) spaceSign in40 minInput: nums = [1, 4, 2, 7, 3, 3], k = 3Output: [4, 7, 7, 7]Start
- EasyMajority Value#counting#single-passO(n) timeO(1) space15 minInput: nums = [3, 3, 4]Output: 3Start
- MediumRotate Right By K#in-place#reversalO(n) timeO(1) spaceSign in25 minInput: nums = [1, 2, 3, 4, 5, 6, 7], k = 3Output: [5, 6, 7, 1, 2, 3, 4]Start
- MediumSpiral Grid Walk#matrix-traversal#boundary-shrinkingO(rows · cols) timeO(rows · cols) spaceSign in25 minInput: [[7]]Output: [7]Start
- EasyPush Target Values Back#two-pointers#write-pointerO(n) timeO(1) space15 minInput: nums = [4, 0, 7, 0, 2], v = 0Output: [4, 7, 2, 0, 0]Start
- MediumSubarray Sums Divisible by K#prefix-sums#hash-map#modular-arithmeticO(n) timeO(min(n, k)) spaceSign in25 minInput: nums = [2, -2, 3, 1, 5], k = 3Output: 6Start
- HardSmallest Absent Positive#cyclic-sort#index-as-homeO(n) timeO(1) spaceSign in35 minInput: nums = [5, 3, -1, 1, 2]Output: 4Start
- HardWater Held Between Bars#two-pointers#running-maximumO(n) timeO(1) spaceSign in35 minInput: heights = [3, 0, 2, 0, 4, 1, 2]Output: 8Start
- EasySquares of a Sorted List#two-pointers#merge-from-backO(n) timeO(n) space15 minInput: nums = [-5, -2, 1, 3, 4]Output: [1, 4, 9, 16, 25]Start
- EasyReverse Every K Block#in-place-reversal#two-pointersO(n) timeO(1) space15 minInput: nums = [1, 2, 3, 4, 5, 6, 7, 8], k = 3Output: [3, 2, 1, 6, 5, 4, 7, 8]Start
- EasyBalance Point Index#prefix-sums#running-sumO(n) timeO(1) space15 minInput: values = [2, 7, 1, 5, 4]Output: 2Start
- MediumLongest Window Within Budget#sliding-window#two-pointersO(n) timeO(1) spaceSign in25 minInput: costs = [4, 1, 1, 3, 2, 6], budget = 6Output: 3Start
- EasyTaller Than Everything After#running-maximum#linear-scanO(n) timeO(n) space15 minInput: heights = [16, 17, 4, 3, 5, 2]Output: [17, 5, 2]Start
- MediumThree Values Summing to Zero#two-pointers#sort-first#skip-duplicatesO(n²) timeO(n²) spaceSign in30 minInput: nums = [-1, 0, 1, 2, -1, -4]Output: [[-1, -1, 2], [-1, 0, 1]]Start
- MediumNext Larger Arrangement#in-place-reversal#suffix-scanO(n) timeO(1) spaceSign in25 minInput: nums = [1, 3, 2]Output: [2, 1, 3]Start
- MediumLargest Product Subarray#kadane#running-min-maxO(n) timeO(n) spaceSign in25 minInput: nums = [2, 3, -2, 4]Output: 6Start
Topic · Strings
0 / 16 completed- EasyLongest Shared Prefix#column-scan#string-comparisonO(total characters) timeO(len(words) + len(words[0])) space15 minInput: words = ["flower", "flow", "flight"]Output: "fl"Start
- EasyFirst Unique Character#hash-map#two-passO(n) timeO(k) space15 minInput: text = "reference"Output: 2Start
- MediumRun Length Compression#two-pointers#run-length-encodingO(n) timeO(n) spaceSign in25 minInput: text = "aaabccdddd"Output: "a3bc2d4"Start
- MediumMultiply Digit Strings#digit-arithmetic#carry-propagationO(len(a) · len(b)) timeO(len(a) + len(b)) spaceSign in30 minInput: a = "123", b = "456"Output: "56088"Start
- HardMinimum Window Cover#sliding-window#hash-mapO(len(text) + len(need)) timeO(len(text) + len(need)) spaceSign in45 minInput: text = "ADOBECODEBANC", need = "ABC"Output: "BANC"Start
- MediumGroup Anagrams Together#hash-map#canonical-formO(n · k log k) timeO(n · k) spaceSign in20 minInput: words = ["eat", "tea", "tan", "ate", "nat", "bat"]Output: [["ate", "eat", "tea"], ["bat"], ["nat", "tan"]]Start
- MediumRepeated DNA Sequences#rolling-hash#hash-setO(n) timeO(n) spaceSign in30 minInput: dna = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"Output: ["AAAAACCCCC", "CCCCCAAAAA"]Start
- EasyPalindrome After One Deletion#two-pointers#greedyO(n) timeO(1) space20 minInput: s = "racexcar"Output: TrueStart
- EasyReverse the Word Order#two-pointers#word-splitO(n) timeO(n) space10 minInput: s = " the sky is blue "Output: "blue is sky the"Start
- HardShortest Palindrome by Prepending#kmp#palindromeO(n) timeO(n) spaceSign in40 minInput: s = "abacd"Output: "dcabacd"Start
- MediumCount Palindromic Substrings#expand-around-center#palindromeO(n²) timeO(1) spaceSign in25 minInput: s = "level"Output: 7Start
- MediumSmallest Repeating Unit#kmp#string-periodO(n) timeO(n) spaceSign in25 minInput: s = "xyzxyzxyz"Output: "xyz"Start
- HardHow Often Each Prefix Appears#z-algorithm#suffix-sumsO(n) timeO(n) spaceSign in40 minInput: s = "abacaba"Output: [4, 2, 2, 1, 1, 1, 1]Start
- EasyPack a Word List Into One String#length-prefix#string-parsingO(L) timeO(L) space20 minInput: words = ["hi", "#1"]Output: pack -> "2#hi2##1"Start
- MediumAnagram Positions in a Text#fixed-sliding-window#frequency-countO(len(text) + len(key)) timeO(len(text)) spaceSign in25 minInput: text = "cbaebabacd", key = "abc"Output: [0, 6]Start
- EasyRoman Numeral to Integer#string-scan#lookup-tableO(n) timeO(1) space15 minInput: s = "LVIII"Output: 58Start
Topic · Searching
0 / 13 completed- EasyInteger Square Root#binary-search#monotonic-predicateO(log n) timeO(1) space20 minInput: n = 8Output: 2Start
- MediumPeak In Bumpy List#binary-search#slope-followingO(log n) timeO(1) spaceSign in30 minInput: nums = [1, 2, 3, 1]Output: 2Start
- HardMedian Of Two Sorted Lists#binary-search#partitioningO(log min(m, n)) timeO(1) spaceSign in50 minInput: a = [1, 3], b = [2]Output: 2.0Start
- MediumFirst And Last Occurrence#binary-search#boundary-searchO(log n) timeO(1) spaceSign in25 minInput: nums = [5, 7, 7, 8, 8, 10], target = 8Output: (3, 4)Start
- MediumMinimum Daily Capacity#binary-search-on-answer#greedy-checkO(n log(sum(weights))) timeO(1) spaceSign in30 minInput: weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], days = 5Output: 15Start
- EasyNearest Two Words#single-pass#linear-scanO(n) timeO(1) space15 minInput: words = ["cat", "dog", "fox", "cat", "owl", "dog"], a = "cat", b = "dog"Output: 1Start
- MediumCount the Rotations#binary-search#boundary-searchO(log n) timeO(1) spaceSign in20 minInput: nums = [15, 18, 2, 3, 6, 12]Output: 2Start
- MediumSearch a List of Unknown Length#binary-search#exponential-searchO(log p) timeO(1) spaceSign in25 minInput: values = [2, 5, 5, 9, 14, 20, 31], target = 9Output: 3Start
- EasyKth Number Missing From a List#binary-search#countingO(log n) timeO(1) space20 minInput: nums = [2, 3, 4, 7, 11], k = 5Output: 9Start
- MediumValue at a Point in Time#binary-search#upper-bound#versioned-storeO(log v) timeO(number of set calls) spaceSign in25 minInput: set("port", "80", 10), get("port", 9), get("port", 10)Output: ["", "80"]Start
- EasyNext Letter After the Target#binary-search#upper-boundO(log n) timeO(1) space15 minInput: letters = ["c", "f", "j"], target = "a"Output: "c"Start
- MediumTarget in a Rotated Sorted List#binary-search#rotated-arrayO(log n) timeO(1) spaceSign in20 minInput: nums = [4, 5, 6, 7, 0, 1, 2], target = 0Output: 4Start
- HardKth Smallest Pair Distance#binary-search-on-answer#two-pointers#sortingO(n log n + n log(max − min)) timeO(n) spaceSign in35 minInput: nums = [1, 3, 1], k = 1Output: 0Start
Topic · Sorting
0 / 15 completed- EasyOut Of Place Count#sorting#pairwise-comparisonO(n log n) timeO(n) space15 minInput: heights = [1, 1, 4, 2, 1, 3]Output: 3Start
- MediumThree Way Flag Sort#dutch-national-flag#in-placeO(n) timeO(1) spaceSign in30 minInput: values = [2, 0, 2, 1, 1, 0]Output: [0, 0, 1, 1, 2, 2]Start
- MediumLargest Number Arrangement#custom-comparator#sortingO(n log n) timeO(n) spaceSign in30 minInput: nums = [3, 30, 34, 5, 9]Output: "9534330"Start
- MediumH Index From Citations#sorting#countingO(n log n) timeO(1) spaceSign in20 minInput: citations = [3, 0, 6, 1, 5]Output: 3Start
- HardMaximum Gap Buckets#bucket-sort#pigeonholeO(n log n) timeO(n) spaceSign in40 minInput: nums = [3, 6, 9, 1]Output: 3Start
- EasyInsertion Sort Shift Count#insertion-sort#stable-sortO(n²) timeO(n) space15 minInput: nums = [3, 1, 2]Output: 2Start
- MediumSort a Linked Chain#divide-and-conquer#fast-slow-pointersO(n log n) timeO(log n) spaceSign in30 minInput: 4 -> 1 -> 3 -> 1 -> 2Output: 1 -> 1 -> 2 -> 3 -> 4Start
- MediumFewest Swaps to Sort#cycle-decomposition#selection-sortO(n log n) timeO(n) spaceSign in25 minInput: nums = [4, 3, 1, 2]Output: 3Start
- MediumKth Smallest by Partitioning#quickselect#three-way-partitionO(n) timeO(n) spaceSign in30 minInput: nums = [7, 2, 9, 4, 4, 1], k = 3Output: 4Start
- EasyPairs Below a Budget#sorting#two-pointersO(n log n) timeO(n) space20 minInput: prices = [4, -2, 0, 3, 1], budget = 3Output: 5Start
- MediumOrder After K Digit Passes#radix-sort#stable-sort#bucket-sortO(k · n) timeO(n) spaceSign in25 minInput: nums = [53, 7, 318, 90, 41, 206, 17], k = 1Output: [90, 41, 53, 206, 7, 17, 318]Start
- HardCount Out-of-Order Pairs#merge-sort#divide-and-conquer#inversion-countO(n log n) timeO(n) spaceSign in35 minInput: nums = [2, 4, 1, 3, 5]Output: 3Start
- EasySort by Another List's Order#counting-sort#custom-orderO(n + k) timeO(n + k) space15 minInput: values = [2, 3, 1, 3, 2, 4, 6, 7, 9, 2, 19], order = [2, 1, 4, 3, 9, 6]Output: [2, 2, 2, 1, 4, 3, 3, 9, 6, 7, 19]Start
- MediumPancake Flips to Sort#selection-sort#prefix-reversalO(n²) timeO(n) spaceSign in25 minInput: arr = [3, 2, 4, 1]Output: [3, 4, 2, 3, 2]Start
- EasyPairs With the Smallest Gap#sort-first#adjacent-scanO(n log n) timeO(n) space15 minInput: nums = [4, 2, 1, 3]Output: [[1, 2], [2, 3], [3, 4]]Start
Topic · Linked Lists
0 / 14 completed- EasyMerge Sorted Chains#two-pointers#dummy-nodeO(n + m) timeO(1) space20 minInput: a = 1 -> 4 -> 6, b = 2 -> 3Output: 1 -> 2 -> 3 -> 4 -> 6Start
- MediumDrop Nth From End#fast-slow-pointers#dummy-nodeO(L) timeO(1) spaceSign in25 minInput: head = 1 -> 2 -> 3 -> 4 -> 5, n = 2Output: 1 -> 2 -> 3 -> 5Start
- MediumWeave List Halves#fast-slow-pointers#list-reversalO(n) timeO(1) spaceSign in35 minInput: head = 1 -> 2 -> 3 -> 4Output: 1 -> 4 -> 2 -> 3Start
- EasyRemove Value Nodes#dummy-node#pointer-relinkingO(n) timeO(1) space15 minInput: head = 1 -> 2 -> 6 -> 3 -> 6, target = 6Output: 1 -> 2 -> 3Start
- MediumAdd Two Digit Chains#dummy-node#carry-propagationO(max(m, n)) timeO(max(m, n)) spaceSign in25 minInput: a = 2 -> 4 -> 3, b = 5 -> 6 -> 4Output: 7 -> 0 -> 8Start
- MediumPartition Around Value#dummy-node#list-splittingO(n) timeO(1) spaceSign in30 minInput: head = 1 -> 4 -> 3 -> 2 -> 5 -> 2, pivot = 3Output: 1 -> 2 -> 2 -> 4 -> 3 -> 5Start
- EasyLoop in a Chain#fast-slow-pointers#cycle-detectionO(n) timeO(1) space15 minInput: values = [3, 2, 0, -4], pos = 1Output: TrueStart
- EasyBack and Forward History#doubly-linked-list#designO(n + Σk) timeO(n) space20 minInput: home = "x", ops = [("back", 2), ("forward", 3)]Output: ['x', 'x']Start
- MediumWhere the Loop Begins#fast-slow-pointers#cycle-detectionO(n) timeO(1) spaceSign in30 minInput: values = [3, 2, 0, -4], pos = 1Output: 2Start
- MediumClone a Chain With Jump Links#pointer-relinking#in-placeO(n) timeO(n) spaceSign in30 minInput: chain = [(3, None), (8, 0), (5, 3), (1, 1)]Output: [(3, None), (8, 0), (5, 3), (1, 1)], built from new nodes onlyStart
- EasyChain Reads the Same Backwards#fast-slow-pointers#in-place-reversalO(n) timeO(1) space20 minInput: 1 -> 2 -> 2 -> 1Output: TrueStart
- MediumLeast Recently Used Cache#doubly-linked-list#hash-map#sentinel-nodesO(1) timeO(capacity) spaceSign in35 minStart
- HardReverse Nodes in Groups of K#in-place-reversal#dummy-headO(n) timeO(1) spaceSign in35 minInput: list = 1 -> 2 -> 3 -> 4 -> 5, k = 2Output: 2 -> 1 -> 4 -> 3 -> 5Start
- EasyWhere Two Chains Merge#two-pointers#list-traversalO(m + n) timeO(1) space15 minInput: a = 2 -> 6 -> 4, b = 1 -> 5, no shared nodesOutput: NoneStart
Topic · Stacks & Queues
0 / 15 completed- EasyConstant Time Min Stack#stack#auxiliary-stackO(1) timeO(n) space20 minStart
- MediumDays Until Warmer#monotonic-stackO(n) timeO(n) spaceSign in30 minInput: temps = [30, 32, 31, 35]Output: [1, 2, 1, 0]Start
- EasyCollapse Adjacent Pairs#stack#string-scanO(n) timeO(n) space15 minInput: text = "abbaca"Output: "ca"Start
- MediumDecode Nested Repeats#stack#string-parsingO(output · depth) timeO(output + depth) spaceSign in30 minInput: text = "3[a]2[bc]"Output: "aaabcbc"Start
- HardLargest Bar Rectangle#monotonic-stackO(n) timeO(n) spaceSign in45 minInput: heights = [2, 1, 5, 6, 2, 3]Output: 10Start
- EasyRequests in the Last Window#queue#sliding-windowO(n) timeO(n) space15 minInput: times = [0, 400, 900, 1000, 1400], w = 1000Output: [1, 2, 3, 3, 3]Start
- EasyTwo-Stack Queue Operations#two-stacks#amortizedO(m) timeO(m) space15 minInput: ops = [["push", 7], ["pop"], ["push", 8], ["push", 9], ["peek"]]Output: [7, 8]Start
- MediumRing Buffer Deque#circular-buffer#designO(1) timeO(capacity) spaceSign in25 minStart
- EasyEvaluate Postfix Tokens#stack#expression-evaluationO(n) timeO(n) space15 minInput: tokens = ["2", "1", "+", "3", "*"]Output: 9Start
- MediumColliding Rocks in a Row#stack#pop-while-weakerO(n) timeO(n) spaceSign in25 minInput: rocks = [5, 10, -5]Output: [5, 10]Start
- HardEvaluate Sums With Brackets#stack#expression-parsing#sign-trackingO(n) timeO(depth) spaceSign in40 minInput: s = "1 + 1"Output: 2Start
- EasyNext Greater Value Lookup#monotonic-stack#hash-mapO(n + q) timeO(n + q) space15 minInput: nums = [4, 1, 3, 6, 2, 5], queries = [1, 3, 2, 6]Output: [3, 6, 5, -1]Start
- EasyPrices After the Next Discount#monotonic-stack#next-smallerO(n) timeO(n) space15 minInput: prices = [8, 4, 6, 2, 3]Output: [4, 2, 4, 2, 3]Start
- MediumSimplify a Unix Path#stack#string-parsingO(n) timeO(n) spaceSign in20 minInput: path = "/a/./b/../../c/"Output: "/c"Start
- HardShortest Run Summing to at Least K#monotonic-deque#prefix-sumO(n) timeO(n) spaceSign in40 minInput: nums = [2, -1, 2], k = 3Output: 3Start
Topic · Hash Tables
0 / 14 completed- EasyRepeated Value Check#hash-set#single-passO(n) timeO(n) space10 minInput: items = [4, 1, 9, 1]Output: TrueStart
- MediumSubarrays Summing To K#prefix-sums#hash-mapO(n) timeO(n) spaceSign in30 minInput: nums = [1, 2, 3, 1], k = 3Output: 2Start
- MediumLongest Consecutive Run#hash-set#countingO(n) timeO(n) spaceSign in30 minInput: nums = [9, 4, 2, 3, 1, 8]Output: 4Start
- EasyShared Values Of Two Lists#hash-set#membership-testO(n + m) timeO(m) space15 minInput: a = [1, 2, 2, 1], b = [2, 2]Output: [2]Start
- EasyConsistent Renaming Check#hash-map#bijectionO(n) timeO(n) space20 minInput: a = "egg", b = "add"Output: TrueStart
- MediumFour List Zero Tuples#hash-map#meet-in-the-middleO(n²) timeO(n²) spaceSign in30 minInput: a = [1, 2], b = [-2, -1], c = [-1, 2], d = [0, 2]Output: 2Start
- EasyClosest Repeat Distance#hash-map#single-passO(n) timeO(n) space15 minInput: values = [7, 1, 3, 7, 1, 7]Output: 2Start
- MediumWhere Linear Probing Lands#open-addressing#union-findO(m + n log m) timeO(m) spaceSign in30 minInput: m = 7, keys = [10, 3, 17, 24, 5]Output: [3, 4, 5, 6, 0]Start
- MediumSort Letters by Frequency#bucket-sort#countingO(n) timeO(n) spaceSign in20 minInput: text = "banana"Output: "aaannb"Start
- HardLeast Frequently Used Cache#design#hash-map#frequency-bucketsO(1) timeO(capacity) spaceSign in45 minStart
- MediumLongest Balanced Zeros and Ones#prefix-sum#first-seen-indexO(n) timeO(n) spaceSign in20 minInput: bits = [0, 1, 0]Output: 2Start
- EasyCount Pairs With a Given Gap#hash-map#complement-lookupO(n) timeO(n) space15 minInput: nums = [3, 1, 4, 1, 5], k = 2Output: 2Start
- EasyRansom Note From a Magazine#frequency-count#hash-mapO(n + m) timeO(1) space10 minInput: note = "aab", banner = "baa"Output: TrueStart
- MediumGroup Words by Letter Shift#canonical-key#hash-map#groupingO(n · L) timeO(n · L) spaceSign in20 minInput: words = ["abc", "bcd", "acef", "xyz", "az", "ba", "a", "z"]Output: [["abc", "bcd", "xyz"], ["acef"], ["az", "ba"], ["a", "z"]]Start
Topic · Recursion
0 / 14 completed- EasyFlatten a Nested List#recursion#tree-walkO(n) timeO(n) space15 minInput: items = [1, [2, [3, 4]], 5]Output: [1, 2, 3, 4, 5]Start
- MediumDisc Tower Moves#recursion#divide-and-conquerO(2ⁿ) timeO(2ⁿ) spaceSign in20 minInput: n = 1, src = "A", dst = "C", spare = "B"Output: [("A", "C")]Start
- MediumFast Power#recursion#divide-and-conquerO(log |exp|) timeO(log |exp|) spaceSign in20 minInput: base = 2, exp = 10Output: 1024Start
- EasyDepth Weighted Nested Sum#recursion#pass-downO(n) timeO(d) space15 minInput: items = [[1, 1], 2, [1, 1]]Output: 10Start
- MediumSymbol In A Doubling Row#recursion#halvingO(n) timeO(n) spaceSign in25 minInput: n = 4, k = 5Output: 1Start
- MediumEvery Way To Bracket#divide-and-conquer#memoizationO(4ⁿ / √n) timeO(4ⁿ / √n) spaceSign in30 minInput: expr = "2-1-1"Output: [0, 2]Start
- MediumKth Smallest BST Key, Iteratively#explicit-stack#inorderO(h + k) timeO(h) spaceSign in25 minInput: same tree; k = 8Output: 14Start
- EasyHalve or Subtract One Steps#tail-recursion#bit-countingO(log n) timeO(1) space15 minInput: n = 14Output: 6Start
- EasyLook and Say Term#recursion#run-lengthO(1.31ⁿ) timeO(1.31ⁿ) space15 minInput: n = 4Output: "1211"Start
- MediumUpside-Down Numbers of a Given Length#recursion#build-from-inside-outO(n · 5^(n/2)) timeO(n · 5^(n/2)) spaceSign in25 minInput: n = 2Output: ["11", "69", "88", "96"]Start
- EasyNth Tribonacci Number#recurrence#rolling-stateO(n) timeO(1) space10 minInput: n = 4Output: 4Start
- HardScrambled String Check#recursion#memoization#divide-and-conquerO(n⁴ log n) timeO(n³) spaceSign in40 minInput: s1 = "great", s2 = "rgeat"Output: TrueStart
- MediumLast Friend Standing in a Circle#recursion#josephus#recurrenceO(n) timeO(1) spaceSign in25 minInput: n = 5, k = 2Output: 3Start
- EasyPalindrome Check Ignoring Punctuation#tail-recursion#two-pointersO(n) timeO(1) space15 minInput: s = "A man, a plan, a canal: Panama"Output: TrueStart
Topic · Backtracking
0 / 14 completed- MediumPhone Keypad Words#backtracking#decision-treeO(n · 3ⁿ) timeO(n · 3ⁿ) spaceSign in20 minInput: digits = "23"Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]Start
- MediumCombinations That Sum#backtracking#pruningO(n^(target / min)) timeO(n^(target / min)) spaceSign in25 minInput: nums = [2, 3, 6, 7], target = 7Output: [[2, 2, 3], [7]]Start
- MediumSplit Into Palindromes#backtracking#pruningO(n · 2ⁿ) timeO(n · 2ⁿ) spaceSign in25 minInput: s = "aab"Output: [["a", "a", "b"], ["aa", "b"]]Start
- EasyFlip Letter Case Variants#backtracking#include-excludeO(n · 2^L) timeO(n · 2^L) space15 minInput: s = "a1b"Output: ["a1b", "a1B", "A1b", "A1B"]Start
- MediumBalanced Bracket Strings#backtracking#pruningO(4ⁿ / √n) timeO(4ⁿ / √n) spaceSign in25 minInput: n = 3Output: ["((()))", "(()())", "(())()", "()(())", "()()()"]Start
- HardCount Queen Placements#backtracking#constraint-setsO(n!) timeO(n) spaceSign in40 minInput: n = 4Output: 2Start
- MediumDistinct Arrangements#backtracking#pruning#sortingO(n · n!) timeO(n · n!) spaceSign in30 minInput: vals = [1, 2, 1]Output: [[1, 1, 2], [1, 2, 1], [2, 1, 1]]Start
- MediumDotted Addresses From Digits#backtracking#pruningO(1) timeO(1) spaceSign in30 minInput: s = "25525511135"Output: ["255.255.11.135", "255.255.111.35"]Start
- HardFill a Sudoku Grid#backtracking#constraint-setsSign in45 minInput: the first row is "11......." and the rest are emptyOutput: FalseStart
- HardMatchsticks Into a Square#backtracking#pruning#k-way-partitionO(4ⁿ) timeO(n) spaceSign in40 minInput: sticks = [1, 1, 2, 2, 2]Output: TrueStart
- EasyBinary Strings With No Adjacent Ones#backtracking#pruningO(n · 1.62ⁿ) timeO(n · 1.62ⁿ) space15 minInput: n = 3Output: ["000", "001", "010", "100", "101"]Start
- MediumTrace a Word Through a Letter Grid#backtracking#grid-dfs#pruningO(rows · cols · 3^L) timeO(rows · cols + L) spaceSign in25 minInput: board = ["ABCE", "SFCS", "ADEE"], word = "ABCCED"Output: TrueStart
- EasyChoose K of the First N Numbers#backtracking#combinations#pruningO(k · C(n, k)) timeO(k · C(n, k)) space15 minInput: n = 4, k = 2Output: [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]Start
- EasyDigit Orderings Under a Limit#backtracking#permutations#pruningO(n · n!) timeO(n!) space15 minInput: digits = [3, 1, 2], limit = 300Output: [123, 132, 213, 231]Start
Topic · Greedy
0 / 13 completed- MediumFewest Removals to Unclash#greedy#interval-scheduling#sortingO(n log n) timeO(1) spaceSign in20 minInput: spans = [(1, 2), (2, 3), (3, 4), (1, 3)]Output: 1Start
- MediumFewest Hops to the End#greedy#reach-frontierO(n) timeO(1) spaceSign in20 minInput: nums = [2, 3, 1, 1, 4]Output: 2Start
- MediumSplit String Into Blocks#greedy#last-occurrenceO(n) timeO(1) spaceSign in20 minInput: s = "abacdc"Output: [3, 3]Start
- EasyHand Out Cookies#greedy#sorting#two-pointersO(n log n + m log m) timeO(n + m) space15 minInput: wants = [1, 2, 3], sizes = [1, 1]Output: 1Start
- MediumCircular Fuel Route#greedy#running-sumO(n) timeO(1) spaceSign in25 minInput: fuel = [1, 2, 3, 4, 5], cost = [3, 4, 5, 1, 2]Output: 3Start
- HardFair Candy Shares#greedy#two-passO(n) timeO(n) spaceSign in40 minInput: scores = [1, 0, 2]Output: 5Start
- MediumCheapest Rope Joining#greedy#min-heapO(n log n) timeO(n) spaceSign in25 minInput: lengths = [4, 3, 2, 6]Output: 29Start
- EasySplit Candidates Between Two Cities#greedy#sort-by-differenceO(n log n) timeO(n) space20 minInput: costs = [[10, 20], [30, 200], [400, 50], [30, 20]]Output: 110Start
- MediumMost Events You Can Attend#greedy#min-heap#earliest-deadlineO(n log n) timeO(n) spaceSign in30 minInput: events = [[1, 2], [2, 3], [3, 4], [1, 2]]Output: 4Start
- MediumFewest Clips to Cover a Broadcast#greedy#reach-frontier#interval-coverO(n + T) timeO(T) spaceSign in25 minInput: clips = [[0, 2], [4, 6], [8, 10], [1, 9], [1, 5], [5, 9]], T = 10Output: 3Start
- EasySmallest Start for a Positive Walk#running-sum#prefix-minimumO(n) timeO(1) space10 minInput: nums = [-3, 2, -3, 4, 2]Output: 5Start
- MediumLongest Chain of Pairs#greedy#sort-by-end#interval-schedulingO(n log n) timeO(n) spaceSign in20 minInput: pairs = [[1, 2], [2, 3], [3, 4]]Output: 2Start
- EasyCan the Last Index Be Reached#greedy#farthest-reachO(n) timeO(1) space15 minInput: jumps = [2, 3, 1, 1, 4]Output: TrueStart
Topic · Trees & BST
0 / 17 completed- EasyDeepest Level Count#dfs#recursionO(n) timeO(h) space15 minInput: tree = 3 with children 9 and 20, where 20 has children 15 and 7Output: 3Start
- MediumZigzag Level Walk#bfs#level-orderO(n) timeO(n) spaceSign in30 minInput: tree = 3 with children 9 and 20, where 20 has children 15 and 7Output: [[3], [20, 9], [15, 7]]Start
- MediumRight Edge View#bfs#level-orderO(n) timeO(n) spaceSign in25 minInput: tree = 1, left child 2 with right child 5, right child 3 with right child 4Output: [1, 3, 4]Start
- EasyMirror Symmetry Check#recursion#paired-traversalO(n) timeO(h) space20 minInput: tree = 1, left 2 with children 3 and 4, right 2 with children 4 and 3Output: TrueStart
- EasyRoot To Leaf Target Sum#dfs#recursionO(n) timeO(h) space20 minInput: tree = 1 with a single left child 2; target = 1Output: FalseStart
- MediumWidest Node To Node Path#dfs#post-orderO(n) timeO(h) spaceSign in30 minInput: tree = 1 with left child 2 having children 4 and 5, and right child 3Output: 3Start
- HardRebuild From Two Walks#divide-and-conquer#hash-map#recursionO(n) timeO(n) spaceSign in45 minInput: before = [3, 9, 20, 15, 7], middle = [9, 3, 15, 20, 7]Output: 3 with left child 9 and right child 20, whose children are 15 and 7Start
- EasyClosest Key in a BST#bst#search-pathO(h) timeO(1) space15 minInput: same tree; target = 12.2Output: 14Start
- MediumDistance Between Two BST Keys#bst#lowest-common-ancestorO(h) timeO(1) spaceSign in25 minInput: same tree; a = 6, b = 7Output: 1Start
- EasyShallowest Leaf Depth#bfs#level-orderO(n) timeO(w) space15 minInput: tree = 6, left 2 (whose left is 1, whose left is 0), right 9Output: 2Start
- MediumFlatten a Tree Into a Chain#preorder#explicit-stackO(n) timeO(h) spaceSign in25 minInput: tree = 7, left 3 (children 1 and 5), right 9 (left child 8)Output: chain 7 -> 3 -> 1 -> 5 -> 9 -> 8Start
- MediumTop View of a Tree#bfs#column-indexO(n) timeO(n) spaceSign in25 minInput: tree = 8, left 4, whose left is 2Output: [2, 4, 8]Start
- MediumLargest BST Inside a Tree#post-order#bstO(n) timeO(h) spaceSign in30 minInput: tree = 5, left 3, right 8 (children 7 and 9)Output: 5Start
- MediumCompact BST Serialization#preorder#monotonic-stack#bstO(n) timeO(n) spaceSign in30 minInput: tree = 8, left 3 (children 1 and 6), right 10 (right child 14)Output: encode -> "8 3 1 6 10 14"Start
- EasyMirror a Binary Tree#recursion#tree-traversalO(n) timeO(h) space10 minInput: tree = 4, left 2 (children 1 and 3), right 7 (children 6 and 9)Output: [4, 7, 2, 9, 6, 3, 1]Start
- HardBest Path Sum Between Any Nodes#post-order#tree-dp#global-bestO(n) timeO(h) spaceSign in35 minInput: tree = -10, left 9, right 20 (children 15 and 7)Output: 42Start
- EasyHeight-Balanced Tree Check#post-order#early-exitO(n) timeO(h) space15 minInput: tree = 3, left 9, right 20 (children 15 and 7)Output: TrueStart
Topic · Tries
0 / 12 completed- MediumWildcard Word Search#trie#backtrackingO(26ᵈ · m) timeO(total characters) spaceSign in30 minInput: words = ["bad", "dad", "mad"], query = ".ad"Output: TrueStart
- MediumReplace Words With Roots#trie#prefix-matchO(R + S) timeO(R + S) spaceSign in25 minInput: roots = ["cat", "bat", "rat"], sentence = "the cattle was rattled by the battery"Output: "the cat was rat by the bat"Start
- HardMaximum XOR Pair#bit-trie#greedyO(n · b) timeO(n · b) spaceSign in40 minInput: nums = [3, 10, 5, 25, 2, 8]Output: 28Start
- EasyPrefix Tree Operations#trie#designO(L) timeO(total characters) space20 minInput: insert("apple"), has_word("apple"), has_word("app"), has_prefix("app")Output: True, False, TrueStart
- MediumTypeahead Top Three#trie#prefix-matchO(n log n + total characters) timeO(total characters) spaceSign in30 minInput: products = ["mobile", "mouse", "moneypot", "monitor", "mousepad"], word = "mouse"Output: [["mobile", "moneypot", "monitor"],Start
- HardDictionary Words In A Grid#trie#backtracking#grid-dfsO(cells · 4 · 3^(L−1)) timeO(total word characters) spaceSign in45 minInput: grid = [["a"]], words = ["a", "aa"]Output: ["a"]Start
- MediumLongest Word Built Letter by Letter#trie#dfsO(total characters) timeO(total characters) spaceSign in25 minInput: words = ["w", "wo", "wor", "worl", "world"]Output: "world"Start
- EasySum of Values by Prefix#trie#designO(L) timeO(total characters) space20 minInput: put("apple", 3), total("ap"), put("app", 2), total("ap"), total("apple")Output: 3, 5, 3Start
- HardWord Endings in a Letter Stream#trie#reversed-trie#streamO(L) timeO(total characters + L) spaceSign in40 minInput: words = ["cd", "f", "kl"], stream = "abcdefghijkl"Output: [F, F, F, T, F, T, F, F, F, F, F, T]Start
- MediumShortest Unique Prefixes#trie#prefix-countO(L) timeO(L) spaceSign in25 minInput: words = ["zebra", "dog", "duck", "dove"]Output: ["z", "dog", "du", "dov"]Start
- EasySpot Dictionary Words in a Text#trie#prefix-pruningO(n · L + W) timeO(W + n · L) space15 minInput: text = "bytesofcode", words = ["byte", "bytes", "code", "of", "so"]Output: [[0, 3], [0, 4], [4, 5], [5, 6], [7, 10]]Start
- MediumShortest Encoding of a Word List#trie#suffix-sharingO(W) timeO(W) spaceSign in25 minInput: words = ["time", "me", "bell"]Output: 10Start
Topic · Heaps
0 / 14 completed- MediumKth Largest Value#min-heap#top-kO(n log k) timeO(k) spaceSign in25 minInput: nums = [3, 2, 1, 5, 6, 4], k = 2Output: 5Start
- EasySmash Heaviest Stones#max-heap#simulationO(n log n) timeO(n) space20 minInput: stones = [2, 7, 4, 1, 8, 1]Output: 1Start
- MediumClosest Points To Origin#max-heap#top-kO(n log k) timeO(k) spaceSign in30 minInput: points = [[3, 3], [5, -1], [-2, 4]], k = 2Output: [(3, 3), (-2, 4)]Start
- HardRunning Median Stream#two-heaps#streamingO(n log n) timeO(n) spaceSign in45 minInput: stream = [5, 15, 1, 3]Output: [5.0, 10.0, 5.0, 4.0]Start
- MediumTask Scheduler Cooldown#heap#greedyO(n log d + n · gap) timeO(d) spaceSign in35 minInput: tasks = ["a", "a", "a", "b", "b", "b"], gap = 2Output: 8Start
- MediumReorganize String Gaps#heap#greedyO(n log d) timeO(n) spaceSign in30 minInput: s = "aab"Output: "aba"Start
- EasyMin-Heap Array Check#heap#array-as-treeO(n) timeO(1) space15 minInput: values = [1, 3, 2, 7, 4]Output: TrueStart
- MediumSort a Nearly Sorted List#min-heap#k-sortedO(n log k) timeO(n) spaceSign in25 minInput: nums = [3, 1, 2, 6, 4, 5], k = 2Output: [1, 2, 3, 4, 5, 6]Start
- MediumHow Far Bricks and Ladders Go#min-heap#greedyO(n log ladders) timeO(ladders) spaceSign in30 minInput: heights = [4, 2, 7, 6, 9, 14, 12], bricks = 5, ladders = 1Output: 4Start
- MediumProcess Tasks on One CPU#min-heap#event-simulationO(n log n) timeO(n) spaceSign in30 minInput: tasks = [[1, 2], [2, 4], [3, 2], [4, 1]]Output: [0, 2, 3, 1]Start
- EasyK Weakest Squads#top-k#max-heapO(m · n + m log k) timeO(k) space20 minInput: roster = [[1, 1, 0, 0, 0], [1, 1, 1, 1, 0], [1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 1, 1]], k = 3Output: [2, 0, 3]Start
- EasyClosest K Values to a Target#top-k#max-heapO(n log k) timeO(k) space15 minInput: nums = [9, 2, 14, 5, 7, 11], target = 8, k = 3Output: [5, 7, 9]Start
- EasyHeapify a List in Place#heapify#sift-downO(n) timeO(1) space15 minInput: nums = [5, 3, 8, 1, 2]Output: [1, 2, 8, 3, 5]Start
- MediumSpread Letters at Least K Apart#max-heap#greedy#cooldown-queueO(n) timeO(n) spaceSign in30 minInput: s = "aabbcc", k = 3Output: "abcabc"Start
Topic · Two Heaps & K-Way Merge
0 / 14 completed- MediumKth Smallest In Matrix#k-way-merge#heapO(n + k log n) timeO(n) spaceSign in30 minInput: matrix = [[1, 5, 9], [10, 11, 13], [12, 13, 15]], k = 8Output: 13Start
- HardSmallest Range K Lists#k-way-merge#sliding-windowO(n log k) timeO(k) spaceSign in45 minInput: lists = [[4, 10, 15, 24, 26], [0, 9, 12, 20], [5, 18, 22, 30]]Output: [20, 24]Start
- HardCapital Project Picks#two-heaps#greedyO(n log n) timeO(n) spaceSign in40 minInput: projects = [(0, 1), (1, 2), (2, 3)], capital = 0, rounds = 2Output: 3Start
- EasyMerge K Sorted Runs#k-way-merge#min-heapO(n log k) timeO(n) space20 minInput: lists = [[1, 4, 5], [1, 3, 4], [2, 6]]Output: [1, 1, 2, 3, 4, 4, 5, 6]Start
- MediumK Smallest Pair Sums#k-way-merge#min-heapO(k log k) timeO(k) spaceSign in30 minInput: a = [1, 7, 11], b = [2, 4, 6], k = 3Output: [[1, 2], [1, 4], [1, 6]]Start
- HardRolling Window Median#two-heaps#lazy-deletion#sliding-windowO(n log n) timeO(n) spaceSign in45 minInput: nums = [1, 3, -1, -3, 5, 3, 6, 7], k = 3Output: [1.0, -1.0, -1.0, 3.0, 5.0, 6.0]Start
- MediumK Most Frequent Values#top-k#min-heap#hash-mapO(n + d log k) timeO(d) spaceSign in25 minInput: values = [4, 1, 4, 2, 1, 4, 3], k = 2Output: [4, 1]Start
- MediumNext Span to the Right#two-heaps#max-heapO(n log n) timeO(n) spaceSign in30 minInput: spans = [[3, 4], [2, 3], [1, 2]]Output: [-1, 0, 1]Start
- MediumKth Smallest Prime Fraction#k-way-merge#min-heapO((n + k) log n) timeO(n) spaceSign in30 minInput: values = [1, 2, 3, 5], k = 3Output: [2, 5]Start
- EasyMiddle Score After Each Entry#two-heaps#streamingO(n log n) timeO(n) space20 minInput: scores = [5, 15, 1, 3]Output: [5, 5, 5, 3]Start
- EasyBid-Ask Spread After Each Quote#two-heaps#max-heap#min-heapO(n log n) timeO(n) space15 minInput: quotes = [("buy", 100), ("sell", 105), ("buy", 102), ("sell", 104), ("buy", 99)]Output: [None, 5, 3, 2, 2]Start
- MediumK Most Frequent Words#top-k#min-heap#hash-mapO(n + m log k) timeO(m) spaceSign in20 minInput: words = ["red", "blue", "red", "green", "blue", "red"], k = 2Output: ["red", "blue"]Start
- EasyKth Largest in a Score Stream#min-heap#top-k#data-streamO(n log k) timeO(k) space15 minInput: k = 3, scores = [4, 5, 8, 2], then add 3, 5, 10, 9, 4Output: [4, 5, 5, 8, 8]Start
- HardCheapest Way to Level Each Window#two-heaps#sliding-window#lazy-deletionO(n log n) timeO(n) spaceSign in40 minInput: nums = [1, 3, 2, 8, 5, 5], k = 3Output: [2, 6, 6, 3]Start
Topic · Graphs
0 / 21 completed- MediumCount Island Blobs#dfs#flood-fill#grid-traversalO(rows · cols) timeO(rows · cols) spaceSign in30 minInput: [[1]]Output: 1Start
- MediumCourse Order Feasibility#topological-sort#cycle-detectionO(n + p) timeO(n + p) spaceSign in35 minInput: n = 3, pairs = [[1, 0], [2, 1]]Output: TrueStart
- HardWord Ladder Steps#bfs#shortest-pathO(N · L² · 26) timeO(N · L) spaceSign in45 minInput: start = hit, target = cog, words = [hot, dot, dog, lot, log, cog]Output: 5Start
- EasyTrusted Town Judge#degree-counting#directed-graphO(n + p) timeO(n) space15 minInput: n = 2, trust = [[1, 2]]Output: 2Start
- MediumDeep Copy A Graph#dfs#hash-mapO(V + E) timeO(V) spaceSign in30 minInput: a square: 1 - 2 - 3 - 4 - 1Output: a new square with the same four labels and the same four linksStart
- MediumSpreading Rot Minutes#bfs#multi-source#grid-traversalO(rows · cols) timeO(rows · cols) spaceSign in30 minInput: [[0, 2]]Output: 0Start
- MediumTwo Colour Split Check#bfs#graph-colouringO(V + E) timeO(V) spaceSign in30 minInput: adj = [[1, 3], [0, 2], [1, 3], [0, 2]]Output: TrueStart
- MediumSignal Spread Time#dijkstra#shortest-path#min-heapO((n + m) log m) timeO(n + m) spaceSign in30 minInput: n = 3, links = [(0, 1, 4)], source = 0Output: -1Start
- MediumCheapest Trip Within a Stop Limit#bellman-ford#shortest-pathO(k · (n + m)) timeO(n) spaceSign in35 minInput: n = 3, flights = [(0, 1, 5)], src = 0, dst = 2, k = 1Output: -1Start
- HardMutual Reach Groups#strongly-connected-components#dfsO(n log n + m) timeO(n + m) spaceSign in45 minInput: n = 5, edges = [(0, 1), (1, 2), (2, 0), (2, 3), (3, 4)]Output: [[0, 1, 2], [3], [4]]Start
- HardRising Tide Crossing#union-find#minimum-spanning-tree#sortingO(rc log rc) timeO(rc) spaceSign in45 minInput: heights = [[7]]Output: 7Start
- MediumNodes Clear of Cycles#dfs#graph-colouring#cycle-detectionO(n + e) timeO(n) spaceSign in30 minInput: graph = [[1, 2], [2], [3], [], [5], [4], [3, 4]]Output: [0, 1, 2, 3]Start
- EasyMutual Follow Pairs#adjacency-set#directed-graphO(n + m) timeO(n + m) space15 minInput: n = 4, follows = [[0, 1], [1, 0], [1, 2], [2, 3], [3, 2], [0, 2]]Output: 2Start
- HardWater Every House#prim#virtual-nodeO((n + m) log(n + m)) timeO(n + m) spaceSign in40 minInput: wells = [3, 4, 2], pipes = [[1, 2, 1], [2, 3, 5]]Output: 6Start
- HardFewest Roads to Link Every Town#strongly-connected-components#directed-graphO(n + r) timeO(n + r) spaceSign in45 minInput: n = 5, roads = [(0, 1), (1, 2), (2, 0), (3, 2), (3, 4)]Output: 2Start
- EasyOrder the Build Steps#topological-sort#indegreeO(n + m) timeO(n + m) space20 minInput: n = 4, deps = [[0, 1], [0, 2], [1, 3], [2, 3]]Output: [0, 1, 2, 3]Start
- EasyDeadlock in a Wait-For Graph#cycle-detection#graph-colouring#topological-sortO(n + m) timeO(n + m) space20 minInput: n = 4, waits = [[0, 1], [1, 2], [2, 0], [3, 0]]Output: TrueStart
- EasyCheapest Route Between Two Stops#dijkstra#min-heapO((n + m) log n) timeO(n + m) space20 minInput: n = 5, roads = [[0, 1, 4], [0, 2, 1], [2, 1, 2], [1, 3, 1], [2, 3, 5], [3, 4, 3]], src = 0, dst = 4Output: 7Start
- EasyShortest Paths With Rebate Roads#bellman-ford#negative-edgesO(n · m) timeO(n) space20 minInput: n = 4, roads = [[0, 1, 4], [0, 2, 5], [2, 1, -3], [1, 3, 2]], src = 0Output: [0, 2, 5, 4]Start
- HardAlien Alphabet Order#topological-sort#graph-from-constraintsO(L) timeO(len(words)) spaceSign in40 minInput: words = ["wrt", "wrf", "er", "ett", "rftt"]Output: "wertf"Start
- EasyOpen Every Locked Room#dfs#reachabilityO(n + k) timeO(n) space15 minInput: rooms = [[1], [2], [3], []]Output: TrueStart
Topic · Matrix & Grid
0 / 14 completed- EasyPerimeter Of An Island#grid-scan#neighbour-checkO(rows · cols) timeO(1) space20 minInput: grid = [[1]]Output: 4Start
- MediumZero Out Rows And Columns#grid-marking#in-placeO(rows · cols) timeO(rows + cols) spaceSign in25 minStart
- MediumSearch A Sorted Grid#staircase-walk#grid-searchO(rows + cols) timeO(1) spaceSign in25 minInput: same grid, target = 10Output: NoneStart
- EasyRepaint A Connected Region#flood-fill#dfsO(rows · cols) timeO(rows · cols) space15 minInput: grid = [[5]], row = 0, col = 0, colour = 3Output: [[3]]Start
- MediumRotate A Square Grid#in-place#transpose-reverseO(n²) timeO(1) spaceSign in20 minInput: grid = [[7]]Output: [[7]]Start
- HardLongest Climbing Path#grid-dfs#memoizationO(rows · cols) timeO(rows · cols) spaceSign in40 minStart
- MediumLandlocked Islands#flood-fill#grid-traversalO(rows · cols) timeO(rows · cols) spaceSign in30 minInput: grid = [[1]]Output: 0Start
- MediumShortest Clear Grid Path#bfs#grid-traversal#shortest-pathO(rows · cols) timeO(rows · cols) spaceSign in25 minInput: grid = [[0]]Output: 0Start
- HardLargest All-Ones Rectangle#monotonic-stack#grid-scanO(rows · cols) timeO(cols) spaceSign in45 minInput: grid = [[1, 1, 0, 1, 1, 1]]Output: 3Start
- EasySame Value Along Every Diagonal#matrix-indexing#diagonalsO(rows · cols) timeO(1) space15 minInput: grid = [[1, 2, 3, 4], [5, 1, 2, 3], [9, 5, 1, 2]]Output: TrueStart
- MediumNext Generation of Cells#eight-neighbours#in-place-encodingO(rows · cols) timeO(1) spaceSign in25 minInput: board = [[0, 1, 0], [0, 0, 1], [1, 1, 1], [0, 0, 0]]Output: [[0, 0, 0], [1, 0, 1], [0, 1, 1], [0, 1, 0]]Start
- MediumCells Draining to Both Coasts#reverse-flood-fill#multi-source-searchO(rows · cols · log(rows · cols)) timeO(rows · cols) spaceSign in30 minInput: heights = [[1, 2], [4, 3]]Output: [[0, 1], [1, 0], [1, 1]]Start
- EasyLargest Island Area#flood-fill#dfs#grid-traversalO(rows · cols) timeO(rows · cols) space15 minInput: grid = [[1, 1, 0, 0], [1, 0, 0, 1], [0, 0, 1, 1], [0, 0, 1, 0]]Output: 4Start
- EasyFill a Grid in Spiral Order#matrix-traversal#direction-turningO(rows · cols) timeO(rows · cols) space15 minInput: rows = 3, cols = 3Output: [[1, 2, 3], [8, 9, 4], [7, 6, 5]]Start
Topic · Union-Find
0 / 12 completed- MediumCount Provinces#union-find#connected-componentsO(n² · α(n)) timeO(n) spaceSign in25 minInput: matrix = [[1, 1, 0], [1, 1, 0], [0, 0, 1]]Output: 2Start
- MediumRedundant Connection#union-find#cycle-detectionO(n · α(n)) timeO(n) spaceSign in25 minInput: edges = [[1, 2], [1, 3], [2, 3]]Output: [2, 3]Start
- HardAccounts Merge By Email#union-find#hash-mapO(E log E) timeO(E) spaceSign in45 minInput: [["Jo", "a@x", "b@x"], ["Jo", "b@x", "c@x"], ["Kim", "d@x"]]Output: [["Jo", "a@x", "b@x", "c@x"], ["Kim", "d@x"]]Start
- EasyReachable Pair Check#union-find#connectivityO((n + m) · α(n)) timeO(n) space15 minInput: n = 3, links = [[0, 1], [1, 2], [2, 0]], source = 0, target = 2Output: TrueStart
- MediumConsistent Equalities#union-find#two-phaseO(n) timeO(1) spaceSign in25 minInput: rules = ["a==b", "b!=a"]Output: FalseStart
- MediumStones Sharing A Line#union-find#connected-componentsO(n · α(n)) timeO(n) spaceSign in30 minInput: stones = [[0, 0], [0, 1], [1, 0], [1, 2], [2, 1], [2, 2]]Output: 5Start
- MediumEarliest Moment All Connected#union-find#sort-by-timeO(m log m + m · α(n)) timeO(n + m) spaceSign in25 minInput: n = 5, logs = [[20, 0, 1], [3, 3, 4], [5, 1, 2], [9, 2, 3], [12, 0, 3]]Output: 12Start
- MediumSmallest Equivalent String#union-find#stringsO(n + m) timeO(m) spaceSign in25 minInput: a = "parker", b = "morris", text = "parser"Output: "makkek"Start
- HardSpare Roads for Two Travellers#union-find#greedyO(m · α(n)) timeO(n) spaceSign in45 minInput: n = 4, roads = [[3, 1, 2], [3, 2, 3], [1, 1, 3], [1, 2, 4], [1, 1, 2], [2, 3, 4]]Output: 2Start
- HardLargest Group by Shared Factor#union-find#prime-factorsO(n · √max(nums)) timeO(n) spaceSign in45 minInput: nums = [4, 6, 15, 35]Output: 4Start
- EasyEdges Form a Single Tree#union-find#cycle-detectionO(n · α(n)) timeO(n) space15 minInput: n = 5, edges = [[0, 1], [0, 2], [0, 3], [1, 4]]Output: TrueStart
- MediumIslands After Each Land Drop#union-find#online-connectivity#gridO(k · α(m · n)) timeO(k) spaceSign in30 minInput: m = 3, n = 3, positions = [[0, 0], [0, 1], [1, 2], [2, 1]]Output: [1, 1, 2, 3]Start
Topic · Intervals
0 / 13 completed- MediumNon Overlapping Removals#intervals#greedyO(n log n) timeO(n) spaceSign in25 minInput: intervals = [[1, 2], [2, 3], [3, 4], [1, 3]]Output: 1Start
- HardEmployee Free Time#intervals#mergeO(n log n) timeO(n) spaceSign in40 minInput: schedules = [[[1, 2], [5, 6]], [[1, 3]], [[4, 10]]]Output: [[3, 4]]Start
- MediumCar Pooling Capacity#intervals#sweep-lineO(n log n) timeO(n) spaceSign in25 minInput: trips = [(2, 1, 5), (3, 3, 7)], capacity = 4Output: FalseStart
- EasyAttend Every Meeting#intervals#sortingO(n log n) timeO(n) space15 minInput: meetings = [[0, 30], [5, 10], [15, 20]]Output: FalseStart
- EasyCondense Values Into Ranges#intervals#single-passO(n) timeO(n) space15 minInput: nums = [0, 1, 2, 4, 5, 7]Output: ["0->2", "4->5", "7"]Start
- MediumMerge Overlapping Spans#intervals#sorting#mergeO(n log n) timeO(n) spaceSign in20 minInput: spans = [[1, 3], [8, 10], [2, 6], [15, 18]]Output: [[1, 6], [8, 10], [15, 18]]Start
- MediumInsert and Merge a Span#intervals#mergeO(n) timeO(n) spaceSign in25 minInput: spans = [[1, 2], [4, 6], [9, 10]], new = [5, 9]Output: [[1, 2], [4, 10]]Start
- MediumOverlap of Two Span Lists#intervals#two-pointersO(m + n) timeO(m + n) spaceSign in25 minInput: a = [[0, 2], [5, 10], [13, 23], [24, 25]], b = [[1, 5], [8, 12], [15, 24], [25, 26]]Output: [[1, 2], [5, 5], [8, 10], [15, 23], [24, 24], [25, 25]]Start
- MediumDrop Spans Covered by Others#intervals#sort-by-startO(n log n) timeO(n) spaceSign in20 minInput: spans = [[1, 4], [3, 6], [2, 8]]Output: 2Start
- MediumCalendar Without Double Booking#sorted-intervals#bisect-insert#half-open-intervalsO(n) timeO(n) spaceSign in25 minInput: book(10, 20), book(15, 25), book(20, 30)Output: [True, False, True]Start
- MediumFewest Shots to Burst Every Balloon#intervals#greedy#sort-by-endO(n log n) timeO(n) spaceSign in25 minInput: balloons = [[10, 16], [2, 8], [1, 6], [7, 12]]Output: 2Start
- MediumRooms Needed for Every Meeting#min-heap#sweep-line#sortingO(n log n) timeO(n) spaceSign in20 minInput: meetings = [(0, 30), (5, 10), (15, 20)]Output: 2Start
- EasyCut a Span Out of Sorted Spans#interval-overlap#single-passO(n) timeO(n) space15 minInput: spans = [[0, 2], [3, 4], [5, 7]], cut = [1, 6]Output: [[0, 1], [6, 7]]Start
Topic · Bit Manipulation
0 / 14 completed- EasyReverse Bit Order#bit-shifting#accumulatorO(1) timeO(1) space20 minInput: value = 1Output: 2147483648Start
- MediumSingle Value Among Triples#bit-counting#modular-arithmeticO(n) timeO(1) spaceSign in30 minInput: nums = [2, 2, 3, 2]Output: 3Start
- EasyThe Missing Value#xor-cancel#single-passO(n) timeO(1) space20 minInput: nums = [3, 0, 1]Output: 2Start
- EasyDiffering Bit Count#xor#bit-countingO(log max(a, b)) timeO(1) space15 minInput: a = 1, b = 4Output: 2Start
- EasySet Bits For Every Number#bit-shifting#reuse-smaller-answerO(n) timeO(n) space20 minInput: n = 5Output: [0, 1, 1, 2, 1, 2]Start
- MediumTwo Lone Values#xor-cancel#bit-partitionO(n) timeO(1) spaceSign in30 minInput: nums = [1, 2, 1, 3, 2, 5]Output: [3, 5]Start
- EasyPower of Four Check#bitmask#power-of-twoO(1) timeO(1) space15 minInput: n = 16Output: TrueStart
- EasyEvery Subset by Bitmask#bitmask#subsetsO(n · 2ⁿ) timeO(n · 2ⁿ) space20 minInput: items = ["a", "b"]Output: [[], ['a'], ['b'], ['a', 'b']]Start
- MediumSort by Equal-Bit Swaps#popcount#adjacent-swapsO(n log m) timeO(1) spaceSign in25 minInput: nums = [6, 5, 3, 16, 8, 31]Output: TrueStart
- HardShortest Walk Through Every Node#bitmask#bfsO(n² · 2ⁿ) timeO(n · 2ⁿ) spaceSign in45 minInput: adj = [[1, 3, 4], [0, 2], [1, 3, 5], [2, 0], [0], [2]]Output: 6Start
- MediumAdd Two Numbers Without Plus#bitwise-add#carry-propagation#twos-complementO(1) timeO(1) spaceSign in25 minInput: a = 1, b = 2Output: 3Start
- MediumBitwise AND Across a Range#common-prefix#bit-shiftO(1) timeO(1) spaceSign in20 minInput: lo = 5, hi = 7Output: 4Start
- MediumWord Pairs With No Shared Letters#bitmask#set-as-integerO(L + n²) timeO(n) spaceSign in20 minInput: words = ["abcw", "baz", "foo", "bar", "xtfn", "abcdef"]Output: 16Start
- MediumTotal Bit Differences Across Pairs#bit-counting#per-bit-contributionO(n) timeO(1) spaceSign in20 minInput: nums = [4, 14, 2]Output: 6Start
Topic · Math & Number Theory
0 / 13 completed- EasyTrailing Zeros Of A Factorial#factor-counting#mathO(log n) timeO(1) space20 minInput: n = 5Output: 1Start
- MediumPrimes Below A Limit#sieve#precomputationO(n log log n) timeO(n) spaceSign in25 minInput: limit = 10Output: 4Start
- MediumPower Under A Modulus#fast-exponentiation#modular-arithmeticO(log exp) timeO(1) spaceSign in25 minInput: base = 2, exp = 10, mod = 1000Output: 24Start
- EasyRepeated Digit Sum#modular-arithmetic#mathO(1) timeO(1) space15 minInput: n = 38Output: 2Start
- MediumMeasure With Two Jugs#gcd#mathO(log min(a, b)) timeO(1) spaceSign in25 minInput: a = 3, b = 5, t = 4Output: TrueStart
- MediumChoose K Modulo A Prime#combinatorics#modular-inverseO(min(k, n − k) + log p) timeO(1) spaceSign in30 minInput: n = 5, k = 2Output: 10Start
- EasyLeast Common Multiple of a List#gcd#lcmO(n log(max(nums))) timeO(1) space15 minInput: nums = [4, 6, 10]Output: 60Start
- MediumFraction as a Repeating Decimal#long-division#hash-mapO(den) timeO(den) spaceSign in30 minInput: num = 1, den = 6Output: "0.1(6)"Start
- HardPrimes in a Wide Range#segmented-sieve#sieveO((√hi + hi − lo) log log hi) timeO(√hi + hi − lo) spaceSign in40 minInput: lo = 10, hi = 30Output: 6Start
- EasyOne Row of Pascal's Triangle#binomial-coefficients#multiplicative-formulaO(k) timeO(k) space15 minInput: k = 3Output: [1, 3, 3, 1]Start
- EasyGreatest Common Divisor of Strings#gcd#string-periodO(len(a) + len(b)) timeO(len(a) + len(b)) space15 minInput: a = "ABCABC", b = "ABC"Output: "ABC"Start
- MediumSong Pairs Filling Whole Minutes#modular-arithmetic#remainder-countO(n) timeO(1) spaceSign in20 minInput: times = [30, 20, 150, 100, 40]Output: 3Start
- MediumPower With a Huge Exponent#fast-exponentiation#modular-arithmeticO(len(b)) timeO(1) spaceSign in25 minInput: a = 2, b = [3]Output: 8Start
Topic · Dynamic Programming
0 / 27 completed- EasyCheapest Stair Climb#bottom-up-dp#rolling-variablesO(n) timeO(1) space20 minInput: cost = [10, 15, 20]Output: 15Start
- MediumGrid Paths With Blocks#grid-dp#bottom-up-dpO(rows · cols) timeO(cols) spaceSign in30 minInput: [[0]]Output: 1Start
- MediumSentence Segmentation#bottom-up-dp#hash-setO(L³) timeO(L) spaceSign in30 minInput: text = applepen, words = [apple, pen]Output: TrueStart
- HardTrading With Cooldown#state-machine-dp#rolling-variablesO(n) timeO(n) spaceSign in45 minInput: prices = [1, 2, 3, 0, 2]Output: 3Start
- EasyPaint Houses Cheaply#bottom-up-dp#rolling-variablesO(n) timeO(1) space20 minInput: costs = [[7, 6, 2]]Output: 2Start
- MediumDecode Digit Message#bottom-up-dp#rolling-variablesO(n) timeO(1) spaceSign in30 minInput: digits = "226"Output: 3Start
- MediumUnique BST Shapes#bottom-up-dp#countingO(n²) timeO(n) spaceSign in30 minInput: n = 3Output: 5Start
- HardPop Balloons For Coins#interval-dp#bottom-up-dpO(n³) timeO(n²) spaceSign in50 minInput: values = [3, 1, 5, 8]Output: 167Start
- EasyNon-Adjacent Harvest#bottom-up-dp#rolling-variablesO(n) timeO(1) space20 minInput: yields = [2, 7, 9, 3, 1]Output: 12Start
- MediumFewest Coins for an Amount#bottom-up-dp#unbounded-knapsackO(amount · len(coins)) timeO(amount) spaceSign in30 minInput: coins = [1, 4, 6], amount = 8Output: 2Start
- MediumLongest Rising Subsequence#bottom-up-dp#subsequence-dpO(n²) timeO(n) spaceSign in30 minInput: nums = [4, 1, 3, 2, 5, 3, 6]Output: 4Start
- MediumFewest Edits Between Words#string-dp#bottom-up-dpO(len(a) · len(b)) timeO(len(b)) spaceSign in35 minInput: a = "carpet", b = "parrot"Output: 3Start
- HardNesting Envelopes#binary-search#patience-sorting#sortingO(n log n) timeO(n) spaceSign in45 minInput: envelopes = [[4, 5], [4, 6], [6, 7], [2, 3], [1, 1]]Output: 4Start
- HardCheapest Stick Cuts#interval-dp#bottom-up-dpO(m³) timeO(m²) spaceSign in50 minInput: length = 10, marks = [2, 4, 7]Output: 20Start
- MediumWays to Pay an Amount#unbounded-knapsack#bottom-up-dpO(k · amount) timeO(amount) spaceSign in25 minInput: coins = [2, 3, 5], amount = 10Output: 4Start
- HardBuild a Shortest Supersequence#string-dp#subsequence-dpO(len(a) · len(b)) timeO(len(a) · len(b)) spaceSign in45 minInput: a = "tile", b = "style"Output: "stiyle"Start
- MediumLongest Palindromic Subsequence#lcs#2d-dpO(n²) timeO(n) spaceSign in30 minInput: s = "character"Output: 5Start
- MediumSigns That Hit a Target#0-1-knapsack#subset-countO(n · sum(nums)) timeO(sum(nums)) spaceSign in30 minInput: nums = [1, 2, 3, 4], target = 2Output: 2Start
- HardFewest Watchers on a Tree#tree-dp#state-machineO(n) timeO(h) spaceSign in45 minInput: tree = 1, left 2, whose children are 3 and 4Output: 1Start
- HardPie Slices With Two Friends#circular-dp#exact-count-dpO(n²) timeO(n) spaceSign in45 minInput: slices = [4, 1, 2, 8, 3, 5]Output: 13Start
- MediumBest Value Van Load#unbounded-knapsack#bottom-up-dpO(W · len(crates)) timeO(W) spaceSign in25 minInput: W = 10, crates (weight, value) = [(3, 5), (4, 7), (6, 11)]Output: 18Start
- MediumClosest Two-Team Split#0-1-knapsack#subset-sumO(n · sum(ratings)) timeO(sum(ratings)) spaceSign in30 minInput: ratings = [5, 8, 13, 2]Output: 2Start
- EasyGift Cards for an Exact Total#0-1-knapsack#subset-sumO(n · total) timeO(total) space20 minInput: cards = [3, 34, 4, 12, 5, 2], total = 9Output: TrueStart
- EasyExact Change With Unlimited Coins#unbounded-knapsack#bottom-up-dpO(len(coins) · amount) timeO(amount) space15 minInput: coins = [4, 7], amount = 15Output: TrueStart
- EasyCheapest Path Across a Grid#grid-dp#2d-dpO(rows · cols) timeO(rows · cols) space20 minInput: grid = [[1, 3, 1], [1, 5, 1], [4, 2, 1]]Output: 7Start
- EasyFewest Deletions to Match Two Words#lcs#string-dpO(m · n) timeO(m · n) space20 minInput: a = "sea", b = "eat"Output: 2Start
- MediumInterleave Two Strings#two-string-dp#rolling-rowO(len(a) · len(b)) timeO(len(b)) spaceSign in30 minInput: a = "aabcc", b = "dbbca", c = "aadbbcbcac"Output: TrueStart
Topic · System Design
0 / 8 completed- EasyToken Bucket Rate Limiter#token-bucket#integer-mathO(n) timeO(n) space15 minInput: capacity = 2, per_second = 1, times_ms = [0, 0, 0, 500, 1000, 3000]Output: [True, True, False, False, True, True]Start
- EasyRead Quorum for a Write Quorum#quorum#pigeonholeO(1) timeO(1) space10 minInput: n = 3, w = 2Output: (2, 1)Start
- MediumConsistent Hashing Ring#consistent-hashing#virtual-nodes#bisectO(log p) timeO(p) spaceSign in25 minInput: nodes = db-a, db-b, db-c; owner("user:42") before and after db-d joinsOutput: db-c db-cStart
- MediumBloom Filter Sizing#bloom-filter#double-hashingO(k) timeO(m) spaceSign in25 minInput: n = 1000, p = 0.01Output: (9586, 7)Start
- MediumLeast-Connections Load Balancer#least-connections#min-heap#event-simulationO(n (log n + s)) timeO(n + s) spaceSign in25 minInput: servers = ["a", "b"], requests = [(0, 10), (1, 2), (2, 5), (3, 1), (4, 1)]Output: (['a', 'b', 'a', 'b', 'b'], {'a': 2, 'b': 1})Start
- EasyLatency Percentiles by Nearest Rank#percentiles#sortingO(n log n + q) timeO(n) space10 minInput: latencies = [12, 15, 11, 13, 240, 14, 12, 16, 13, 12], ps = [50, 90, 99]Output: {50: 13, 90: 16, 99: 240}Start
- MediumVisibility Timeouts in a Message Queue#message-queue#event-simulationO(p · m) timeO(p + m) spaceSign in25 minInput: messages = ["poison"], polls at 0, 10, 20 and 30 by "a", work = {"a": 99}, timeout = 10, max_receives = 3Output: ([(0, 'a', 'poison'), (10, 'a', 'poison'), (20, 'a', 'poison'), (30, 'a', None)], [], ['poison'])Start
- MediumCritical Path Through a Trace#distributed-tracing#interval-union#tree-walkO(n log n) timeO(n) spaceSign in25 minInput: [("r", None, "api", 0, 50), ("p", "r", "search", 0, 50), ("q", "r", "ads", 10, 30)]Output: ({'ads': 20, 'api': 0, 'search': 50}, ['r', 'p'])Start
Topic · System Design Cases
0 / 4 completed- EasyURL Shortener Capacity Estimate#capacity-estimation#back-of-the-envelopeO(log(total links)) timeO(1) space15 minInput: new_per_day = 100_000_000, reads_per_write = 100, bytes_per_url = 500, years = 10, peak = 3Output: {'write_qps': 1158, 'read_qps': 115741, 'peak_read_qps': 347223, 'storage_tb': 182.5, 'code_length': 7}Start
- MediumFeed Fan-Out Cost#fan-out#cost-modelO(E + U) timeO(E + U) spaceSign in25 minInput: the same graph and posts, but only ann opens the feed, once a dayOutput: ({'push': 93, 'pull': 4, 'hybrid': 14}, 'pull')Start
- MediumRate-Limit Tiers for an API Gateway#rate-limiting#sliding-window-logO(r log n) timeO(n) spaceSign in25 minInput: tiers = {"free": [(10, 1)]}, requests from "a" at 0, 9, 10, 19, 20Output: {'a': [3, 2]}Start
- EasyCache Hit Ratio for a News Feed#lru-cache#hit-ratioO(n) timeO(c) space15 minInput: feed = ["a", "b", "c", "a", "b", "c"], capacity = 2Output: 0.0Start
Topic · AI & ML
0 / 8 completed- EasySoftmax With Temperature#softmax#numerical-stabilityO(v) timeO(v) space15 minInput: logits = [2.0, 1.0, 0.1], temperature = 1.0Output: [0.659, 0.242, 0.099]Start
- EasyKV Cache Memory Budget#capacity-math#memory-estimateO(1) timeO(1) space10 minInput: layers = 32, kv_heads = 32, head_dim = 128, tokens = 4096, batch = 1, 2 bytes per numberOutput: 2048.0Start
- MediumNearest Documents by Cosine#vector-math#partial-sortO(n · d + n log k) timeO(n) spaceSign in20 minInput: query = [2, 0, 0], k = 2, articles = b [1, 0, 0], a [3, 0, 0], c [0, 1, 0]Output: [('a', 1.0), ('b', 1.0)]Start
- MediumTrim a Chat to Fit the Context#token-budget#newest-firstO(t) timeO(1) spaceSign in20 minInput: budget = 100, system = 20, reserve = 25, turns = [10, 30, 10, 20, 15]Output: 2Start
- HardLearn Byte Pair Merges#byte-pair-encoding#pair-countingO(m · L) timeO(L) spaceSign in35 minInput: words = {"low": 5, "lower": 2, "newest": 6, "widest": 3}, merges = 4Output: [('e', 's'), ('es', 't'), ('l', 'o'), ('lo', 'w')]Start
- EasyInt8 Quantization Round Trip#quantization#scale-and-roundO(n) timeO(n) space15 minInput: [0.4, -2.54, 0.013, 1.0]Output: ([20, -127, 1, 50], 0.02, 0.007)Start
- MediumTarget Passes in Speculative Decoding#speculative-decoding#draft-and-verifyO(n · k) timeO(n) spaceSign in25 minInput: prompt = ["the"], draft guesses "a" after "on" where the target says "the", k = 4, n = 8Output: (['cat', 'sat', 'on', 'the', 'cat', 'sat', 'on', 'the'], 2)Start
- HardInverted-File Search Recall#vector-search#inverted-file-index#recall-at-kO(n · c + c · q · n log n) timeO(n + c) spaceSign in35 minInput: the same vectors and centroids, queries = [(6, 1)], k = 2Output: [0.5, 1.0, 1.0]Start
Topic · Low-Level Design
0 / 8 completed- EasyParking Lot Fee Calculator#class-design#pricing-rules15 minInput: same lot, fee("car", 26 * 60)Output: 26Start
- EasyCoin Vending Machine#class-design#state-machine15 minInput: then insert(100), select("A1"), select("A1")Output: ['credit 125', 'vend A1, change 60', 'sold out']Start
- MediumLRU Cache With Expiry#ordered-dict#lazy-expiry#min-heapO(log n) timeO(number of puts) spaceSign in30 minInput: then get("a", now=10)Output: NoneStart
- MediumEvent Bus With Topic Wildcards#observer#topic-matchingO(s · d) timeO(s · d) spaceSign in25 minInput: then unsubscribe(the audit token), publish("order.created", "o8")Output: 0Start
- HardIn-Memory File System#class-design#path-walk#invariantsSign in35 minInput: then read("/logs/app/today.txt"), size("/")Output: 'boot ok\nuser in\n' 23Start
- EasyBest Discount Strategy at Checkout#strategy-pattern#class-designO(p · c) timeO(1) space15 minInput: cart = [("coffee", 1200, 3), ("mug", 900, 2)], all three promotionsOutput: ('buy 2 coffee get 1 free', 4200)Start
- MediumElevator Stops in Sweep Order#elevator-sweep#event-simulationO(F · p + r log r) timeO(r) spaceSign in25 minInput: start = 3, requests = [(0, 5), (0, 1), (1, 4), (6, 2)]Output: [(1, 4), (2, 5), (6, 1), (7, 2)]Start
- HardLegal Moves That Keep the King Safe#board-model#move-generation#check-detectionO(P² · 27²) timeO(P) spaceSign in35 minInput: {"h8": "k", "g7": "Q", "f6": "K"}, black to moveOutput: ('checkmate', [])Start
Topic · Concurrency
0 / 8 completed- EasyLost Updates in a Shared Counter#race-condition#step-simulationO(s) timeO(t) space15 minInput: threads = 2, schedule = [0, 0, 0, 1, 1, 1]Output: 2Start
- EasyThread Pool Size for a Workload#capacity-math#integer-ceilingO(1) timeO(1) space10 minInput: cores = 8, utilization = 100, wait_ms = 90, compute_ms = 10Output: 80Start
- MediumDeadlocked Threads in a Wait Graph#wait-for-graph#cycle-detectionO(t + l) timeO(t) spaceSign in25 minInput: holds = {"a": "T1", "b": "T2"}, waits = {"T1": "b", "T2": "a"}Output: ['T1', 'T2']Start
- MediumStart Times Behind a Semaphore#min-heap#event-simulationO(n log p) timeO(n) spaceSign in20 minInput: permits = 2, jobs = [(0, 5), (1, 3), (2, 4), (3, 1)]Output: [0, 1, 4, 5]Start
- HardBounded Buffer Hand-Offs#bounded-queue#event-simulation#fifo-fairnessO(n) timeO(n) spaceSign in35 minInput: capacity = 1, calls = put P1 a, put P2 b, take C1, take C2, take C1, put P1 cOutput: ([('C1', 'a'), ('C2', 'b'), ('C1', 'c')], [])Start
- EasyRetries in a Compare-and-Swap Loop#compare-and-swap#step-simulationO(s) timeO(t) space15 minInput: start = 0, amounts = [5, 7], schedule = [0, 1, 0, 1, 1, 1]Output: (12, [0, 1])Start
- MediumFinish Times on a Single Event Loop#event-loop#min-heap#event-simulationO(s log n) timeO(n) spaceSign in25 minInput: [("api", 0, [2, 10, 1]), ("report", 1, [30]), ("ping", 3, [1])]Output: {'report': 32, 'ping': 33, 'api': 34}Start
- MediumLock Order That Prevents Deadlock#lock-ordering#topological-sort#min-heapO(E + L log L) timeO(E + L) spaceSign in25 minInput: [["accounts", "ledger"], ["ledger", "audit"], ["accounts", "audit"]]Output: ['accounts', 'ledger', 'audit']Start
Topic · SQL
0 / 15 completed- EasySecond Highest Salary#scalar-subquery#aggregate10 minInput: employee = [(1, "Ana", 300), (2, "Ben", 200), (3, "Cy", 100)]Output: [(200,)]Start
- EasyEmails Used More Than Once#group-by#having10 minInput: account = [(1, "a@x.io"), (2, "b@x.io"), (3, "a@x.io"), (4, "c@x.io"), (5, "b@x.io"), (6, "a@x.io")]Output: [("a@x.io", 3), ("b@x.io", 2)]Start
- EasyCustomers Who Never Ordered#left-join#anti-join15 minStart
- EasyPaid More Than Their Manager#self-join15 minInput: employee = [(1, "Ana", 120, None), (2, "Ben", 90, 1), (3, "Cleo", 130, 1), (4, "Dev", 95, 3), (5, "Finn", 100, 4)]Output: [("Cleo", 130, 120), ("Finn", 100, 95)]Start
- MediumDepartment With the Highest Average Pay#group-by#cte#tiesSign in20 minInput: employee = [(1, "Ana", "eng", 120), (2, "Cleo", "eng", 130), (3, "Dev", "ops", 95), (4, "Finn", "ops", 100), (5, "Gus", "hr", 70)]Output: [("eng", 125.0)]Start
- MediumTop Two Earners per Department#window-function#top-n-per-groupSign in25 minInput: employee = [(1, "Ana", "eng", 120), (2, "Ben", "eng", 90), (3, "Cleo", "eng", 130), (4, "Dev", "ops", 95), (5, "Eve", "ops", 80), (6, "Finn", "ops", 100)]Output: [("eng", "Cleo", 130), ("eng", "Ana", 120), ("ops", "Finn", 100), ("ops", "Dev", 95)]Start
- MediumAuthor Book Counts in One Query#n-plus-one#left-join#group-bySign in20 minStart
- MediumRunning Balance per Account#window-function#running-total#window-frameSign in25 minInput: txn = [(1, "A", "2026-09-01", 100), (2, "B", "2026-09-01", 50), (3, "A", "2026-09-02", -30), (4, "A", "2026-09-02", 20), (5, "B", "2026-09-03", -50)]Output: [("A", "2026-09-01", 100, 100), ("A", "2026-09-02", -30, 70), ("A", "2026-09-02", 20, 90),Start
- MediumLogged In Three Days in a Row#window-function#consecutive-rows#dedupeSign in25 minInput: login = [("kim", "2026-09-01"), ("kim", "2026-09-02"), ("kim", "2026-09-03"), ("lee", "2026-09-01"), ("lee", "2026-09-02"), ("lee", "2026-09-04")]Output: [("kim",)]Start
- HardCollapse a Status Log Into Runs#gaps-and-islands#window-function#row-numberSign in35 minInput: status_log = [("2026-09-01", "up"), ("2026-09-02", "up"), ("2026-09-03", "down"), ("2026-09-04", "up"), ("2026-09-05", "up")]Output: [("up", "2026-09-01", "2026-09-02", 2), ("down", "2026-09-03", "2026-09-03", 1), ("up", "2026-09-04", "2026-09-05", 2)]Start
- MediumSame Reading Three Times in a Row#self-join#consecutive-rows#distinctSign in20 minInput: reading = [(1, 1), (2, 1), (3, 1), (4, 2), (5, 1), (6, 2), (7, 2)]Output: [(1,)]Start
- MediumHighest Paid in Every Department#correlated-subquery#max#tiesSign in20 minInput: employee = [(1, "Ana", "eng", 120), (2, "Ben", "eng", 150), (3, "Cy", "ops", 90), (4, "Dee", "ops", 80)]Output: [("eng", "Ben", 150), ("ops", "Cy", 90)]Start
- MediumCustomers Who Bought Every Product#group-by#having#count-distinctSign in20 minInput: product = [5, 6], purchase = [(1, 5), (2, 6), (3, 5), (3, 6), (1, 6)]Output: [(1,), (3,)]Start
- HardUsers Retained Month Over Month#cte#self-join#retentionSign in35 minInput: activity = [(1, "2026-01-05"), (1, "2026-01-20"), (2, "2026-01-09"), (1, "2026-02-02"), (3, "2026-02-14"), (2, "2026-03-01"), (3, "2026-03-30")]Output: [("2026-01", 2, 0), ("2026-02", 2, 1), ("2026-03", 2, 1)]Start
- EasyQuarterly Sales as Columns#pivot#case-when#group-by15 minInput: sales = [("east", 1, 100), ("east", 2, 50), ("west", 1, 70), ("east", 1, 30), ("west", 4, 20)]Output: [("east", 130, 50, 0, 0), ("west", 70, 0, 0, 20)]Start