From a7d29b7cce3eac61aa36e4fc70ff3003f77091d2 Mon Sep 17 00:00:00 2001 From: Kai Chappell Date: Sun, 13 Jul 2025 19:53:34 +0100 Subject: [PATCH] feat(content): function signatures + test cases --- backend/data/questions/01-matrix.yaml | 20 +++++++++ backend/data/questions/132-pattern.yaml | 24 +++++++++++ backend/data/questions/2-keys-keyboard.yaml | 22 ++++++++++ backend/data/questions/24-game.yaml | 22 ++++++++++ .../questions/3sum-with-multiplicity.yaml | 22 ++++++++++ backend/data/questions/4sum-ii.yaml | 18 ++++++++ .../a-number-after-a-double-reversal.yaml | 22 ++++++++++ backend/data/questions/accounts-merge.yaml | 16 +++++++ .../add-minimum-number-of-rungs.yaml | 22 ++++++++++ .../data/questions/add-one-row-to-tree.yaml | 18 ++++++++ .../add-to-array-form-of-integer.yaml | 22 ++++++++++ backend/data/questions/add-two-integers.yaml | 20 +++++++++ .../data/questions/add-two-numbers-ii.yaml | 22 ++++++++++ .../questions/adding-spaces-to-a-string.yaml | 20 +++++++++ .../adding-two-negabinary-numbers.yaml | 20 +++++++++ backend/data/questions/additive-number.yaml | 24 +++++++++++ backend/data/questions/advantage-shuffle.yaml | 18 ++++++++ .../airplane-seat-assignment-probability.yaml | 18 ++++++++ .../data/questions/alert-using-same-key.yaml | 18 ++++++++ ...ns-with-highest-score-of-binary-array.yaml | 22 ++++++++++ ...l-elements-in-two-binary-search-trees.yaml | 18 ++++++++ .../all-nodes-distance-k-in-binary-tree.yaml | 20 +++++++++ .../all-paths-from-source-to-target.yaml | 18 ++++++++ .../all-possible-full-binary-trees.yaml | 20 +++++++++ .../data/questions/allocate-mailboxes.yaml | 20 +++++++++ .../data/questions/alphabet-board-path.yaml | 20 +++++++++ .../data/questions/alternating-digit-sum.yaml | 22 ++++++++++ .../data/questions/ambiguous-coordinates.yaml | 16 +++++++ ...f-time-for-binary-tree-to-be-infected.yaml | 20 +++++++++ .../angle-between-hands-of-a-clock.yaml | 22 ++++++++++ ...racters-to-string-to-make-subsequence.yaml | 22 ++++++++++ .../append-k-integers-with-minimal-sum.yaml | 22 ++++++++++ ...wise-operations-to-make-strings-equal.yaml | 24 +++++++++++ .../apply-operations-to-an-array.yaml | 20 +++++++++ .../arithmetic-slices-ii-subsequence.yaml | 24 +++++++++++ backend/data/questions/arithmetic-slices.yaml | 20 +++++++++ .../data/questions/arithmetic-subarrays.yaml | 24 +++++++++++ backend/data/questions/arranging-coins.yaml | 20 +++++++++ backend/data/questions/array-nesting.yaml | 20 +++++++++ .../questions/array-of-doubled-pairs.yaml | 26 ++++++++++++ backend/data/questions/array-partition.yaml | 20 +++++++++ ...nts-not-equal-to-average-of-neighbors.yaml | 20 +++++++++ .../as-far-from-land-as-possible.yaml | 20 +++++++++ backend/data/questions/assign-cookies.yaml | 22 ++++++++++ .../available-captures-for-rook.yaml | 22 ++++++++++ .../average-of-levels-in-binary-tree.yaml | 18 ++++++++ ...-salary-excluding-minimum-and-maximum.yaml | 20 +++++++++ ...ue-of-even-numbers-divisible-by-three.yaml | 24 +++++++++++ .../data/questions/average-waiting-time.yaml | 20 +++++++++ .../questions/avoid-flood-in-the-city.yaml | 22 ++++++++++ backend/data/questions/bag-of-tokens.yaml | 22 ++++++++++ .../balance-a-binary-search-tree.yaml | 20 +++++++++ .../data/questions/balanced-binary-tree.yaml | 22 ++++++++++ backend/data/questions/base-7.yaml | 22 ++++++++++ backend/data/questions/baseball-game.yaml | 22 ++++++++++ .../data/questions/basic-calculator-iv.yaml | 24 +++++++++++ backend/data/questions/basic-calculator.yaml | 24 +++++++++++ .../questions/battleships-in-a-board.yaml | 20 +++++++++ .../questions/beautiful-arrangement-ii.yaml | 22 ++++++++++ .../data/questions/beautiful-arrangement.yaml | 20 +++++++++ backend/data/questions/beautiful-array.yaml | 22 ++++++++++ backend/data/questions/best-poker-hand.yaml | 24 +++++++++++ .../best-position-for-a-service-centre.yaml | 22 ++++++++++ .../data/questions/best-sightseeing-pair.yaml | 20 +++++++++ .../best-team-with-no-conflicts.yaml | 24 +++++++++++ .../best-time-to-buy-and-sell-stock-ii.yaml | 24 +++++++++++ .../best-time-to-buy-and-sell-stock-iii.yaml | 24 +++++++++++ .../best-time-to-buy-and-sell-stock-iv.yaml | 22 ++++++++++ ...e-to-buy-and-sell-stock-with-cooldown.yaml | 22 ++++++++++ ...y-and-sell-stock-with-transaction-fee.yaml | 22 ++++++++++ backend/data/questions/binary-gap.yaml | 24 +++++++++++ .../binary-number-with-alternating-bits.yaml | 26 ++++++++++++ .../binary-prefix-divisible-by-5.yaml | 24 +++++++++++ .../binary-search-tree-iterator.yaml | 16 +++++++ ...inary-search-tree-to-greater-sum-tree.yaml | 18 ++++++++ ...g-with-substrings-representing-1-to-n.yaml | 22 ++++++++++ .../questions/binary-subarrays-with-sum.yaml | 22 ++++++++++ .../data/questions/binary-tree-cameras.yaml | 20 +++++++++ .../questions/binary-tree-coloring-game.yaml | 22 ++++++++++ .../binary-tree-inorder-traversal.yaml | 22 ++++++++++ .../binary-tree-level-order-traversal-ii.yaml | 20 +++++++++ .../binary-tree-maximum-path-sum.yaml | 22 ++++++++++ backend/data/questions/binary-tree-paths.yaml | 18 ++++++++ .../binary-tree-postorder-traversal.yaml | 20 +++++++++ .../binary-tree-preorder-traversal.yaml | 20 +++++++++ .../data/questions/binary-tree-pruning.yaml | 24 +++++++++++ .../binary-tree-right-side-view.yaml | 24 +++++++++++ backend/data/questions/binary-tree-tilt.yaml | 26 ++++++++++++ ...ary-tree-zigzag-level-order-traversal.yaml | 22 ++++++++++ .../questions/binary-trees-with-factors.yaml | 24 +++++++++++ backend/data/questions/binary-watch.yaml | 20 +++++++++ .../bitwise-and-of-numbers-range.yaml | 26 ++++++++++++ .../questions/bitwise-ors-of-subarrays.yaml | 24 +++++++++++ .../bitwise-xor-of-all-pairings.yaml | 22 ++++++++++ .../data/questions/boats-to-save-people.yaml | 26 ++++++++++++ .../data/questions/break-a-palindrome.yaml | 24 +++++++++++ backend/data/questions/brick-wall.yaml | 20 +++++++++ backend/data/questions/broken-calculator.yaml | 26 ++++++++++++ backend/data/questions/buddy-strings.yaml | 24 +++++++++++ .../build-an-array-with-stack-operations.yaml | 22 ++++++++++ .../build-array-from-permutation.yaml | 22 ++++++++++ backend/data/questions/bulb-switcher-ii.yaml | 22 ++++++++++ backend/data/questions/bulb-switcher.yaml | 24 +++++++++++ backend/data/questions/bulls-and-cows.yaml | 24 +++++++++++ backend/data/questions/bus-routes.yaml | 22 ++++++++++ .../data/questions/cache-with-time-limit.yaml | 16 +++++++ .../calculate-amount-paid-in-taxes.yaml | 20 +++++++++ .../calculate-digit-sum-of-a-string.yaml | 20 +++++++++ .../calculate-money-in-leetcode-bank.yaml | 24 +++++++++++ .../data/questions/camelcase-matching.yaml | 20 +++++++++ .../can-convert-string-in-k-moves.yaml | 24 +++++++++++ backend/data/questions/can-i-win.yaml | 26 ++++++++++++ ...-arithmetic-progression-from-sequence.yaml | 24 +++++++++++ backend/data/questions/can-place-flowers.yaml | 24 +++++++++++ ...pacity-to-ship-packages-within-d-days.yaml | 24 +++++++++++ .../data/questions/capitalize-the-title.yaml | 22 ++++++++++ backend/data/questions/car-fleet.yaml | 24 +++++++++++ backend/data/questions/car-pooling.yaml | 24 +++++++++++ .../data/questions/card-flipping-game.yaml | 20 +++++++++ .../categorize-box-according-to-criteria.yaml | 20 +++++++++ .../cells-in-a-range-on-an-excel-sheet.yaml | 18 ++++++++ .../cells-with-odd-values-in-a-matrix.yaml | 20 +++++++++ .../data/questions/chalkboard-xor-game.yaml | 24 +++++++++++ backend/data/questions/champagne-tower.yaml | 24 +++++++++++ .../cheapest-flights-within-k-stops.yaml | 20 +++++++++ ...array-formation-through-concatenation.yaml | 22 ++++++++++ .../check-completeness-of-a-binary-tree.yaml | 24 +++++++++++ .../check-distances-between-same-letters.yaml | 16 +++++++ ...-1s-are-at-least-length-k-places-away.yaml | 20 +++++++++ ...ters-have-equal-number-of-occurrences.yaml | 20 +++++++++ ...-if-all-integers-in-range-are-covered.yaml | 18 ++++++++ .../check-if-array-is-sorted-and-rotated.yaml | 26 ++++++++++++ .../check-if-it-is-a-straight-line.yaml | 20 +++++++++ .../check-if-matrix-is-x-matrix.yaml | 18 ++++++++ .../check-if-n-and-its-double-exist.yaml | 22 ++++++++++ ...f-numbers-are-ascending-in-a-sentence.yaml | 20 +++++++++ ...ne-string-swap-can-make-strings-equal.yaml | 22 ++++++++++ .../check-if-string-is-a-prefix-of-array.yaml | 18 ++++++++ .../check-if-the-sentence-is-pangram.yaml | 22 ++++++++++ ...k-if-two-string-arrays-are-equivalent.yaml | 20 +++++++++ .../data/questions/combination-sum-iii.yaml | 24 +++++++++++ .../data/questions/combination-sum-iv.yaml | 22 ++++++++++ .../questions/concatenation-of-array.yaml | 20 +++++++++ ...e-from-preorder-and-inorder-traversal.yaml | 20 +++++++++ .../data/questions/contains-duplicate-ii.yaml | 24 +++++++++++ .../questions/continuous-subarray-sum.yaml | 26 ++++++++++++ .../convert-bst-to-greater-tree.yaml | 22 ++++++++++ ...rt-sorted-array-to-binary-search-tree.yaml | 22 ++++++++++ .../copy-list-with-random-pointer.yaml | 24 +++++++++++ .../count-good-nodes-in-binary-tree.yaml | 24 +++++++++++ .../data/questions/course-schedule-iv.yaml | 24 +++++++++++ .../delete-leaves-with-a-given-value.yaml | 24 +++++++++++ .../data/questions/delete-node-in-a-bst.yaml | 24 +++++++++++ ...n-add-and-search-words-data-structure.yaml | 34 +++++++++++++++ .../data/questions/design-circular-queue.yaml | 34 +++++++++++++++ backend/data/questions/design-hashmap.yaml | 34 +++++++++++++++ backend/data/questions/design-hashset.yaml | 20 +++++++++ backend/data/questions/design-twitter.yaml | 20 +++++++++ backend/data/questions/detect-squares.yaml | 20 +++++++++ .../data/questions/distinct-subsequences.yaml | 24 +++++++++++ backend/data/questions/dota2-senate.yaml | 24 +++++++++++ backend/data/questions/evaluate-division.yaml | 22 ++++++++++ .../questions/find-in-mountain-array.yaml | 24 +++++++++++ .../questions/find-k-closest-elements.yaml | 22 ++++++++++ .../find-median-from-data-stream.yaml | 20 +++++++++ .../data/questions/find-the-town-judge.yaml | 22 ++++++++++ .../questions/first-missing-positive.yaml | 26 ++++++++++++ .../greatest-common-divisor-of-strings.yaml | 24 +++++++++++ .../guess-number-higher-or-lower.yaml | 24 +++++++++++ backend/data/questions/hand-of-straights.yaml | 24 +++++++++++ backend/data/questions/house-robber-ii.yaml | 26 ++++++++++++ backend/data/questions/house-robber-iii.yaml | 22 ++++++++++ .../implement-queue-using-stacks.yaml | 18 ++++++++ .../implement-stack-using-queues.yaml | 18 ++++++++ .../questions/implement-trie-prefix-tree.yaml | 20 +++++++++ .../insert-into-a-binary-search-tree.yaml | 22 ++++++++++ .../data/questions/interleaving-string.yaml | 26 ++++++++++++ backend/data/questions/ipo.yaml | 22 ++++++++++ backend/data/questions/island-perimeter.yaml | 24 +++++++++++ backend/data/questions/jump-game-vii.yaml | 22 ++++++++++ .../questions/k-closest-points-to-origin.yaml | 20 +++++++++ .../data/questions/koko-eating-bananas.yaml | 24 +++++++++++ .../kth-largest-element-in-a-stream.yaml | 20 +++++++++ .../data/questions/last-stone-weight-ii.yaml | 24 +++++++++++ backend/data/questions/last-stone-weight.yaml | 22 ++++++++++ backend/data/questions/lemonade-change.yaml | 22 ++++++++++ backend/data/questions/lfu-cache.yaml | 42 +++++++++++++++++++ .../data/questions/longest-happy-string.yaml | 29 +++++++++++++ .../longest-increasing-path-in-a-matrix.yaml | 26 ++++++++++++ .../questions/longest-turbulent-subarray.yaml | 26 ++++++++++++ .../questions/longest-valid-parentheses.yaml | 26 ++++++++++++ backend/data/questions/lru-cache.yaml | 38 +++++++++++++++++ .../data/questions/majority-element-ii.yaml | 26 ++++++++++++ .../data/questions/matchsticks-to-square.yaml | 24 +++++++++++ .../data/questions/max-area-of-island.yaml | 33 +++++++++++++++ .../questions/maximum-frequency-stack.yaml | 38 +++++++++++++++++ .../questions/merge-strings-alternately.yaml | 20 +++++++++ .../one-bit-and-two-bit-characters.yaml | 20 +++++++++ backend/data/questions/reverse-string.yaml | 18 ++++++++ backend/data/questions/transpose-matrix.yaml | 18 ++++++++ .../unique-number-of-occurrences.yaml | 20 +++++++++ .../data/questions/valid-palindrome-ii.yaml | 22 ++++++++++ .../verifying-an-alien-dictionary.yaml | 20 +++++++++ 203 files changed, 4526 insertions(+) diff --git a/backend/data/questions/01-matrix.yaml b/backend/data/questions/01-matrix.yaml index c5fb26d..eead7b6 100644 --- a/backend/data/questions/01-matrix.yaml +++ b/backend/data/questions/01-matrix.yaml @@ -11,6 +11,26 @@ patterns: - matrix-traversal - dynamic-programming +function_signature: "def update_matrix(mat: list[list[int]]) -> list[list[int]]:" + +test_cases: + visible: + - input: { mat: [[0, 0, 0], [0, 1, 0], [0, 0, 0]] } + expected: [[0, 0, 0], [0, 1, 0], [0, 0, 0]] + - input: { mat: [[0, 0, 0], [0, 1, 0], [1, 1, 1]] } + expected: [[0, 0, 0], [0, 1, 0], [1, 2, 1]] + hidden: + - input: { mat: [[0]] } + expected: [[0]] + - input: { mat: [[1, 0, 1], [1, 1, 1], [1, 1, 1]] } + expected: [[1, 0, 1], [2, 1, 2], [3, 2, 3]] + - input: { mat: [[1, 1, 1], [1, 1, 1], [1, 1, 0]] } + expected: [[4, 3, 2], [3, 2, 1], [2, 1, 0]] + - input: { mat: [[0, 1], [1, 1]] } + expected: [[0, 1], [1, 2]] + - input: { mat: [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]] } + expected: [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]] + description: | Given an `m x n` binary matrix `mat`, return *the distance of the nearest* `0` *for each cell*. diff --git a/backend/data/questions/132-pattern.yaml b/backend/data/questions/132-pattern.yaml index 905e108..edaf703 100644 --- a/backend/data/questions/132-pattern.yaml +++ b/backend/data/questions/132-pattern.yaml @@ -9,6 +9,30 @@ categories: patterns: - monotonic-stack +function_signature: "def find132pattern(nums: list[int]) -> bool:" + +test_cases: + visible: + - input: { nums: [1, 2, 3, 4] } + expected: false + - input: { nums: [3, 1, 4, 2] } + expected: true + - input: { nums: [-1, 3, 2, 0] } + expected: true + hidden: + - input: { nums: [1, 2] } + expected: false + - input: { nums: [3, 5, 0, 3, 4] } + expected: true + - input: { nums: [1, 0, 1, -4, -3] } + expected: false + - input: { nums: [1, 2, 2, 2] } + expected: false + - input: { nums: [-2, 1, 2, -2, 1, 2] } + expected: true + - input: { nums: [1, 3, 2, 4, 5, 6, 7, 8, 9, 10] } + expected: true + description: | Given an array of `n` integers `nums`, a **132 pattern** is a subsequence of three integers `nums[i]`, `nums[j]` and `nums[k]` such that `i < j < k` and `nums[i] < nums[k] < nums[j]`. diff --git a/backend/data/questions/2-keys-keyboard.yaml b/backend/data/questions/2-keys-keyboard.yaml index f78465b..b2805fd 100644 --- a/backend/data/questions/2-keys-keyboard.yaml +++ b/backend/data/questions/2-keys-keyboard.yaml @@ -9,6 +9,28 @@ categories: patterns: - dynamic-programming +function_signature: "def min_steps(n: int) -> int:" + +test_cases: + visible: + - input: { n: 3 } + expected: 3 + - input: { n: 1 } + expected: 0 + hidden: + - input: { n: 4 } + expected: 4 + - input: { n: 6 } + expected: 5 + - input: { n: 12 } + expected: 7 + - input: { n: 17 } + expected: 17 + - input: { n: 100 } + expected: 14 + - input: { n: 1000 } + expected: 21 + description: | There is only one character `'A'` on the screen of a notepad. You can perform one of two operations on this notepad for each step: diff --git a/backend/data/questions/24-game.yaml b/backend/data/questions/24-game.yaml index 2ba2002..072c37b 100644 --- a/backend/data/questions/24-game.yaml +++ b/backend/data/questions/24-game.yaml @@ -10,6 +10,28 @@ categories: patterns: - backtracking +function_signature: "def judge_point24(cards: list[int]) -> bool:" + +test_cases: + visible: + - input: { cards: [4, 1, 8, 7] } + expected: true + - input: { cards: [1, 2, 1, 2] } + expected: false + hidden: + - input: { cards: [8, 3, 8, 3] } + expected: true + - input: { cards: [1, 1, 1, 1] } + expected: false + - input: { cards: [1, 5, 5, 5] } + expected: true + - input: { cards: [3, 3, 8, 8] } + expected: true + - input: { cards: [1, 9, 1, 2] } + expected: true + - input: { cards: [1, 1, 7, 7] } + expected: false + description: | You are given an integer array `cards` of length `4`. You have four cards, each containing a number in the range `[1, 9]`. You should arrange the numbers on these cards in a mathematical expression using the operators `['+', '-', '*', '/']` and the parentheses `'('` and `')'` to get the value 24. diff --git a/backend/data/questions/3sum-with-multiplicity.yaml b/backend/data/questions/3sum-with-multiplicity.yaml index ebca770..f4233b3 100644 --- a/backend/data/questions/3sum-with-multiplicity.yaml +++ b/backend/data/questions/3sum-with-multiplicity.yaml @@ -10,6 +10,28 @@ categories: patterns: - two-pointers +function_signature: "def three_sum_multi(arr: list[int], target: int) -> int:" + +test_cases: + visible: + - input: { arr: [1, 1, 2, 2, 3, 3, 4, 4, 5, 5], target: 8 } + expected: 20 + - input: { arr: [1, 1, 2, 2, 2, 2], target: 5 } + expected: 12 + - input: { arr: [2, 1, 3], target: 6 } + expected: 1 + hidden: + - input: { arr: [0, 0, 0], target: 0 } + expected: 1 + - input: { arr: [0, 0, 0, 0, 0], target: 0 } + expected: 10 + - input: { arr: [1, 2, 3, 4, 5, 6], target: 12 } + expected: 4 + - input: { arr: [3, 3, 3, 3, 3], target: 9 } + expected: 10 + - input: { arr: [1, 1, 1, 1, 1, 1], target: 3 } + expected: 20 + description: | Given an integer array `arr`, and an integer `target`, return the number of tuples `i, j, k` such that `i < j < k` and `arr[i] + arr[j] + arr[k] == target`. diff --git a/backend/data/questions/4sum-ii.yaml b/backend/data/questions/4sum-ii.yaml index 827e8b4..4b9c203 100644 --- a/backend/data/questions/4sum-ii.yaml +++ b/backend/data/questions/4sum-ii.yaml @@ -9,6 +9,24 @@ categories: patterns: - two-pointers +function_signature: "def four_sum_count(nums1: list[int], nums2: list[int], nums3: list[int], nums4: list[int]) -> int:" + +test_cases: + visible: + - input: { nums1: [1, 2], nums2: [-2, -1], nums3: [-1, 2], nums4: [0, 2] } + expected: 2 + - input: { nums1: [0], nums2: [0], nums3: [0], nums4: [0] } + expected: 1 + hidden: + - input: { nums1: [-1, -1], nums2: [-1, 1], nums3: [-1, 1], nums4: [1, -1] } + expected: 6 + - input: { nums1: [1], nums2: [-1], nums3: [0], nums4: [0] } + expected: 1 + - input: { nums1: [0, 1, -1], nums2: [-1, 1, 0], nums3: [0, 0, 1], nums4: [-1, 1, 1] } + expected: 17 + - input: { nums1: [1, 1, 1], nums2: [1, 1, 1], nums3: [-1, -1, -1], nums4: [-1, -1, -1] } + expected: 81 + description: | Given four integer arrays `nums1`, `nums2`, `nums3`, and `nums4` all of length `n`, return the number of tuples `(i, j, k, l)` such that: diff --git a/backend/data/questions/a-number-after-a-double-reversal.yaml b/backend/data/questions/a-number-after-a-double-reversal.yaml index acd6739..d3d59dd 100644 --- a/backend/data/questions/a-number-after-a-double-reversal.yaml +++ b/backend/data/questions/a-number-after-a-double-reversal.yaml @@ -8,6 +8,28 @@ categories: patterns: - greedy +function_signature: "def is_same_after_reversals(num: int) -> bool:" + +test_cases: + visible: + - input: { num: 526 } + expected: true + - input: { num: 1800 } + expected: false + - input: { num: 0 } + expected: true + hidden: + - input: { num: 1 } + expected: true + - input: { num: 10 } + expected: false + - input: { num: 100 } + expected: false + - input: { num: 123 } + expected: true + - input: { num: 12300 } + expected: false + description: | **Reversing** an integer means to reverse all its digits. diff --git a/backend/data/questions/accounts-merge.yaml b/backend/data/questions/accounts-merge.yaml index a5ad6cf..b7ac21d 100644 --- a/backend/data/questions/accounts-merge.yaml +++ b/backend/data/questions/accounts-merge.yaml @@ -11,6 +11,22 @@ patterns: - union-find - dfs +function_signature: "def accounts_merge(accounts: list[list[str]]) -> list[list[str]]:" + +test_cases: + visible: + - input: { accounts: [["John", "johnsmith@mail.com", "john_newyork@mail.com"], ["John", "johnsmith@mail.com", "john00@mail.com"], ["Mary", "mary@mail.com"], ["John", "johnnybravo@mail.com"]] } + expected: [["John", "john00@mail.com", "john_newyork@mail.com", "johnsmith@mail.com"], ["Mary", "mary@mail.com"], ["John", "johnnybravo@mail.com"]] + - input: { accounts: [["Gabe", "Gabe0@m.co", "Gabe3@m.co", "Gabe1@m.co"], ["Kevin", "Kevin3@m.co", "Kevin5@m.co", "Kevin0@m.co"]] } + expected: [["Gabe", "Gabe0@m.co", "Gabe1@m.co", "Gabe3@m.co"], ["Kevin", "Kevin0@m.co", "Kevin3@m.co", "Kevin5@m.co"]] + hidden: + - input: { accounts: [["Alex", "a@mail.com"]] } + expected: [["Alex", "a@mail.com"]] + - input: { accounts: [["David", "d1@m.co", "d2@m.co"], ["David", "d2@m.co", "d3@m.co"], ["David", "d3@m.co", "d4@m.co"]] } + expected: [["David", "d1@m.co", "d2@m.co", "d3@m.co", "d4@m.co"]] + - input: { accounts: [["A", "a@a.com"], ["B", "b@b.com"], ["A", "a@a.com"]] } + expected: [["A", "a@a.com"], ["B", "b@b.com"]] + description: | Given a list of `accounts` where each element `accounts[i]` is a list of strings, where the first element `accounts[i][0]` is a name, and the rest of the elements are **emails** representing emails of the account. diff --git a/backend/data/questions/add-minimum-number-of-rungs.yaml b/backend/data/questions/add-minimum-number-of-rungs.yaml index 308e581..68c8faf 100644 --- a/backend/data/questions/add-minimum-number-of-rungs.yaml +++ b/backend/data/questions/add-minimum-number-of-rungs.yaml @@ -8,6 +8,28 @@ categories: patterns: - greedy +function_signature: "def add_rungs(rungs: list[int], dist: int) -> int:" + +test_cases: + visible: + - input: { rungs: [1, 3, 5, 10], dist: 2 } + expected: 2 + - input: { rungs: [3, 6, 8, 10], dist: 3 } + expected: 0 + - input: { rungs: [3, 4, 6, 7], dist: 2 } + expected: 1 + hidden: + - input: { rungs: [5], dist: 10 } + expected: 0 + - input: { rungs: [10], dist: 3 } + expected: 3 + - input: { rungs: [1, 100], dist: 10 } + expected: 9 + - input: { rungs: [1, 2, 3, 4, 5], dist: 1 } + expected: 0 + - input: { rungs: [4, 8, 12, 16], dist: 3 } + expected: 4 + description: | You are given a **strictly increasing** integer array `rungs` that represents the **height** of rungs on a ladder. You are currently on the **floor** at height `0`, and you want to reach the last rung. diff --git a/backend/data/questions/add-one-row-to-tree.yaml b/backend/data/questions/add-one-row-to-tree.yaml index f2fc73a..1ef18e6 100644 --- a/backend/data/questions/add-one-row-to-tree.yaml +++ b/backend/data/questions/add-one-row-to-tree.yaml @@ -12,6 +12,24 @@ patterns: - dfs - tree-traversal +function_signature: "def add_one_row(root: TreeNode, val: int, depth: int) -> TreeNode:" + +test_cases: + visible: + - input: { root: [4, 2, 6, 3, 1, 5], val: 1, depth: 2 } + expected: [4, 1, 1, 2, null, null, 6, 3, 1, 5] + - input: { root: [4, 2, null, 3, 1], val: 1, depth: 3 } + expected: [4, 2, null, 1, 1, 3, null, null, 1] + hidden: + - input: { root: [1], val: 2, depth: 1 } + expected: [2, 1] + - input: { root: [1, 2, 3], val: 5, depth: 2 } + expected: [1, 5, 5, 2, null, null, 3] + - input: { root: [1], val: 2, depth: 2 } + expected: [1, 2, 2] + - input: { root: [4, 2, 6, 3, 1, 5], val: 1, depth: 1 } + expected: [1, 4, null, 2, 6, 3, 1, 5] + description: | Given the `root` of a binary tree and two integers `val` and `depth`, add a row of nodes with value `val` at the given depth `depth`. diff --git a/backend/data/questions/add-to-array-form-of-integer.yaml b/backend/data/questions/add-to-array-form-of-integer.yaml index ccd70fd..251c4e0 100644 --- a/backend/data/questions/add-to-array-form-of-integer.yaml +++ b/backend/data/questions/add-to-array-form-of-integer.yaml @@ -9,6 +9,28 @@ categories: patterns: - two-pointers +function_signature: "def add_to_array_form(num: list[int], k: int) -> list[int]:" + +test_cases: + visible: + - input: { num: [1, 2, 0, 0], k: 34 } + expected: [1, 2, 3, 4] + - input: { num: [2, 7, 4], k: 181 } + expected: [4, 5, 5] + - input: { num: [2, 1, 5], k: 806 } + expected: [1, 0, 2, 1] + hidden: + - input: { num: [0], k: 1 } + expected: [1] + - input: { num: [9, 9, 9], k: 1 } + expected: [1, 0, 0, 0] + - input: { num: [1], k: 99 } + expected: [1, 0, 0] + - input: { num: [0], k: 10000 } + expected: [1, 0, 0, 0, 0] + - input: { num: [5, 5, 5], k: 555 } + expected: [1, 1, 1, 0] + description: | The **array-form** of an integer `num` is an array representing its digits in left to right order. diff --git a/backend/data/questions/add-two-integers.yaml b/backend/data/questions/add-two-integers.yaml index 2dfcf38..57b7891 100644 --- a/backend/data/questions/add-two-integers.yaml +++ b/backend/data/questions/add-two-integers.yaml @@ -7,6 +7,26 @@ categories: - math patterns: [] +function_signature: "def sum(num1: int, num2: int) -> int:" + +test_cases: + visible: + - input: { num1: 12, num2: 5 } + expected: 17 + - input: { num1: -10, num2: 4 } + expected: -6 + hidden: + - input: { num1: 0, num2: 0 } + expected: 0 + - input: { num1: -100, num2: 100 } + expected: 0 + - input: { num1: 50, num2: 50 } + expected: 100 + - input: { num1: -50, num2: -50 } + expected: -100 + - input: { num1: 1, num2: -1 } + expected: 0 + description: | Given two integers `num1` and `num2`, return *the **sum** of the two integers*. diff --git a/backend/data/questions/add-two-numbers-ii.yaml b/backend/data/questions/add-two-numbers-ii.yaml index 0ee95e1..6974047 100644 --- a/backend/data/questions/add-two-numbers-ii.yaml +++ b/backend/data/questions/add-two-numbers-ii.yaml @@ -10,6 +10,28 @@ categories: patterns: - linkedlist-reversal +function_signature: "def add_two_numbers(l1: ListNode, l2: ListNode) -> ListNode:" + +test_cases: + visible: + - input: { l1: [7, 2, 4, 3], l2: [5, 6, 4] } + expected: [7, 8, 0, 7] + - input: { l1: [2, 4, 3], l2: [5, 6, 4] } + expected: [8, 0, 7] + - input: { l1: [0], l2: [0] } + expected: [0] + hidden: + - input: { l1: [9, 9, 9], l2: [1] } + expected: [1, 0, 0, 0] + - input: { l1: [5], l2: [5] } + expected: [1, 0] + - input: { l1: [1, 2, 3, 4, 5], l2: [6, 7, 8, 9] } + expected: [1, 9, 1, 3, 4] + - input: { l1: [9, 9, 9, 9, 9], l2: [9, 9, 9, 9, 9] } + expected: [1, 9, 9, 9, 9, 8] + - input: { l1: [1], l2: [9, 9, 9, 9] } + expected: [1, 0, 0, 0, 0] + description: | You are given two **non-empty** linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. diff --git a/backend/data/questions/adding-spaces-to-a-string.yaml b/backend/data/questions/adding-spaces-to-a-string.yaml index 62212b8..da1b946 100644 --- a/backend/data/questions/adding-spaces-to-a-string.yaml +++ b/backend/data/questions/adding-spaces-to-a-string.yaml @@ -10,6 +10,26 @@ categories: patterns: - two-pointers +function_signature: "def add_spaces(s: str, spaces: list[int]) -> str:" + +test_cases: + visible: + - input: { s: "LeetcodeHelpsMeLearn", spaces: [8, 13, 15] } + expected: "Leetcode Helps Me Learn" + - input: { s: "icodeinpython", spaces: [1, 5, 7, 9] } + expected: "i code in py thon" + - input: { s: "spacing", spaces: [0, 1, 2, 3, 4, 5, 6] } + expected: " s p a c i n g" + hidden: + - input: { s: "abc", spaces: [1] } + expected: "a bc" + - input: { s: "abc", spaces: [0] } + expected: " abc" + - input: { s: "EnjoyYourCoffee", spaces: [5, 9] } + expected: "Enjoy Your Coffee" + - input: { s: "hello", spaces: [1, 2, 3, 4] } + expected: "h e l l o" + description: | You are given a **0-indexed** string `s` and a **0-indexed** integer array `spaces` that describes the indices in the original string where spaces will be added. Each space should be inserted **before** the character at the given index. diff --git a/backend/data/questions/adding-two-negabinary-numbers.yaml b/backend/data/questions/adding-two-negabinary-numbers.yaml index 7a4dc5b..8840023 100644 --- a/backend/data/questions/adding-two-negabinary-numbers.yaml +++ b/backend/data/questions/adding-two-negabinary-numbers.yaml @@ -9,6 +9,26 @@ categories: patterns: - two-pointers +function_signature: "def add_negabinary(arr1: list[int], arr2: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { arr1: [1, 1, 1, 1, 1], arr2: [1, 0, 1] } + expected: [1, 0, 0, 0, 0] + - input: { arr1: [0], arr2: [0] } + expected: [0] + - input: { arr1: [0], arr2: [1] } + expected: [1] + hidden: + - input: { arr1: [1], arr2: [1] } + expected: [1, 1, 0] + - input: { arr1: [1, 0], arr2: [1, 0] } + expected: [1, 1, 0, 0] + - input: { arr1: [1, 1], arr2: [1, 1] } + expected: [0] + - input: { arr1: [1, 0, 1], arr2: [1, 0, 1] } + expected: [1, 1, 1, 1, 0] + description: | Given two numbers `arr1` and `arr2` in base **-2** (negabinary), return the result of adding them together. diff --git a/backend/data/questions/additive-number.yaml b/backend/data/questions/additive-number.yaml index a4be580..de8cc5e 100644 --- a/backend/data/questions/additive-number.yaml +++ b/backend/data/questions/additive-number.yaml @@ -9,6 +9,30 @@ categories: patterns: - backtracking +function_signature: "def is_additive_number(num: str) -> bool:" + +test_cases: + visible: + - input: { num: "112358" } + expected: true + - input: { num: "199100199" } + expected: true + - input: { num: "1023" } + expected: false + hidden: + - input: { num: "123" } + expected: true + - input: { num: "12" } + expected: false + - input: { num: "101" } + expected: true + - input: { num: "000" } + expected: true + - input: { num: "111" } + expected: false + - input: { num: "1212122436" } + expected: true + description: | An **additive number** is a string whose digits can form an **additive sequence**. diff --git a/backend/data/questions/advantage-shuffle.yaml b/backend/data/questions/advantage-shuffle.yaml index 2aac7ee..0e00da8 100644 --- a/backend/data/questions/advantage-shuffle.yaml +++ b/backend/data/questions/advantage-shuffle.yaml @@ -10,6 +10,24 @@ patterns: - greedy - two-pointers +function_signature: "def advantage_count(nums1: list[int], nums2: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { nums1: [2, 7, 11, 15], nums2: [1, 10, 4, 11] } + expected: [2, 11, 7, 15] + - input: { nums1: [12, 24, 8, 32], nums2: [13, 25, 32, 11] } + expected: [24, 32, 8, 12] + hidden: + - input: { nums1: [1], nums2: [1] } + expected: [1] + - input: { nums1: [5, 5, 5], nums2: [1, 2, 3] } + expected: [5, 5, 5] + - input: { nums1: [1, 2, 3], nums2: [3, 2, 1] } + expected: [1, 3, 2] + - input: { nums1: [2, 0, 4, 1, 2], nums2: [1, 3, 0, 0, 2] } + expected: [2, 4, 1, 2, 0] + description: | You are given two integer arrays `nums1` and `nums2` both of the same length. The **advantage** of `nums1` with respect to `nums2` is the number of indices `i` for which `nums1[i] > nums2[i]`. diff --git a/backend/data/questions/airplane-seat-assignment-probability.yaml b/backend/data/questions/airplane-seat-assignment-probability.yaml index 235c9cd..0cc152e 100644 --- a/backend/data/questions/airplane-seat-assignment-probability.yaml +++ b/backend/data/questions/airplane-seat-assignment-probability.yaml @@ -9,6 +9,24 @@ categories: patterns: - dynamic-programming +function_signature: "def nth_person_gets_nth_seat(n: int) -> float:" + +test_cases: + visible: + - input: { n: 1 } + expected: 1.0 + - input: { n: 2 } + expected: 0.5 + hidden: + - input: { n: 3 } + expected: 0.5 + - input: { n: 10 } + expected: 0.5 + - input: { n: 100 } + expected: 0.5 + - input: { n: 1000 } + expected: 0.5 + description: | `n` passengers board an airplane with exactly `n` seats. The first passenger has lost their ticket and picks a seat randomly. After that, the rest of the passengers will: diff --git a/backend/data/questions/alert-using-same-key.yaml b/backend/data/questions/alert-using-same-key.yaml index e07b82c..1cc7b0d 100644 --- a/backend/data/questions/alert-using-same-key.yaml +++ b/backend/data/questions/alert-using-same-key.yaml @@ -11,6 +11,24 @@ categories: patterns: - sliding-window +function_signature: "def alert_names(key_name: list[str], key_time: list[str]) -> list[str]:" + +test_cases: + visible: + - input: { key_name: ["daniel", "daniel", "daniel", "luis", "luis", "luis", "luis"], key_time: ["10:00", "10:40", "11:00", "09:00", "11:00", "13:00", "15:00"] } + expected: ["daniel"] + - input: { key_name: ["alice", "alice", "alice", "bob", "bob", "bob", "bob"], key_time: ["12:01", "12:00", "18:00", "21:00", "21:20", "21:30", "23:00"] } + expected: ["bob"] + hidden: + - input: { key_name: ["a", "a", "a"], key_time: ["01:00", "01:30", "02:00"] } + expected: ["a"] + - input: { key_name: ["a", "b", "c"], key_time: ["01:00", "02:00", "03:00"] } + expected: [] + - input: { key_name: ["a", "a", "a", "b", "b", "b"], key_time: ["00:00", "00:30", "01:00", "23:00", "23:30", "23:59"] } + expected: ["a", "b"] + - input: { key_name: ["john", "john", "john"], key_time: ["08:00", "09:01", "10:00"] } + expected: [] + description: | LeetCode company workers use key-cards to unlock office doors. Each time a worker uses their key-card, the security system saves the worker's name and the time when it was used. The system emits an **alert** if any worker uses the key-card **three or more times** in a one-hour period. diff --git a/backend/data/questions/all-divisions-with-highest-score-of-binary-array.yaml b/backend/data/questions/all-divisions-with-highest-score-of-binary-array.yaml index b1f8764..c0dacb0 100644 --- a/backend/data/questions/all-divisions-with-highest-score-of-binary-array.yaml +++ b/backend/data/questions/all-divisions-with-highest-score-of-binary-array.yaml @@ -8,6 +8,28 @@ categories: patterns: - prefix-sum +function_signature: "def max_score_indices(nums: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { nums: [0, 0, 1, 0] } + expected: [2, 4] + - input: { nums: [0, 0, 0] } + expected: [3] + - input: { nums: [1, 1] } + expected: [0] + hidden: + - input: { nums: [0] } + expected: [1] + - input: { nums: [1] } + expected: [0] + - input: { nums: [0, 1, 0, 1] } + expected: [2] + - input: { nums: [1, 0, 1, 0, 1] } + expected: [0, 2, 4] + - input: { nums: [0, 0, 0, 0] } + expected: [4] + description: | You are given a **0-indexed** binary array `nums` of length `n`. `nums` can be divided at index `i` (where `0 <= i <= n`) into two arrays (possibly empty) `nums_left` and `nums_right`: diff --git a/backend/data/questions/all-elements-in-two-binary-search-trees.yaml b/backend/data/questions/all-elements-in-two-binary-search-trees.yaml index 62c64d4..085ce04 100644 --- a/backend/data/questions/all-elements-in-two-binary-search-trees.yaml +++ b/backend/data/questions/all-elements-in-two-binary-search-trees.yaml @@ -10,6 +10,24 @@ patterns: - tree-traversal - two-pointers +function_signature: "def get_all_elements(root1: TreeNode, root2: TreeNode) -> list[int]:" + +test_cases: + visible: + - input: { root1: [2, 1, 4], root2: [1, 0, 3] } + expected: [0, 1, 1, 2, 3, 4] + - input: { root1: [1, null, 8], root2: [8, 1] } + expected: [1, 1, 8, 8] + hidden: + - input: { root1: [], root2: [5, 1, 7] } + expected: [1, 5, 7] + - input: { root1: [1], root2: [] } + expected: [1] + - input: { root1: [], root2: [] } + expected: [] + - input: { root1: [0, -10, 10], root2: [5, 1, 7, 0, 2] } + expected: [-10, 0, 0, 1, 2, 5, 7, 10] + description: | Given two binary search trees `root1` and `root2`, return *a list containing all the integers from both trees sorted in **ascending** order*. diff --git a/backend/data/questions/all-nodes-distance-k-in-binary-tree.yaml b/backend/data/questions/all-nodes-distance-k-in-binary-tree.yaml index 4799947..40cba3c 100644 --- a/backend/data/questions/all-nodes-distance-k-in-binary-tree.yaml +++ b/backend/data/questions/all-nodes-distance-k-in-binary-tree.yaml @@ -11,6 +11,26 @@ patterns: - bfs - dfs +function_signature: "def distance_k(root: TreeNode, target: TreeNode, k: int) -> list[int]:" + +test_cases: + visible: + - input: { root: [3, 5, 1, 6, 2, null, 8, null, null, 7, 4], target: 5, k: 2 } + expected: [7, 4, 1] + - input: { root: [1], target: 1, k: 3 } + expected: [] + hidden: + - input: { root: [0, 1, null, 3, 2], target: 2, k: 1 } + expected: [1] + - input: { root: [0, 1, 2], target: 0, k: 1 } + expected: [1, 2] + - input: { root: [0, 1, 2], target: 0, k: 0 } + expected: [0] + - input: { root: [3, 5, 1, 6, 2, 0, 8, null, null, 7, 4], target: 3, k: 1 } + expected: [5, 1] + - input: { root: [1, 2, 3, 4], target: 4, k: 2 } + expected: [1] + description: | Given the `root` of a binary tree, the value of a target node `target`, and an integer `k`, return *an array of the values of all nodes that have a distance* `k` *from the target node*. diff --git a/backend/data/questions/all-paths-from-source-to-target.yaml b/backend/data/questions/all-paths-from-source-to-target.yaml index f828b42..cbcca31 100644 --- a/backend/data/questions/all-paths-from-source-to-target.yaml +++ b/backend/data/questions/all-paths-from-source-to-target.yaml @@ -10,6 +10,24 @@ patterns: - dfs - backtracking +function_signature: "def all_paths_source_target(graph: list[list[int]]) -> list[list[int]]:" + +test_cases: + visible: + - input: { graph: [[1, 2], [3], [3], []] } + expected: [[0, 1, 3], [0, 2, 3]] + - input: { graph: [[4, 3, 1], [3, 2, 4], [3], [4], []] } + expected: [[0, 4], [0, 3, 4], [0, 1, 3, 4], [0, 1, 2, 3, 4], [0, 1, 4]] + hidden: + - input: { graph: [[1], []] } + expected: [[0, 1]] + - input: { graph: [[1, 2, 3], [4], [4], [4], []] } + expected: [[0, 1, 4], [0, 2, 4], [0, 3, 4]] + - input: { graph: [[2, 1], [2], []] } + expected: [[0, 2], [0, 1, 2]] + - input: { graph: [[1, 3], [2], [3], []] } + expected: [[0, 1, 2, 3], [0, 3]] + description: | Given a directed acyclic graph (**DAG**) of `n` nodes labeled from `0` to `n - 1`, find all possible paths from node `0` to node `n - 1` and return them in **any order**. diff --git a/backend/data/questions/all-possible-full-binary-trees.yaml b/backend/data/questions/all-possible-full-binary-trees.yaml index 4086940..ab90a9f 100644 --- a/backend/data/questions/all-possible-full-binary-trees.yaml +++ b/backend/data/questions/all-possible-full-binary-trees.yaml @@ -11,6 +11,26 @@ patterns: - backtracking - dynamic-programming +function_signature: "def all_possible_fbt(n: int) -> list[TreeNode]:" + +test_cases: + visible: + - input: { n: 7 } + expected: 5 + - input: { n: 3 } + expected: 1 + hidden: + - input: { n: 1 } + expected: 1 + - input: { n: 2 } + expected: 0 + - input: { n: 5 } + expected: 2 + - input: { n: 9 } + expected: 14 + - input: { n: 4 } + expected: 0 + description: | Given an integer `n`, return *a list of all possible **full binary trees** with* `n` *nodes*. Each node of each tree in the answer must have `Node.val == 0`. diff --git a/backend/data/questions/allocate-mailboxes.yaml b/backend/data/questions/allocate-mailboxes.yaml index 33578e3..20d7a9f 100644 --- a/backend/data/questions/allocate-mailboxes.yaml +++ b/backend/data/questions/allocate-mailboxes.yaml @@ -11,6 +11,26 @@ categories: patterns: - dynamic-programming +function_signature: "def min_distance(houses: list[int], k: int) -> int:" + +test_cases: + visible: + - input: { houses: [1, 4, 8, 10, 20], k: 3 } + expected: 5 + - input: { houses: [2, 3, 5, 12, 18], k: 2 } + expected: 9 + hidden: + - input: { houses: [1, 2, 3], k: 1 } + expected: 2 + - input: { houses: [1, 2, 3], k: 3 } + expected: 0 + - input: { houses: [7, 4, 6, 1], k: 1 } + expected: 8 + - input: { houses: [3, 6, 14, 10], k: 4 } + expected: 0 + - input: { houses: [1, 10, 100], k: 2 } + expected: 9 + description: | Given the array `houses` where `houses[i]` is the location of the ith house along a street and an integer `k`, allocate `k` mailboxes in the street. diff --git a/backend/data/questions/alphabet-board-path.yaml b/backend/data/questions/alphabet-board-path.yaml index 2e5c883..1666797 100644 --- a/backend/data/questions/alphabet-board-path.yaml +++ b/backend/data/questions/alphabet-board-path.yaml @@ -9,6 +9,26 @@ categories: patterns: - matrix-traversal +function_signature: "def alphabet_board_path(target: str) -> str:" + +test_cases: + visible: + - input: { target: "leet" } + expected: "DDR!UURRR!!DDD!" + - input: { target: "code" } + expected: "RR!DDRR!UUL!R!" + hidden: + - input: { target: "a" } + expected: "!" + - input: { target: "z" } + expected: "DDDDD!" + - input: { target: "zdz" } + expected: "DDDDD!UUUUURRR!LLLDDDDD!" + - input: { target: "aa" } + expected: "!!" + - input: { target: "abc" } + expected: "!R!R!" + description: | On an alphabet board, we start at position `(0, 0)`, corresponding to character `board[0][0]`. diff --git a/backend/data/questions/alternating-digit-sum.yaml b/backend/data/questions/alternating-digit-sum.yaml index b64a4ac..40a4a68 100644 --- a/backend/data/questions/alternating-digit-sum.yaml +++ b/backend/data/questions/alternating-digit-sum.yaml @@ -8,6 +8,28 @@ categories: patterns: - greedy +function_signature: "def alternate_digit_sum(n: int) -> int:" + +test_cases: + visible: + - input: { n: 521 } + expected: 4 + - input: { n: 111 } + expected: 1 + - input: { n: 886996 } + expected: 0 + hidden: + - input: { n: 1 } + expected: 1 + - input: { n: 10 } + expected: 1 + - input: { n: 99 } + expected: 0 + - input: { n: 12345 } + expected: 3 + - input: { n: 54321 } + expected: 3 + description: | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules: diff --git a/backend/data/questions/ambiguous-coordinates.yaml b/backend/data/questions/ambiguous-coordinates.yaml index 4887556..ea652fb 100644 --- a/backend/data/questions/ambiguous-coordinates.yaml +++ b/backend/data/questions/ambiguous-coordinates.yaml @@ -9,6 +9,22 @@ categories: patterns: - backtracking +function_signature: "def ambiguous_coordinates(s: str) -> list[str]:" + +test_cases: + visible: + - input: { s: "(123)" } + expected: ["(1, 2.3)", "(1, 23)", "(1.2, 3)", "(12, 3)"] + - input: { s: "(0123)" } + expected: ["(0, 1.23)", "(0, 12.3)", "(0, 123)", "(0.1, 2.3)", "(0.1, 23)", "(0.12, 3)"] + hidden: + - input: { s: "(00011)" } + expected: ["(0, 0.011)", "(0.001, 1)"] + - input: { s: "(100)" } + expected: ["(10, 0)", "(1, 0.0)"] + - input: { s: "(12)" } + expected: ["(1, 2)"] + description: | We had some 2-dimensional coordinates, like `"(1, 3)"` or `"(2, 0.5)"`. Then, we removed all commas, decimal points, and spaces and ended up with the string `s`. diff --git a/backend/data/questions/amount-of-time-for-binary-tree-to-be-infected.yaml b/backend/data/questions/amount-of-time-for-binary-tree-to-be-infected.yaml index fa601e1..7537455 100644 --- a/backend/data/questions/amount-of-time-for-binary-tree-to-be-infected.yaml +++ b/backend/data/questions/amount-of-time-for-binary-tree-to-be-infected.yaml @@ -11,6 +11,26 @@ patterns: - bfs - tree-traversal +function_signature: "def amount_of_time(root: TreeNode, start: int) -> int:" + +test_cases: + visible: + - input: { root: [1, 5, 3, null, 4, 10, 6, 9, 2], start: 3 } + expected: 4 + - input: { root: [1], start: 1 } + expected: 0 + hidden: + - input: { root: [1, 2, null, 3], start: 3 } + expected: 2 + - input: { root: [1, 2, 3], start: 2 } + expected: 2 + - input: { root: [1, 2, 3, 4, 5, 6, 7], start: 4 } + expected: 4 + - input: { root: [1, 2, 3, 4, 5], start: 1 } + expected: 2 + - input: { root: [2, 5, null, null, 3, 4, null, 10, 9, null, null, 1], start: 9 } + expected: 5 + description: | You are given the `root` of a binary tree with **unique** values, and an integer `start`. At minute `0`, an **infection** starts from the node with value `start`. diff --git a/backend/data/questions/angle-between-hands-of-a-clock.yaml b/backend/data/questions/angle-between-hands-of-a-clock.yaml index b04844b..00d5ba4 100644 --- a/backend/data/questions/angle-between-hands-of-a-clock.yaml +++ b/backend/data/questions/angle-between-hands-of-a-clock.yaml @@ -8,6 +8,28 @@ categories: patterns: - greedy +function_signature: "def angle_clock(hour: int, minutes: int) -> float:" + +test_cases: + visible: + - input: { hour: 12, minutes: 30 } + expected: 165.0 + - input: { hour: 3, minutes: 30 } + expected: 75.0 + - input: { hour: 3, minutes: 15 } + expected: 7.5 + hidden: + - input: { hour: 12, minutes: 0 } + expected: 0.0 + - input: { hour: 6, minutes: 0 } + expected: 180.0 + - input: { hour: 1, minutes: 57 } + expected: 76.5 + - input: { hour: 4, minutes: 50 } + expected: 155.0 + - input: { hour: 9, minutes: 0 } + expected: 90.0 + description: | Given two numbers, `hour` and `minutes`, return *the smaller angle (in degrees) formed between the hour and the minute hand*. diff --git a/backend/data/questions/append-characters-to-string-to-make-subsequence.yaml b/backend/data/questions/append-characters-to-string-to-make-subsequence.yaml index 07c0e4c..e901ccd 100644 --- a/backend/data/questions/append-characters-to-string-to-make-subsequence.yaml +++ b/backend/data/questions/append-characters-to-string-to-make-subsequence.yaml @@ -10,6 +10,28 @@ patterns: - two-pointers - greedy +function_signature: "def append_characters(s: str, t: str) -> int:" + +test_cases: + visible: + - input: { s: "coaching", t: "coding" } + expected: 4 + - input: { s: "abcde", t: "a" } + expected: 0 + - input: { s: "z", t: "abcde" } + expected: 5 + hidden: + - input: { s: "abc", t: "abc" } + expected: 0 + - input: { s: "abc", t: "d" } + expected: 1 + - input: { s: "aaa", t: "aaaa" } + expected: 1 + - input: { s: "xyz", t: "xyz" } + expected: 0 + - input: { s: "abc", t: "axbxc" } + expected: 4 + description: | You are given two strings `s` and `t` consisting of only lowercase English letters. diff --git a/backend/data/questions/append-k-integers-with-minimal-sum.yaml b/backend/data/questions/append-k-integers-with-minimal-sum.yaml index 4d98aa5..fc6a983 100644 --- a/backend/data/questions/append-k-integers-with-minimal-sum.yaml +++ b/backend/data/questions/append-k-integers-with-minimal-sum.yaml @@ -10,6 +10,28 @@ categories: patterns: - greedy +function_signature: "def min_sum(nums: list[int], k: int) -> int:" + +test_cases: + visible: + - input: { nums: [1, 4, 25, 10, 25], k: 2 } + expected: 5 + - input: { nums: [5, 6], k: 6 } + expected: 25 + hidden: + - input: { nums: [1], k: 1 } + expected: 2 + - input: { nums: [1, 2, 3], k: 2 } + expected: 9 + - input: { nums: [2, 4, 6], k: 3 } + expected: 6 + - input: { nums: [1000000000], k: 1 } + expected: 1 + - input: { nums: [1, 2, 3, 4, 5], k: 5 } + expected: 40 + - input: { nums: [3, 3, 3], k: 4 } + expected: 12 + description: | You are given an integer array `nums` and an integer `k`. Append `k` **unique positive** integers that do **not** appear in `nums` to `nums` such that the resulting total sum is **minimum**. diff --git a/backend/data/questions/apply-bitwise-operations-to-make-strings-equal.yaml b/backend/data/questions/apply-bitwise-operations-to-make-strings-equal.yaml index b8c79dd..4832af6 100644 --- a/backend/data/questions/apply-bitwise-operations-to-make-strings-equal.yaml +++ b/backend/data/questions/apply-bitwise-operations-to-make-strings-equal.yaml @@ -9,6 +9,30 @@ categories: patterns: - greedy +function_signature: "def make_strings_equal(s: str, target: str) -> bool:" + +test_cases: + visible: + - input: { s: "1010", target: "0110" } + expected: true + - input: { s: "11", target: "00" } + expected: false + hidden: + - input: { s: "00", target: "00" } + expected: true + - input: { s: "00", target: "11" } + expected: false + - input: { s: "11", target: "11" } + expected: true + - input: { s: "10", target: "01" } + expected: true + - input: { s: "0000", target: "0000" } + expected: true + - input: { s: "1111", target: "0001" } + expected: true + - input: { s: "0001", target: "1110" } + expected: true + description: | You are given two **0-indexed binary** strings `s` and `target` of the same length `n`. You can do the following operation on `s` **any** number of times: diff --git a/backend/data/questions/apply-operations-to-an-array.yaml b/backend/data/questions/apply-operations-to-an-array.yaml index e69400d..0cb5f33 100644 --- a/backend/data/questions/apply-operations-to-an-array.yaml +++ b/backend/data/questions/apply-operations-to-an-array.yaml @@ -9,6 +9,26 @@ categories: patterns: - two-pointers +function_signature: "def apply_operations(nums: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { nums: [1, 2, 2, 1, 1, 0] } + expected: [1, 4, 2, 0, 0, 0] + - input: { nums: [0, 1] } + expected: [1, 0] + hidden: + - input: { nums: [1, 1] } + expected: [2, 0] + - input: { nums: [2, 2, 2] } + expected: [4, 2, 0] + - input: { nums: [0, 0, 0] } + expected: [0, 0, 0] + - input: { nums: [1, 2, 3, 4] } + expected: [1, 2, 3, 4] + - input: { nums: [1, 1, 1, 1] } + expected: [2, 2, 0, 0] + description: | You are given a **0-indexed** array `nums` of size `n` consisting of **non-negative** integers. diff --git a/backend/data/questions/arithmetic-slices-ii-subsequence.yaml b/backend/data/questions/arithmetic-slices-ii-subsequence.yaml index c859796..4f42a50 100644 --- a/backend/data/questions/arithmetic-slices-ii-subsequence.yaml +++ b/backend/data/questions/arithmetic-slices-ii-subsequence.yaml @@ -10,6 +10,30 @@ categories: patterns: - dynamic-programming +function_signature: "def number_of_arithmetic_slices(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [2, 4, 6, 8, 10] } + expected: 7 + - input: { nums: [7, 7, 7, 7, 7] } + expected: 16 + hidden: + - input: { nums: [1] } + expected: 0 + - input: { nums: [1, 2] } + expected: 0 + - input: { nums: [1, 2, 3] } + expected: 1 + - input: { nums: [1, 3, 5, 7] } + expected: 3 + - input: { nums: [0, 0, 0, 0] } + expected: 5 + - input: { nums: [1, 1, 1, 1, 1, 1] } + expected: 42 + - input: { nums: [1, 2, 3, 4, 5, 6] } + expected: 12 + description: | Given an integer array `nums`, return *the number of all the **arithmetic subsequences** of* `nums`. diff --git a/backend/data/questions/arithmetic-slices.yaml b/backend/data/questions/arithmetic-slices.yaml index 1802e75..23ce000 100644 --- a/backend/data/questions/arithmetic-slices.yaml +++ b/backend/data/questions/arithmetic-slices.yaml @@ -9,6 +9,26 @@ categories: patterns: - dynamic-programming +function_signature: "def number_of_arithmetic_slices(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [1, 2, 3, 4] } + expected: 3 + - input: { nums: [1] } + expected: 0 + hidden: + - input: { nums: [1, 2] } + expected: 0 + - input: { nums: [1, 2, 3] } + expected: 1 + - input: { nums: [1, 2, 3, 4, 5] } + expected: 6 + - input: { nums: [7, 7, 7, 7] } + expected: 3 + - input: { nums: [1, 2, 3, 5, 7] } + expected: 1 + description: | An integer array is called *arithmetic* if it consists of **at least three elements** and if the difference between any two consecutive elements is the same. diff --git a/backend/data/questions/arithmetic-subarrays.yaml b/backend/data/questions/arithmetic-subarrays.yaml index 870b73a..4b1d252 100644 --- a/backend/data/questions/arithmetic-subarrays.yaml +++ b/backend/data/questions/arithmetic-subarrays.yaml @@ -10,6 +10,30 @@ categories: patterns: - two-pointers +function_signature: "def check_arithmetic_subarrays(nums: list[int], l: list[int], r: list[int]) -> list[bool]:" + +test_cases: + visible: + - input: { nums: [4, 6, 5, 9, 3, 7], l: [0, 0, 2], r: [2, 3, 5] } + expected: [true, false, true] + - input: { nums: [-12, -9, -3, -12, -6, 15, 20, -25, -20, -15, -10], l: [0, 1, 6, 4, 8, 7], r: [4, 4, 9, 7, 9, 10] } + expected: [false, true, false, false, true, true] + hidden: + - input: { nums: [1, 2, 3], l: [0], r: [2] } + expected: [true] + - input: { nums: [7, 7, 7, 7], l: [0], r: [3] } + expected: [true] + - input: { nums: [1, 2, 4], l: [0], r: [2] } + expected: [false] + - input: { nums: [5, 3], l: [0], r: [1] } + expected: [true] + - input: { nums: [1, 3, 3, 5], l: [0], r: [3] } + expected: [false] + - input: { nums: [10, 20, 30, 40, 50], l: [0, 1, 2], r: [4, 3, 4] } + expected: [true, true, true] + - input: { nums: [100, -100], l: [0], r: [1] } + expected: [true] + description: | A sequence of numbers is called **arithmetic** if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence `s` is arithmetic if and only if `s[i+1] - s[i] == s[1] - s[0]` for all valid `i`. diff --git a/backend/data/questions/arranging-coins.yaml b/backend/data/questions/arranging-coins.yaml index 08db0be..9595c87 100644 --- a/backend/data/questions/arranging-coins.yaml +++ b/backend/data/questions/arranging-coins.yaml @@ -9,6 +9,26 @@ categories: patterns: - binary-search +function_signature: "def arrange_coins(n: int) -> int:" + +test_cases: + visible: + - input: { n: 5 } + expected: 2 + - input: { n: 8 } + expected: 3 + hidden: + - input: { n: 1 } + expected: 1 + - input: { n: 3 } + expected: 2 + - input: { n: 6 } + expected: 3 + - input: { n: 10 } + expected: 4 + - input: { n: 100 } + expected: 13 + description: | You have `n` coins and you want to build a staircase with these coins. The staircase consists of `k` rows where the ith row has exactly `i` coins. The last row of the staircase **may be** incomplete. diff --git a/backend/data/questions/array-nesting.yaml b/backend/data/questions/array-nesting.yaml index 4792c98..fa8fa93 100644 --- a/backend/data/questions/array-nesting.yaml +++ b/backend/data/questions/array-nesting.yaml @@ -8,6 +8,26 @@ categories: patterns: - dfs +function_signature: "def array_nesting(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [5, 4, 0, 3, 1, 6, 2] } + expected: 4 + - input: { nums: [0, 1, 2] } + expected: 1 + hidden: + - input: { nums: [0] } + expected: 1 + - input: { nums: [1, 0] } + expected: 2 + - input: { nums: [0, 2, 1] } + expected: 2 + - input: { nums: [2, 0, 1] } + expected: 3 + - input: { nums: [1, 2, 3, 0] } + expected: 4 + description: | You are given an integer array `nums` of length `n` where `nums` is a permutation of the numbers in the range `[0, n - 1]`. diff --git a/backend/data/questions/array-of-doubled-pairs.yaml b/backend/data/questions/array-of-doubled-pairs.yaml index 691df7a..fbf1092 100644 --- a/backend/data/questions/array-of-doubled-pairs.yaml +++ b/backend/data/questions/array-of-doubled-pairs.yaml @@ -10,6 +10,32 @@ categories: patterns: - greedy +function_signature: "def can_reorder_doubled(arr: list[int]) -> bool:" + +test_cases: + visible: + - input: { arr: [3, 1, 3, 6] } + expected: false + - input: { arr: [2, 1, 2, 6] } + expected: false + - input: { arr: [4, -2, 2, -4] } + expected: true + hidden: + - input: { arr: [1, 2, 4, 8] } + expected: true + - input: { arr: [0, 0] } + expected: true + - input: { arr: [0, 0, 0, 0] } + expected: true + - input: { arr: [-2, -4] } + expected: true + - input: { arr: [-1, -2, -4, -8] } + expected: true + - input: { arr: [1, 2, 1, 2] } + expected: true + - input: { arr: [1, 3] } + expected: false + description: | Given an integer array of even length `arr`, return `true` *if it is possible to reorder* `arr` *such that* `arr[2 * i + 1] = 2 * arr[2 * i]` *for every* `0 <= i < len(arr) / 2`, *or* `false` *otherwise*. diff --git a/backend/data/questions/array-partition.yaml b/backend/data/questions/array-partition.yaml index 2c6cd09..86110e8 100644 --- a/backend/data/questions/array-partition.yaml +++ b/backend/data/questions/array-partition.yaml @@ -9,6 +9,26 @@ categories: patterns: - greedy +function_signature: "def array_pair_sum(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [1, 4, 3, 2] } + expected: 4 + - input: { nums: [6, 2, 6, 5, 1, 2] } + expected: 9 + hidden: + - input: { nums: [1, 2] } + expected: 1 + - input: { nums: [1, 1, 1, 1] } + expected: 2 + - input: { nums: [-1, -2, -3, -4] } + expected: -6 + - input: { nums: [-5, 5, -3, 3] } + expected: -2 + - input: { nums: [1, 2, 3, 4, 5, 6] } + expected: 9 + description: | Given an integer array `nums` of `2n` integers, group these integers into `n` pairs `(a1, b1), (a2, b2), ..., (an, bn)` such that the sum of `min(ai, bi)` for all `i` is **maximised**. diff --git a/backend/data/questions/array-with-elements-not-equal-to-average-of-neighbors.yaml b/backend/data/questions/array-with-elements-not-equal-to-average-of-neighbors.yaml index ab23645..590534d 100644 --- a/backend/data/questions/array-with-elements-not-equal-to-average-of-neighbors.yaml +++ b/backend/data/questions/array-with-elements-not-equal-to-average-of-neighbors.yaml @@ -9,6 +9,26 @@ categories: patterns: - greedy +function_signature: "def rearrange_array(nums: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { nums: [1, 2, 3, 4, 5] } + expected: [1, 2, 4, 5, 3] + - input: { nums: [6, 2, 0, 9, 7] } + expected: [9, 7, 6, 2, 0] + hidden: + - input: { nums: [1, 2, 3] } + expected: [1, 3, 2] + - input: { nums: [10, 20, 30, 40] } + expected: [10, 30, 20, 40] + - input: { nums: [5, 10, 15, 20, 25, 30] } + expected: [5, 15, 10, 25, 20, 30] + - input: { nums: [100, 200, 300] } + expected: [100, 300, 200] + - input: { nums: [1, 3, 5, 7, 9, 11, 13] } + expected: [1, 5, 3, 9, 7, 13, 11] + description: | You are given a **0-indexed** array `nums` of **distinct** integers. You want to rearrange the elements in the array such that every element in the rearranged array is **not** equal to the **average** of its neighbors. diff --git a/backend/data/questions/as-far-from-land-as-possible.yaml b/backend/data/questions/as-far-from-land-as-possible.yaml index fb8bc5c..d6fdc61 100644 --- a/backend/data/questions/as-far-from-land-as-possible.yaml +++ b/backend/data/questions/as-far-from-land-as-possible.yaml @@ -10,6 +10,26 @@ patterns: - bfs - matrix-traversal +function_signature: "def max_distance(grid: list[list[int]]) -> int:" + +test_cases: + visible: + - input: { grid: [[1, 0, 1], [0, 0, 0], [1, 0, 1]] } + expected: 2 + - input: { grid: [[1, 0, 0], [0, 0, 0], [0, 0, 0]] } + expected: 4 + hidden: + - input: { grid: [[1, 1, 1], [1, 1, 1], [1, 1, 1]] } + expected: -1 + - input: { grid: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] } + expected: -1 + - input: { grid: [[1, 0], [0, 0]] } + expected: 2 + - input: { grid: [[0, 0, 0], [0, 1, 0], [0, 0, 0]] } + expected: 2 + - input: { grid: [[1, 1], [1, 0]] } + expected: 1 + description: | Given an `n x n` `grid` containing only values `0` and `1`, where `0` represents water and `1` represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. diff --git a/backend/data/questions/assign-cookies.yaml b/backend/data/questions/assign-cookies.yaml index 9f054ed..bf66f80 100644 --- a/backend/data/questions/assign-cookies.yaml +++ b/backend/data/questions/assign-cookies.yaml @@ -11,6 +11,28 @@ patterns: - greedy - two-pointers +function_signature: "def find_content_children(g: list[int], s: list[int]) -> int:" + +test_cases: + visible: + - input: { g: [1, 2, 3], s: [1, 1] } + expected: 1 + - input: { g: [1, 2], s: [1, 2, 3] } + expected: 2 + hidden: + - input: { g: [1, 2, 3], s: [] } + expected: 0 + - input: { g: [10, 9, 8, 7], s: [5, 6, 7, 8] } + expected: 2 + - input: { g: [1, 1, 1, 1], s: [1, 1, 1, 1] } + expected: 4 + - input: { g: [1], s: [1] } + expected: 1 + - input: { g: [5], s: [4] } + expected: 0 + - input: { g: [2, 3, 4], s: [1, 2, 3, 4, 5] } + expected: 3 + description: | Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. diff --git a/backend/data/questions/available-captures-for-rook.yaml b/backend/data/questions/available-captures-for-rook.yaml index ebc5192..761489e 100644 --- a/backend/data/questions/available-captures-for-rook.yaml +++ b/backend/data/questions/available-captures-for-rook.yaml @@ -8,6 +8,28 @@ categories: patterns: - matrix-traversal +function_signature: "def num_rook_captures(board: list[list[str]]) -> int:" + +test_cases: + visible: + - input: { board: [[".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", "p", ".", ".", ".", "."], [".", ".", ".", "R", ".", ".", ".", "p"], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", "p", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."]] } + expected: 3 + - input: { board: [[".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", "R", ".", ".", "."]] } + expected: 0 + - input: { board: [[".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", "p", ".", ".", ".", "."], [".", ".", ".", "p", ".", ".", ".", "."], ["p", "p", ".", "R", ".", "p", "B", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", "B", ".", ".", ".", "."], [".", ".", ".", "p", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."]] } + expected: 3 + hidden: + - input: { board: [["R", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."]] } + expected: 0 + - input: { board: [["p", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], ["R", ".", ".", ".", ".", ".", ".", "p"], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."]] } + expected: 2 + - input: { board: [[".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", "B", ".", "R", ".", "B", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."]] } + expected: 0 + - input: { board: [[".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], ["p", ".", ".", "R", ".", ".", ".", "p"], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."]] } + expected: 2 + - input: { board: [[".", ".", ".", "p", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", "R", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", "p", ".", ".", ".", "."]] } + expected: 2 + description: | You are given an `8 x 8` **matrix** representing a chessboard. There is **exactly one** white rook represented by `'R'`, some number of white bishops `'B'`, and some number of black pawns `'p'`. Empty squares are represented by `'.'`. diff --git a/backend/data/questions/average-of-levels-in-binary-tree.yaml b/backend/data/questions/average-of-levels-in-binary-tree.yaml index b51e562..1136a99 100644 --- a/backend/data/questions/average-of-levels-in-binary-tree.yaml +++ b/backend/data/questions/average-of-levels-in-binary-tree.yaml @@ -10,6 +10,24 @@ patterns: - bfs - tree-traversal +function_signature: "def average_of_levels(root: TreeNode) -> list[float]:" + +test_cases: + visible: + - input: { root: [3, 9, 20, null, null, 15, 7] } + expected: [3.0, 14.5, 11.0] + - input: { root: [3, 9, 20, 15, 7] } + expected: [3.0, 14.5, 11.0] + hidden: + - input: { root: [1] } + expected: [1.0] + - input: { root: [1, 2, 3, 4, 5, 6, 7] } + expected: [1.0, 2.5, 5.5] + - input: { root: [1, 2, null, 3, null, 4] } + expected: [1.0, 2.0, 3.0, 4.0] + - input: { root: [0, -1, 1] } + expected: [0.0, 0.0] + description: | Given the `root` of a binary tree, return *the average value of the nodes on each level in the form of an array*. diff --git a/backend/data/questions/average-salary-excluding-minimum-and-maximum.yaml b/backend/data/questions/average-salary-excluding-minimum-and-maximum.yaml index 76e0e92..b882fda 100644 --- a/backend/data/questions/average-salary-excluding-minimum-and-maximum.yaml +++ b/backend/data/questions/average-salary-excluding-minimum-and-maximum.yaml @@ -9,6 +9,26 @@ categories: patterns: - greedy +function_signature: "def average(salary: list[int]) -> float:" + +test_cases: + visible: + - input: { salary: [4000, 3000, 1000, 2000] } + expected: 2500.0 + - input: { salary: [1000, 2000, 3000] } + expected: 2000.0 + hidden: + - input: { salary: [6000, 5000, 4000, 3000, 2000, 1000] } + expected: 3500.0 + - input: { salary: [8000, 9000, 2000, 3000, 6000, 1000] } + expected: 4750.0 + - input: { salary: [48000, 59000, 99000, 13000, 78000, 45000, 31000, 17000, 39000, 37000, 93000, 77000, 33000, 28000, 4000, 54000, 67000, 6000, 1000, 11000] } + expected: 41111.11111111111 + - input: { salary: [1000, 1001, 1002] } + expected: 1001.0 + - input: { salary: [100000, 200000, 300000] } + expected: 200000.0 + description: | You are given an array of **unique** integers `salary` where `salary[i]` is the salary of the ith employee. diff --git a/backend/data/questions/average-value-of-even-numbers-divisible-by-three.yaml b/backend/data/questions/average-value-of-even-numbers-divisible-by-three.yaml index c192757..c81bb44 100644 --- a/backend/data/questions/average-value-of-even-numbers-divisible-by-three.yaml +++ b/backend/data/questions/average-value-of-even-numbers-divisible-by-three.yaml @@ -9,6 +9,30 @@ categories: patterns: - prefix-sum +function_signature: "def average_value(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [1, 3, 6, 10, 12, 15] } + expected: 9 + - input: { nums: [1, 2, 4, 7, 10] } + expected: 0 + hidden: + - input: { nums: [6] } + expected: 6 + - input: { nums: [6, 12, 18] } + expected: 12 + - input: { nums: [1, 2, 3, 4, 5] } + expected: 0 + - input: { nums: [6, 6, 6, 6] } + expected: 6 + - input: { nums: [12, 24, 36, 48, 60] } + expected: 36 + - input: { nums: [5, 7, 11, 13, 17, 19] } + expected: 0 + - input: { nums: [6, 12, 1, 2, 3, 18] } + expected: 12 + description: | Given an integer array `nums` of **positive** integers, return *the average value of all even integers that are divisible by* `3`. diff --git a/backend/data/questions/average-waiting-time.yaml b/backend/data/questions/average-waiting-time.yaml index fb04062..dad8f46 100644 --- a/backend/data/questions/average-waiting-time.yaml +++ b/backend/data/questions/average-waiting-time.yaml @@ -8,6 +8,26 @@ categories: patterns: - greedy +function_signature: "def average_waiting_time(customers: list[list[int]]) -> float:" + +test_cases: + visible: + - input: { customers: [[1, 2], [2, 5], [4, 3]] } + expected: 5.0 + - input: { customers: [[5, 2], [5, 4], [10, 3], [20, 1]] } + expected: 3.25 + hidden: + - input: { customers: [[1, 1]] } + expected: 1.0 + - input: { customers: [[1, 5], [2, 3], [3, 2]] } + expected: 5.0 + - input: { customers: [[1, 1], [2, 1], [3, 1]] } + expected: 1.0 + - input: { customers: [[1, 10], [1, 10], [1, 10]] } + expected: 20.0 + - input: { customers: [[10, 5], [20, 5], [30, 5]] } + expected: 5.0 + description: | There is a restaurant with a single chef. You are given an array `customers`, where `customers[i] = [arrival_i, time_i]`: diff --git a/backend/data/questions/avoid-flood-in-the-city.yaml b/backend/data/questions/avoid-flood-in-the-city.yaml index dd2db6a..4432b00 100644 --- a/backend/data/questions/avoid-flood-in-the-city.yaml +++ b/backend/data/questions/avoid-flood-in-the-city.yaml @@ -10,6 +10,28 @@ patterns: - greedy - binary-search +function_signature: "def avoid_flood(rains: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { rains: [1, 2, 3, 4] } + expected: [-1, -1, -1, -1] + - input: { rains: [1, 2, 0, 0, 2, 1] } + expected: [-1, -1, 2, 1, -1, -1] + - input: { rains: [1, 2, 0, 1, 2] } + expected: [] + hidden: + - input: { rains: [1, 0, 1] } + expected: [-1, 1, -1] + - input: { rains: [0, 1, 1] } + expected: [] + - input: { rains: [1, 1] } + expected: [] + - input: { rains: [0] } + expected: [1] + - input: { rains: [1] } + expected: [-1] + description: | Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the nth lake, that lake becomes full of water. If it rains over a lake that is **full of water**, there will be a **flood**. diff --git a/backend/data/questions/bag-of-tokens.yaml b/backend/data/questions/bag-of-tokens.yaml index 37875a5..327227e 100644 --- a/backend/data/questions/bag-of-tokens.yaml +++ b/backend/data/questions/bag-of-tokens.yaml @@ -11,6 +11,28 @@ patterns: - two-pointers - greedy +function_signature: "def bag_of_tokens_score(tokens: list[int], power: int) -> int:" + +test_cases: + visible: + - input: { tokens: [100], power: 50 } + expected: 0 + - input: { tokens: [200, 100], power: 150 } + expected: 1 + - input: { tokens: [100, 200, 300, 400], power: 200 } + expected: 2 + hidden: + - input: { tokens: [], power: 100 } + expected: 0 + - input: { tokens: [100], power: 100 } + expected: 1 + - input: { tokens: [100, 100, 100], power: 200 } + expected: 2 + - input: { tokens: [71, 55, 82], power: 54 } + expected: 0 + - input: { tokens: [26, 33, 59], power: 45 } + expected: 1 + description: | You start with an initial **power** of `power`, an initial **score** of `0`, and a bag of tokens given as an integer array `tokens`, where each `tokens[i]` denotes the value of the ith token. diff --git a/backend/data/questions/balance-a-binary-search-tree.yaml b/backend/data/questions/balance-a-binary-search-tree.yaml index d5712af..b7791ab 100644 --- a/backend/data/questions/balance-a-binary-search-tree.yaml +++ b/backend/data/questions/balance-a-binary-search-tree.yaml @@ -9,6 +9,26 @@ patterns: - tree-traversal - dfs +function_signature: "def balance_bst(root: TreeNode) -> TreeNode:" + +test_cases: + visible: + - input: { root: [1, null, 2, null, 3, null, 4] } + expected: [2, 1, 3, null, null, null, 4] + - input: { root: [2, 1, 3] } + expected: [2, 1, 3] + hidden: + - input: { root: [1] } + expected: [1] + - input: { root: [1, null, 2] } + expected: [1, null, 2] + - input: { root: [3, 2, null, 1] } + expected: [2, 1, 3] + - input: { root: [1, null, 2, null, 3, null, 4, null, 5] } + expected: [3, 1, 4, null, 2, null, 5] + - input: { root: [5, 4, null, 3, null, 2, null, 1] } + expected: [3, 1, 4, null, 2, null, 5] + description: | Given the `root` of a binary search tree, return *a **balanced** binary search tree with the same node values*. If there is more than one answer, return **any of them**. diff --git a/backend/data/questions/balanced-binary-tree.yaml b/backend/data/questions/balanced-binary-tree.yaml index 06bac0d..4dc1fb6 100644 --- a/backend/data/questions/balanced-binary-tree.yaml +++ b/backend/data/questions/balanced-binary-tree.yaml @@ -10,6 +10,28 @@ patterns: - dfs - tree-traversal +function_signature: "def is_balanced(root: TreeNode) -> bool:" + +test_cases: + visible: + - input: { root: [3, 9, 20, null, null, 15, 7] } + expected: true + - input: { root: [1, 2, 2, 3, 3, null, null, 4, 4] } + expected: false + - input: { root: [] } + expected: true + hidden: + - input: { root: [1] } + expected: true + - input: { root: [1, 2, null, 3] } + expected: false + - input: { root: [1, null, 2, null, 3] } + expected: false + - input: { root: [1, 2, 3, 4, 5, 6, 7] } + expected: true + - input: { root: [1, 2, 2, 3, null, null, 3, 4, null, null, 4] } + expected: false + description: | Given a binary tree, determine if it is **height-balanced**. diff --git a/backend/data/questions/base-7.yaml b/backend/data/questions/base-7.yaml index 3689ea7..0f1480e 100644 --- a/backend/data/questions/base-7.yaml +++ b/backend/data/questions/base-7.yaml @@ -9,6 +9,28 @@ categories: patterns: - greedy +function_signature: "def convert_to_base7(num: int) -> str:" + +test_cases: + visible: + - input: { num: 100 } + expected: "202" + - input: { num: -7 } + expected: "-10" + hidden: + - input: { num: 0 } + expected: "0" + - input: { num: 7 } + expected: "10" + - input: { num: 1 } + expected: "1" + - input: { num: -1 } + expected: "-1" + - input: { num: 49 } + expected: "100" + - input: { num: -100 } + expected: "-202" + description: | Given an integer `num`, return *a string of its **base 7** representation*. diff --git a/backend/data/questions/baseball-game.yaml b/backend/data/questions/baseball-game.yaml index d5e4989..c6c545a 100644 --- a/backend/data/questions/baseball-game.yaml +++ b/backend/data/questions/baseball-game.yaml @@ -9,6 +9,28 @@ categories: patterns: - monotonic-stack +function_signature: "def cal_points(operations: list[str]) -> int:" + +test_cases: + visible: + - input: { operations: ["5", "2", "C", "D", "+"] } + expected: 30 + - input: { operations: ["5", "-2", "4", "C", "D", "9", "+", "+"] } + expected: 27 + - input: { operations: ["1", "C"] } + expected: 0 + hidden: + - input: { operations: ["1"] } + expected: 1 + - input: { operations: ["5", "10", "+"] } + expected: 30 + - input: { operations: ["3", "D", "D", "D"] } + expected: 45 + - input: { operations: ["-5", "10", "+", "D"] } + expected: 20 + - input: { operations: ["1", "2", "3", "4", "5"] } + expected: 15 + description: | You are keeping the scores for a baseball game with strange rules. At the beginning of the game, you start with an empty record. diff --git a/backend/data/questions/basic-calculator-iv.yaml b/backend/data/questions/basic-calculator-iv.yaml index 500ba1f..5b3be44 100644 --- a/backend/data/questions/basic-calculator-iv.yaml +++ b/backend/data/questions/basic-calculator-iv.yaml @@ -12,6 +12,30 @@ categories: patterns: - backtracking +function_signature: "def basic_calculator_iv(expression: str, evalvars: list[str], evalints: list[int]) -> list[str]:" + +test_cases: + visible: + - input: { expression: "e + 8 - a + 5", evalvars: ["e"], evalints: [1] } + expected: ["-1*a", "14"] + - input: { expression: "e - 8 + temperature - pressure", evalvars: ["e", "temperature"], evalints: [1, 12] } + expected: ["-1*pressure", "5"] + - input: { expression: "(e + 8) * (e - 8)", evalvars: [], evalints: [] } + expected: ["1*e*e", "-64"] + hidden: + - input: { expression: "0", evalvars: [], evalints: [] } + expected: [] + - input: { expression: "a * b", evalvars: [], evalints: [] } + expected: ["1*a*b"] + - input: { expression: "a * b * c", evalvars: ["a"], evalints: [2] } + expected: ["2*b*c"] + - input: { expression: "(a + b) * (a - b)", evalvars: [], evalints: [] } + expected: ["1*a*a", "-1*b*b"] + - input: { expression: "a + b + c", evalvars: ["a", "b", "c"], evalints: [1, 2, 3] } + expected: ["6"] + - input: { expression: "a * a * a - a * a + a - 1", evalvars: [], evalints: [] } + expected: ["1*a*a*a", "-1*a*a", "1*a", "-1"] + description: | Given an expression such as `expression = "e + 8 - a + 5"` and an evaluation map such as `{"e": 1}` (given in terms of `evalvars = ["e"]` and `evalints = [1]`), return a list of tokens representing the **simplified expression**, such as `["-1*a","14"]`. diff --git a/backend/data/questions/basic-calculator.yaml b/backend/data/questions/basic-calculator.yaml index bb2770b..79886cb 100644 --- a/backend/data/questions/basic-calculator.yaml +++ b/backend/data/questions/basic-calculator.yaml @@ -10,6 +10,30 @@ categories: patterns: - monotonic-stack +function_signature: "def calculate(s: str) -> int:" + +test_cases: + visible: + - input: { s: "1 + 1" } + expected: 2 + - input: { s: " 2-1 + 2 " } + expected: 3 + - input: { s: "(1+(4+5+2)-3)+(6+8)" } + expected: 23 + hidden: + - input: { s: "1" } + expected: 1 + - input: { s: "-1" } + expected: -1 + - input: { s: "-(3+2)" } + expected: -5 + - input: { s: "1-(5)" } + expected: -4 + - input: { s: "2147483647" } + expected: 2147483647 + - input: { s: "1-(-2)" } + expected: 3 + description: | Given a string `s` representing a valid expression, implement a basic calculator to evaluate it, and return *the result of the evaluation*. diff --git a/backend/data/questions/battleships-in-a-board.yaml b/backend/data/questions/battleships-in-a-board.yaml index 88a8d14..309f851 100644 --- a/backend/data/questions/battleships-in-a-board.yaml +++ b/backend/data/questions/battleships-in-a-board.yaml @@ -9,6 +9,26 @@ categories: patterns: - matrix-traversal +function_signature: "def count_battleships(board: list[list[str]]) -> int:" + +test_cases: + visible: + - input: { board: [["X", ".", ".", "X"], [".", ".", ".", "X"], [".", ".", ".", "X"]] } + expected: 2 + - input: { board: [["."]] } + expected: 0 + hidden: + - input: { board: [["X"]] } + expected: 1 + - input: { board: [["X", "X", "X"]] } + expected: 1 + - input: { board: [["X"], ["X"], ["X"]] } + expected: 1 + - input: { board: [["X", ".", "X"], [".", ".", "."], ["X", ".", "X"]] } + expected: 4 + - input: { board: [[".", ".", "."], [".", ".", "."], [".", ".", "."]] } + expected: 0 + description: | Given an `m x n` matrix `board` where each cell is a battleship `'X'` or empty `'.'`, return *the number of **battleships** on the board*. diff --git a/backend/data/questions/beautiful-arrangement-ii.yaml b/backend/data/questions/beautiful-arrangement-ii.yaml index 5023bbb..331d51a 100644 --- a/backend/data/questions/beautiful-arrangement-ii.yaml +++ b/backend/data/questions/beautiful-arrangement-ii.yaml @@ -9,6 +9,28 @@ categories: patterns: - greedy +function_signature: "def construct_array(n: int, k: int) -> list[int]:" + +test_cases: + visible: + - input: { n: 3, k: 1 } + expected: [1, 2, 3] + - input: { n: 3, k: 2 } + expected: [1, 3, 2] + hidden: + - input: { n: 2, k: 1 } + expected: [1, 2] + - input: { n: 5, k: 1 } + expected: [1, 2, 3, 4, 5] + - input: { n: 5, k: 4 } + expected: [1, 5, 2, 4, 3] + - input: { n: 6, k: 3 } + expected: [1, 4, 2, 3, 5, 6] + - input: { n: 10, k: 5 } + expected: [1, 6, 2, 5, 3, 4, 7, 8, 9, 10] + - input: { n: 4, k: 3 } + expected: [1, 4, 2, 3] + description: | Given two integers `n` and `k`, construct a list `answer` that contains `n` different positive integers ranging from `1` to `n` and obeys the following requirement: diff --git a/backend/data/questions/beautiful-arrangement.yaml b/backend/data/questions/beautiful-arrangement.yaml index b040315..64dca76 100644 --- a/backend/data/questions/beautiful-arrangement.yaml +++ b/backend/data/questions/beautiful-arrangement.yaml @@ -9,6 +9,26 @@ categories: patterns: - backtracking +function_signature: "def count_arrangement(n: int) -> int:" + +test_cases: + visible: + - input: { n: 2 } + expected: 2 + - input: { n: 1 } + expected: 1 + hidden: + - input: { n: 3 } + expected: 3 + - input: { n: 4 } + expected: 8 + - input: { n: 5 } + expected: 10 + - input: { n: 6 } + expected: 36 + - input: { n: 10 } + expected: 700 + description: | Suppose you have `n` integers labelled `1` through `n`. A permutation of those `n` integers `perm` (**1-indexed**) is considered a **beautiful arrangement** if for every `i` (`1 <= i <= n`), **either** of the following is true: diff --git a/backend/data/questions/beautiful-array.yaml b/backend/data/questions/beautiful-array.yaml index d269fc5..7b41963 100644 --- a/backend/data/questions/beautiful-array.yaml +++ b/backend/data/questions/beautiful-array.yaml @@ -9,6 +9,28 @@ categories: patterns: - dynamic-programming +function_signature: "def beautiful_array(n: int) -> list[int]:" + +test_cases: + visible: + - input: { n: 4 } + expected: [2, 1, 4, 3] + - input: { n: 5 } + expected: [3, 1, 2, 5, 4] + hidden: + - input: { n: 1 } + expected: [1] + - input: { n: 2 } + expected: [1, 2] + - input: { n: 3 } + expected: [1, 3, 2] + - input: { n: 6 } + expected: [3, 1, 2, 5, 6, 4] + - input: { n: 10 } + expected: [5, 3, 1, 7, 9, 6, 2, 4, 10, 8] + - input: { n: 8 } + expected: [5, 3, 1, 7, 6, 2, 4, 8] + description: | An array `nums` of length `n` is **beautiful** if: diff --git a/backend/data/questions/best-poker-hand.yaml b/backend/data/questions/best-poker-hand.yaml index 7901e0c..ecc0c13 100644 --- a/backend/data/questions/best-poker-hand.yaml +++ b/backend/data/questions/best-poker-hand.yaml @@ -9,6 +9,30 @@ categories: patterns: - greedy +function_signature: "def best_hand(ranks: list[int], suits: list[str]) -> str:" + +test_cases: + visible: + - input: { ranks: [13, 2, 3, 1, 9], suits: ["a", "a", "a", "a", "a"] } + expected: "Flush" + - input: { ranks: [4, 4, 2, 4, 4], suits: ["d", "a", "a", "b", "c"] } + expected: "Three of a Kind" + - input: { ranks: [10, 10, 2, 12, 9], suits: ["a", "b", "c", "a", "d"] } + expected: "Pair" + hidden: + - input: { ranks: [1, 2, 3, 4, 5], suits: ["a", "b", "c", "d", "a"] } + expected: "High Card" + - input: { ranks: [3, 3, 3, 3, 5], suits: ["a", "b", "c", "d", "a"] } + expected: "Three of a Kind" + - input: { ranks: [1, 1, 2, 2, 3], suits: ["a", "b", "c", "d", "a"] } + expected: "Pair" + - input: { ranks: [7, 7, 7, 7, 7], suits: ["a", "a", "a", "a", "a"] } + expected: "Flush" + - input: { ranks: [13, 13, 13, 1, 1], suits: ["b", "c", "d", "a", "b"] } + expected: "Three of a Kind" + - input: { ranks: [2, 4, 6, 8, 10], suits: ["d", "d", "d", "d", "d"] } + expected: "Flush" + description: | You are given an integer array `ranks` and a character array `suits`. You have `5` cards where the ith card has a rank of `ranks[i]` and a suit of `suits[i]`. diff --git a/backend/data/questions/best-position-for-a-service-centre.yaml b/backend/data/questions/best-position-for-a-service-centre.yaml index 640a033..759c5fb 100644 --- a/backend/data/questions/best-position-for-a-service-centre.yaml +++ b/backend/data/questions/best-position-for-a-service-centre.yaml @@ -9,6 +9,28 @@ categories: patterns: - greedy +function_signature: "def get_min_dist_sum(positions: list[list[int]]) -> float:" + +test_cases: + visible: + - input: { positions: [[0, 1], [1, 0], [1, 2], [2, 1]] } + expected: 4.00000 + - input: { positions: [[1, 1], [3, 3]] } + expected: 2.82843 + hidden: + - input: { positions: [[0, 0]] } + expected: 0.00000 + - input: { positions: [[0, 0], [2, 0]] } + expected: 2.00000 + - input: { positions: [[0, 0], [0, 1], [1, 0], [1, 1]] } + expected: 2.82843 + - input: { positions: [[1, 1], [1, 1], [1, 1]] } + expected: 0.00000 + - input: { positions: [[0, 0], [50, 50], [100, 100]] } + expected: 141.42136 + - input: { positions: [[1, 2], [3, 4], [5, 6], [7, 8]] } + expected: 11.31371 + description: | A delivery company wants to build a new service center in a new city. The company knows the positions of all the customers in this city on a 2D-Map and wants to build the new center in a position such that **the sum of the Euclidean distances to all customers is minimum**. diff --git a/backend/data/questions/best-sightseeing-pair.yaml b/backend/data/questions/best-sightseeing-pair.yaml index f3b5231..bb7a5a4 100644 --- a/backend/data/questions/best-sightseeing-pair.yaml +++ b/backend/data/questions/best-sightseeing-pair.yaml @@ -9,6 +9,26 @@ categories: patterns: - greedy +function_signature: "def max_score_sightseeing_pair(values: list[int]) -> int:" + +test_cases: + visible: + - input: { values: [8, 1, 5, 2, 6] } + expected: 11 + - input: { values: [1, 2] } + expected: 2 + hidden: + - input: { values: [1, 3, 5] } + expected: 7 + - input: { values: [1, 1, 1, 1] } + expected: 1 + - input: { values: [10, 1, 1, 1, 1, 1, 10] } + expected: 15 + - input: { values: [5, 4, 3, 2, 1] } + expected: 8 + - input: { values: [1, 2, 3, 4, 5] } + expected: 8 + description: | You are given an integer array `values` where `values[i]` represents the value of the ith sightseeing spot. Two sightseeing spots `i` and `j` have a **distance** `j - i` between them. diff --git a/backend/data/questions/best-team-with-no-conflicts.yaml b/backend/data/questions/best-team-with-no-conflicts.yaml index 479efc6..0f5d6ff 100644 --- a/backend/data/questions/best-team-with-no-conflicts.yaml +++ b/backend/data/questions/best-team-with-no-conflicts.yaml @@ -10,6 +10,30 @@ categories: patterns: - dynamic-programming +function_signature: "def best_team_score(scores: list[int], ages: list[int]) -> int:" + +test_cases: + visible: + - input: { scores: [1, 3, 5, 10, 15], ages: [1, 2, 3, 4, 5] } + expected: 34 + - input: { scores: [4, 5, 6, 5], ages: [2, 1, 2, 1] } + expected: 16 + - input: { scores: [1, 2, 3, 5], ages: [8, 9, 10, 1] } + expected: 6 + hidden: + - input: { scores: [1], ages: [1] } + expected: 1 + - input: { scores: [5, 5], ages: [3, 3] } + expected: 10 + - input: { scores: [1, 1, 1, 1, 1], ages: [5, 4, 3, 2, 1] } + expected: 5 + - input: { scores: [10, 20, 5], ages: [1, 2, 3] } + expected: 35 + - input: { scores: [319, 776], ages: [8, 3] } + expected: 776 + - input: { scores: [9, 2, 8, 8, 2], ages: [4, 1, 3, 3, 5] } + expected: 27 + description: | You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the **sum** of scores of all the players in the team. diff --git a/backend/data/questions/best-time-to-buy-and-sell-stock-ii.yaml b/backend/data/questions/best-time-to-buy-and-sell-stock-ii.yaml index 3bb718f..f3f43d5 100644 --- a/backend/data/questions/best-time-to-buy-and-sell-stock-ii.yaml +++ b/backend/data/questions/best-time-to-buy-and-sell-stock-ii.yaml @@ -9,6 +9,30 @@ categories: patterns: - greedy +function_signature: "def max_profit(prices: list[int]) -> int:" + +test_cases: + visible: + - input: { prices: [7, 1, 5, 3, 6, 4] } + expected: 7 + - input: { prices: [1, 2, 3, 4, 5] } + expected: 4 + - input: { prices: [7, 6, 4, 3, 1] } + expected: 0 + hidden: + - input: { prices: [1] } + expected: 0 + - input: { prices: [2, 1] } + expected: 0 + - input: { prices: [1, 2] } + expected: 1 + - input: { prices: [3, 3, 3, 3] } + expected: 0 + - input: { prices: [1, 2, 1, 2, 1, 2] } + expected: 3 + - input: { prices: [5, 1, 3, 2, 8, 4, 9] } + expected: 14 + description: | You are given an integer array `prices` where `prices[i]` is the price of a given stock on the ith day. diff --git a/backend/data/questions/best-time-to-buy-and-sell-stock-iii.yaml b/backend/data/questions/best-time-to-buy-and-sell-stock-iii.yaml index 6357f08..961c931 100644 --- a/backend/data/questions/best-time-to-buy-and-sell-stock-iii.yaml +++ b/backend/data/questions/best-time-to-buy-and-sell-stock-iii.yaml @@ -9,6 +9,30 @@ categories: patterns: - dynamic-programming +function_signature: "def max_profit(prices: list[int]) -> int:" + +test_cases: + visible: + - input: { prices: [3, 3, 5, 0, 0, 3, 1, 4] } + expected: 6 + - input: { prices: [1, 2, 3, 4, 5] } + expected: 4 + - input: { prices: [7, 6, 4, 3, 1] } + expected: 0 + hidden: + - input: { prices: [1] } + expected: 0 + - input: { prices: [1, 2] } + expected: 1 + - input: { prices: [2, 1, 2, 0, 1] } + expected: 2 + - input: { prices: [1, 2, 4, 2, 5, 7, 2, 4, 9, 0] } + expected: 13 + - input: { prices: [6, 1, 3, 2, 4, 7] } + expected: 7 + - input: { prices: [3, 3, 3, 3, 3] } + expected: 0 + description: | You are given an array `prices` where `prices[i]` is the price of a given stock on the ith day. diff --git a/backend/data/questions/best-time-to-buy-and-sell-stock-iv.yaml b/backend/data/questions/best-time-to-buy-and-sell-stock-iv.yaml index beaf922..0291a6a 100644 --- a/backend/data/questions/best-time-to-buy-and-sell-stock-iv.yaml +++ b/backend/data/questions/best-time-to-buy-and-sell-stock-iv.yaml @@ -9,6 +9,28 @@ categories: patterns: - dynamic-programming +function_signature: "def max_profit(k: int, prices: list[int]) -> int:" + +test_cases: + visible: + - input: { k: 2, prices: [2, 4, 1] } + expected: 2 + - input: { k: 2, prices: [3, 2, 6, 5, 0, 3] } + expected: 7 + hidden: + - input: { k: 1, prices: [1, 2, 3, 4, 5] } + expected: 4 + - input: { k: 0, prices: [1, 2, 3] } + expected: 0 + - input: { k: 2, prices: [1] } + expected: 0 + - input: { k: 100, prices: [1, 2, 3, 4, 5] } + expected: 4 + - input: { k: 2, prices: [5, 4, 3, 2, 1] } + expected: 0 + - input: { k: 3, prices: [1, 2, 4, 2, 5, 7, 2, 4, 9, 0] } + expected: 15 + description: | You are given an integer array `prices` where `prices[i]` is the price of a given stock on the ith day, and an integer `k`. diff --git a/backend/data/questions/best-time-to-buy-and-sell-stock-with-cooldown.yaml b/backend/data/questions/best-time-to-buy-and-sell-stock-with-cooldown.yaml index 2de3dfe..901e171 100644 --- a/backend/data/questions/best-time-to-buy-and-sell-stock-with-cooldown.yaml +++ b/backend/data/questions/best-time-to-buy-and-sell-stock-with-cooldown.yaml @@ -9,6 +9,28 @@ categories: patterns: - dynamic-programming +function_signature: "def max_profit(prices: list[int]) -> int:" + +test_cases: + visible: + - input: { prices: [1, 2, 3, 0, 2] } + expected: 3 + - input: { prices: [1] } + expected: 0 + hidden: + - input: { prices: [1, 2] } + expected: 1 + - input: { prices: [2, 1] } + expected: 0 + - input: { prices: [1, 2, 3, 4, 5] } + expected: 4 + - input: { prices: [1, 2, 4, 2, 5, 7, 2, 4, 9, 0] } + expected: 13 + - input: { prices: [6, 1, 6, 4, 3, 0, 2] } + expected: 7 + - input: { prices: [3, 3, 3, 3] } + expected: 0 + description: | You are given an array `prices` where `prices[i]` is the price of a given stock on the ith day. diff --git a/backend/data/questions/best-time-to-buy-and-sell-stock-with-transaction-fee.yaml b/backend/data/questions/best-time-to-buy-and-sell-stock-with-transaction-fee.yaml index 3dde5b6..b4f8ec5 100644 --- a/backend/data/questions/best-time-to-buy-and-sell-stock-with-transaction-fee.yaml +++ b/backend/data/questions/best-time-to-buy-and-sell-stock-with-transaction-fee.yaml @@ -10,6 +10,28 @@ patterns: - dynamic-programming - greedy +function_signature: "def max_profit(prices: list[int], fee: int) -> int:" + +test_cases: + visible: + - input: { prices: [1, 3, 2, 8, 4, 9], fee: 2 } + expected: 8 + - input: { prices: [1, 3, 7, 5, 10, 3], fee: 3 } + expected: 6 + hidden: + - input: { prices: [1], fee: 1 } + expected: 0 + - input: { prices: [1, 2], fee: 1 } + expected: 0 + - input: { prices: [1, 3], fee: 1 } + expected: 1 + - input: { prices: [1, 5, 2, 8], fee: 2 } + expected: 6 + - input: { prices: [2, 1, 4, 4, 2, 3, 2, 5, 1, 2], fee: 1 } + expected: 6 + - input: { prices: [4, 5, 2, 4, 3, 3, 1, 2, 5, 4], fee: 1 } + expected: 4 + description: | You are given an array `prices` where `prices[i]` is the price of a given stock on the ith day, and an integer `fee` representing a transaction fee. diff --git a/backend/data/questions/binary-gap.yaml b/backend/data/questions/binary-gap.yaml index a8d171f..e78956e 100644 --- a/backend/data/questions/binary-gap.yaml +++ b/backend/data/questions/binary-gap.yaml @@ -8,6 +8,30 @@ categories: patterns: - two-pointers +function_signature: "def binary_gap(n: int) -> int:" + +test_cases: + visible: + - input: { n: 22 } + expected: 2 + - input: { n: 8 } + expected: 0 + - input: { n: 5 } + expected: 2 + hidden: + - input: { n: 1 } + expected: 0 + - input: { n: 6 } + expected: 1 + - input: { n: 9 } + expected: 3 + - input: { n: 15 } + expected: 1 + - input: { n: 17 } + expected: 4 + - input: { n: 1073741824 } + expected: 0 + description: | Given a positive integer `n`, find and return *the **longest distance** between any two **adjacent*** `1`*'s in the binary representation of* `n`. If there are no two adjacent `1`'s, return `0`. diff --git a/backend/data/questions/binary-number-with-alternating-bits.yaml b/backend/data/questions/binary-number-with-alternating-bits.yaml index 5414126..63f2fba 100644 --- a/backend/data/questions/binary-number-with-alternating-bits.yaml +++ b/backend/data/questions/binary-number-with-alternating-bits.yaml @@ -8,6 +8,32 @@ categories: patterns: - greedy +function_signature: "def has_alternating_bits(n: int) -> bool:" + +test_cases: + visible: + - input: { n: 5 } + expected: true + - input: { n: 7 } + expected: false + - input: { n: 11 } + expected: false + hidden: + - input: { n: 1 } + expected: true + - input: { n: 2 } + expected: true + - input: { n: 10 } + expected: true + - input: { n: 21 } + expected: true + - input: { n: 15 } + expected: false + - input: { n: 1431655765 } + expected: true + - input: { n: 4 } + expected: false + description: | Given a positive integer `n`, check whether it has **alternating bits**: namely, if two adjacent bits will always have different values. diff --git a/backend/data/questions/binary-prefix-divisible-by-5.yaml b/backend/data/questions/binary-prefix-divisible-by-5.yaml index b642248..66cc58e 100644 --- a/backend/data/questions/binary-prefix-divisible-by-5.yaml +++ b/backend/data/questions/binary-prefix-divisible-by-5.yaml @@ -9,6 +9,30 @@ categories: patterns: - prefix-sum +function_signature: "def prefixes_div_by5(nums: list[int]) -> list[bool]:" + +test_cases: + visible: + - input: { nums: [0, 1, 1] } + expected: [true, false, false] + - input: { nums: [1, 1, 1] } + expected: [false, false, false] + - input: { nums: [1, 0, 1, 0] } + expected: [false, false, true, false] + hidden: + - input: { nums: [0] } + expected: [true] + - input: { nums: [1] } + expected: [false] + - input: { nums: [1, 0, 1] } + expected: [false, false, true] + - input: { nums: [0, 0, 0, 0, 0] } + expected: [true, true, true, true, true] + - input: { nums: [1, 1, 0, 0, 1] } + expected: [false, false, false, false, false] + - input: { nums: [1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1] } + expected: [false, false, false, false, true, true, true, false, false, true, true, true, true, true, true, false, false, false, false, false] + description: | You are given a binary array `nums` (**0-indexed**). diff --git a/backend/data/questions/binary-search-tree-iterator.yaml b/backend/data/questions/binary-search-tree-iterator.yaml index 40fdcad..179fff9 100644 --- a/backend/data/questions/binary-search-tree-iterator.yaml +++ b/backend/data/questions/binary-search-tree-iterator.yaml @@ -10,6 +10,22 @@ patterns: - tree-traversal - monotonic-stack +function_signature: "class BSTIterator:\n def __init__(self, root: TreeNode): ...\n def next(self) -> int: ...\n def hasNext(self) -> bool: ..." + +test_cases: + visible: + - input: { operations: ["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"], args: [[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []] } + expected: [null, 3, 7, true, 9, true, 15, true, 20, false] + hidden: + - input: { operations: ["BSTIterator", "hasNext", "next", "hasNext"], args: [[[1]], [], [], []] } + expected: [null, true, 1, false] + - input: { operations: ["BSTIterator", "next", "next", "next", "hasNext"], args: [[[2, 1, 3]], [], [], [], []] } + expected: [null, 1, 2, 3, false] + - input: { operations: ["BSTIterator", "next", "next", "next", "next", "next"], args: [[[5, 3, 7, 2, 4, 6, 8]], [], [], [], [], []] } + expected: [null, 2, 3, 4, 5, 6] + - input: { operations: ["BSTIterator", "hasNext", "hasNext", "next", "hasNext"], args: [[[10]], [], [], [], []] } + expected: [null, true, true, 10, false] + description: | Implement the `BSTIterator` class that represents an iterator over the **in-order traversal** of a binary search tree (BST): diff --git a/backend/data/questions/binary-search-tree-to-greater-sum-tree.yaml b/backend/data/questions/binary-search-tree-to-greater-sum-tree.yaml index da50c12..e443617 100644 --- a/backend/data/questions/binary-search-tree-to-greater-sum-tree.yaml +++ b/backend/data/questions/binary-search-tree-to-greater-sum-tree.yaml @@ -9,6 +9,24 @@ patterns: - dfs - tree-traversal +function_signature: "def bst_to_gst(root: TreeNode) -> TreeNode:" + +test_cases: + visible: + - input: { root: [4, 1, 6, 0, 2, 5, 7, null, null, null, 3, null, null, null, 8] } + expected: [30, 36, 21, 36, 35, 26, 15, null, null, null, 33, null, null, null, 8] + - input: { root: [0, null, 1] } + expected: [1, null, 1] + hidden: + - input: { root: [1] } + expected: [1] + - input: { root: [2, 1, 3] } + expected: [5, 6, 3] + - input: { root: [3, 2, 4, 1] } + expected: [7, 9, 4, 10] + - input: { root: [5, 3, 7, 2, 4, 6, 8] } + expected: [26, 33, 15, 35, 30, 21, 8] + description: | Given the `root` of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST. diff --git a/backend/data/questions/binary-string-with-substrings-representing-1-to-n.yaml b/backend/data/questions/binary-string-with-substrings-representing-1-to-n.yaml index c7dcc8b..0d4a074 100644 --- a/backend/data/questions/binary-string-with-substrings-representing-1-to-n.yaml +++ b/backend/data/questions/binary-string-with-substrings-representing-1-to-n.yaml @@ -9,6 +9,28 @@ categories: patterns: - sliding-window +function_signature: "def query_string(s: str, n: int) -> bool:" + +test_cases: + visible: + - input: { s: "0110", n: 3 } + expected: true + - input: { s: "0110", n: 4 } + expected: false + hidden: + - input: { s: "1", n: 1 } + expected: true + - input: { s: "0", n: 1 } + expected: false + - input: { s: "110101011011000011011111000000", n: 15 } + expected: false + - input: { s: "1111000110110111011100011", n: 12 } + expected: true + - input: { s: "10101010101010", n: 7 } + expected: false + - input: { s: "1010110001010100111010011110100101110", n: 20 } + expected: false + description: | Given a binary string `s` and a positive integer `n`, return `true` *if the binary representation of all the integers in the range* `[1, n]` *are **substrings** of* `s`*, or* `false` *otherwise*. diff --git a/backend/data/questions/binary-subarrays-with-sum.yaml b/backend/data/questions/binary-subarrays-with-sum.yaml index 933be4a..ac759b6 100644 --- a/backend/data/questions/binary-subarrays-with-sum.yaml +++ b/backend/data/questions/binary-subarrays-with-sum.yaml @@ -10,6 +10,28 @@ patterns: - sliding-window - prefix-sum +function_signature: "def num_subarrays_with_sum(nums: list[int], goal: int) -> int:" + +test_cases: + visible: + - input: { nums: [1, 0, 1, 0, 1], goal: 2 } + expected: 4 + - input: { nums: [0, 0, 0, 0, 0], goal: 0 } + expected: 15 + hidden: + - input: { nums: [1, 1, 1, 1, 1], goal: 3 } + expected: 3 + - input: { nums: [1, 0, 0, 0, 1], goal: 1 } + expected: 8 + - input: { nums: [0, 1, 0], goal: 1 } + expected: 4 + - input: { nums: [1], goal: 1 } + expected: 1 + - input: { nums: [0], goal: 0 } + expected: 1 + - input: { nums: [1, 1, 1], goal: 5 } + expected: 0 + description: | Given a binary array `nums` and an integer `goal`, return *the number of non-empty **subarrays** with a sum equal to* `goal`. diff --git a/backend/data/questions/binary-tree-cameras.yaml b/backend/data/questions/binary-tree-cameras.yaml index 171071c..eca6170 100644 --- a/backend/data/questions/binary-tree-cameras.yaml +++ b/backend/data/questions/binary-tree-cameras.yaml @@ -10,6 +10,26 @@ patterns: - dfs - greedy +function_signature: "def min_camera_cover(root: TreeNode) -> int:" + +test_cases: + visible: + - input: { root: [0, 0, null, 0, 0] } + expected: 1 + - input: { root: [0, 0, null, 0, null, 0, null, null, 0] } + expected: 2 + hidden: + - input: { root: [0] } + expected: 1 + - input: { root: [0, 0] } + expected: 1 + - input: { root: [0, 0, 0] } + expected: 1 + - input: { root: [0, 0, 0, 0, 0, 0, 0] } + expected: 2 + - input: { root: [0, 0, null, 0, null, 0, null, 0] } + expected: 2 + description: | You are given the `root` of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children. diff --git a/backend/data/questions/binary-tree-coloring-game.yaml b/backend/data/questions/binary-tree-coloring-game.yaml index 6ba2099..05e2f20 100644 --- a/backend/data/questions/binary-tree-coloring-game.yaml +++ b/backend/data/questions/binary-tree-coloring-game.yaml @@ -9,6 +9,28 @@ patterns: - dfs - tree-traversal +function_signature: "def btree_game_winning_move(root: TreeNode, n: int, x: int) -> bool:" + +test_cases: + visible: + - input: { root: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], n: 11, x: 3 } + expected: true + - input: { root: [1, 2, 3], n: 3, x: 1 } + expected: false + hidden: + - input: { root: [1], n: 1, x: 1 } + expected: false + - input: { root: [1, 2, 3, 4, 5, null, null], n: 5, x: 2 } + expected: true + - input: { root: [1, 2, 3, 4, 5, 6, 7], n: 7, x: 1 } + expected: true + - input: { root: [1, 2, null, 3, null, 4, null, 5], n: 5, x: 3 } + expected: false + - input: { root: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], n: 15, x: 4 } + expected: true + - input: { root: [1, 2, 3, null, null, 4, 5], n: 5, x: 3 } + expected: false + description: | Two players play a turn-based game on a binary tree. We are given the `root` of this binary tree, and the number of nodes `n` in the tree. `n` is odd, and each node has a distinct value from `1` to `n`. diff --git a/backend/data/questions/binary-tree-inorder-traversal.yaml b/backend/data/questions/binary-tree-inorder-traversal.yaml index 93afbaf..ddd70af 100644 --- a/backend/data/questions/binary-tree-inorder-traversal.yaml +++ b/backend/data/questions/binary-tree-inorder-traversal.yaml @@ -11,6 +11,28 @@ patterns: - tree-traversal - dfs +function_signature: "def inorder_traversal(root: TreeNode) -> list[int]:" + +test_cases: + visible: + - input: { root: [1, null, 2, 3] } + expected: [1, 3, 2] + - input: { root: [] } + expected: [] + - input: { root: [1] } + expected: [1] + hidden: + - input: { root: [1, 2, 3, 4, 5, null, 8, null, null, 6, 7, 9] } + expected: [4, 2, 6, 5, 7, 1, 3, 9, 8] + - input: { root: [1, 2, null, 3, null, 4] } + expected: [4, 3, 2, 1] + - input: { root: [1, null, 2, null, 3, null, 4] } + expected: [1, 2, 3, 4] + - input: { root: [5, 3, 7, 2, 4, 6, 8] } + expected: [2, 3, 4, 5, 6, 7, 8] + - input: { root: [-1, -2, -3] } + expected: [-2, -1, -3] + description: | Given the `root` of a binary tree, return *the inorder traversal of its nodes' values*. diff --git a/backend/data/questions/binary-tree-level-order-traversal-ii.yaml b/backend/data/questions/binary-tree-level-order-traversal-ii.yaml index 23a2b84..afe35e8 100644 --- a/backend/data/questions/binary-tree-level-order-traversal-ii.yaml +++ b/backend/data/questions/binary-tree-level-order-traversal-ii.yaml @@ -10,6 +10,26 @@ patterns: - bfs - tree-traversal +function_signature: "def level_order_bottom(root: TreeNode) -> list[list[int]]:" + +test_cases: + visible: + - input: { root: [3, 9, 20, null, null, 15, 7] } + expected: [[15, 7], [9, 20], [3]] + - input: { root: [1] } + expected: [[1]] + - input: { root: [] } + expected: [] + hidden: + - input: { root: [1, 2, 3, 4, 5, 6, 7] } + expected: [[4, 5, 6, 7], [2, 3], [1]] + - input: { root: [1, 2, null, 3, null, 4] } + expected: [[4], [3], [2], [1]] + - input: { root: [1, null, 2, null, 3] } + expected: [[3], [2], [1]] + - input: { root: [-10, 9, 20, null, null, 15, 7] } + expected: [[15, 7], [9, 20], [-10]] + description: | Given the `root` of a binary tree, return *the bottom-up level order traversal of its nodes' values* (i.e., from left to right, level by level from leaf to root). diff --git a/backend/data/questions/binary-tree-maximum-path-sum.yaml b/backend/data/questions/binary-tree-maximum-path-sum.yaml index ea2af84..3cdfc80 100644 --- a/backend/data/questions/binary-tree-maximum-path-sum.yaml +++ b/backend/data/questions/binary-tree-maximum-path-sum.yaml @@ -11,6 +11,28 @@ patterns: - dfs - dynamic-programming +function_signature: "def max_path_sum(root: TreeNode) -> int:" + +test_cases: + visible: + - input: { root: [1, 2, 3] } + expected: 6 + - input: { root: [-10, 9, 20, null, null, 15, 7] } + expected: 42 + hidden: + - input: { root: [1] } + expected: 1 + - input: { root: [-3] } + expected: -3 + - input: { root: [2, -1] } + expected: 2 + - input: { root: [-2, -1] } + expected: -1 + - input: { root: [5, 4, 8, 11, null, 13, 4, 7, 2, null, null, null, 1] } + expected: 48 + - input: { root: [1, -2, -3, 1, 3, -2, null, -1] } + expected: 3 + description: | A **path** in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence **at most once**. Note that the path does not need to pass through the root. diff --git a/backend/data/questions/binary-tree-paths.yaml b/backend/data/questions/binary-tree-paths.yaml index 3ef0813..77f7359 100644 --- a/backend/data/questions/binary-tree-paths.yaml +++ b/backend/data/questions/binary-tree-paths.yaml @@ -12,6 +12,24 @@ patterns: - backtracking - tree-traversal +function_signature: "def binary_tree_paths(root: TreeNode) -> list[str]:" + +test_cases: + visible: + - input: { root: [1, 2, 3, null, 5] } + expected: ["1->2->5", "1->3"] + - input: { root: [1] } + expected: ["1"] + hidden: + - input: { root: [1, 2, 3] } + expected: ["1->2", "1->3"] + - input: { root: [1, 2, null, 3, null, 4] } + expected: ["1->2->3->4"] + - input: { root: [1, 2, 3, 4, 5, 6, 7] } + expected: ["1->2->4", "1->2->5", "1->3->6", "1->3->7"] + - input: { root: [-1, -2, -3] } + expected: ["-1->-2", "-1->-3"] + description: | Given the `root` of a binary tree, return *all root-to-leaf paths in **any order***. diff --git a/backend/data/questions/binary-tree-postorder-traversal.yaml b/backend/data/questions/binary-tree-postorder-traversal.yaml index 261b36c..74a3e2e 100644 --- a/backend/data/questions/binary-tree-postorder-traversal.yaml +++ b/backend/data/questions/binary-tree-postorder-traversal.yaml @@ -11,6 +11,26 @@ patterns: - dfs - tree-traversal +function_signature: "def postorder_traversal(root: TreeNode) -> list[int]:" + +test_cases: + visible: + - input: { root: [1, null, 2, 3] } + expected: [3, 2, 1] + - input: { root: [] } + expected: [] + - input: { root: [1] } + expected: [1] + hidden: + - input: { root: [1, 2, 3, 4, 5, null, 8, null, null, 6, 7, 9] } + expected: [4, 6, 7, 5, 2, 9, 8, 3, 1] + - input: { root: [1, 2, null, 3, null, 4] } + expected: [4, 3, 2, 1] + - input: { root: [1, null, 2, null, 3] } + expected: [3, 2, 1] + - input: { root: [5, 3, 7, 2, 4, 6, 8] } + expected: [2, 4, 3, 6, 8, 7, 5] + description: | Given the `root` of a binary tree, return *the postorder traversal of its nodes' values*. diff --git a/backend/data/questions/binary-tree-preorder-traversal.yaml b/backend/data/questions/binary-tree-preorder-traversal.yaml index 45a321d..e1bf938 100644 --- a/backend/data/questions/binary-tree-preorder-traversal.yaml +++ b/backend/data/questions/binary-tree-preorder-traversal.yaml @@ -11,6 +11,26 @@ patterns: - tree-traversal - dfs +function_signature: "def preorder_traversal(root: TreeNode) -> list[int]:" + +test_cases: + visible: + - input: { root: [1, null, 2, 3] } + expected: [1, 2, 3] + - input: { root: [] } + expected: [] + - input: { root: [1] } + expected: [1] + hidden: + - input: { root: [1, 2, 3, 4, 5, null, 8, null, null, 6, 7, 9] } + expected: [1, 2, 4, 5, 6, 7, 3, 8, 9] + - input: { root: [1, 2, null, 3, null, 4] } + expected: [1, 2, 3, 4] + - input: { root: [1, null, 2, null, 3, null, 4] } + expected: [1, 2, 3, 4] + - input: { root: [5, 3, 7, 2, 4, 6, 8] } + expected: [5, 3, 2, 4, 7, 6, 8] + description: | Given the `root` of a binary tree, return *the preorder traversal of its nodes' values*. diff --git a/backend/data/questions/binary-tree-pruning.yaml b/backend/data/questions/binary-tree-pruning.yaml index d44d4e6..5da9716 100644 --- a/backend/data/questions/binary-tree-pruning.yaml +++ b/backend/data/questions/binary-tree-pruning.yaml @@ -10,6 +10,30 @@ patterns: - dfs - tree-traversal +function_signature: "def prune_tree(root: TreeNode) -> TreeNode:" + +test_cases: + visible: + - input: { root: [1, null, 0, 0, 1] } + expected: [1, null, 0, null, 1] + - input: { root: [1, 0, 1, 0, 0, 0, 1] } + expected: [1, null, 1, null, 1] + - input: { root: [1, 1, 0, 1, 1, 0, 1, 0] } + expected: [1, 1, 0, 1, 1, null, 1] + hidden: + - input: { root: [1] } + expected: [1] + - input: { root: [0] } + expected: null + - input: { root: [0, 0, 0] } + expected: null + - input: { root: [1, 1, 1, 1, 1, 1, 1] } + expected: [1, 1, 1, 1, 1, 1, 1] + - input: { root: [0, 0, 0, 1] } + expected: [0, 0, null, 1] + - input: { root: [1, 0, 0, 0, 0, 0, 1] } + expected: [1, null, 0, null, 1] + description: | Given the `root` of a binary tree, return *the same tree where every subtree (of the given tree) not containing a* `1` *has been removed*. diff --git a/backend/data/questions/binary-tree-right-side-view.yaml b/backend/data/questions/binary-tree-right-side-view.yaml index 4aef43d..ec53a3d 100644 --- a/backend/data/questions/binary-tree-right-side-view.yaml +++ b/backend/data/questions/binary-tree-right-side-view.yaml @@ -10,6 +10,30 @@ patterns: - dfs - tree-traversal +function_signature: "def right_side_view(root: TreeNode) -> list[int]:" + +test_cases: + visible: + - input: { root: [1, 2, 3, null, 5, null, 4] } + expected: [1, 3, 4] + - input: { root: [1, 2, 3, 4, null, null, null, 5] } + expected: [1, 3, 4, 5] + - input: { root: [1, null, 3] } + expected: [1, 3] + hidden: + - input: { root: [] } + expected: [] + - input: { root: [1] } + expected: [1] + - input: { root: [1, 2, null] } + expected: [1, 2] + - input: { root: [1, 2, 3, 4, 5, 6, 7] } + expected: [1, 3, 7] + - input: { root: [1, 2, null, 3, null, 4, null, 5] } + expected: [1, 2, 3, 4, 5] + - input: { root: [0, -1, 100] } + expected: [0, 100] + description: | Given the `root` of a binary tree, imagine yourself standing on the **right side** of it, return *the values of the nodes you can see ordered from top to bottom*. diff --git a/backend/data/questions/binary-tree-tilt.yaml b/backend/data/questions/binary-tree-tilt.yaml index b391ef6..9f288b4 100644 --- a/backend/data/questions/binary-tree-tilt.yaml +++ b/backend/data/questions/binary-tree-tilt.yaml @@ -10,6 +10,32 @@ patterns: - dfs - tree-traversal +function_signature: "def find_tilt(root: TreeNode) -> int:" + +test_cases: + visible: + - input: { root: [1, 2, 3] } + expected: 1 + - input: { root: [4, 2, 9, 3, 5, null, 7] } + expected: 15 + - input: { root: [21, 7, 14, 1, 1, 2, 2, 3, 3] } + expected: 9 + hidden: + - input: { root: [] } + expected: 0 + - input: { root: [1] } + expected: 0 + - input: { root: [1, 2, null] } + expected: 2 + - input: { root: [1, null, 3] } + expected: 3 + - input: { root: [0, 0, 0] } + expected: 0 + - input: { root: [5, 5, 5, 5, 5, 5, 5] } + expected: 0 + - input: { root: [1, 2, 3, 4, null, 5, 6] } + expected: 11 + description: | Given the `root` of a binary tree, return *the sum of every tree node's **tilt***. diff --git a/backend/data/questions/binary-tree-zigzag-level-order-traversal.yaml b/backend/data/questions/binary-tree-zigzag-level-order-traversal.yaml index 68f5220..e3f274f 100644 --- a/backend/data/questions/binary-tree-zigzag-level-order-traversal.yaml +++ b/backend/data/questions/binary-tree-zigzag-level-order-traversal.yaml @@ -10,6 +10,28 @@ patterns: - bfs - tree-traversal +function_signature: "def zigzag_level_order(root: TreeNode) -> list[list[int]]:" + +test_cases: + visible: + - input: { root: [3, 9, 20, null, null, 15, 7] } + expected: [[3], [20, 9], [15, 7]] + - input: { root: [1] } + expected: [[1]] + - input: { root: [] } + expected: [] + hidden: + - input: { root: [1, 2, 3, 4, 5, 6, 7] } + expected: [[1], [3, 2], [4, 5, 6, 7]] + - input: { root: [1, 2, null, 3, null, 4] } + expected: [[1], [2], [3], [4]] + - input: { root: [1, 2, 3, 4, null, null, 5] } + expected: [[1], [3, 2], [4, 5]] + - input: { root: [0, -1, 100, -50, 50, -100, 200] } + expected: [[0], [100, -1], [-50, 50, -100, 200]] + - input: { root: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] } + expected: [[1], [3, 2], [4, 5, 6, 7], [15, 14, 13, 12, 11, 10, 9, 8]] + description: | Given the `root` of a binary tree, return *the zigzag level order traversal of its nodes' values* (i.e., from left to right, then right to left for the next level and alternate between). diff --git a/backend/data/questions/binary-trees-with-factors.yaml b/backend/data/questions/binary-trees-with-factors.yaml index 26eca25..cda2b32 100644 --- a/backend/data/questions/binary-trees-with-factors.yaml +++ b/backend/data/questions/binary-trees-with-factors.yaml @@ -11,6 +11,30 @@ categories: patterns: - dynamic-programming +function_signature: "def num_factored_binary_trees(arr: list[int]) -> int:" + +test_cases: + visible: + - input: { arr: [2, 4] } + expected: 3 + - input: { arr: [2, 4, 5, 10] } + expected: 7 + hidden: + - input: { arr: [2] } + expected: 1 + - input: { arr: [2, 3, 5, 7, 11] } + expected: 5 + - input: { arr: [2, 4, 8] } + expected: 7 + - input: { arr: [2, 4, 8, 16] } + expected: 15 + - input: { arr: [2, 3, 6, 18] } + expected: 7 + - input: { arr: [18, 3, 6, 2] } + expected: 7 + - input: { arr: [2, 4, 16, 8] } + expected: 15 + description: | Given an array of unique integers, `arr`, where each integer `arr[i]` is strictly greater than `1`. diff --git a/backend/data/questions/binary-watch.yaml b/backend/data/questions/binary-watch.yaml index 245e492..32e84aa 100644 --- a/backend/data/questions/binary-watch.yaml +++ b/backend/data/questions/binary-watch.yaml @@ -9,6 +9,26 @@ categories: patterns: - backtracking +function_signature: "def read_binary_watch(turned_on: int) -> list[str]:" + +test_cases: + visible: + - input: { turned_on: 1 } + expected: ["0:01", "0:02", "0:04", "0:08", "0:16", "0:32", "1:00", "2:00", "4:00", "8:00"] + - input: { turned_on: 9 } + expected: [] + hidden: + - input: { turned_on: 0 } + expected: ["0:00"] + - input: { turned_on: 2 } + expected: ["0:03", "0:05", "0:06", "0:09", "0:10", "0:12", "0:17", "0:18", "0:20", "0:24", "0:33", "0:34", "0:36", "0:40", "0:48", "1:01", "1:02", "1:04", "1:08", "1:16", "1:32", "2:01", "2:02", "2:04", "2:08", "2:16", "2:32", "3:00", "4:01", "4:02", "4:04", "4:08", "4:16", "4:32", "5:00", "6:00", "8:01", "8:02", "8:04", "8:08", "8:16", "8:32", "9:00", "10:00"] + - input: { turned_on: 10 } + expected: [] + - input: { turned_on: 8 } + expected: ["7:31", "7:47", "7:55", "7:59", "11:31", "11:47", "11:55", "11:59"] + - input: { turned_on: 5 } + expected: ["0:31", "0:47", "0:55", "0:59", "1:15", "1:23", "1:27", "1:29", "1:30", "1:39", "1:43", "1:45", "1:46", "1:51", "1:53", "1:54", "1:57", "1:58", "2:15", "2:23", "2:27", "2:29", "2:30", "2:39", "2:43", "2:45", "2:46", "2:51", "2:53", "2:54", "2:57", "2:58", "3:07", "3:11", "3:13", "3:14", "3:19", "3:21", "3:22", "3:25", "3:26", "3:28", "3:35", "3:37", "3:38", "3:41", "3:42", "3:44", "3:49", "3:50", "3:52", "3:56", "4:15", "4:23", "4:27", "4:29", "4:30", "4:39", "4:43", "4:45", "4:46", "4:51", "4:53", "4:54", "4:57", "4:58", "5:07", "5:11", "5:13", "5:14", "5:19", "5:21", "5:22", "5:25", "5:26", "5:28", "5:35", "5:37", "5:38", "5:41", "5:42", "5:44", "5:49", "5:50", "5:52", "5:56", "6:07", "6:11", "6:13", "6:14", "6:19", "6:21", "6:22", "6:25", "6:26", "6:28", "6:35", "6:37", "6:38", "6:41", "6:42", "6:44", "6:49", "6:50", "6:52", "6:56", "7:03", "7:05", "7:06", "7:09", "7:10", "7:12", "7:17", "7:18", "7:20", "7:24", "7:33", "7:34", "7:36", "7:40", "7:48", "8:15", "8:23", "8:27", "8:29", "8:30", "8:39", "8:43", "8:45", "8:46", "8:51", "8:53", "8:54", "8:57", "8:58", "9:07", "9:11", "9:13", "9:14", "9:19", "9:21", "9:22", "9:25", "9:26", "9:28", "9:35", "9:37", "9:38", "9:41", "9:42", "9:44", "9:49", "9:50", "9:52", "9:56", "10:07", "10:11", "10:13", "10:14", "10:19", "10:21", "10:22", "10:25", "10:26", "10:28", "10:35", "10:37", "10:38", "10:41", "10:42", "10:44", "10:49", "10:50", "10:52", "10:56", "11:03", "11:05", "11:06", "11:09", "11:10", "11:12", "11:17", "11:18", "11:20", "11:24", "11:33", "11:34", "11:36", "11:40", "11:48"] + description: | A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right. diff --git a/backend/data/questions/bitwise-and-of-numbers-range.yaml b/backend/data/questions/bitwise-and-of-numbers-range.yaml index f57566d..2bbf8da 100644 --- a/backend/data/questions/bitwise-and-of-numbers-range.yaml +++ b/backend/data/questions/bitwise-and-of-numbers-range.yaml @@ -8,6 +8,32 @@ categories: patterns: - binary-search +function_signature: "def range_bitwise_and(left: int, right: int) -> int:" + +test_cases: + visible: + - input: { left: 5, right: 7 } + expected: 4 + - input: { left: 0, right: 0 } + expected: 0 + - input: { left: 1, right: 2147483647 } + expected: 0 + hidden: + - input: { left: 1, right: 1 } + expected: 1 + - input: { left: 10, right: 10 } + expected: 10 + - input: { left: 0, right: 1 } + expected: 0 + - input: { left: 12, right: 15 } + expected: 12 + - input: { left: 8, right: 10 } + expected: 8 + - input: { left: 1073741824, right: 2147483647 } + expected: 1073741824 + - input: { left: 600000000, right: 600000001 } + expected: 600000000 + description: | Given two integers `left` and `right` that represent the range `[left, right]`, return *the bitwise AND of all numbers in this range, inclusive*. diff --git a/backend/data/questions/bitwise-ors-of-subarrays.yaml b/backend/data/questions/bitwise-ors-of-subarrays.yaml index 490b0f2..3bcb45c 100644 --- a/backend/data/questions/bitwise-ors-of-subarrays.yaml +++ b/backend/data/questions/bitwise-ors-of-subarrays.yaml @@ -10,6 +10,30 @@ categories: patterns: - dynamic-programming +function_signature: "def subarray_bitwise_ors(arr: list[int]) -> int:" + +test_cases: + visible: + - input: { arr: [0] } + expected: 1 + - input: { arr: [1, 1, 2] } + expected: 3 + - input: { arr: [1, 2, 4] } + expected: 6 + hidden: + - input: { arr: [1] } + expected: 1 + - input: { arr: [0, 0, 0] } + expected: 1 + - input: { arr: [1, 2, 3, 4, 5] } + expected: 7 + - input: { arr: [7, 7, 7] } + expected: 1 + - input: { arr: [1, 3, 5, 7] } + expected: 4 + - input: { arr: [8, 4, 2, 1] } + expected: 10 + description: | Given an integer array `arr`, return *the number of distinct bitwise ORs of all the non-empty subarrays of* `arr`. diff --git a/backend/data/questions/bitwise-xor-of-all-pairings.yaml b/backend/data/questions/bitwise-xor-of-all-pairings.yaml index 7f105e5..288017b 100644 --- a/backend/data/questions/bitwise-xor-of-all-pairings.yaml +++ b/backend/data/questions/bitwise-xor-of-all-pairings.yaml @@ -9,6 +9,28 @@ categories: patterns: - greedy +function_signature: "def xor_all_nums(nums1: list[int], nums2: list[int]) -> int:" + +test_cases: + visible: + - input: { nums1: [2, 1, 3], nums2: [10, 2, 5, 0] } + expected: 13 + - input: { nums1: [1, 2], nums2: [3, 4] } + expected: 0 + hidden: + - input: { nums1: [1], nums2: [1] } + expected: 0 + - input: { nums1: [5], nums2: [3, 7] } + expected: 0 + - input: { nums1: [1, 2, 3], nums2: [4] } + expected: 4 + - input: { nums1: [0], nums2: [0, 0, 0] } + expected: 0 + - input: { nums1: [1, 1], nums2: [2, 2] } + expected: 0 + - input: { nums1: [7, 8, 9], nums2: [1, 2, 3] } + expected: 0 + description: | You are given two **0-indexed** arrays, `nums1` and `nums2`, consisting of non-negative integers. diff --git a/backend/data/questions/boats-to-save-people.yaml b/backend/data/questions/boats-to-save-people.yaml index 1cf2f59..8358051 100644 --- a/backend/data/questions/boats-to-save-people.yaml +++ b/backend/data/questions/boats-to-save-people.yaml @@ -11,6 +11,32 @@ patterns: - two-pointers - greedy +function_signature: "def num_rescue_boats(people: list[int], limit: int) -> int:" + +test_cases: + visible: + - input: { people: [1, 2], limit: 3 } + expected: 1 + - input: { people: [3, 2, 2, 1], limit: 3 } + expected: 3 + - input: { people: [3, 5, 3, 4], limit: 5 } + expected: 4 + hidden: + - input: { people: [1], limit: 3 } + expected: 1 + - input: { people: [5, 5, 5, 5], limit: 5 } + expected: 4 + - input: { people: [1, 1, 1, 1], limit: 3 } + expected: 2 + - input: { people: [1, 2, 3, 4, 5], limit: 5 } + expected: 3 + - input: { people: [2, 2, 2, 2], limit: 4 } + expected: 2 + - input: { people: [3, 8, 1, 4, 6, 5, 2, 7], limit: 9 } + expected: 5 + - input: { people: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], limit: 2 } + expected: 5 + description: | You are given an array `people` where `people[i]` is the weight of the ith person, and an **infinite number of boats** where each boat can carry a maximum weight of `limit`. Each boat carries **at most two people** at the same time, provided the sum of the weight of those people is at most `limit`. diff --git a/backend/data/questions/break-a-palindrome.yaml b/backend/data/questions/break-a-palindrome.yaml index cf2d546..56d8ad2 100644 --- a/backend/data/questions/break-a-palindrome.yaml +++ b/backend/data/questions/break-a-palindrome.yaml @@ -8,6 +8,30 @@ categories: patterns: - greedy +function_signature: "def break_palindrome(palindrome: str) -> str:" + +test_cases: + visible: + - input: { palindrome: "abccba" } + expected: "aaccba" + - input: { palindrome: "a" } + expected: "" + hidden: + - input: { palindrome: "aa" } + expected: "ab" + - input: { palindrome: "aba" } + expected: "abb" + - input: { palindrome: "aaa" } + expected: "aab" + - input: { palindrome: "aaaa" } + expected: "aaab" + - input: { palindrome: "bab" } + expected: "aab" + - input: { palindrome: "abba" } + expected: "aaba" + - input: { palindrome: "zyzyz" } + expected: "ayzyz" + description: | Given a palindromic string of lowercase English letters `palindrome`, replace **exactly one** character with any lowercase English letter so that the resulting string is **not** a palindrome and that it is the **lexicographically smallest** one possible. diff --git a/backend/data/questions/brick-wall.yaml b/backend/data/questions/brick-wall.yaml index a491205..f9454a8 100644 --- a/backend/data/questions/brick-wall.yaml +++ b/backend/data/questions/brick-wall.yaml @@ -9,6 +9,26 @@ categories: patterns: - prefix-sum +function_signature: "def least_bricks(wall: list[list[int]]) -> int:" + +test_cases: + visible: + - input: { wall: [[1, 2, 2, 1], [3, 1, 2], [1, 3, 2], [2, 4], [3, 1, 2], [1, 3, 1, 1]] } + expected: 2 + - input: { wall: [[1], [1], [1]] } + expected: 3 + hidden: + - input: { wall: [[1, 1], [1, 1], [1, 1]] } + expected: 0 + - input: { wall: [[3, 1], [1, 3], [2, 2]] } + expected: 1 + - input: { wall: [[5]] } + expected: 1 + - input: { wall: [[1, 1, 1, 1], [2, 2], [1, 3], [4]] } + expected: 1 + - input: { wall: [[2, 2, 2], [2, 2, 2], [2, 2, 2]] } + expected: 0 + description: | There is a rectangular brick wall in front of you with `n` rows of bricks. The ith row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row is the same. diff --git a/backend/data/questions/broken-calculator.yaml b/backend/data/questions/broken-calculator.yaml index 6123c2b..69d1fd4 100644 --- a/backend/data/questions/broken-calculator.yaml +++ b/backend/data/questions/broken-calculator.yaml @@ -8,6 +8,32 @@ categories: patterns: - greedy +function_signature: "def broken_calc(start_value: int, target: int) -> int:" + +test_cases: + visible: + - input: { start_value: 2, target: 3 } + expected: 2 + - input: { start_value: 5, target: 8 } + expected: 2 + - input: { start_value: 3, target: 10 } + expected: 3 + hidden: + - input: { start_value: 1, target: 1 } + expected: 0 + - input: { start_value: 10, target: 5 } + expected: 5 + - input: { start_value: 1, target: 1000000000 } + expected: 39 + - input: { start_value: 1, target: 2 } + expected: 1 + - input: { start_value: 1, target: 1024 } + expected: 10 + - input: { start_value: 100, target: 1 } + expected: 99 + - input: { start_value: 1, target: 17 } + expected: 6 + description: | There is a broken calculator that has the integer `startValue` on its display initially. In one operation, you can: diff --git a/backend/data/questions/buddy-strings.yaml b/backend/data/questions/buddy-strings.yaml index fc98d0f..f1eaf40 100644 --- a/backend/data/questions/buddy-strings.yaml +++ b/backend/data/questions/buddy-strings.yaml @@ -9,6 +9,30 @@ categories: patterns: - two-pointers +function_signature: "def buddy_strings(s: str, goal: str) -> bool:" + +test_cases: + visible: + - input: { s: "ab", goal: "ba" } + expected: true + - input: { s: "ab", goal: "ab" } + expected: false + - input: { s: "aa", goal: "aa" } + expected: true + hidden: + - input: { s: "aaaaaaabc", goal: "aaaaaaacb" } + expected: true + - input: { s: "abcd", goal: "badc" } + expected: false + - input: { s: "a", goal: "a" } + expected: false + - input: { s: "ab", goal: "ca" } + expected: false + - input: { s: "abab", goal: "abab" } + expected: true + - input: { s: "abcdef", goal: "abcfed" } + expected: false + description: | Given two strings `s` and `goal`, return `true` *if you can swap two letters in* `s` *so the result is equal to* `goal`, *otherwise, return* `false`. diff --git a/backend/data/questions/build-an-array-with-stack-operations.yaml b/backend/data/questions/build-an-array-with-stack-operations.yaml index 4a54820..4319f00 100644 --- a/backend/data/questions/build-an-array-with-stack-operations.yaml +++ b/backend/data/questions/build-an-array-with-stack-operations.yaml @@ -9,6 +9,28 @@ categories: patterns: - two-pointers +function_signature: "def build_array(target: list[int], n: int) -> list[str]:" + +test_cases: + visible: + - input: { target: [1, 3], n: 3 } + expected: ["Push", "Push", "Pop", "Push"] + - input: { target: [1, 2, 3], n: 3 } + expected: ["Push", "Push", "Push"] + - input: { target: [1, 2], n: 4 } + expected: ["Push", "Push"] + hidden: + - input: { target: [1], n: 1 } + expected: ["Push"] + - input: { target: [2], n: 2 } + expected: ["Push", "Pop", "Push"] + - input: { target: [3], n: 5 } + expected: ["Push", "Pop", "Push", "Pop", "Push"] + - input: { target: [1, 4], n: 5 } + expected: ["Push", "Push", "Pop", "Push", "Pop", "Push"] + - input: { target: [2, 3, 4], n: 4 } + expected: ["Push", "Pop", "Push", "Push", "Push"] + description: | You are given an integer array `target` and an integer `n`. diff --git a/backend/data/questions/build-array-from-permutation.yaml b/backend/data/questions/build-array-from-permutation.yaml index 9dfcb9e..58f68d3 100644 --- a/backend/data/questions/build-array-from-permutation.yaml +++ b/backend/data/questions/build-array-from-permutation.yaml @@ -8,6 +8,28 @@ categories: patterns: - matrix-traversal +function_signature: "def build_array(nums: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { nums: [0, 2, 1, 5, 3, 4] } + expected: [0, 1, 2, 4, 5, 3] + - input: { nums: [5, 0, 1, 2, 3, 4] } + expected: [4, 5, 0, 1, 2, 3] + hidden: + - input: { nums: [0] } + expected: [0] + - input: { nums: [1, 0] } + expected: [0, 1] + - input: { nums: [0, 1, 2, 3, 4] } + expected: [0, 1, 2, 3, 4] + - input: { nums: [4, 3, 2, 1, 0] } + expected: [0, 1, 2, 3, 4] + - input: { nums: [2, 0, 1] } + expected: [1, 2, 0] + - input: { nums: [3, 0, 2, 1] } + expected: [1, 3, 2, 0] + description: | Given a **zero-based permutation** `nums` (**0-indexed**), build an array `ans` of the **same length** where `ans[i] = nums[nums[i]]` for each `0 <= i < nums.length` and return it. diff --git a/backend/data/questions/bulb-switcher-ii.yaml b/backend/data/questions/bulb-switcher-ii.yaml index 179d0e8..ec149a2 100644 --- a/backend/data/questions/bulb-switcher-ii.yaml +++ b/backend/data/questions/bulb-switcher-ii.yaml @@ -8,6 +8,28 @@ categories: patterns: - greedy +function_signature: "def flip_lights(n: int, presses: int) -> int:" + +test_cases: + visible: + - input: { n: 1, presses: 1 } + expected: 2 + - input: { n: 2, presses: 1 } + expected: 3 + - input: { n: 3, presses: 1 } + expected: 4 + hidden: + - input: { n: 1, presses: 0 } + expected: 1 + - input: { n: 3, presses: 2 } + expected: 7 + - input: { n: 3, presses: 3 } + expected: 8 + - input: { n: 10, presses: 5 } + expected: 8 + - input: { n: 2, presses: 2 } + expected: 4 + description: | There is a room with `n` bulbs labelled from `1` to `n` that all are turned on initially, and **four buttons** on the wall. Each of the four buttons has a different functionality: diff --git a/backend/data/questions/bulb-switcher.yaml b/backend/data/questions/bulb-switcher.yaml index 2ef93b4..4691859 100644 --- a/backend/data/questions/bulb-switcher.yaml +++ b/backend/data/questions/bulb-switcher.yaml @@ -8,6 +8,30 @@ categories: patterns: - greedy +function_signature: "def bulb_switch(n: int) -> int:" + +test_cases: + visible: + - input: { n: 3 } + expected: 1 + - input: { n: 0 } + expected: 0 + - input: { n: 1 } + expected: 1 + hidden: + - input: { n: 4 } + expected: 2 + - input: { n: 9 } + expected: 3 + - input: { n: 16 } + expected: 4 + - input: { n: 25 } + expected: 5 + - input: { n: 100 } + expected: 10 + - input: { n: 99999999 } + expected: 9999 + description: | There are `n` bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb. diff --git a/backend/data/questions/bulls-and-cows.yaml b/backend/data/questions/bulls-and-cows.yaml index 18943a8..e6d76cd 100644 --- a/backend/data/questions/bulls-and-cows.yaml +++ b/backend/data/questions/bulls-and-cows.yaml @@ -9,6 +9,30 @@ categories: patterns: - two-pointers +function_signature: "def get_hint(secret: str, guess: str) -> str:" + +test_cases: + visible: + - input: { secret: "1807", guess: "7810" } + expected: "1A3B" + - input: { secret: "1123", guess: "0111" } + expected: "1A1B" + hidden: + - input: { secret: "1", guess: "0" } + expected: "0A0B" + - input: { secret: "1", guess: "1" } + expected: "1A0B" + - input: { secret: "1111", guess: "1111" } + expected: "4A0B" + - input: { secret: "1234", guess: "4321" } + expected: "0A4B" + - input: { secret: "1122", guess: "2211" } + expected: "0A4B" + - input: { secret: "0000", guess: "1111" } + expected: "0A0B" + - input: { secret: "1234", guess: "0000" } + expected: "0A0B" + description: | You are playing the **Bulls and Cows** game with your friend. diff --git a/backend/data/questions/bus-routes.yaml b/backend/data/questions/bus-routes.yaml index 5d422f2..33541e2 100644 --- a/backend/data/questions/bus-routes.yaml +++ b/backend/data/questions/bus-routes.yaml @@ -10,6 +10,28 @@ categories: patterns: - bfs +function_signature: "def num_buses_to_destination(routes: list[list[int]], source: int, target: int) -> int:" + +test_cases: + visible: + - input: { routes: [[1, 2, 7], [3, 6, 7]], source: 1, target: 6 } + expected: 2 + - input: { routes: [[7, 12], [4, 5, 15], [6], [15, 19], [9, 12, 13]], source: 15, target: 12 } + expected: -1 + hidden: + - input: { routes: [[1, 2, 3]], source: 1, target: 1 } + expected: 0 + - input: { routes: [[1, 2, 3]], source: 1, target: 3 } + expected: 1 + - input: { routes: [[1, 2], [2, 3], [3, 4]], source: 1, target: 4 } + expected: 3 + - input: { routes: [[1, 5], [5, 10], [10, 20]], source: 1, target: 20 } + expected: 3 + - input: { routes: [[1, 2, 3], [4, 5, 6]], source: 1, target: 6 } + expected: -1 + - input: { routes: [[1, 2, 3, 4, 5]], source: 1, target: 5 } + expected: 1 + description: | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the ith bus repeats forever. diff --git a/backend/data/questions/cache-with-time-limit.yaml b/backend/data/questions/cache-with-time-limit.yaml index e5a7689..548c9ec 100644 --- a/backend/data/questions/cache-with-time-limit.yaml +++ b/backend/data/questions/cache-with-time-limit.yaml @@ -8,6 +8,22 @@ categories: patterns: - heap +function_signature: "class TimeLimitedCache { set(key: number, value: number, duration: number): boolean; get(key: number): number; count(): number; }" + +test_cases: + visible: + - input: { actions: ["TimeLimitedCache", "set", "get", "count", "get"], values: [[], [1, 42, 100], [1], [], [1]], timeDelays: [0, 0, 50, 50, 150] } + expected: [null, false, 42, 1, -1] + - input: { actions: ["TimeLimitedCache", "set", "set", "get", "get", "get", "count"], values: [[], [1, 42, 50], [1, 50, 100], [1], [1], [1], []], timeDelays: [0, 0, 40, 50, 120, 200, 250] } + expected: [null, false, true, 50, 50, -1, 0] + hidden: + - input: { actions: ["TimeLimitedCache", "set", "count", "set", "count"], values: [[], [1, 10, 100], [], [2, 20, 100], []], timeDelays: [0, 0, 0, 0, 0] } + expected: [null, false, 1, false, 2] + - input: { actions: ["TimeLimitedCache", "get"], values: [[], [1]], timeDelays: [0, 0] } + expected: [null, -1] + - input: { actions: ["TimeLimitedCache", "set", "set", "get"], values: [[], [1, 100, 50], [1, 200, 100], [1]], timeDelays: [0, 0, 25, 75] } + expected: [null, false, true, 200] + description: | Write a class that allows getting and setting key-value pairs, however a **time until expiration** is associated with each key. diff --git a/backend/data/questions/calculate-amount-paid-in-taxes.yaml b/backend/data/questions/calculate-amount-paid-in-taxes.yaml index 3214571..60868e8 100644 --- a/backend/data/questions/calculate-amount-paid-in-taxes.yaml +++ b/backend/data/questions/calculate-amount-paid-in-taxes.yaml @@ -9,6 +9,26 @@ categories: patterns: - greedy +function_signature: "def calculate_tax(brackets: list[list[int]], income: int) -> float:" + +test_cases: + visible: + - input: { brackets: [[3, 50], [7, 10], [12, 25]], income: 10 } + expected: 2.65 + - input: { brackets: [[1, 0], [4, 25], [5, 50]], income: 2 } + expected: 0.25 + - input: { brackets: [[2, 50]], income: 0 } + expected: 0.0 + hidden: + - input: { brackets: [[10, 10]], income: 10 } + expected: 1.0 + - input: { brackets: [[5, 100]], income: 5 } + expected: 5.0 + - input: { brackets: [[10, 0], [20, 50]], income: 15 } + expected: 2.5 + - input: { brackets: [[100, 10], [200, 20], [300, 30]], income: 250 } + expected: 45.0 + description: | You are given a **0-indexed** 2D integer array `brackets` where `brackets[i] = [upper_i, percent_i]` means that the ith tax bracket has an upper bound of `upper_i` and is taxed at a rate of `percent_i`. The brackets are **sorted** by upper bound (i.e., `upper_{i-1} < upper_i` for `0 < i < brackets.length`). diff --git a/backend/data/questions/calculate-digit-sum-of-a-string.yaml b/backend/data/questions/calculate-digit-sum-of-a-string.yaml index 087d174..71c6bd6 100644 --- a/backend/data/questions/calculate-digit-sum-of-a-string.yaml +++ b/backend/data/questions/calculate-digit-sum-of-a-string.yaml @@ -8,6 +8,26 @@ categories: patterns: - sliding-window +function_signature: "def digit_sum(s: str, k: int) -> str:" + +test_cases: + visible: + - input: { s: "11111222223", k: 3 } + expected: "135" + - input: { s: "00000000", k: 3 } + expected: "000" + hidden: + - input: { s: "1", k: 2 } + expected: "1" + - input: { s: "123", k: 3 } + expected: "123" + - input: { s: "999", k: 2 } + expected: "27" + - input: { s: "12345", k: 2 } + expected: "39" + - input: { s: "111111", k: 2 } + expected: "6" + description: | You are given a string `s` consisting of digits and an integer `k`. diff --git a/backend/data/questions/calculate-money-in-leetcode-bank.yaml b/backend/data/questions/calculate-money-in-leetcode-bank.yaml index 32d86ce..850c39e 100644 --- a/backend/data/questions/calculate-money-in-leetcode-bank.yaml +++ b/backend/data/questions/calculate-money-in-leetcode-bank.yaml @@ -8,6 +8,30 @@ categories: patterns: - prefix-sum +function_signature: "def total_money(n: int) -> int:" + +test_cases: + visible: + - input: { n: 4 } + expected: 10 + - input: { n: 10 } + expected: 37 + - input: { n: 20 } + expected: 96 + hidden: + - input: { n: 1 } + expected: 1 + - input: { n: 7 } + expected: 28 + - input: { n: 8 } + expected: 30 + - input: { n: 14 } + expected: 63 + - input: { n: 100 } + expected: 678 + - input: { n: 1000 } + expected: 7089 + description: | Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**. diff --git a/backend/data/questions/camelcase-matching.yaml b/backend/data/questions/camelcase-matching.yaml index 738cc2c..a4a7695 100644 --- a/backend/data/questions/camelcase-matching.yaml +++ b/backend/data/questions/camelcase-matching.yaml @@ -10,6 +10,26 @@ categories: patterns: - two-pointers +function_signature: "def camelMatch(queries: list[str], pattern: str) -> list[bool]:" + +test_cases: + visible: + - input: { queries: ["FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"], pattern: "FB" } + expected: [true, false, true, true, false] + - input: { queries: ["FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"], pattern: "FoBa" } + expected: [true, false, true, false, false] + - input: { queries: ["FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"], pattern: "FoBaT" } + expected: [false, true, false, false, false] + hidden: + - input: { queries: ["a"], pattern: "a" } + expected: [true] + - input: { queries: ["AB", "aB", "Ab"], pattern: "A" } + expected: [false, false, true] + - input: { queries: ["abc"], pattern: "ABC" } + expected: [false] + - input: { queries: ["aksvbjLiknuTzqon", "ksvjLimflkpnTzqn", "mmkasvjLiknTxzqn", "ksvjLiurknTzzqbn", "ksvsjLctikgnTzqn", "knaborsvjLiworknTzqn"], pattern: "ksvjLiknTzqn" } + expected: [true, true, true, false, false, false] + description: | Given an array of strings `queries` and a string `pattern`, return a boolean array `answer` where `answer[i]` is `true` if `queries[i]` matches `pattern`, and `false` otherwise. diff --git a/backend/data/questions/can-convert-string-in-k-moves.yaml b/backend/data/questions/can-convert-string-in-k-moves.yaml index 205c07a..59062d5 100644 --- a/backend/data/questions/can-convert-string-in-k-moves.yaml +++ b/backend/data/questions/can-convert-string-in-k-moves.yaml @@ -9,6 +9,30 @@ categories: patterns: - greedy +function_signature: "def can_convert_string(s: str, t: str, k: int) -> bool:" + +test_cases: + visible: + - input: { s: "input", t: "ouput", k: 9 } + expected: true + - input: { s: "abc", t: "bcd", k: 10 } + expected: false + - input: { s: "aab", t: "bbb", k: 27 } + expected: true + hidden: + - input: { s: "a", t: "a", k: 0 } + expected: true + - input: { s: "a", t: "b", k: 0 } + expected: false + - input: { s: "a", t: "b", k: 1 } + expected: true + - input: { s: "ab", t: "ab", k: 100 } + expected: true + - input: { s: "aaa", t: "bbb", k: 53 } + expected: true + - input: { s: "abc", t: "abcd", k: 100 } + expected: false + description: | Given two strings `s` and `t`, your goal is to convert `s` into `t` in `k` moves or less. diff --git a/backend/data/questions/can-i-win.yaml b/backend/data/questions/can-i-win.yaml index 01ae9fa..a36623d 100644 --- a/backend/data/questions/can-i-win.yaml +++ b/backend/data/questions/can-i-win.yaml @@ -10,6 +10,32 @@ patterns: - dynamic-programming - backtracking +function_signature: "def can_i_win(max_choosable: int, desired_total: int) -> bool:" + +test_cases: + visible: + - input: { max_choosable: 10, desired_total: 11 } + expected: false + - input: { max_choosable: 10, desired_total: 0 } + expected: true + - input: { max_choosable: 10, desired_total: 1 } + expected: true + hidden: + - input: { max_choosable: 1, desired_total: 1 } + expected: true + - input: { max_choosable: 1, desired_total: 2 } + expected: false + - input: { max_choosable: 4, desired_total: 6 } + expected: true + - input: { max_choosable: 5, desired_total: 50 } + expected: false + - input: { max_choosable: 10, desired_total: 40 } + expected: false + - input: { max_choosable: 20, desired_total: 210 } + expected: false + - input: { max_choosable: 3, desired_total: 5 } + expected: true + description: | In the "100 game" two players take turns adding, to a running total, any integer from `1` to `10`. The player who first causes the running total to **reach or exceed** 100 wins. diff --git a/backend/data/questions/can-make-arithmetic-progression-from-sequence.yaml b/backend/data/questions/can-make-arithmetic-progression-from-sequence.yaml index e050c33..36f05d8 100644 --- a/backend/data/questions/can-make-arithmetic-progression-from-sequence.yaml +++ b/backend/data/questions/can-make-arithmetic-progression-from-sequence.yaml @@ -9,6 +9,30 @@ categories: patterns: - two-pointers +function_signature: "def can_make_arithmetic_progression(arr: list[int]) -> bool:" + +test_cases: + visible: + - input: { arr: [3, 5, 1] } + expected: true + - input: { arr: [1, 2, 4] } + expected: false + hidden: + - input: { arr: [1, 2] } + expected: true + - input: { arr: [5, 5, 5, 5] } + expected: true + - input: { arr: [0, 0] } + expected: true + - input: { arr: [-1, -5, -3] } + expected: true + - input: { arr: [1, 100] } + expected: true + - input: { arr: [1, 2, 3, 4, 6] } + expected: false + - input: { arr: [10, 5, 0, -5, -10] } + expected: true + description: | A sequence of numbers is called an **arithmetic progression** if the difference between any two consecutive elements is the same. diff --git a/backend/data/questions/can-place-flowers.yaml b/backend/data/questions/can-place-flowers.yaml index 082e940..6df40dc 100644 --- a/backend/data/questions/can-place-flowers.yaml +++ b/backend/data/questions/can-place-flowers.yaml @@ -8,6 +8,30 @@ categories: patterns: - greedy +function_signature: "def can_place_flowers(flowerbed: list[int], n: int) -> bool:" + +test_cases: + visible: + - input: { flowerbed: [1, 0, 0, 0, 1], n: 1 } + expected: true + - input: { flowerbed: [1, 0, 0, 0, 1], n: 2 } + expected: false + hidden: + - input: { flowerbed: [0], n: 1 } + expected: true + - input: { flowerbed: [1], n: 0 } + expected: true + - input: { flowerbed: [0, 0, 0, 0, 0], n: 3 } + expected: true + - input: { flowerbed: [0, 0, 0, 0, 0], n: 4 } + expected: false + - input: { flowerbed: [1, 0, 0, 0, 0, 1], n: 1 } + expected: true + - input: { flowerbed: [0, 0, 1, 0, 0], n: 2 } + expected: true + - input: { flowerbed: [1, 0, 1, 0, 1], n: 1 } + expected: false + description: | You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in **adjacent** plots. diff --git a/backend/data/questions/capacity-to-ship-packages-within-d-days.yaml b/backend/data/questions/capacity-to-ship-packages-within-d-days.yaml index d118176..53ef9b3 100644 --- a/backend/data/questions/capacity-to-ship-packages-within-d-days.yaml +++ b/backend/data/questions/capacity-to-ship-packages-within-d-days.yaml @@ -9,6 +9,30 @@ categories: patterns: - binary-search +function_signature: "def ship_within_days(weights: list[int], days: int) -> int:" + +test_cases: + visible: + - input: { weights: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], days: 5 } + expected: 15 + - input: { weights: [3, 2, 2, 4, 1, 4], days: 3 } + expected: 6 + - input: { weights: [1, 2, 3, 1, 1], days: 4 } + expected: 3 + hidden: + - input: { weights: [1], days: 1 } + expected: 1 + - input: { weights: [10, 10, 10], days: 3 } + expected: 10 + - input: { weights: [10, 10, 10], days: 1 } + expected: 30 + - input: { weights: [1, 2, 3, 4, 5], days: 1 } + expected: 15 + - input: { weights: [1, 2, 3, 4, 5], days: 5 } + expected: 5 + - input: { weights: [500, 500, 500, 500], days: 2 } + expected: 1000 + description: | A conveyor belt has packages that must be shipped from one port to another within `days` days. diff --git a/backend/data/questions/capitalize-the-title.yaml b/backend/data/questions/capitalize-the-title.yaml index f3276ae..fcaf884 100644 --- a/backend/data/questions/capitalize-the-title.yaml +++ b/backend/data/questions/capitalize-the-title.yaml @@ -8,6 +8,28 @@ categories: patterns: - two-pointers +function_signature: "def capitalize_title(title: str) -> str:" + +test_cases: + visible: + - input: { title: "capiTalIze tHe titLe" } + expected: "Capitalize The Title" + - input: { title: "First leTTeR of EACH Word" } + expected: "First Letter of Each Word" + - input: { title: "i lOve leetcode" } + expected: "i Love Leetcode" + hidden: + - input: { title: "TO BE OR NOT TO BE" } + expected: "to be or Not to be" + - input: { title: "a" } + expected: "a" + - input: { title: "AB" } + expected: "ab" + - input: { title: "ABC" } + expected: "Abc" + - input: { title: "the QUICK brown FOX" } + expected: "The Quick Brown Fox" + description: | You are given a string `title` consisting of one or more words separated by a single space, where each word consists of English letters. **Capitalize** the string by changing the capitalization of each word such that: diff --git a/backend/data/questions/car-fleet.yaml b/backend/data/questions/car-fleet.yaml index c5bbc74..74635c1 100644 --- a/backend/data/questions/car-fleet.yaml +++ b/backend/data/questions/car-fleet.yaml @@ -10,6 +10,30 @@ categories: patterns: - monotonic-stack +function_signature: "def car_fleet(target: int, position: list[int], speed: list[int]) -> int:" + +test_cases: + visible: + - input: { target: 12, position: [10, 8, 0, 5, 3], speed: [2, 4, 1, 1, 3] } + expected: 3 + - input: { target: 10, position: [3], speed: [3] } + expected: 1 + - input: { target: 100, position: [0, 2, 4], speed: [4, 2, 1] } + expected: 1 + hidden: + - input: { target: 10, position: [], speed: [] } + expected: 0 + - input: { target: 10, position: [0, 5], speed: [1, 1] } + expected: 2 + - input: { target: 10, position: [6, 8], speed: [3, 2] } + expected: 2 + - input: { target: 10, position: [2, 4], speed: [3, 2] } + expected: 1 + - input: { target: 100, position: [0, 50, 99], speed: [1, 1, 1] } + expected: 3 + - input: { target: 20, position: [0, 10], speed: [10, 5] } + expected: 1 + description: | There are `n` cars at given miles away from the starting mile `0`, travelling to reach the mile `target`. diff --git a/backend/data/questions/car-pooling.yaml b/backend/data/questions/car-pooling.yaml index 0966eed..efeb158 100644 --- a/backend/data/questions/car-pooling.yaml +++ b/backend/data/questions/car-pooling.yaml @@ -10,6 +10,30 @@ patterns: - prefix-sum - intervals +function_signature: "def car_pooling(trips: list[list[int]], capacity: int) -> bool:" + +test_cases: + visible: + - input: { trips: [[2, 1, 5], [3, 3, 7]], capacity: 4 } + expected: false + - input: { trips: [[2, 1, 5], [3, 3, 7]], capacity: 5 } + expected: true + hidden: + - input: { trips: [[1, 0, 1]], capacity: 1 } + expected: true + - input: { trips: [[2, 0, 5]], capacity: 1 } + expected: false + - input: { trips: [[3, 2, 7], [3, 7, 9], [8, 3, 9]], capacity: 11 } + expected: true + - input: { trips: [[2, 1, 5], [3, 5, 7]], capacity: 3 } + expected: true + - input: { trips: [[10, 0, 1], [10, 1, 2], [10, 2, 3]], capacity: 10 } + expected: true + - input: { trips: [[9, 0, 1], [3, 3, 7]], capacity: 4 } + expected: false + - input: { trips: [[4, 0, 5], [4, 3, 8], [2, 5, 10]], capacity: 6 } + expected: false + description: | There is a car with `capacity` empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west). diff --git a/backend/data/questions/card-flipping-game.yaml b/backend/data/questions/card-flipping-game.yaml index 70f6e36..85d0885 100644 --- a/backend/data/questions/card-flipping-game.yaml +++ b/backend/data/questions/card-flipping-game.yaml @@ -9,6 +9,26 @@ categories: patterns: - greedy +function_signature: "def flipgame(fronts: list[int], backs: list[int]) -> int:" + +test_cases: + visible: + - input: { fronts: [1, 2, 4, 4, 7], backs: [1, 3, 4, 1, 3] } + expected: 2 + - input: { fronts: [1], backs: [1] } + expected: 0 + hidden: + - input: { fronts: [1, 2], backs: [2, 1] } + expected: 1 + - input: { fronts: [2, 2], backs: [2, 2] } + expected: 0 + - input: { fronts: [1, 1], backs: [1, 2] } + expected: 2 + - input: { fronts: [5, 3, 7], backs: [5, 3, 8] } + expected: 7 + - input: { fronts: [1, 2, 3], backs: [4, 5, 6] } + expected: 1 + description: | You are given two **0-indexed** integer arrays `fronts` and `backs` of length `n`, where the ith card has the positive integer `fronts[i]` printed on the front and `backs[i]` printed on the back. Initially, each card is placed on a table such that the front number is facing up and the other is facing down. diff --git a/backend/data/questions/categorize-box-according-to-criteria.yaml b/backend/data/questions/categorize-box-according-to-criteria.yaml index 9539738..d2eb340 100644 --- a/backend/data/questions/categorize-box-according-to-criteria.yaml +++ b/backend/data/questions/categorize-box-according-to-criteria.yaml @@ -8,6 +8,26 @@ categories: patterns: - greedy +function_signature: "def categorize_box(length: int, width: int, height: int, mass: int) -> str:" + +test_cases: + visible: + - input: { length: 1000, width: 35, height: 700, mass: 300 } + expected: "Heavy" + - input: { length: 200, width: 50, height: 800, mass: 50 } + expected: "Neither" + hidden: + - input: { length: 10000, width: 1, height: 1, mass: 1 } + expected: "Bulky" + - input: { length: 1000, width: 1000, height: 1000, mass: 100 } + expected: "Both" + - input: { length: 100, width: 100, height: 100, mass: 99 } + expected: "Neither" + - input: { length: 1, width: 10000, height: 1, mass: 200 } + expected: "Both" + - input: { length: 9999, width: 9999, height: 9999, mass: 50 } + expected: "Bulky" + description: | Given four integers `length`, `width`, `height`, and `mass`, representing the dimensions and mass of a box, respectively, return *a string representing the **category** of the box*. diff --git a/backend/data/questions/cells-in-a-range-on-an-excel-sheet.yaml b/backend/data/questions/cells-in-a-range-on-an-excel-sheet.yaml index 80bfb8b..a8e6f19 100644 --- a/backend/data/questions/cells-in-a-range-on-an-excel-sheet.yaml +++ b/backend/data/questions/cells-in-a-range-on-an-excel-sheet.yaml @@ -9,6 +9,24 @@ categories: patterns: - matrix-traversal +function_signature: "def cells_in_range(s: str) -> list[str]:" + +test_cases: + visible: + - input: { s: "K1:L2" } + expected: ["K1", "K2", "L1", "L2"] + - input: { s: "A1:F1" } + expected: ["A1", "B1", "C1", "D1", "E1", "F1"] + hidden: + - input: { s: "A1:A1" } + expected: ["A1"] + - input: { s: "A1:A3" } + expected: ["A1", "A2", "A3"] + - input: { s: "B2:D4" } + expected: ["B2", "B3", "B4", "C2", "C3", "C4", "D2", "D3", "D4"] + - input: { s: "Z1:Z9" } + expected: ["Z1", "Z2", "Z3", "Z4", "Z5", "Z6", "Z7", "Z8", "Z9"] + description: | A cell `(r, c)` of an Excel sheet is represented as a string `""` where: diff --git a/backend/data/questions/cells-with-odd-values-in-a-matrix.yaml b/backend/data/questions/cells-with-odd-values-in-a-matrix.yaml index ef942ba..db5e911 100644 --- a/backend/data/questions/cells-with-odd-values-in-a-matrix.yaml +++ b/backend/data/questions/cells-with-odd-values-in-a-matrix.yaml @@ -9,6 +9,26 @@ categories: patterns: - prefix-sum +function_signature: "def odd_cells(m: int, n: int, indices: list[list[int]]) -> int:" + +test_cases: + visible: + - input: { m: 2, n: 3, indices: [[0, 1], [1, 1]] } + expected: 6 + - input: { m: 2, n: 2, indices: [[1, 1], [0, 0]] } + expected: 0 + hidden: + - input: { m: 1, n: 1, indices: [[0, 0]] } + expected: 1 + - input: { m: 3, n: 3, indices: [[0, 0], [1, 1], [2, 2]] } + expected: 0 + - input: { m: 2, n: 2, indices: [[0, 0]] } + expected: 3 + - input: { m: 5, n: 5, indices: [[0, 0], [0, 1], [0, 2]] } + expected: 20 + - input: { m: 3, n: 4, indices: [[0, 0], [1, 1], [0, 1]] } + expected: 6 + description: | There is an `m x n` matrix that is initialised to all `0`'s. There is also a 2D array `indices` where each `indices[i] = [r_i, c_i]` represents a **0-indexed location** to perform some increment operations on the matrix. diff --git a/backend/data/questions/chalkboard-xor-game.yaml b/backend/data/questions/chalkboard-xor-game.yaml index d2e7e9c..115c942 100644 --- a/backend/data/questions/chalkboard-xor-game.yaml +++ b/backend/data/questions/chalkboard-xor-game.yaml @@ -9,6 +9,30 @@ categories: patterns: - greedy +function_signature: "def xor_game(nums: list[int]) -> bool:" + +test_cases: + visible: + - input: { nums: [1, 1, 2] } + expected: false + - input: { nums: [0, 1] } + expected: true + - input: { nums: [1, 2, 3] } + expected: true + hidden: + - input: { nums: [1] } + expected: false + - input: { nums: [0, 0] } + expected: true + - input: { nums: [1, 1] } + expected: true + - input: { nums: [1, 2, 3, 4] } + expected: true + - input: { nums: [5, 5, 5] } + expected: false + - input: { nums: [1, 2, 4, 8] } + expected: true + description: | You are given an array of integers `nums` representing the numbers written on a chalkboard. diff --git a/backend/data/questions/champagne-tower.yaml b/backend/data/questions/champagne-tower.yaml index bab6dbd..342da28 100644 --- a/backend/data/questions/champagne-tower.yaml +++ b/backend/data/questions/champagne-tower.yaml @@ -9,6 +9,30 @@ categories: patterns: - dynamic-programming +function_signature: "def champagne_tower(poured: int, query_row: int, query_glass: int) -> float:" + +test_cases: + visible: + - input: { poured: 1, query_row: 1, query_glass: 1 } + expected: 0.0 + - input: { poured: 2, query_row: 1, query_glass: 1 } + expected: 0.5 + - input: { poured: 100000009, query_row: 33, query_glass: 17 } + expected: 1.0 + hidden: + - input: { poured: 0, query_row: 0, query_glass: 0 } + expected: 0.0 + - input: { poured: 1, query_row: 0, query_glass: 0 } + expected: 1.0 + - input: { poured: 2, query_row: 0, query_glass: 0 } + expected: 1.0 + - input: { poured: 4, query_row: 2, query_glass: 1 } + expected: 0.5 + - input: { poured: 6, query_row: 2, query_glass: 0 } + expected: 0.75 + - input: { poured: 25, query_row: 6, query_glass: 1 } + expected: 1.0 + description: | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne. diff --git a/backend/data/questions/cheapest-flights-within-k-stops.yaml b/backend/data/questions/cheapest-flights-within-k-stops.yaml index 5bd0323..059d62f 100644 --- a/backend/data/questions/cheapest-flights-within-k-stops.yaml +++ b/backend/data/questions/cheapest-flights-within-k-stops.yaml @@ -10,6 +10,26 @@ patterns: - bfs - dynamic-programming +function_signature: "def findCheapestPrice(n: int, flights: list[list[int]], src: int, dst: int, k: int) -> int:" + +test_cases: + visible: + - input: { n: 4, flights: [[0, 1, 100], [1, 2, 100], [2, 0, 100], [1, 3, 600], [2, 3, 200]], src: 0, dst: 3, k: 1 } + expected: 700 + - input: { n: 3, flights: [[0, 1, 100], [1, 2, 100], [0, 2, 500]], src: 0, dst: 2, k: 1 } + expected: 200 + - input: { n: 3, flights: [[0, 1, 100], [1, 2, 100], [0, 2, 500]], src: 0, dst: 2, k: 0 } + expected: 500 + hidden: + - input: { n: 2, flights: [[0, 1, 100]], src: 0, dst: 1, k: 0 } + expected: 100 + - input: { n: 3, flights: [[0, 1, 100], [1, 2, 100]], src: 0, dst: 2, k: 0 } + expected: -1 + - input: { n: 4, flights: [[0, 1, 1], [0, 2, 5], [1, 2, 1], [2, 3, 1]], src: 0, dst: 3, k: 1 } + expected: 6 + - input: { n: 5, flights: [[0, 1, 5], [1, 2, 5], [0, 3, 2], [3, 1, 2], [1, 4, 1], [4, 2, 1]], src: 0, dst: 2, k: 2 } + expected: 7 + description: | There are `n` cities connected by some number of flights. You are given an array `flights` where `flights[i] = [from_i, to_i, price_i]` indicates that there is a flight from city `from_i` to city `to_i` with cost `price_i`. diff --git a/backend/data/questions/check-array-formation-through-concatenation.yaml b/backend/data/questions/check-array-formation-through-concatenation.yaml index 0406ce0..da7d08c 100644 --- a/backend/data/questions/check-array-formation-through-concatenation.yaml +++ b/backend/data/questions/check-array-formation-through-concatenation.yaml @@ -9,6 +9,28 @@ categories: patterns: - greedy +function_signature: "def can_form_array(arr: list[int], pieces: list[list[int]]) -> bool:" + +test_cases: + visible: + - input: { arr: [15, 88], pieces: [[88], [15]] } + expected: true + - input: { arr: [49, 18, 16], pieces: [[16, 18, 49]] } + expected: false + - input: { arr: [91, 4, 64, 78], pieces: [[78], [4, 64], [91]] } + expected: true + hidden: + - input: { arr: [1], pieces: [[1]] } + expected: true + - input: { arr: [1, 2, 3], pieces: [[1], [2], [3]] } + expected: true + - input: { arr: [1, 2, 3], pieces: [[2], [1], [3]] } + expected: true + - input: { arr: [1, 2, 3], pieces: [[3, 2, 1]] } + expected: false + - input: { arr: [1, 2, 3, 4], pieces: [[1, 2], [3, 4]] } + expected: true + description: | You are given an array of **distinct** integers `arr` and an array of integer arrays `pieces`, where the integers in `pieces` are **distinct**. Your goal is to form `arr` by concatenating the arrays in `pieces` **in any order**. However, you are **not** allowed to reorder the integers in each array `pieces[i]`. diff --git a/backend/data/questions/check-completeness-of-a-binary-tree.yaml b/backend/data/questions/check-completeness-of-a-binary-tree.yaml index fbcd926..c48a6ff 100644 --- a/backend/data/questions/check-completeness-of-a-binary-tree.yaml +++ b/backend/data/questions/check-completeness-of-a-binary-tree.yaml @@ -9,6 +9,30 @@ patterns: - bfs - tree-traversal +function_signature: "def is_complete_tree(root: TreeNode) -> bool:" + +test_cases: + visible: + - input: { root: [1, 2, 3, 4, 5, 6] } + expected: true + - input: { root: [1, 2, 3, 4, 5, null, 7] } + expected: false + hidden: + - input: { root: [1] } + expected: true + - input: { root: [1, 2] } + expected: true + - input: { root: [1, null, 2] } + expected: false + - input: { root: [1, 2, 3, 4, 5, 6, 7] } + expected: true + - input: { root: [1, 2, 3, 4, null, 6, 7] } + expected: false + - input: { root: [1, 2, 3, null, null, 6, 7] } + expected: false + - input: { root: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } + expected: true + description: | Given the `root` of a binary tree, determine if it is a *complete binary tree*. diff --git a/backend/data/questions/check-distances-between-same-letters.yaml b/backend/data/questions/check-distances-between-same-letters.yaml index 702af59..ce2b265 100644 --- a/backend/data/questions/check-distances-between-same-letters.yaml +++ b/backend/data/questions/check-distances-between-same-letters.yaml @@ -10,6 +10,22 @@ categories: patterns: - two-pointers +function_signature: "def check_distances(s: str, distance: list[int]) -> bool:" + +test_cases: + visible: + - input: { s: "abaccb", distance: [1, 3, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] } + expected: true + - input: { s: "aa", distance: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] } + expected: false + hidden: + - input: { s: "zz", distance: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] } + expected: true + - input: { s: "abba", distance: [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] } + expected: true + - input: { s: "aabb", distance: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] } + expected: true + description: | You are given a **0-indexed** string `s` consisting of only lowercase English letters, where each letter in `s` appears **exactly twice**. You are also given a **0-indexed** integer array `distance` of length `26`. diff --git a/backend/data/questions/check-if-all-1s-are-at-least-length-k-places-away.yaml b/backend/data/questions/check-if-all-1s-are-at-least-length-k-places-away.yaml index c36e9c5..c2da6f3 100644 --- a/backend/data/questions/check-if-all-1s-are-at-least-length-k-places-away.yaml +++ b/backend/data/questions/check-if-all-1s-are-at-least-length-k-places-away.yaml @@ -8,6 +8,26 @@ categories: patterns: - two-pointers +function_signature: "def k_length_apart(nums: list[int], k: int) -> bool:" + +test_cases: + visible: + - input: { nums: [1, 0, 0, 0, 1, 0, 0, 1], k: 2 } + expected: true + - input: { nums: [1, 0, 0, 1, 0, 1], k: 2 } + expected: false + hidden: + - input: { nums: [1], k: 0 } + expected: true + - input: { nums: [0, 0, 0], k: 5 } + expected: true + - input: { nums: [1, 1], k: 0 } + expected: false + - input: { nums: [1, 0, 1], k: 1 } + expected: true + - input: { nums: [1, 0, 0, 0, 0, 1], k: 4 } + expected: true + description: | Given a binary array `nums` and an integer `k`, return `true` *if all* `1`*'s are at least* `k` *places away from each other, otherwise return* `false`. diff --git a/backend/data/questions/check-if-all-characters-have-equal-number-of-occurrences.yaml b/backend/data/questions/check-if-all-characters-have-equal-number-of-occurrences.yaml index 8aadcc9..38f1843 100644 --- a/backend/data/questions/check-if-all-characters-have-equal-number-of-occurrences.yaml +++ b/backend/data/questions/check-if-all-characters-have-equal-number-of-occurrences.yaml @@ -9,6 +9,26 @@ categories: patterns: - prefix-sum +function_signature: "def are_occurrences_equal(s: str) -> bool:" + +test_cases: + visible: + - input: { s: "abacbc" } + expected: true + - input: { s: "aaabb" } + expected: false + hidden: + - input: { s: "a" } + expected: true + - input: { s: "aabbcc" } + expected: true + - input: { s: "aabbccc" } + expected: false + - input: { s: "zzzz" } + expected: true + - input: { s: "abcdefg" } + expected: true + description: | Given a string `s`, return `true` *if* `s` *is a **good** string, or* `false` *otherwise*. diff --git a/backend/data/questions/check-if-all-integers-in-range-are-covered.yaml b/backend/data/questions/check-if-all-integers-in-range-are-covered.yaml index da8aa03..fa73dfb 100644 --- a/backend/data/questions/check-if-all-integers-in-range-are-covered.yaml +++ b/backend/data/questions/check-if-all-integers-in-range-are-covered.yaml @@ -9,6 +9,24 @@ categories: patterns: - prefix-sum +function_signature: "def is_covered(ranges: list[list[int]], left: int, right: int) -> bool:" + +test_cases: + visible: + - input: { ranges: [[1, 2], [3, 4], [5, 6]], left: 2, right: 5 } + expected: true + - input: { ranges: [[1, 10], [10, 20]], left: 21, right: 21 } + expected: false + hidden: + - input: { ranges: [[1, 50]], left: 1, right: 50 } + expected: true + - input: { ranges: [[1, 2]], left: 1, right: 3 } + expected: false + - input: { ranges: [[1, 1], [3, 3]], left: 1, right: 3 } + expected: false + - input: { ranges: [[1, 5], [6, 10]], left: 1, right: 10 } + expected: true + description: | You are given a 2D integer array `ranges` and two integers `left` and `right`. Each `ranges[i] = [start_i, end_i]` represents an **inclusive** interval between `start_i` and `end_i`. diff --git a/backend/data/questions/check-if-array-is-sorted-and-rotated.yaml b/backend/data/questions/check-if-array-is-sorted-and-rotated.yaml index 7d41811..6536e3b 100644 --- a/backend/data/questions/check-if-array-is-sorted-and-rotated.yaml +++ b/backend/data/questions/check-if-array-is-sorted-and-rotated.yaml @@ -8,6 +8,32 @@ categories: patterns: - two-pointers +function_signature: "def check(nums: list[int]) -> bool:" + +test_cases: + visible: + - input: { nums: [3, 4, 5, 1, 2] } + expected: true + - input: { nums: [2, 1, 3, 4] } + expected: false + - input: { nums: [1, 2, 3] } + expected: true + hidden: + - input: { nums: [1] } + expected: true + - input: { nums: [2, 1] } + expected: true + - input: { nums: [1, 1, 1] } + expected: true + - input: { nums: [3, 4, 5, 1, 2, 2] } + expected: false + - input: { nums: [6, 10, 6] } + expected: true + - input: { nums: [1, 2, 3, 4, 5] } + expected: true + - input: { nums: [5, 1, 2, 3, 4] } + expected: true + description: | Given an array `nums`, return `true` *if the array was originally sorted in non-decreasing order, then rotated **some** number of positions (including zero)*. Otherwise, return `false`. diff --git a/backend/data/questions/check-if-it-is-a-straight-line.yaml b/backend/data/questions/check-if-it-is-a-straight-line.yaml index e5598ec..309dfd6 100644 --- a/backend/data/questions/check-if-it-is-a-straight-line.yaml +++ b/backend/data/questions/check-if-it-is-a-straight-line.yaml @@ -9,6 +9,26 @@ categories: patterns: - two-pointers +function_signature: "def check_straight_line(coordinates: list[list[int]]) -> bool:" + +test_cases: + visible: + - input: { coordinates: [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]] } + expected: true + - input: { coordinates: [[1, 1], [2, 2], [3, 4], [4, 5], [5, 6], [7, 7]] } + expected: false + hidden: + - input: { coordinates: [[0, 0], [1, 1]] } + expected: true + - input: { coordinates: [[0, 0], [0, 1], [0, 2]] } + expected: true + - input: { coordinates: [[1, 0], [2, 0], [3, 0]] } + expected: true + - input: { coordinates: [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]] } + expected: true + - input: { coordinates: [[0, 0], [1, 1], [2, 3]] } + expected: false + description: | You are given an array `coordinates`, where `coordinates[i] = [x, y]` represents the coordinate of a point. Check if these points make a straight line in the XY plane. diff --git a/backend/data/questions/check-if-matrix-is-x-matrix.yaml b/backend/data/questions/check-if-matrix-is-x-matrix.yaml index 8c6ec47..dcddeef 100644 --- a/backend/data/questions/check-if-matrix-is-x-matrix.yaml +++ b/backend/data/questions/check-if-matrix-is-x-matrix.yaml @@ -9,6 +9,24 @@ categories: patterns: - matrix-traversal +function_signature: "def check_x_matrix(grid: list[list[int]]) -> bool:" + +test_cases: + visible: + - input: { grid: [[2, 0, 0, 1], [0, 3, 1, 0], [0, 5, 2, 0], [4, 0, 0, 2]] } + expected: true + - input: { grid: [[5, 7, 0], [0, 3, 1], [0, 5, 0]] } + expected: false + hidden: + - input: { grid: [[1, 0, 1], [0, 1, 0], [1, 0, 1]] } + expected: true + - input: { grid: [[1, 0, 0], [0, 1, 0], [0, 0, 1]] } + expected: false + - input: { grid: [[0, 0, 1], [0, 1, 0], [1, 0, 0]] } + expected: false + - input: { grid: [[5, 0, 5], [0, 5, 0], [5, 0, 5]] } + expected: true + description: | A square matrix is said to be an **X-Matrix** if **both** of the following conditions hold: diff --git a/backend/data/questions/check-if-n-and-its-double-exist.yaml b/backend/data/questions/check-if-n-and-its-double-exist.yaml index 0d1aff6..7b181ce 100644 --- a/backend/data/questions/check-if-n-and-its-double-exist.yaml +++ b/backend/data/questions/check-if-n-and-its-double-exist.yaml @@ -9,6 +9,28 @@ categories: patterns: - two-pointers +function_signature: "def check_if_exist(arr: list[int]) -> bool:" + +test_cases: + visible: + - input: { arr: [10, 2, 5, 3] } + expected: true + - input: { arr: [3, 1, 7, 11] } + expected: false + - input: { arr: [7, 1, 14, 11] } + expected: true + hidden: + - input: { arr: [0, 0] } + expected: true + - input: { arr: [-2, 0, 10, -19, 4, 6, -8] } + expected: false + - input: { arr: [-10, 12, -20, -8, 15] } + expected: true + - input: { arr: [1, 2, 3, 4] } + expected: true + - input: { arr: [1, 3, 5, 7] } + expected: false + description: | Given an array `arr` of integers, check if there exist two indices `i` and `j` such that: diff --git a/backend/data/questions/check-if-numbers-are-ascending-in-a-sentence.yaml b/backend/data/questions/check-if-numbers-are-ascending-in-a-sentence.yaml index 334d2a2..3086ac8 100644 --- a/backend/data/questions/check-if-numbers-are-ascending-in-a-sentence.yaml +++ b/backend/data/questions/check-if-numbers-are-ascending-in-a-sentence.yaml @@ -8,6 +8,26 @@ categories: patterns: - two-pointers +function_signature: "def are_numbers_ascending(s: str) -> bool:" + +test_cases: + visible: + - input: { s: "1 box has 3 blue 4 red 6 green and 12 yellow marbles" } + expected: true + - input: { s: "hello world 5 x 5" } + expected: false + - input: { s: "sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s" } + expected: false + hidden: + - input: { s: "a 1 b 2 c 3" } + expected: true + - input: { s: "1 2 3 4 5" } + expected: true + - input: { s: "5 4 3 2 1" } + expected: false + - input: { s: "a 10 b 20" } + expected: true + description: | A sentence is a list of **tokens** separated by a **single** space with no leading or trailing spaces. Every token is either a **positive number** consisting of digits `0-9` with no leading zeros, or a **word** consisting of lowercase English letters. diff --git a/backend/data/questions/check-if-one-string-swap-can-make-strings-equal.yaml b/backend/data/questions/check-if-one-string-swap-can-make-strings-equal.yaml index 2021fcc..8d85937 100644 --- a/backend/data/questions/check-if-one-string-swap-can-make-strings-equal.yaml +++ b/backend/data/questions/check-if-one-string-swap-can-make-strings-equal.yaml @@ -9,6 +9,28 @@ categories: patterns: - two-pointers +function_signature: "def are_almost_equal(s1: str, s2: str) -> bool:" + +test_cases: + visible: + - input: { s1: "bank", s2: "kanb" } + expected: true + - input: { s1: "attack", s2: "defend" } + expected: false + - input: { s1: "kelb", s2: "kelb" } + expected: true + hidden: + - input: { s1: "a", s2: "a" } + expected: true + - input: { s1: "ab", s2: "ba" } + expected: true + - input: { s1: "ab", s2: "cd" } + expected: false + - input: { s1: "abc", s2: "adc" } + expected: false + - input: { s1: "abcd", s2: "dcba" } + expected: false + description: | You are given two strings `s1` and `s2` of equal length. A **string swap** is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices. diff --git a/backend/data/questions/check-if-string-is-a-prefix-of-array.yaml b/backend/data/questions/check-if-string-is-a-prefix-of-array.yaml index 32c8189..9ff13b9 100644 --- a/backend/data/questions/check-if-string-is-a-prefix-of-array.yaml +++ b/backend/data/questions/check-if-string-is-a-prefix-of-array.yaml @@ -9,6 +9,24 @@ categories: patterns: - two-pointers +function_signature: "def is_prefix_string(s: str, words: list[str]) -> bool:" + +test_cases: + visible: + - input: { s: "iloveleetcode", words: ["i", "love", "leetcode", "apples"] } + expected: true + - input: { s: "iloveleetcode", words: ["apples", "i", "love", "leetcode"] } + expected: false + hidden: + - input: { s: "a", words: ["a", "b"] } + expected: true + - input: { s: "abc", words: ["abc"] } + expected: true + - input: { s: "ab", words: ["a", "bc"] } + expected: false + - input: { s: "abc", words: ["ab", "c", "d"] } + expected: true + description: | Given a string `s` and an array of strings `words`, determine whether `s` is a **prefix string** of `words`. diff --git a/backend/data/questions/check-if-the-sentence-is-pangram.yaml b/backend/data/questions/check-if-the-sentence-is-pangram.yaml index ab2eb4e..9fc6c6f 100644 --- a/backend/data/questions/check-if-the-sentence-is-pangram.yaml +++ b/backend/data/questions/check-if-the-sentence-is-pangram.yaml @@ -9,6 +9,28 @@ categories: patterns: - prefix-sum +function_signature: "def check_if_pangram(sentence: str) -> bool:" + +test_cases: + visible: + - input: { sentence: "thequickbrownfoxjumpsoverthelazydog" } + expected: true + - input: { sentence: "leetcode" } + expected: false + hidden: + - input: { sentence: "abcdefghijklmnopqrstuvwxyz" } + expected: true + - input: { sentence: "a" } + expected: false + - input: { sentence: "abcdefghijklmnopqrstuvwxy" } + expected: false + - input: { sentence: "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz" } + expected: true + - input: { sentence: "zyxwvutsrqponmlkjihgfedcba" } + expected: true + - input: { sentence: "qwertyuiopasdfghjklzxcvbnm" } + expected: true + description: | A **pangram** is a sentence where every letter of the English alphabet appears at least once. diff --git a/backend/data/questions/check-if-two-string-arrays-are-equivalent.yaml b/backend/data/questions/check-if-two-string-arrays-are-equivalent.yaml index 8d55908..74aace5 100644 --- a/backend/data/questions/check-if-two-string-arrays-are-equivalent.yaml +++ b/backend/data/questions/check-if-two-string-arrays-are-equivalent.yaml @@ -9,6 +9,26 @@ categories: patterns: - two-pointers +function_signature: "def array_strings_are_equal(word1: list[str], word2: list[str]) -> bool:" + +test_cases: + visible: + - input: { word1: ["ab", "c"], word2: ["a", "bc"] } + expected: true + - input: { word1: ["a", "cb"], word2: ["ab", "c"] } + expected: false + - input: { word1: ["abc", "d", "defg"], word2: ["abcddefg"] } + expected: true + hidden: + - input: { word1: ["a"], word2: ["a"] } + expected: true + - input: { word1: ["a", "b", "c"], word2: ["abc"] } + expected: true + - input: { word1: ["ab"], word2: ["a", "b"] } + expected: true + - input: { word1: ["abc"], word2: ["ab"] } + expected: false + description: | Given two string arrays `word1` and `word2`, return `true` *if the two arrays **represent** the same string, and* `false` *otherwise*. diff --git a/backend/data/questions/combination-sum-iii.yaml b/backend/data/questions/combination-sum-iii.yaml index 5260b5e..aed18c9 100644 --- a/backend/data/questions/combination-sum-iii.yaml +++ b/backend/data/questions/combination-sum-iii.yaml @@ -9,6 +9,30 @@ categories: patterns: - backtracking +function_signature: "def combination_sum3(k: int, n: int) -> list[list[int]]:" + +test_cases: + visible: + - input: { k: 3, n: 7 } + expected: [[1, 2, 4]] + - input: { k: 3, n: 9 } + expected: [[1, 2, 6], [1, 3, 5], [2, 3, 4]] + - input: { k: 4, n: 1 } + expected: [] + hidden: + - input: { k: 2, n: 3 } + expected: [[1, 2]] + - input: { k: 2, n: 17 } + expected: [[8, 9]] + - input: { k: 2, n: 18 } + expected: [] + - input: { k: 9, n: 45 } + expected: [[1, 2, 3, 4, 5, 6, 7, 8, 9]] + - input: { k: 3, n: 15 } + expected: [[1, 5, 9], [1, 6, 8], [2, 4, 9], [2, 5, 8], [2, 6, 7], [3, 4, 8], [3, 5, 7], [4, 5, 6]] + - input: { k: 5, n: 15 } + expected: [[1, 2, 3, 4, 5]] + description: | Find all valid combinations of `k` numbers that sum up to `n` such that the following conditions are true: diff --git a/backend/data/questions/combination-sum-iv.yaml b/backend/data/questions/combination-sum-iv.yaml index 2ce8b64..7cde568 100644 --- a/backend/data/questions/combination-sum-iv.yaml +++ b/backend/data/questions/combination-sum-iv.yaml @@ -9,6 +9,28 @@ categories: patterns: - dynamic-programming +function_signature: "def combination_sum4(nums: list[int], target: int) -> int:" + +test_cases: + visible: + - input: { nums: [1, 2, 3], target: 4 } + expected: 7 + - input: { nums: [9], target: 3 } + expected: 0 + hidden: + - input: { nums: [1], target: 1 } + expected: 1 + - input: { nums: [1, 2], target: 3 } + expected: 3 + - input: { nums: [2, 3], target: 6 } + expected: 4 + - input: { nums: [1, 2, 3], target: 5 } + expected: 13 + - input: { nums: [3, 4, 5, 6], target: 10 } + expected: 18 + - input: { nums: [5, 10], target: 15 } + expected: 3 + description: | Given an array of **distinct** integers `nums` and a target integer `target`, return *the number of possible combinations that add up to* `target`. diff --git a/backend/data/questions/concatenation-of-array.yaml b/backend/data/questions/concatenation-of-array.yaml index 1625ea1..32185f7 100644 --- a/backend/data/questions/concatenation-of-array.yaml +++ b/backend/data/questions/concatenation-of-array.yaml @@ -8,6 +8,26 @@ categories: patterns: - two-pointers +function_signature: "def get_concatenation(nums: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { nums: [1, 2, 1] } + expected: [1, 2, 1, 1, 2, 1] + - input: { nums: [1, 3, 2, 1] } + expected: [1, 3, 2, 1, 1, 3, 2, 1] + hidden: + - input: { nums: [1] } + expected: [1, 1] + - input: { nums: [5, 4, 3, 2, 1] } + expected: [5, 4, 3, 2, 1, 5, 4, 3, 2, 1] + - input: { nums: [1, 1, 1] } + expected: [1, 1, 1, 1, 1, 1] + - input: { nums: [7] } + expected: [7, 7] + - input: { nums: [100, 200] } + expected: [100, 200, 100, 200] + description: | Given an integer array `nums` of length `n`, you want to create an array `ans` of length `2n` where `ans[i] == nums[i]` and `ans[i + n] == nums[i]` for `0 <= i < n` (**0-indexed**). diff --git a/backend/data/questions/construct-binary-tree-from-preorder-and-inorder-traversal.yaml b/backend/data/questions/construct-binary-tree-from-preorder-and-inorder-traversal.yaml index b52a81a..e8f9aa0 100644 --- a/backend/data/questions/construct-binary-tree-from-preorder-and-inorder-traversal.yaml +++ b/backend/data/questions/construct-binary-tree-from-preorder-and-inorder-traversal.yaml @@ -11,6 +11,26 @@ patterns: - dfs - tree-traversal +function_signature: "def build_tree(preorder: list[int], inorder: list[int]) -> TreeNode | None:" + +test_cases: + visible: + - input: { preorder: [3, 9, 20, 15, 7], inorder: [9, 3, 15, 20, 7] } + expected: [3, 9, 20, null, null, 15, 7] + - input: { preorder: [-1], inorder: [-1] } + expected: [-1] + hidden: + - input: { preorder: [1, 2], inorder: [2, 1] } + expected: [1, 2] + - input: { preorder: [1, 2], inorder: [1, 2] } + expected: [1, null, 2] + - input: { preorder: [1, 2, 3], inorder: [2, 1, 3] } + expected: [1, 2, 3] + - input: { preorder: [1, 2, 4, 5, 3, 6, 7], inorder: [4, 2, 5, 1, 6, 3, 7] } + expected: [1, 2, 3, 4, 5, 6, 7] + - input: { preorder: [5, 4, 3, 2, 1], inorder: [1, 2, 3, 4, 5] } + expected: [5, 4, null, 3, null, 2, null, 1] + description: | Given two integer arrays `preorder` and `inorder` where `preorder` is the preorder traversal of a binary tree and `inorder` is the inorder traversal of the same tree, construct and return *the binary tree*. diff --git a/backend/data/questions/contains-duplicate-ii.yaml b/backend/data/questions/contains-duplicate-ii.yaml index 2eced67..0b93ad6 100644 --- a/backend/data/questions/contains-duplicate-ii.yaml +++ b/backend/data/questions/contains-duplicate-ii.yaml @@ -9,6 +9,30 @@ categories: patterns: - sliding-window +function_signature: "def contains_nearby_duplicate(nums: list[int], k: int) -> bool:" + +test_cases: + visible: + - input: { nums: [1, 2, 3, 1], k: 3 } + expected: true + - input: { nums: [1, 0, 1, 1], k: 1 } + expected: true + - input: { nums: [1, 2, 3, 1, 2, 3], k: 2 } + expected: false + hidden: + - input: { nums: [1], k: 1 } + expected: false + - input: { nums: [1, 1], k: 0 } + expected: false + - input: { nums: [1, 2, 1], k: 2 } + expected: true + - input: { nums: [99, 99], k: 2 } + expected: true + - input: { nums: [1, 2, 3, 4, 5], k: 3 } + expected: false + - input: { nums: [0, 1, 2, 3, 4, 0, 0, 7, 8, 9, 10, 11, 12, 0], k: 1 } + expected: true + description: | Given an integer array `nums` and an integer `k`, return `true` *if there are two **distinct indices*** `i` *and* `j` *in the array such that* `nums[i] == nums[j]` *and* `abs(i - j) <= k`. diff --git a/backend/data/questions/continuous-subarray-sum.yaml b/backend/data/questions/continuous-subarray-sum.yaml index cd3a007..d6465e7 100644 --- a/backend/data/questions/continuous-subarray-sum.yaml +++ b/backend/data/questions/continuous-subarray-sum.yaml @@ -10,6 +10,32 @@ categories: patterns: - prefix-sum +function_signature: "def check_subarray_sum(nums: list[int], k: int) -> bool:" + +test_cases: + visible: + - input: { nums: [23, 2, 4, 6, 7], k: 6 } + expected: true + - input: { nums: [23, 2, 6, 4, 7], k: 6 } + expected: true + - input: { nums: [23, 2, 6, 4, 7], k: 13 } + expected: false + hidden: + - input: { nums: [0, 0], k: 1 } + expected: true + - input: { nums: [1, 0], k: 2 } + expected: false + - input: { nums: [5, 0, 0, 0], k: 3 } + expected: true + - input: { nums: [1, 2, 3], k: 5 } + expected: true + - input: { nums: [1, 2, 12], k: 6 } + expected: false + - input: { nums: [23, 2, 4, 6, 6], k: 7 } + expected: true + - input: { nums: [1, 1], k: 1 } + expected: true + description: | Given an integer array `nums` and an integer `k`, return `true` if `nums` has a **good subarray** or `false` otherwise. diff --git a/backend/data/questions/convert-bst-to-greater-tree.yaml b/backend/data/questions/convert-bst-to-greater-tree.yaml index e1259d7..939a8c9 100644 --- a/backend/data/questions/convert-bst-to-greater-tree.yaml +++ b/backend/data/questions/convert-bst-to-greater-tree.yaml @@ -9,6 +9,28 @@ patterns: - dfs - tree-traversal +function_signature: "def convert_bst(root: TreeNode | None) -> TreeNode | None:" + +test_cases: + visible: + - input: { root: [4, 1, 6, 0, 2, 5, 7, null, null, null, 3, null, null, null, 8] } + expected: [30, 36, 21, 36, 35, 26, 15, null, null, null, 33, null, null, null, 8] + - input: { root: [0, null, 1] } + expected: [1, null, 1] + hidden: + - input: { root: [] } + expected: [] + - input: { root: [5] } + expected: [5] + - input: { root: [2, 1, 3] } + expected: [5, 6, 3] + - input: { root: [5, 3, 8, 1, 4, 6, 9] } + expected: [33, 37, 17, 38, 34, 23, 9] + - input: { root: [1, null, 2, null, 3, null, 4] } + expected: [10, null, 9, null, 7, null, 4] + - input: { root: [-3, -4, -2] } + expected: [-5, -9, -2] + description: | Given the `root` of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST. diff --git a/backend/data/questions/convert-sorted-array-to-binary-search-tree.yaml b/backend/data/questions/convert-sorted-array-to-binary-search-tree.yaml index adba56b..b158715 100644 --- a/backend/data/questions/convert-sorted-array-to-binary-search-tree.yaml +++ b/backend/data/questions/convert-sorted-array-to-binary-search-tree.yaml @@ -11,6 +11,28 @@ patterns: - binary-search - dfs +function_signature: "def sorted_array_to_bst(nums: list[int]) -> TreeNode | None:" + +test_cases: + visible: + - input: { nums: [-10, -3, 0, 5, 9] } + expected: [0, -3, 9, -10, null, 5] + - input: { nums: [1, 3] } + expected: [3, 1] + hidden: + - input: { nums: [0] } + expected: [0] + - input: { nums: [1, 2, 3, 4, 5, 6, 7] } + expected: [4, 2, 6, 1, 3, 5, 7] + - input: { nums: [-5, -3, -1, 0, 2, 4, 6] } + expected: [0, -3, 4, -5, -1, 2, 6] + - input: { nums: [1, 2] } + expected: [2, 1] + - input: { nums: [1, 2, 3, 4, 5] } + expected: [3, 2, 5, 1, null, 4] + - input: { nums: [-10000, 0, 10000] } + expected: [0, -10000, 10000] + description: | Given an integer array `nums` where the elements are sorted in **ascending order**, convert *it to a* ***height-balanced*** *binary search tree*. diff --git a/backend/data/questions/copy-list-with-random-pointer.yaml b/backend/data/questions/copy-list-with-random-pointer.yaml index 6675e17..9b7bf26 100644 --- a/backend/data/questions/copy-list-with-random-pointer.yaml +++ b/backend/data/questions/copy-list-with-random-pointer.yaml @@ -9,6 +9,30 @@ categories: patterns: - linkedlist-reversal +function_signature: "def copy_random_list(head: Node | None) -> Node | None:" + +test_cases: + visible: + - input: { head: [[7, null], [13, 0], [11, 4], [10, 2], [1, 0]] } + expected: [[7, null], [13, 0], [11, 4], [10, 2], [1, 0]] + - input: { head: [[1, 1], [2, 1]] } + expected: [[1, 1], [2, 1]] + - input: { head: [[3, null], [3, 0], [3, null]] } + expected: [[3, null], [3, 0], [3, null]] + hidden: + - input: { head: [] } + expected: [] + - input: { head: [[1, null]] } + expected: [[1, null]] + - input: { head: [[5, 0]] } + expected: [[5, 0]] + - input: { head: [[1, 1], [2, 0]] } + expected: [[1, 1], [2, 0]] + - input: { head: [[1, null], [2, null], [3, null], [4, null], [5, null]] } + expected: [[1, null], [2, null], [3, null], [4, null], [5, null]] + - input: { head: [[-1, 0], [0, 1], [1, 0]] } + expected: [[-1, 0], [0, 1], [1, 0]] + description: | A linked list of length `n` is given such that each node contains an additional random pointer, which could point to any node in the list, or `null`. diff --git a/backend/data/questions/count-good-nodes-in-binary-tree.yaml b/backend/data/questions/count-good-nodes-in-binary-tree.yaml index 38baa6e..a858ea8 100644 --- a/backend/data/questions/count-good-nodes-in-binary-tree.yaml +++ b/backend/data/questions/count-good-nodes-in-binary-tree.yaml @@ -9,6 +9,30 @@ patterns: - dfs - tree-traversal +function_signature: "def good_nodes(root: TreeNode) -> int:" + +test_cases: + visible: + - input: { root: [3, 1, 4, 3, null, 1, 5] } + expected: 4 + - input: { root: [3, 3, null, 4, 2] } + expected: 3 + - input: { root: [1] } + expected: 1 + hidden: + - input: { root: [2, 2, 2] } + expected: 3 + - input: { root: [5, 4, 3, 2, 1] } + expected: 1 + - input: { root: [1, 2, 3, 4, 5, 6, 7] } + expected: 7 + - input: { root: [-1, -2, -3, -4, -5] } + expected: 1 + - input: { root: [10, 5, 15, 3, 7, 12, 20] } + expected: 4 + - input: { root: [9, 3, 10, null, 6, 9, 14, 4, 8] } + expected: 4 + description: | Given a binary tree `root`, a node *X* in the tree is named **good** if in the path from root to *X* there are no nodes with a value *greater than* X. diff --git a/backend/data/questions/course-schedule-iv.yaml b/backend/data/questions/course-schedule-iv.yaml index 5f70af4..5a1e00b 100644 --- a/backend/data/questions/course-schedule-iv.yaml +++ b/backend/data/questions/course-schedule-iv.yaml @@ -10,6 +10,30 @@ patterns: - dfs - dynamic-programming +function_signature: "def check_if_prerequisite(num_courses: int, prerequisites: list[list[int]], queries: list[list[int]]) -> list[bool]:" + +test_cases: + visible: + - input: { num_courses: 2, prerequisites: [[1, 0]], queries: [[0, 1], [1, 0]] } + expected: [false, true] + - input: { num_courses: 2, prerequisites: [], queries: [[1, 0], [0, 1]] } + expected: [false, false] + - input: { num_courses: 3, prerequisites: [[1, 2], [1, 0], [2, 0]], queries: [[1, 0], [1, 2]] } + expected: [true, true] + hidden: + - input: { num_courses: 3, prerequisites: [[0, 1], [1, 2]], queries: [[0, 2]] } + expected: [true] + - input: { num_courses: 4, prerequisites: [[0, 1], [1, 2], [2, 3]], queries: [[0, 3], [3, 0], [1, 3]] } + expected: [true, false, true] + - input: { num_courses: 5, prerequisites: [], queries: [[0, 1], [2, 3], [4, 0]] } + expected: [false, false, false] + - input: { num_courses: 4, prerequisites: [[0, 1], [0, 2], [1, 3], [2, 3]], queries: [[0, 3], [1, 2]] } + expected: [true, false] + - input: { num_courses: 3, prerequisites: [[0, 1]], queries: [[0, 1], [1, 0], [0, 2], [2, 1]] } + expected: [true, false, false, false] + - input: { num_courses: 6, prerequisites: [[0, 1], [1, 2], [3, 4], [4, 5]], queries: [[0, 2], [3, 5], [0, 5], [2, 5]] } + expected: [true, true, false, false] + description: | There are a total of `numCourses` courses you have to take, labeled from `0` to `numCourses - 1`. You are given an array `prerequisites` where `prerequisites[i] = [a_i, b_i]` indicates that you **must** take course `a_i` first if you want to take course `b_i`. diff --git a/backend/data/questions/delete-leaves-with-a-given-value.yaml b/backend/data/questions/delete-leaves-with-a-given-value.yaml index 9afe094..25035bb 100644 --- a/backend/data/questions/delete-leaves-with-a-given-value.yaml +++ b/backend/data/questions/delete-leaves-with-a-given-value.yaml @@ -10,6 +10,30 @@ patterns: - dfs - tree-traversal +function_signature: "def remove_leaf_nodes(root: TreeNode | None, target: int) -> TreeNode | None:" + +test_cases: + visible: + - input: { root: [1, 2, 3, 2, null, 2, 4], target: 2 } + expected: [1, null, 3, null, 4] + - input: { root: [1, 3, 3, 3, 2], target: 3 } + expected: [1, 3, null, null, 2] + - input: { root: [1, 2, null, 2, null, 2], target: 2 } + expected: [1] + hidden: + - input: { root: [2], target: 2 } + expected: [] + - input: { root: [1], target: 2 } + expected: [1] + - input: { root: [1, 1, 1], target: 1 } + expected: [] + - input: { root: [5, 3, 7, 2, 4, 6, 8], target: 9 } + expected: [5, 3, 7, 2, 4, 6, 8] + - input: { root: [1, 2, 3, 4, 2, 2, 5], target: 2 } + expected: [1, 2, 3, 4, null, null, 5] + - input: { root: [3, 3, 3, 3, 3, 3, 3], target: 3 } + expected: [] + description: | Given a binary tree `root` and an integer `target`, delete all the **leaf nodes** with value `target`. diff --git a/backend/data/questions/delete-node-in-a-bst.yaml b/backend/data/questions/delete-node-in-a-bst.yaml index b00d31c..f0865f1 100644 --- a/backend/data/questions/delete-node-in-a-bst.yaml +++ b/backend/data/questions/delete-node-in-a-bst.yaml @@ -9,6 +9,30 @@ patterns: - tree-traversal - dfs +function_signature: "def delete_node(root: TreeNode | None, key: int) -> TreeNode | None:" + +test_cases: + visible: + - input: { root: [5, 3, 6, 2, 4, null, 7], key: 3 } + expected: [5, 4, 6, 2, null, null, 7] + - input: { root: [5, 3, 6, 2, 4, null, 7], key: 0 } + expected: [5, 3, 6, 2, 4, null, 7] + - input: { root: [], key: 0 } + expected: [] + hidden: + - input: { root: [5], key: 5 } + expected: [] + - input: { root: [5, 3, 7], key: 5 } + expected: [7, 3] + - input: { root: [5, 3, 7, 2, 4, 6, 8], key: 3 } + expected: [5, 4, 7, 2, null, 6, 8] + - input: { root: [5, 3, 7, 2, 4, 6, 8], key: 7 } + expected: [5, 3, 8, 2, 4, 6] + - input: { root: [2, 1, 3], key: 1 } + expected: [2, null, 3] + - input: { root: [50, 30, 70, 20, 40, 60, 80], key: 50 } + expected: [60, 30, 70, 20, 40, null, 80] + description: | Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return *the **root node reference** (possibly updated) of the BST*. diff --git a/backend/data/questions/design-add-and-search-words-data-structure.yaml b/backend/data/questions/design-add-and-search-words-data-structure.yaml index 8bfae23..da17060 100644 --- a/backend/data/questions/design-add-and-search-words-data-structure.yaml +++ b/backend/data/questions/design-add-and-search-words-data-structure.yaml @@ -10,6 +10,40 @@ patterns: - trie - dfs +function_signature: "class WordDictionary: ..." + +test_cases: + visible: + - input: + operations: ["WordDictionary", "addWord", "addWord", "addWord", "search", "search", "search", "search"] + arguments: [[], ["bad"], ["dad"], ["mad"], ["pad"], ["bad"], [".ad"], ["b.."]] + expected: [null, null, null, null, false, true, true, true] + hidden: + - input: + operations: ["WordDictionary", "addWord", "search", "search"] + arguments: [[], ["a"], ["a"], ["."]] + expected: [null, null, true, true] + - input: + operations: ["WordDictionary", "addWord", "addWord", "search", "search", "search"] + arguments: [[], ["apple"], ["app"], ["app"], ["apple"], ["appl"]] + expected: [null, null, null, true, true, false] + - input: + operations: ["WordDictionary", "search"] + arguments: [[], ["a"]] + expected: [null, false] + - input: + operations: ["WordDictionary", "addWord", "addWord", "search", "search"] + arguments: [[], ["at"], ["and"], ["a"], [".at"]] + expected: [null, null, null, false, false] + - input: + operations: ["WordDictionary", "addWord", "addWord", "addWord", "search", "search", "search"] + arguments: [[], ["abc"], ["adc"], ["aec"], ["a.c"], ["..c"], ["..."]] + expected: [null, null, null, null, true, true, true] + - input: + operations: ["WordDictionary", "addWord", "search", "search", "search"] + arguments: [[], ["ab"], ["a."], [".b"], [".."]] + expected: [null, null, true, true, true] + description: | Design a data structure that supports adding new words and finding if a string matches any previously added string. diff --git a/backend/data/questions/design-circular-queue.yaml b/backend/data/questions/design-circular-queue.yaml index da94066..2f6f9c5 100644 --- a/backend/data/questions/design-circular-queue.yaml +++ b/backend/data/questions/design-circular-queue.yaml @@ -9,6 +9,40 @@ categories: patterns: - two-pointers +function_signature: "class MyCircularQueue: ..." + +test_cases: + visible: + - input: + operations: ["MyCircularQueue", "enQueue", "enQueue", "enQueue", "enQueue", "Rear", "isFull", "deQueue", "enQueue", "Rear"] + arguments: [[3], [1], [2], [3], [4], [], [], [], [4], []] + expected: [null, true, true, true, false, 3, true, true, true, 4] + hidden: + - input: + operations: ["MyCircularQueue", "isEmpty", "enQueue", "isEmpty", "Front", "deQueue", "isEmpty"] + arguments: [[1], [], [5], [], [], [], []] + expected: [null, true, true, false, 5, true, true] + - input: + operations: ["MyCircularQueue", "enQueue", "enQueue", "Front", "Rear", "deQueue", "Front"] + arguments: [[2], [1], [2], [], [], [], []] + expected: [null, true, true, 1, 2, true, 2] + - input: + operations: ["MyCircularQueue", "deQueue", "Front", "Rear"] + arguments: [[3], [], [], []] + expected: [null, false, -1, -1] + - input: + operations: ["MyCircularQueue", "enQueue", "enQueue", "enQueue", "deQueue", "enQueue", "Front", "Rear"] + arguments: [[3], [1], [2], [3], [], [4], [], []] + expected: [null, true, true, true, true, true, 2, 4] + - input: + operations: ["MyCircularQueue", "enQueue", "deQueue", "enQueue", "deQueue", "enQueue", "Front", "Rear"] + arguments: [[1], [10], [], [20], [], [30], [], []] + expected: [null, true, true, true, true, true, 30, 30] + - input: + operations: ["MyCircularQueue", "isFull", "enQueue", "enQueue", "isFull", "enQueue", "isFull"] + arguments: [[2], [], [1], [2], [], [3], []] + expected: [null, false, true, true, true, false, true] + description: | Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle, and the last position is connected back to the first position to make a circle. It is also called "Ring Buffer". diff --git a/backend/data/questions/design-hashmap.yaml b/backend/data/questions/design-hashmap.yaml index 13cde2f..92fccea 100644 --- a/backend/data/questions/design-hashmap.yaml +++ b/backend/data/questions/design-hashmap.yaml @@ -10,6 +10,40 @@ categories: patterns: - heap +function_signature: "class MyHashMap: ..." + +test_cases: + visible: + - input: + operations: ["MyHashMap", "put", "put", "get", "get", "put", "get", "remove", "get"] + arguments: [[], [1, 1], [2, 2], [1], [3], [2, 1], [2], [2], [2]] + expected: [null, null, null, 1, -1, null, 1, null, -1] + hidden: + - input: + operations: ["MyHashMap", "get", "remove"] + arguments: [[], [5], [5]] + expected: [null, -1, null] + - input: + operations: ["MyHashMap", "put", "put", "get", "get"] + arguments: [[], [1, 100], [1001, 200], [1], [1001]] + expected: [null, null, null, 100, 200] + - input: + operations: ["MyHashMap", "put", "get", "put", "get"] + arguments: [[], [10, 5], [10], [10, 15], [10]] + expected: [null, null, 5, null, 15] + - input: + operations: ["MyHashMap", "put", "put", "put", "remove", "get", "get"] + arguments: [[], [1, 1], [2, 2], [3, 3], [2], [2], [3]] + expected: [null, null, null, null, null, -1, 3] + - input: + operations: ["MyHashMap", "put", "put", "put", "get", "get", "get"] + arguments: [[], [0, 0], [500000, 500], [1000000, 1000], [0], [500000], [1000000]] + expected: [null, null, null, null, 0, 500, 1000] + - input: + operations: ["MyHashMap", "put", "remove", "put", "get"] + arguments: [[], [5, 10], [5], [5, 20], [5]] + expected: [null, null, null, null, 20] + description: | Design a HashMap without using any built-in hash table libraries. diff --git a/backend/data/questions/design-hashset.yaml b/backend/data/questions/design-hashset.yaml index 32c4f86..92ae401 100644 --- a/backend/data/questions/design-hashset.yaml +++ b/backend/data/questions/design-hashset.yaml @@ -9,6 +9,26 @@ categories: patterns: - heap +function_signature: "class MyHashSet:\n def __init__(self): ...\n def add(self, key: int) -> None: ...\n def remove(self, key: int) -> None: ...\n def contains(self, key: int) -> bool: ..." + +test_cases: + visible: + - input: { operations: ["MyHashSet", "add", "add", "contains", "contains", "add", "contains", "remove", "contains"], arguments: [[], [1], [2], [1], [3], [2], [2], [2], [2]] } + expected: [null, null, null, true, false, null, true, null, false] + - input: { operations: ["MyHashSet", "add", "contains", "remove", "contains"], arguments: [[], [5], [5], [5], [5]] } + expected: [null, null, true, null, false] + hidden: + - input: { operations: ["MyHashSet", "contains"], arguments: [[], [0]] } + expected: [null, false] + - input: { operations: ["MyHashSet", "add", "add", "add", "contains", "contains", "contains"], arguments: [[], [0], [1000000], [500000], [0], [1000000], [500000]] } + expected: [null, null, null, null, true, true, true] + - input: { operations: ["MyHashSet", "add", "add", "remove", "add", "contains"], arguments: [[], [1], [1], [1], [1], [1]] } + expected: [null, null, null, null, null, true] + - input: { operations: ["MyHashSet", "remove", "contains"], arguments: [[], [100], [100]] } + expected: [null, null, false] + - input: { operations: ["MyHashSet", "add", "add", "add", "remove", "remove", "contains", "contains"], arguments: [[], [769], [1538], [2307], [769], [1538], [769], [2307]] } + expected: [null, null, null, null, null, null, false, true] + description: | Design a HashSet without using any built-in hash table libraries. diff --git a/backend/data/questions/design-twitter.yaml b/backend/data/questions/design-twitter.yaml index cf502cc..85be422 100644 --- a/backend/data/questions/design-twitter.yaml +++ b/backend/data/questions/design-twitter.yaml @@ -9,6 +9,26 @@ categories: patterns: - heap +function_signature: "class Twitter:\n def __init__(self): ...\n def post_tweet(self, user_id: int, tweet_id: int) -> None: ...\n def get_news_feed(self, user_id: int) -> list[int]: ...\n def follow(self, follower_id: int, followee_id: int) -> None: ...\n def unfollow(self, follower_id: int, followee_id: int) -> None: ..." + +test_cases: + visible: + - input: { operations: ["Twitter", "postTweet", "getNewsFeed", "follow", "postTweet", "getNewsFeed", "unfollow", "getNewsFeed"], arguments: [[], [1, 5], [1], [1, 2], [2, 6], [1], [1, 2], [1]] } + expected: [null, null, [5], null, null, [6, 5], null, [5]] + - input: { operations: ["Twitter", "postTweet", "postTweet", "getNewsFeed"], arguments: [[], [1, 1], [1, 2], [1]] } + expected: [null, null, null, [2, 1]] + hidden: + - input: { operations: ["Twitter", "getNewsFeed"], arguments: [[], [1]] } + expected: [null, []] + - input: { operations: ["Twitter", "follow", "getNewsFeed"], arguments: [[], [1, 2], [1]] } + expected: [null, null, []] + - input: { operations: ["Twitter", "postTweet", "postTweet", "postTweet", "postTweet", "postTweet", "postTweet", "postTweet", "postTweet", "postTweet", "postTweet", "postTweet", "getNewsFeed"], arguments: [[], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1]] } + expected: [null, null, null, null, null, null, null, null, null, null, null, null, [11, 10, 9, 8, 7, 6, 5, 4, 3, 2]] + - input: { operations: ["Twitter", "postTweet", "follow", "follow", "unfollow", "getNewsFeed"], arguments: [[], [2, 5], [1, 2], [1, 2], [1, 2], [1]] } + expected: [null, null, null, null, null, []] + - input: { operations: ["Twitter", "postTweet", "postTweet", "follow", "getNewsFeed"], arguments: [[], [1, 1], [2, 2], [1, 2], [1]] } + expected: [null, null, null, null, [2, 1]] + description: | Design a simplified version of Twitter where users can post tweets, follow/unfollow another user, and is able to see the `10` most recent tweets in the user's news feed. diff --git a/backend/data/questions/detect-squares.yaml b/backend/data/questions/detect-squares.yaml index d920249..bc07743 100644 --- a/backend/data/questions/detect-squares.yaml +++ b/backend/data/questions/detect-squares.yaml @@ -9,6 +9,26 @@ categories: patterns: - heap +function_signature: "class DetectSquares:\n def __init__(self): ...\n def add(self, point: list[int]) -> None: ...\n def count(self, point: list[int]) -> int: ..." + +test_cases: + visible: + - input: { operations: ["DetectSquares", "add", "add", "add", "count", "count", "add", "count"], arguments: [[], [[3, 10]], [[11, 2]], [[3, 2]], [[11, 10]], [[14, 8]], [[11, 2]], [[11, 10]]] } + expected: [null, null, null, null, 1, 0, null, 2] + - input: { operations: ["DetectSquares", "add", "add", "add", "add", "count"], arguments: [[], [[0, 0]], [[0, 1]], [[1, 0]], [[1, 1]], [[0, 0]]] } + expected: [null, null, null, null, null, 1] + hidden: + - input: { operations: ["DetectSquares", "count"], arguments: [[], [[5, 5]]] } + expected: [null, 0] + - input: { operations: ["DetectSquares", "add", "count"], arguments: [[], [[0, 0]], [[0, 0]]] } + expected: [null, null, 0] + - input: { operations: ["DetectSquares", "add", "add", "add", "add", "add", "add", "add", "add", "count"], arguments: [[], [[0, 0]], [[0, 2]], [[2, 0]], [[2, 2]], [[0, 0]], [[0, 2]], [[2, 0]], [[2, 2]], [[0, 0]]] } + expected: [null, null, null, null, null, null, null, null, null, 4] + - input: { operations: ["DetectSquares", "add", "add", "add", "add", "count", "count"], arguments: [[], [[0, 0]], [[0, 5]], [[5, 0]], [[5, 5]], [[0, 0]], [[2, 2]]] } + expected: [null, null, null, null, null, 1, 0] + - input: { operations: ["DetectSquares", "add", "add", "add", "add", "add", "add", "count"], arguments: [[], [[0, 0]], [[0, 3]], [[3, 0]], [[3, 3]], [[0, 1]], [[1, 0]], [[1, 1]]] } + expected: [null, null, null, null, null, null, null, 0] + description: | You are given a stream of points on the X-Y plane. Design an algorithm that: diff --git a/backend/data/questions/distinct-subsequences.yaml b/backend/data/questions/distinct-subsequences.yaml index 295da7d..8eee310 100644 --- a/backend/data/questions/distinct-subsequences.yaml +++ b/backend/data/questions/distinct-subsequences.yaml @@ -9,6 +9,30 @@ categories: patterns: - dynamic-programming +function_signature: "def num_distinct(s: str, t: str) -> int:" + +test_cases: + visible: + - input: { s: "rabbbit", t: "rabbit" } + expected: 3 + - input: { s: "babgbag", t: "bag" } + expected: 5 + hidden: + - input: { s: "a", t: "a" } + expected: 1 + - input: { s: "a", t: "b" } + expected: 0 + - input: { s: "aaa", t: "a" } + expected: 3 + - input: { s: "aaa", t: "aa" } + expected: 3 + - input: { s: "aaa", t: "aaa" } + expected: 1 + - input: { s: "abc", t: "def" } + expected: 0 + - input: { s: "abcde", t: "" } + expected: 1 + description: | Given two strings `s` and `t`, return *the number of distinct **subsequences** of* `s` *which equals* `t`. diff --git a/backend/data/questions/dota2-senate.yaml b/backend/data/questions/dota2-senate.yaml index c5d75dc..c221c2c 100644 --- a/backend/data/questions/dota2-senate.yaml +++ b/backend/data/questions/dota2-senate.yaml @@ -9,6 +9,30 @@ categories: patterns: - greedy +function_signature: "def predict_party_victory(senate: str) -> str:" + +test_cases: + visible: + - input: { senate: "RD" } + expected: "Radiant" + - input: { senate: "RDD" } + expected: "Dire" + hidden: + - input: { senate: "R" } + expected: "Radiant" + - input: { senate: "D" } + expected: "Dire" + - input: { senate: "RRDD" } + expected: "Radiant" + - input: { senate: "DRRD" } + expected: "Dire" + - input: { senate: "RRDDD" } + expected: "Dire" + - input: { senate: "DDRRRR" } + expected: "Radiant" + - input: { senate: "RDRDRD" } + expected: "Radiant" + description: | In the world of Dota2, there are two parties: the **Radiant** and the **Dire**. diff --git a/backend/data/questions/evaluate-division.yaml b/backend/data/questions/evaluate-division.yaml index 7ef6c12..9b71b2c 100644 --- a/backend/data/questions/evaluate-division.yaml +++ b/backend/data/questions/evaluate-division.yaml @@ -11,6 +11,28 @@ patterns: - dfs - union-find +function_signature: "def calc_equation(equations: list[list[str]], values: list[float], queries: list[list[str]]) -> list[float]:" + +test_cases: + visible: + - input: { equations: [["a", "b"], ["b", "c"]], values: [2.0, 3.0], queries: [["a", "c"], ["b", "a"], ["a", "e"], ["a", "a"], ["x", "x"]] } + expected: [6.0, 0.5, -1.0, 1.0, -1.0] + - input: { equations: [["a", "b"], ["b", "c"], ["bc", "cd"]], values: [1.5, 2.5, 5.0], queries: [["a", "c"], ["c", "b"], ["bc", "cd"], ["cd", "bc"]] } + expected: [3.75, 0.4, 5.0, 0.2] + - input: { equations: [["a", "b"]], values: [0.5], queries: [["a", "b"], ["b", "a"], ["a", "c"], ["x", "y"]] } + expected: [0.5, 2.0, -1.0, -1.0] + hidden: + - input: { equations: [["a", "b"]], values: [2.0], queries: [["a", "a"], ["b", "b"]] } + expected: [1.0, 1.0] + - input: { equations: [], values: [], queries: [["a", "b"]] } + expected: [-1.0] + - input: { equations: [["a", "b"], ["c", "d"]], values: [2.0, 3.0], queries: [["a", "d"], ["c", "b"]] } + expected: [-1.0, -1.0] + - input: { equations: [["a", "b"], ["b", "c"], ["c", "d"]], values: [2.0, 3.0, 4.0], queries: [["a", "d"], ["d", "a"]] } + expected: [24.0, 0.041666666666666664] + - input: { equations: [["x", "y"]], values: [1.0], queries: [["x", "y"], ["y", "x"]] } + expected: [1.0, 1.0] + description: | You are given an array of variable pairs `equations` and an array of real numbers `values`, where `equations[i] = [A_i, B_i]` and `values[i]` represent the equation `A_i / B_i = values[i]`. Each `A_i` or `B_i` is a string that represents a single variable. diff --git a/backend/data/questions/find-in-mountain-array.yaml b/backend/data/questions/find-in-mountain-array.yaml index a07036e..c3ff184 100644 --- a/backend/data/questions/find-in-mountain-array.yaml +++ b/backend/data/questions/find-in-mountain-array.yaml @@ -9,6 +9,30 @@ categories: patterns: - binary-search +function_signature: "def find_in_mountain_array(target: int, mountain_arr: MountainArray) -> int:" + +test_cases: + visible: + - input: { mountain_arr: [1, 2, 3, 4, 5, 3, 1], target: 3 } + expected: 2 + - input: { mountain_arr: [0, 1, 2, 4, 2, 1], target: 3 } + expected: -1 + hidden: + - input: { mountain_arr: [1, 2, 3, 4, 5, 3, 1], target: 1 } + expected: 0 + - input: { mountain_arr: [1, 2, 3, 4, 5, 3, 1], target: 5 } + expected: 4 + - input: { mountain_arr: [1, 5, 2], target: 2 } + expected: 2 + - input: { mountain_arr: [1, 5, 2], target: 1 } + expected: 0 + - input: { mountain_arr: [1, 5, 2], target: 5 } + expected: 1 + - input: { mountain_arr: [1, 2, 3, 4, 3, 2, 1], target: 0 } + expected: -1 + - input: { mountain_arr: [0, 5, 3, 1], target: 0 } + expected: 0 + description: | *(This problem is an **interactive problem**.)* diff --git a/backend/data/questions/find-k-closest-elements.yaml b/backend/data/questions/find-k-closest-elements.yaml index 9a7be66..dc159fa 100644 --- a/backend/data/questions/find-k-closest-elements.yaml +++ b/backend/data/questions/find-k-closest-elements.yaml @@ -11,6 +11,28 @@ patterns: - binary-search - two-pointers +function_signature: "def find_closest_elements(arr: list[int], k: int, x: int) -> list[int]:" + +test_cases: + visible: + - input: { arr: [1, 2, 3, 4, 5], k: 4, x: 3 } + expected: [1, 2, 3, 4] + - input: { arr: [1, 1, 2, 3, 4, 5], k: 4, x: -1 } + expected: [1, 1, 2, 3] + hidden: + - input: { arr: [1], k: 1, x: 1 } + expected: [1] + - input: { arr: [1, 2, 3, 4, 5], k: 4, x: -1 } + expected: [1, 2, 3, 4] + - input: { arr: [1, 2, 3, 4, 5], k: 4, x: 10 } + expected: [2, 3, 4, 5] + - input: { arr: [1, 2, 3, 4, 5], k: 5, x: 3 } + expected: [1, 2, 3, 4, 5] + - input: { arr: [1, 1, 1, 10, 10, 10], k: 1, x: 9 } + expected: [10] + - input: { arr: [-2, -1, 1, 2, 3, 4, 5], k: 3, x: 0 } + expected: [-1, 1, 2] + description: | Given a **sorted** integer array `arr`, two integers `k` and `x`, return the `k` closest integers to `x` in the array. The result should also be sorted in ascending order. diff --git a/backend/data/questions/find-median-from-data-stream.yaml b/backend/data/questions/find-median-from-data-stream.yaml index 3f3ec61..5aa9fad 100644 --- a/backend/data/questions/find-median-from-data-stream.yaml +++ b/backend/data/questions/find-median-from-data-stream.yaml @@ -9,6 +9,26 @@ categories: patterns: - heap +function_signature: "class MedianFinder:\n def __init__(self): ...\n def add_num(self, num: int) -> None: ...\n def find_median(self) -> float: ..." + +test_cases: + visible: + - input: { operations: ["MedianFinder", "addNum", "addNum", "findMedian", "addNum", "findMedian"], arguments: [[], [1], [2], [], [3], []] } + expected: [null, null, null, 1.5, null, 2.0] + - input: { operations: ["MedianFinder", "addNum", "findMedian"], arguments: [[], [5], []] } + expected: [null, null, 5.0] + hidden: + - input: { operations: ["MedianFinder", "addNum", "addNum", "addNum", "addNum", "addNum", "findMedian"], arguments: [[], [1], [2], [3], [4], [5], []] } + expected: [null, null, null, null, null, null, 3.0] + - input: { operations: ["MedianFinder", "addNum", "addNum", "findMedian"], arguments: [[], [-1], [-2], []] } + expected: [null, null, null, -1.5] + - input: { operations: ["MedianFinder", "addNum", "addNum", "addNum", "addNum", "findMedian"], arguments: [[], [1], [1], [1], [1], []] } + expected: [null, null, null, null, null, 1.0] + - input: { operations: ["MedianFinder", "addNum", "findMedian", "addNum", "findMedian", "addNum", "findMedian"], arguments: [[], [6], [], [10], [], [2], []] } + expected: [null, null, 6.0, null, 8.0, null, 6.0] + - input: { operations: ["MedianFinder", "addNum", "addNum", "addNum", "findMedian"], arguments: [[], [-100000], [100000], [0], []] } + expected: [null, null, null, null, 0.0] + description: | The **median** is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values. diff --git a/backend/data/questions/find-the-town-judge.yaml b/backend/data/questions/find-the-town-judge.yaml index d88744d..a28768c 100644 --- a/backend/data/questions/find-the-town-judge.yaml +++ b/backend/data/questions/find-the-town-judge.yaml @@ -10,6 +10,28 @@ categories: patterns: - greedy +function_signature: "def find_judge(n: int, trust: list[list[int]]) -> int:" + +test_cases: + visible: + - input: { n: 2, trust: [[1, 2]] } + expected: 2 + - input: { n: 3, trust: [[1, 3], [2, 3]] } + expected: 3 + - input: { n: 3, trust: [[1, 3], [2, 3], [3, 1]] } + expected: -1 + hidden: + - input: { n: 1, trust: [] } + expected: 1 + - input: { n: 2, trust: [] } + expected: -1 + - input: { n: 4, trust: [[1, 3], [1, 4], [2, 3], [2, 4], [4, 3]] } + expected: 3 + - input: { n: 3, trust: [[1, 2], [2, 3]] } + expected: -1 + - input: { n: 4, trust: [[1, 2], [1, 3], [2, 1], [2, 3], [1, 4], [4, 3], [4, 1]] } + expected: 3 + description: | In a town, there are `n` people labeled from `1` to `n`. There is a rumor that one of these people is secretly the town judge. diff --git a/backend/data/questions/first-missing-positive.yaml b/backend/data/questions/first-missing-positive.yaml index 9ab24d4..e4a049a 100644 --- a/backend/data/questions/first-missing-positive.yaml +++ b/backend/data/questions/first-missing-positive.yaml @@ -9,6 +9,32 @@ categories: patterns: - matrix-traversal +function_signature: "def first_missing_positive(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [1, 2, 0] } + expected: 3 + - input: { nums: [3, 4, -1, 1] } + expected: 2 + - input: { nums: [7, 8, 9, 11, 12] } + expected: 1 + hidden: + - input: { nums: [1] } + expected: 2 + - input: { nums: [2] } + expected: 1 + - input: { nums: [1, 2, 3, 4, 5] } + expected: 6 + - input: { nums: [-1, -2, -3] } + expected: 1 + - input: { nums: [0, 0, 0] } + expected: 1 + - input: { nums: [1, 1, 1, 1] } + expected: 2 + - input: { nums: [2, 1] } + expected: 3 + description: | Given an unsorted integer array `nums`, return the *smallest positive integer* that is *not present* in `nums`. diff --git a/backend/data/questions/greatest-common-divisor-of-strings.yaml b/backend/data/questions/greatest-common-divisor-of-strings.yaml index acdf17a..a597837 100644 --- a/backend/data/questions/greatest-common-divisor-of-strings.yaml +++ b/backend/data/questions/greatest-common-divisor-of-strings.yaml @@ -9,6 +9,30 @@ categories: patterns: - greedy +function_signature: "def gcd_of_strings(str1: str, str2: str) -> str:" + +test_cases: + visible: + - input: { str1: "ABCABC", str2: "ABC" } + expected: "ABC" + - input: { str1: "ABABAB", str2: "ABAB" } + expected: "AB" + - input: { str1: "LEET", str2: "CODE" } + expected: "" + hidden: + - input: { str1: "A", str2: "A" } + expected: "A" + - input: { str1: "AAAAAA", str2: "AAA" } + expected: "AAA" + - input: { str1: "ABAB", str2: "AB" } + expected: "AB" + - input: { str1: "AB", str2: "BA" } + expected: "" + - input: { str1: "TAUXXTAUXXTAUXXTAUXXTAUXX", str2: "TAUXXTAUXXTAUXXTAUXXTAUXXTAUXX" } + expected: "TAUXX" + - input: { str1: "ABCDEF", str2: "ABC" } + expected: "" + description: | For two strings `s` and `t`, we say "`t` divides `s`" if and only if `s = t + t + t + ... + t` (i.e., `t` is concatenated with itself one or more times). diff --git a/backend/data/questions/guess-number-higher-or-lower.yaml b/backend/data/questions/guess-number-higher-or-lower.yaml index efb92de..24e9dc0 100644 --- a/backend/data/questions/guess-number-higher-or-lower.yaml +++ b/backend/data/questions/guess-number-higher-or-lower.yaml @@ -8,6 +8,30 @@ categories: patterns: - binary-search +function_signature: "def guess_number(n: int) -> int:" + +test_cases: + visible: + - input: { n: 10, pick: 6 } + expected: 6 + - input: { n: 1, pick: 1 } + expected: 1 + - input: { n: 2, pick: 1 } + expected: 1 + hidden: + - input: { n: 2, pick: 2 } + expected: 2 + - input: { n: 100, pick: 50 } + expected: 50 + - input: { n: 100, pick: 1 } + expected: 1 + - input: { n: 100, pick: 100 } + expected: 100 + - input: { n: 1000000, pick: 999999 } + expected: 999999 + - input: { n: 50, pick: 25 } + expected: 25 + description: | We are playing the Guess Game. The game is as follows: diff --git a/backend/data/questions/hand-of-straights.yaml b/backend/data/questions/hand-of-straights.yaml index f599e78..056c43e 100644 --- a/backend/data/questions/hand-of-straights.yaml +++ b/backend/data/questions/hand-of-straights.yaml @@ -11,6 +11,30 @@ patterns: - greedy - heap +function_signature: "def is_n_straight_hand(hand: list[int], group_size: int) -> bool:" + +test_cases: + visible: + - input: { hand: [1, 2, 3, 6, 2, 3, 4, 7, 8], group_size: 3 } + expected: true + - input: { hand: [1, 2, 3, 4, 5], group_size: 4 } + expected: false + hidden: + - input: { hand: [1], group_size: 1 } + expected: true + - input: { hand: [1, 2, 3], group_size: 1 } + expected: true + - input: { hand: [1, 2, 3], group_size: 3 } + expected: true + - input: { hand: [1, 2, 4], group_size: 3 } + expected: false + - input: { hand: [1, 1, 2, 2, 3, 3], group_size: 3 } + expected: true + - input: { hand: [1, 2, 3, 4, 5, 6], group_size: 2 } + expected: false + - input: { hand: [8, 10, 12], group_size: 3 } + expected: false + description: | Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size `groupSize`, and consists of `groupSize` consecutive cards. diff --git a/backend/data/questions/house-robber-ii.yaml b/backend/data/questions/house-robber-ii.yaml index 2e7bc57..549670c 100644 --- a/backend/data/questions/house-robber-ii.yaml +++ b/backend/data/questions/house-robber-ii.yaml @@ -9,6 +9,32 @@ categories: patterns: - dynamic-programming +function_signature: "def rob(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [2, 3, 2] } + expected: 3 + - input: { nums: [1, 2, 3, 1] } + expected: 4 + - input: { nums: [1, 2, 3] } + expected: 3 + hidden: + - input: { nums: [1] } + expected: 1 + - input: { nums: [1, 2] } + expected: 2 + - input: { nums: [0, 0, 0, 0] } + expected: 0 + - input: { nums: [200, 3, 140, 20, 10] } + expected: 340 + - input: { nums: [1, 3, 1, 3, 100] } + expected: 103 + - input: { nums: [1, 1, 1, 1, 1, 1, 1] } + expected: 3 + - input: { nums: [100, 1, 1, 100] } + expected: 101 + description: | You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are **arranged in a circle**. That means the first house is the neighbour of the last one. Meanwhile, adjacent houses have a security system connected, and **it will automatically contact the police if two adjacent houses were broken into on the same night**. diff --git a/backend/data/questions/house-robber-iii.yaml b/backend/data/questions/house-robber-iii.yaml index abcb67e..86dd0d8 100644 --- a/backend/data/questions/house-robber-iii.yaml +++ b/backend/data/questions/house-robber-iii.yaml @@ -10,6 +10,28 @@ patterns: - dfs - dynamic-programming +function_signature: "def rob(root: TreeNode) -> int:" + +test_cases: + visible: + - input: { root: [3, 2, 3, null, 3, null, 1] } + expected: 7 + - input: { root: [3, 4, 5, 1, 3, null, 1] } + expected: 9 + hidden: + - input: { root: [1] } + expected: 1 + - input: { root: [1, 2, 3] } + expected: 5 + - input: { root: [4, 1, null, 2, null, 3] } + expected: 7 + - input: { root: [2, 1, 3, null, 4] } + expected: 7 + - input: { root: [0, 0, 0, 0, 0] } + expected: 0 + - input: { root: [1, null, 2, null, 3, null, 4] } + expected: 6 + description: | The thief has found himself a new place for his thievery again. There is only one entrance to this area, called `root`. diff --git a/backend/data/questions/implement-queue-using-stacks.yaml b/backend/data/questions/implement-queue-using-stacks.yaml index 8574421..f864207 100644 --- a/backend/data/questions/implement-queue-using-stacks.yaml +++ b/backend/data/questions/implement-queue-using-stacks.yaml @@ -9,6 +9,24 @@ categories: patterns: - monotonic-stack +function_signature: "class MyQueue" + +test_cases: + visible: + - input: { operations: ["MyQueue", "push", "push", "peek", "pop", "empty"], arguments: [[], [1], [2], [], [], []] } + expected: [null, null, null, 1, 1, false] + hidden: + - input: { operations: ["MyQueue", "push", "peek"], arguments: [[], [5], []] } + expected: [null, null, 5] + - input: { operations: ["MyQueue", "push", "push", "push", "pop", "pop", "pop"], arguments: [[], [1], [2], [3], [], [], []] } + expected: [null, null, null, null, 1, 2, 3] + - input: { operations: ["MyQueue", "push", "pop", "push", "pop"], arguments: [[], [1], [], [2], []] } + expected: [null, null, 1, null, 2] + - input: { operations: ["MyQueue", "empty"], arguments: [[], []] } + expected: [null, true] + - input: { operations: ["MyQueue", "push", "push", "pop", "push", "peek"], arguments: [[], [1], [2], [], [3], []] } + expected: [null, null, null, 1, null, 2] + description: | Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (`push`, `peek`, `pop`, and `empty`). diff --git a/backend/data/questions/implement-stack-using-queues.yaml b/backend/data/questions/implement-stack-using-queues.yaml index 15a9b81..0512908 100644 --- a/backend/data/questions/implement-stack-using-queues.yaml +++ b/backend/data/questions/implement-stack-using-queues.yaml @@ -9,6 +9,24 @@ categories: patterns: - monotonic-stack +function_signature: "class MyStack" + +test_cases: + visible: + - input: { operations: ["MyStack", "push", "push", "top", "pop", "empty"], arguments: [[], [1], [2], [], [], []] } + expected: [null, null, null, 2, 2, false] + hidden: + - input: { operations: ["MyStack", "push", "top"], arguments: [[], [5], []] } + expected: [null, null, 5] + - input: { operations: ["MyStack", "push", "push", "push", "pop", "pop", "pop"], arguments: [[], [1], [2], [3], [], [], []] } + expected: [null, null, null, null, 3, 2, 1] + - input: { operations: ["MyStack", "push", "pop", "push", "pop"], arguments: [[], [1], [], [2], []] } + expected: [null, null, 1, null, 2] + - input: { operations: ["MyStack", "empty"], arguments: [[], []] } + expected: [null, true] + - input: { operations: ["MyStack", "push", "push", "pop", "push", "top"], arguments: [[], [1], [2], [], [3], []] } + expected: [null, null, null, 2, null, 3] + description: | Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (`push`, `top`, `pop`, and `empty`). diff --git a/backend/data/questions/implement-trie-prefix-tree.yaml b/backend/data/questions/implement-trie-prefix-tree.yaml index 66db4ba..eca93ee 100644 --- a/backend/data/questions/implement-trie-prefix-tree.yaml +++ b/backend/data/questions/implement-trie-prefix-tree.yaml @@ -9,6 +9,26 @@ categories: patterns: - trie +function_signature: "class Trie" + +test_cases: + visible: + - input: { operations: ["Trie", "insert", "search", "search", "startsWith", "insert", "search"], arguments: [[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]] } + expected: [null, null, true, false, true, null, true] + hidden: + - input: { operations: ["Trie", "insert", "search"], arguments: [[], ["hello"], ["hello"]] } + expected: [null, null, true] + - input: { operations: ["Trie", "search"], arguments: [[], ["nonexistent"]] } + expected: [null, false] + - input: { operations: ["Trie", "insert", "insert", "search", "search"], arguments: [[], ["abc"], ["ab"], ["abc"], ["ab"]] } + expected: [null, null, null, true, true] + - input: { operations: ["Trie", "insert", "startsWith", "startsWith"], arguments: [[], ["prefix"], ["pre"], ["pref"]] } + expected: [null, null, true, true] + - input: { operations: ["Trie", "insert", "startsWith"], arguments: [[], ["a"], ["b"]] } + expected: [null, null, false] + - input: { operations: ["Trie", "insert", "insert", "search", "startsWith"], arguments: [[], ["app"], ["apple"], ["ap"], ["ap"]] } + expected: [null, null, null, false, true] + description: | A [**trie**](https://en.wikipedia.org/wiki/Trie) (pronounced as "try") or **prefix tree** is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker. diff --git a/backend/data/questions/insert-into-a-binary-search-tree.yaml b/backend/data/questions/insert-into-a-binary-search-tree.yaml index caf864c..540210a 100644 --- a/backend/data/questions/insert-into-a-binary-search-tree.yaml +++ b/backend/data/questions/insert-into-a-binary-search-tree.yaml @@ -8,6 +8,28 @@ categories: patterns: - tree-traversal +function_signature: "def insert_into_bst(root: TreeNode, val: int) -> TreeNode:" + +test_cases: + visible: + - input: { root: [4, 2, 7, 1, 3], val: 5 } + expected: [4, 2, 7, 1, 3, 5] + - input: { root: [40, 20, 60, 10, 30, 50, 70], val: 25 } + expected: [40, 20, 60, 10, 30, 50, 70, null, null, 25] + hidden: + - input: { root: [], val: 5 } + expected: [5] + - input: { root: [1], val: 2 } + expected: [1, null, 2] + - input: { root: [2], val: 1 } + expected: [2, 1] + - input: { root: [5, 3, 7], val: 2 } + expected: [5, 3, 7, 2] + - input: { root: [5, 3, 7], val: 8 } + expected: [5, 3, 7, null, null, null, 8] + - input: { root: [10, 5, 15, 3, 7], val: 6 } + expected: [10, 5, 15, 3, 7, null, null, null, null, 6] + description: | You are given the `root` node of a binary search tree (BST) and a `val` to insert into the tree. Return *the root node of the BST after the insertion*. It is **guaranteed** that the new value does not exist in the original BST. diff --git a/backend/data/questions/interleaving-string.yaml b/backend/data/questions/interleaving-string.yaml index 497c6bf..cda3e1c 100644 --- a/backend/data/questions/interleaving-string.yaml +++ b/backend/data/questions/interleaving-string.yaml @@ -9,6 +9,32 @@ categories: patterns: - dynamic-programming +function_signature: "def is_interleave(s1: str, s2: str, s3: str) -> bool:" + +test_cases: + visible: + - input: { s1: "aabcc", s2: "dbbca", s3: "aadbbcbcac" } + expected: true + - input: { s1: "aabcc", s2: "dbbca", s3: "aadbbbaccc" } + expected: false + - input: { s1: "", s2: "", s3: "" } + expected: true + hidden: + - input: { s1: "a", s2: "b", s3: "ab" } + expected: true + - input: { s1: "a", s2: "b", s3: "ba" } + expected: true + - input: { s1: "abc", s2: "def", s3: "abcdef" } + expected: true + - input: { s1: "", s2: "abc", s3: "abc" } + expected: true + - input: { s1: "abc", s2: "", s3: "abc" } + expected: true + - input: { s1: "a", s2: "b", s3: "abc" } + expected: false + - input: { s1: "aaa", s2: "aaa", s3: "aaaaaa" } + expected: true + description: | Given strings `s1`, `s2`, and `s3`, find whether `s3` is formed by an **interleaving** of `s1` and `s2`. diff --git a/backend/data/questions/ipo.yaml b/backend/data/questions/ipo.yaml index 2e7f307..bc71c6e 100644 --- a/backend/data/questions/ipo.yaml +++ b/backend/data/questions/ipo.yaml @@ -11,6 +11,28 @@ patterns: - heap - greedy +function_signature: "def find_maximized_capital(k: int, w: int, profits: list[int], capital: list[int]) -> int:" + +test_cases: + visible: + - input: { k: 2, w: 0, profits: [1, 2, 3], capital: [0, 1, 1] } + expected: 4 + - input: { k: 3, w: 0, profits: [1, 2, 3], capital: [0, 1, 2] } + expected: 6 + hidden: + - input: { k: 1, w: 0, profits: [1, 2, 3], capital: [1, 1, 2] } + expected: 0 + - input: { k: 1, w: 2, profits: [1, 2, 3], capital: [1, 1, 2] } + expected: 5 + - input: { k: 10, w: 0, profits: [1, 2, 3], capital: [0, 1, 1] } + expected: 6 + - input: { k: 1, w: 0, profits: [10], capital: [0] } + expected: 10 + - input: { k: 2, w: 5, profits: [1, 1, 1, 1], capital: [0, 0, 0, 0] } + expected: 7 + - input: { k: 3, w: 0, profits: [4, 5, 6], capital: [0, 0, 0] } + expected: 15 + description: | Suppose LeetCode will start its **IPO** soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the **IPO**. Since it has limited resources, it can only finish at most `k` distinct projects before the **IPO**. Help LeetCode design the best way to maximize its total capital after finishing at most `k` distinct projects. diff --git a/backend/data/questions/island-perimeter.yaml b/backend/data/questions/island-perimeter.yaml index 05647c4..639b195 100644 --- a/backend/data/questions/island-perimeter.yaml +++ b/backend/data/questions/island-perimeter.yaml @@ -9,6 +9,30 @@ categories: patterns: - matrix-traversal +function_signature: "def island_perimeter(grid: list[list[int]]) -> int:" + +test_cases: + visible: + - input: { grid: [[0, 1, 0, 0], [1, 1, 1, 0], [0, 1, 0, 0], [1, 1, 0, 0]] } + expected: 16 + - input: { grid: [[1]] } + expected: 4 + - input: { grid: [[1, 0]] } + expected: 4 + hidden: + - input: { grid: [[1, 1]] } + expected: 6 + - input: { grid: [[1], [1]] } + expected: 6 + - input: { grid: [[1, 1], [1, 1]] } + expected: 8 + - input: { grid: [[0, 1, 0], [1, 1, 1], [0, 1, 0]] } + expected: 12 + - input: { grid: [[1, 1, 1, 1, 1]] } + expected: 12 + - input: { grid: [[0, 0, 0], [0, 1, 0], [0, 0, 0]] } + expected: 4 + description: | You are given a `row x col` grid representing a map where `grid[i][j] = 1` represents land and `grid[i][j] = 0` represents water. diff --git a/backend/data/questions/jump-game-vii.yaml b/backend/data/questions/jump-game-vii.yaml index 3aabaae..6113520 100644 --- a/backend/data/questions/jump-game-vii.yaml +++ b/backend/data/questions/jump-game-vii.yaml @@ -11,6 +11,28 @@ patterns: - sliding-window - dynamic-programming +function_signature: "def can_reach(s: str, min_jump: int, max_jump: int) -> bool:" + +test_cases: + visible: + - input: { s: "011010", min_jump: 2, max_jump: 3 } + expected: true + - input: { s: "01101110", min_jump: 2, max_jump: 3 } + expected: false + hidden: + - input: { s: "00", min_jump: 1, max_jump: 1 } + expected: true + - input: { s: "01", min_jump: 1, max_jump: 1 } + expected: false + - input: { s: "0000", min_jump: 1, max_jump: 3 } + expected: true + - input: { s: "00000000", min_jump: 3, max_jump: 5 } + expected: true + - input: { s: "0100000", min_jump: 2, max_jump: 5 } + expected: true + - input: { s: "01111110", min_jump: 1, max_jump: 6 } + expected: false + description: | You are given a **0-indexed** binary string `s` and two integers `minJump` and `maxJump`. In the beginning, you are standing at index `0`, which is equal to `'0'`. You can move from index `i` to index `j` if the following conditions are fulfilled: diff --git a/backend/data/questions/k-closest-points-to-origin.yaml b/backend/data/questions/k-closest-points-to-origin.yaml index 0b8fe62..a8b7b5f 100644 --- a/backend/data/questions/k-closest-points-to-origin.yaml +++ b/backend/data/questions/k-closest-points-to-origin.yaml @@ -10,6 +10,26 @@ categories: patterns: - heap +function_signature: "def k_closest(points: list[list[int]], k: int) -> list[list[int]]:" + +test_cases: + visible: + - input: { points: [[1, 3], [-2, 2]], k: 1 } + expected: [[-2, 2]] + - input: { points: [[3, 3], [5, -1], [-2, 4]], k: 2 } + expected: [[3, 3], [-2, 4]] + hidden: + - input: { points: [[0, 0]], k: 1 } + expected: [[0, 0]] + - input: { points: [[1, 1], [2, 2], [3, 3]], k: 3 } + expected: [[1, 1], [2, 2], [3, 3]] + - input: { points: [[1, 0], [0, 1]], k: 2 } + expected: [[1, 0], [0, 1]] + - input: { points: [[-5, 4], [3, 2], [1, 1], [0, 2]], k: 2 } + expected: [[1, 1], [0, 2]] + - input: { points: [[10, 10], [-10, -10], [1, 1]], k: 1 } + expected: [[1, 1]] + description: | Given an array of `points` where `points[i] = [x_i, y_i]` represents a point on the **X-Y** plane and an integer `k`, return the `k` closest points to the origin `(0, 0)`. diff --git a/backend/data/questions/koko-eating-bananas.yaml b/backend/data/questions/koko-eating-bananas.yaml index e96242b..10cab8e 100644 --- a/backend/data/questions/koko-eating-bananas.yaml +++ b/backend/data/questions/koko-eating-bananas.yaml @@ -9,6 +9,30 @@ categories: patterns: - binary-search +function_signature: "def min_eating_speed(piles: list[int], h: int) -> int:" + +test_cases: + visible: + - input: { piles: [3, 6, 7, 11], h: 8 } + expected: 4 + - input: { piles: [30, 11, 23, 4, 20], h: 5 } + expected: 30 + - input: { piles: [30, 11, 23, 4, 20], h: 6 } + expected: 23 + hidden: + - input: { piles: [1], h: 1 } + expected: 1 + - input: { piles: [1, 1, 1, 1], h: 4 } + expected: 1 + - input: { piles: [1000000000], h: 2 } + expected: 500000000 + - input: { piles: [312884470], h: 968709470 } + expected: 1 + - input: { piles: [2, 2], h: 2 } + expected: 2 + - input: { piles: [5, 10, 3], h: 4 } + expected: 6 + description: | Koko loves to eat bananas. There are `n` piles of bananas, the ith pile has `piles[i]` bananas. The guards have gone and will come back in `h` hours. diff --git a/backend/data/questions/kth-largest-element-in-a-stream.yaml b/backend/data/questions/kth-largest-element-in-a-stream.yaml index 723c553..9d69610 100644 --- a/backend/data/questions/kth-largest-element-in-a-stream.yaml +++ b/backend/data/questions/kth-largest-element-in-a-stream.yaml @@ -9,6 +9,26 @@ categories: patterns: - heap +function_signature: "class KthLargest:\n def __init__(self, k: int, nums: list[int]):\n def add(self, val: int) -> int:" + +test_cases: + visible: + - input: { operations: ["KthLargest", "add", "add", "add", "add", "add"], arguments: [[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]] } + expected: [null, 4, 5, 5, 8, 8] + - input: { operations: ["KthLargest", "add", "add", "add", "add"], arguments: [[4, [7, 7, 7, 7, 8, 3]], [2], [10], [9], [9]] } + expected: [null, 7, 7, 7, 8] + hidden: + - input: { operations: ["KthLargest", "add"], arguments: [[1, []], [-3]] } + expected: [null, -3] + - input: { operations: ["KthLargest", "add", "add"], arguments: [[1, [1, 2, 3]], [4], [5]] } + expected: [null, 4, 5] + - input: { operations: ["KthLargest", "add", "add", "add"], arguments: [[2, [0]], [1], [2], [3]] } + expected: [null, 0, 1, 2] + - input: { operations: ["KthLargest", "add", "add"], arguments: [[3, [5, 5, 5]], [5], [5]] } + expected: [null, 5, 5] + - input: { operations: ["KthLargest", "add"], arguments: [[1, [-10000]], [10000]] } + expected: [null, 10000] + description: | Design a class to find the `k`th largest element in a stream. diff --git a/backend/data/questions/last-stone-weight-ii.yaml b/backend/data/questions/last-stone-weight-ii.yaml index 490005f..d684e19 100644 --- a/backend/data/questions/last-stone-weight-ii.yaml +++ b/backend/data/questions/last-stone-weight-ii.yaml @@ -9,6 +9,30 @@ categories: patterns: - dynamic-programming +function_signature: "def last_stone_weight_ii(stones: list[int]) -> int:" + +test_cases: + visible: + - input: { stones: [2, 7, 4, 1, 8, 1] } + expected: 1 + - input: { stones: [31, 26, 33, 21, 40] } + expected: 5 + hidden: + - input: { stones: [1] } + expected: 1 + - input: { stones: [1, 1] } + expected: 0 + - input: { stones: [1, 2] } + expected: 1 + - input: { stones: [1, 2, 3] } + expected: 0 + - input: { stones: [100, 100, 100] } + expected: 100 + - input: { stones: [1, 1, 1, 1, 1] } + expected: 1 + - input: { stones: [10, 20, 30, 40] } + expected: 0 + description: | You are given an array of integers `stones` where `stones[i]` is the weight of the ith stone. diff --git a/backend/data/questions/last-stone-weight.yaml b/backend/data/questions/last-stone-weight.yaml index 117f3ff..08236ed 100644 --- a/backend/data/questions/last-stone-weight.yaml +++ b/backend/data/questions/last-stone-weight.yaml @@ -9,6 +9,28 @@ categories: patterns: - heap +function_signature: "def last_stone_weight(stones: list[int]) -> int:" + +test_cases: + visible: + - input: { stones: [2, 7, 4, 1, 8, 1] } + expected: 1 + - input: { stones: [1] } + expected: 1 + hidden: + - input: { stones: [2, 2] } + expected: 0 + - input: { stones: [1, 3] } + expected: 2 + - input: { stones: [10, 4, 2, 10] } + expected: 2 + - input: { stones: [1, 1, 1, 1, 1] } + expected: 1 + - input: { stones: [5, 5, 5, 5] } + expected: 0 + - input: { stones: [1000] } + expected: 1000 + description: | You are given an array of integers `stones` where `stones[i]` is the weight of the ith stone. diff --git a/backend/data/questions/lemonade-change.yaml b/backend/data/questions/lemonade-change.yaml index bfb5435..c4fafba 100644 --- a/backend/data/questions/lemonade-change.yaml +++ b/backend/data/questions/lemonade-change.yaml @@ -8,6 +8,28 @@ categories: patterns: - greedy +function_signature: "def lemonade_change(bills: list[int]) -> bool:" + +test_cases: + visible: + - input: { bills: [5, 5, 5, 10, 20] } + expected: true + - input: { bills: [5, 5, 10, 10, 20] } + expected: false + hidden: + - input: { bills: [5] } + expected: true + - input: { bills: [10] } + expected: false + - input: { bills: [5, 5, 10] } + expected: true + - input: { bills: [5, 5, 5, 5, 20, 20] } + expected: true + - input: { bills: [5, 5, 5, 10, 5, 20, 5, 10, 5, 20] } + expected: true + - input: { bills: [5, 5, 10, 20, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 5, 5, 20, 5, 20, 5] } + expected: true + description: | At a lemonade stand, each lemonade costs `$5`. Customers are standing in a queue to buy from you and order one at a time (in the order specified by `bills`). Each customer will only buy one lemonade and pay with either a `$5`, `$10`, or `$20` bill. You must provide the correct change to each customer so that the net transaction is that the customer pays `$5`. diff --git a/backend/data/questions/lfu-cache.yaml b/backend/data/questions/lfu-cache.yaml index b255bb0..a5ac68a 100644 --- a/backend/data/questions/lfu-cache.yaml +++ b/backend/data/questions/lfu-cache.yaml @@ -9,6 +9,48 @@ categories: patterns: - heap +function_signature: "class LFUCache: def __init__(self, capacity: int); def get(self, key: int) -> int; def put(self, key: int, value: int) -> None" + +test_cases: + visible: + - input: + operations: ["LFUCache", "put", "put", "get", "put", "get", "get", "put", "get", "get", "get"] + arguments: [[2], [1, 1], [2, 2], [1], [3, 3], [2], [3], [4, 4], [1], [3], [4]] + expected: [null, null, null, 1, null, -1, 3, null, -1, 3, 4] + - input: + operations: ["LFUCache", "put", "get"] + arguments: [[1], [1, 1], [1]] + expected: [null, null, 1] + - input: + operations: ["LFUCache", "put", "put", "get", "get"] + arguments: [[2], [1, 10], [2, 20], [1], [2]] + expected: [null, null, null, 10, 20] + hidden: + - input: + operations: ["LFUCache", "put", "put", "put", "get"] + arguments: [[2], [1, 1], [2, 2], [3, 3], [1]] + expected: [null, null, null, null, -1] + - input: + operations: ["LFUCache", "put", "get", "put", "get", "get"] + arguments: [[1], [1, 1], [1], [2, 2], [1], [2]] + expected: [null, null, 1, null, -1, 2] + - input: + operations: ["LFUCache", "put", "put", "get", "get", "put", "get", "get", "get"] + arguments: [[2], [1, 1], [2, 2], [1], [1], [3, 3], [2], [3], [1]] + expected: [null, null, null, 1, 1, null, -1, 3, 1] + - input: + operations: ["LFUCache", "put", "put", "put", "put", "get"] + arguments: [[3], [1, 1], [2, 2], [3, 3], [4, 4], [4]] + expected: [null, null, null, null, null, 4] + - input: + operations: ["LFUCache", "put", "get", "put", "get", "put", "get"] + arguments: [[2], [1, 100], [1], [1, 200], [1], [2, 300], [2]] + expected: [null, null, 100, null, 200, null, 300] + - input: + operations: ["LFUCache", "get"] + arguments: [[2], [1]] + expected: [null, -1] + description: | Design and implement a data structure for a **Least Frequently Used (LFU)** cache. diff --git a/backend/data/questions/longest-happy-string.yaml b/backend/data/questions/longest-happy-string.yaml index a3c4d41..4762fe6 100644 --- a/backend/data/questions/longest-happy-string.yaml +++ b/backend/data/questions/longest-happy-string.yaml @@ -10,6 +10,35 @@ patterns: - greedy - heap +function_signature: "def longest_happy_string(a: int, b: int, c: int) -> str:" + +test_cases: + visible: + - input: { a: 1, b: 1, c: 7 } + expected: "ccaccbcc" + note: "Other valid outputs like 'ccbccacc' are also accepted" + - input: { a: 7, b: 1, c: 0 } + expected: "aabaa" + hidden: + - input: { a: 0, b: 0, c: 1 } + expected: "c" + - input: { a: 1, b: 1, c: 1 } + expected: "abc" + note: "Any permutation is valid" + - input: { a: 2, b: 2, c: 1 } + expected: "aabbc" + note: "Multiple valid outputs" + - input: { a: 0, b: 8, c: 11 } + expected: "ccbccbbccbbccbbccbc" + note: "Length should be 19" + - input: { a: 3, b: 0, c: 0 } + expected: "aa" + - input: { a: 0, b: 0, c: 2 } + expected: "cc" + - input: { a: 4, b: 4, c: 4 } + expected: "aabbccaabbcc" + note: "Multiple valid outputs" + description: | A string `s` is called **happy** if it satisfies the following conditions: diff --git a/backend/data/questions/longest-increasing-path-in-a-matrix.yaml b/backend/data/questions/longest-increasing-path-in-a-matrix.yaml index baaf8c9..d66f4bc 100644 --- a/backend/data/questions/longest-increasing-path-in-a-matrix.yaml +++ b/backend/data/questions/longest-increasing-path-in-a-matrix.yaml @@ -12,6 +12,32 @@ patterns: - dynamic-programming - matrix-traversal +function_signature: "def longest_increasing_path(matrix: list[list[int]]) -> int:" + +test_cases: + visible: + - input: { matrix: [[9, 9, 4], [6, 6, 8], [2, 1, 1]] } + expected: 4 + - input: { matrix: [[3, 4, 5], [3, 2, 6], [2, 2, 1]] } + expected: 4 + - input: { matrix: [[1]] } + expected: 1 + hidden: + - input: { matrix: [[1, 2], [4, 3]] } + expected: 4 + - input: { matrix: [[1, 2, 3], [6, 5, 4], [7, 8, 9]] } + expected: 9 + - input: { matrix: [[7, 8, 9], [6, 1, 2], [5, 4, 3]] } + expected: 7 + - input: { matrix: [[1, 1, 1], [1, 1, 1], [1, 1, 1]] } + expected: 1 + - input: { matrix: [[9, 8, 7], [6, 5, 4], [3, 2, 1]] } + expected: 9 + - input: { matrix: [[1, 2, 3, 4, 5]] } + expected: 5 + - input: { matrix: [[5], [4], [3], [2], [1]] } + expected: 5 + description: | Given an `m x n` integers `matrix`, return *the length of the longest increasing path in* `matrix`. diff --git a/backend/data/questions/longest-turbulent-subarray.yaml b/backend/data/questions/longest-turbulent-subarray.yaml index e5cbac3..82a0553 100644 --- a/backend/data/questions/longest-turbulent-subarray.yaml +++ b/backend/data/questions/longest-turbulent-subarray.yaml @@ -10,6 +10,32 @@ patterns: - sliding-window - dynamic-programming +function_signature: "def max_turbulence_size(arr: list[int]) -> int:" + +test_cases: + visible: + - input: { arr: [9, 4, 2, 10, 7, 8, 8, 1, 9] } + expected: 5 + - input: { arr: [4, 8, 12, 16] } + expected: 2 + - input: { arr: [100] } + expected: 1 + hidden: + - input: { arr: [1, 2] } + expected: 2 + - input: { arr: [2, 1] } + expected: 2 + - input: { arr: [5, 5, 5, 5] } + expected: 1 + - input: { arr: [1, 3, 2, 4, 3, 5, 4] } + expected: 7 + - input: { arr: [9, 9] } + expected: 1 + - input: { arr: [1, 2, 1, 2, 1, 2, 1] } + expected: 7 + - input: { arr: [10, 5, 10, 5, 10] } + expected: 5 + description: | Given an integer array `arr`, return *the length of a maximum size turbulent subarray of* `arr`. diff --git a/backend/data/questions/longest-valid-parentheses.yaml b/backend/data/questions/longest-valid-parentheses.yaml index 8aef82b..2df4692 100644 --- a/backend/data/questions/longest-valid-parentheses.yaml +++ b/backend/data/questions/longest-valid-parentheses.yaml @@ -11,6 +11,32 @@ patterns: - dynamic-programming - monotonic-stack +function_signature: "def longest_valid_parentheses(s: str) -> int:" + +test_cases: + visible: + - input: { s: "(()" } + expected: 2 + - input: { s: ")()())" } + expected: 4 + - input: { s: "" } + expected: 0 + hidden: + - input: { s: "()" } + expected: 2 + - input: { s: "()()" } + expected: 4 + - input: { s: "((()))" } + expected: 6 + - input: { s: "(()()" } + expected: 4 + - input: { s: ")()()((" } + expected: 4 + - input: { s: "((((((" } + expected: 0 + - input: { s: "))))))" } + expected: 0 + description: | Given a string containing just the characters `'('` and `')'`, return *the length of the longest valid (well-formed) parentheses substring*. diff --git a/backend/data/questions/lru-cache.yaml b/backend/data/questions/lru-cache.yaml index e2c42df..fe836e0 100644 --- a/backend/data/questions/lru-cache.yaml +++ b/backend/data/questions/lru-cache.yaml @@ -9,6 +9,44 @@ categories: patterns: - linkedlist-reversal +function_signature: "class LRUCache: def __init__(self, capacity: int); def get(self, key: int) -> int; def put(self, key: int, value: int) -> None" + +test_cases: + visible: + - input: + operations: ["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"] + arguments: [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]] + expected: [null, null, null, 1, null, -1, null, -1, 3, 4] + - input: + operations: ["LRUCache", "put", "get"] + arguments: [[1], [1, 100], [1]] + expected: [null, null, 100] + hidden: + - input: + operations: ["LRUCache", "get"] + arguments: [[1], [1]] + expected: [null, -1] + - input: + operations: ["LRUCache", "put", "put", "put", "get", "get"] + arguments: [[2], [1, 1], [2, 2], [3, 3], [1], [3]] + expected: [null, null, null, null, -1, 3] + - input: + operations: ["LRUCache", "put", "get", "put", "get"] + arguments: [[1], [1, 10], [1], [2, 20], [1]] + expected: [null, null, 10, null, -1] + - input: + operations: ["LRUCache", "put", "put", "get", "put", "put", "get"] + arguments: [[2], [2, 1], [2, 2], [2], [1, 1], [4, 1], [2]] + expected: [null, null, null, 2, null, null, -1] + - input: + operations: ["LRUCache", "put", "put", "put", "put", "get", "get", "get", "get"] + arguments: [[3], [1, 1], [2, 2], [3, 3], [4, 4], [1], [2], [3], [4]] + expected: [null, null, null, null, null, -1, 2, 3, 4] + - input: + operations: ["LRUCache", "put", "put", "get", "put", "get", "get"] + arguments: [[2], [1, 1], [2, 2], [1], [3, 3], [2], [1]] + expected: [null, null, null, 1, null, -1, 1] + description: | Design a data structure that follows the constraints of a **Least Recently Used (LRU) cache**. diff --git a/backend/data/questions/majority-element-ii.yaml b/backend/data/questions/majority-element-ii.yaml index 87c852a..7a17851 100644 --- a/backend/data/questions/majority-element-ii.yaml +++ b/backend/data/questions/majority-element-ii.yaml @@ -9,6 +9,32 @@ categories: patterns: - greedy +function_signature: "def majority_element(nums: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { nums: [3, 2, 3] } + expected: [3] + - input: { nums: [1] } + expected: [1] + - input: { nums: [1, 2] } + expected: [1, 2] + hidden: + - input: { nums: [1, 1, 1, 2, 2, 3] } + expected: [1] + - input: { nums: [1, 2, 3, 4, 5] } + expected: [] + - input: { nums: [2, 2, 2, 2] } + expected: [2] + - input: { nums: [1, 1, 2, 2, 3] } + expected: [1, 2] + - input: { nums: [0, 0, 0] } + expected: [0] + - input: { nums: [-1, -1, -1, 2, 2] } + expected: [-1] + - input: { nums: [1, 2, 1, 2, 1, 2, 3] } + expected: [1, 2] + description: | Given an integer array of size `n`, find all elements that appear **more than** `⌊n/3⌋` times. diff --git a/backend/data/questions/matchsticks-to-square.yaml b/backend/data/questions/matchsticks-to-square.yaml index 3fd10f1..7e6f18c 100644 --- a/backend/data/questions/matchsticks-to-square.yaml +++ b/backend/data/questions/matchsticks-to-square.yaml @@ -9,6 +9,30 @@ categories: patterns: - backtracking +function_signature: "def makesquare(matchsticks: list[int]) -> bool:" + +test_cases: + visible: + - input: { matchsticks: [1, 1, 2, 2, 2] } + expected: true + - input: { matchsticks: [3, 3, 3, 3, 4] } + expected: false + hidden: + - input: { matchsticks: [1, 1, 1, 1] } + expected: true + - input: { matchsticks: [1, 2, 3] } + expected: false + - input: { matchsticks: [5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3] } + expected: true + - input: { matchsticks: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] } + expected: false + - input: { matchsticks: [2, 2, 2, 2, 2, 2, 2, 2] } + expected: true + - input: { matchsticks: [10] } + expected: false + - input: { matchsticks: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] } + expected: true + description: | You are given an integer array `matchsticks` where `matchsticks[i]` is the length of the ith matchstick. You want to use **all the matchsticks** to make one square. You **should not break** any stick, but you can link them up, and each matchstick must be used **exactly one time**. diff --git a/backend/data/questions/max-area-of-island.yaml b/backend/data/questions/max-area-of-island.yaml index 17a7b21..9e08a38 100644 --- a/backend/data/questions/max-area-of-island.yaml +++ b/backend/data/questions/max-area-of-island.yaml @@ -11,6 +11,39 @@ patterns: - bfs - matrix-traversal +function_signature: "def max_area_of_island(grid: list[list[int]]) -> int:" + +test_cases: + visible: + - input: + grid: [[0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0]] + expected: 6 + - input: + grid: [[0, 0, 0, 0, 0, 0, 0, 0]] + expected: 0 + hidden: + - input: + grid: [[1]] + expected: 1 + - input: + grid: [[0]] + expected: 0 + - input: + grid: [[1, 1], [1, 1]] + expected: 4 + - input: + grid: [[1, 0, 1], [0, 0, 0], [1, 0, 1]] + expected: 1 + - input: + grid: [[1, 1, 1, 1, 1]] + expected: 5 + - input: + grid: [[1], [1], [1], [1]] + expected: 4 + - input: + grid: [[1, 0, 0, 1], [1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1]] + expected: 5 + description: | You are given an `m × n` binary matrix `grid`. An island is a group of `1`s (representing land) connected **4-directionally** (horizontal or vertical). You may assume all four edges of the grid are surrounded by water. diff --git a/backend/data/questions/maximum-frequency-stack.yaml b/backend/data/questions/maximum-frequency-stack.yaml index 53337f0..c7f6ac7 100644 --- a/backend/data/questions/maximum-frequency-stack.yaml +++ b/backend/data/questions/maximum-frequency-stack.yaml @@ -9,6 +9,44 @@ categories: patterns: - heap +function_signature: "class FreqStack: def __init__(self); def push(self, val: int) -> None; def pop(self) -> int" + +test_cases: + visible: + - input: + operations: ["FreqStack", "push", "push", "push", "push", "push", "push", "pop", "pop", "pop", "pop"] + arguments: [[], [5], [7], [5], [7], [4], [5], [], [], [], []] + expected: [null, null, null, null, null, null, null, 5, 7, 5, 4] + - input: + operations: ["FreqStack", "push", "push", "push", "pop", "pop"] + arguments: [[], [1], [1], [1], [], []] + expected: [null, null, null, null, 1, 1] + hidden: + - input: + operations: ["FreqStack", "push", "pop"] + arguments: [[], [10], []] + expected: [null, null, 10] + - input: + operations: ["FreqStack", "push", "push", "push", "pop", "push", "pop"] + arguments: [[], [1], [2], [3], [], [1], []] + expected: [null, null, null, null, 3, null, 1] + - input: + operations: ["FreqStack", "push", "push", "push", "push", "pop", "pop"] + arguments: [[], [5], [5], [5], [5], [], []] + expected: [null, null, null, null, null, 5, 5] + - input: + operations: ["FreqStack", "push", "push", "push", "push", "push", "pop", "pop", "pop"] + arguments: [[], [1], [2], [1], [2], [1], [], [], []] + expected: [null, null, null, null, null, null, 1, 2, 1] + - input: + operations: ["FreqStack", "push", "push", "push", "push", "push", "push", "pop", "push", "pop", "pop"] + arguments: [[], [4], [0], [9], [3], [4], [2], [], [6], [], []] + expected: [null, null, null, null, null, null, null, 4, null, 6, 2] + - input: + operations: ["FreqStack", "push", "push", "pop", "push", "pop", "push", "pop"] + arguments: [[], [1], [1], [], [2], [], [2], []] + expected: [null, null, null, 1, null, 2, null, 2] + description: | Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack. diff --git a/backend/data/questions/merge-strings-alternately.yaml b/backend/data/questions/merge-strings-alternately.yaml index 23c5430..f7e9957 100644 --- a/backend/data/questions/merge-strings-alternately.yaml +++ b/backend/data/questions/merge-strings-alternately.yaml @@ -9,6 +9,26 @@ categories: patterns: - two-pointers +function_signature: "def merge_alternately(word1: str, word2: str) -> str:" + +test_cases: + visible: + - input: { word1: "abc", word2: "pqr" } + expected: "apbqcr" + - input: { word1: "ab", word2: "pqrs" } + expected: "apbqrs" + - input: { word1: "abcd", word2: "pq" } + expected: "apbqcd" + hidden: + - input: { word1: "a", word2: "b" } + expected: "ab" + - input: { word1: "a", word2: "xyz" } + expected: "axyz" + - input: { word1: "xyz", word2: "a" } + expected: "xayz" + - input: { word1: "hello", word2: "world" } + expected: "hweolrllod" + description: | You are given two strings `word1` and `word2`. Merge the strings by adding letters in alternating order, starting with `word1`. If a string is longer than the other, append the additional letters onto the end of the merged string. diff --git a/backend/data/questions/one-bit-and-two-bit-characters.yaml b/backend/data/questions/one-bit-and-two-bit-characters.yaml index c6ebd9b..09fcd8e 100644 --- a/backend/data/questions/one-bit-and-two-bit-characters.yaml +++ b/backend/data/questions/one-bit-and-two-bit-characters.yaml @@ -8,6 +8,26 @@ categories: patterns: - greedy +function_signature: "def is_one_bit_character(bits: list[int]) -> bool:" + +test_cases: + visible: + - input: { bits: [1, 0, 0] } + expected: true + - input: { bits: [1, 1, 1, 0] } + expected: false + hidden: + - input: { bits: [0] } + expected: true + - input: { bits: [0, 0] } + expected: true + - input: { bits: [1, 0] } + expected: false + - input: { bits: [1, 1, 0] } + expected: true + - input: { bits: [0, 1, 0] } + expected: false + description: | We have two special characters: diff --git a/backend/data/questions/reverse-string.yaml b/backend/data/questions/reverse-string.yaml index db54b3a..578ac8f 100644 --- a/backend/data/questions/reverse-string.yaml +++ b/backend/data/questions/reverse-string.yaml @@ -9,6 +9,24 @@ categories: patterns: - two-pointers +function_signature: "def reverse_string(s: list[str]) -> None:" + +test_cases: + visible: + - input: { s: ["h", "e", "l", "l", "o"] } + expected: ["o", "l", "l", "e", "h"] + - input: { s: ["H", "a", "n", "n", "a", "h"] } + expected: ["h", "a", "n", "n", "a", "H"] + hidden: + - input: { s: ["a"] } + expected: ["a"] + - input: { s: ["a", "b"] } + expected: ["b", "a"] + - input: { s: ["a", "b", "c"] } + expected: ["c", "b", "a"] + - input: { s: ["1", "2", "3", "4", "5"] } + expected: ["5", "4", "3", "2", "1"] + description: | Write a function that reverses a string. The input string is given as an array of characters `s`. diff --git a/backend/data/questions/transpose-matrix.yaml b/backend/data/questions/transpose-matrix.yaml index 922ef06..d87e393 100644 --- a/backend/data/questions/transpose-matrix.yaml +++ b/backend/data/questions/transpose-matrix.yaml @@ -8,6 +8,24 @@ categories: patterns: - matrix-traversal +function_signature: "def transpose(matrix: list[list[int]]) -> list[list[int]]:" + +test_cases: + visible: + - input: { matrix: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] } + expected: [[1, 4, 7], [2, 5, 8], [3, 6, 9]] + - input: { matrix: [[1, 2, 3], [4, 5, 6]] } + expected: [[1, 4], [2, 5], [3, 6]] + hidden: + - input: { matrix: [[1]] } + expected: [[1]] + - input: { matrix: [[1, 2], [3, 4]] } + expected: [[1, 3], [2, 4]] + - input: { matrix: [[1], [2], [3]] } + expected: [[1, 2, 3]] + - input: { matrix: [[1, 2, 3, 4]] } + expected: [[1], [2], [3], [4]] + description: | Given a 2D integer array `matrix`, return *the **transpose** of* `matrix`. diff --git a/backend/data/questions/unique-number-of-occurrences.yaml b/backend/data/questions/unique-number-of-occurrences.yaml index 7cf4a54..d826899 100644 --- a/backend/data/questions/unique-number-of-occurrences.yaml +++ b/backend/data/questions/unique-number-of-occurrences.yaml @@ -9,6 +9,26 @@ categories: patterns: - prefix-sum +function_signature: "def unique_occurrences(arr: list[int]) -> bool:" + +test_cases: + visible: + - input: { arr: [1, 2, 2, 1, 1, 3] } + expected: true + - input: { arr: [1, 2] } + expected: false + - input: { arr: [-3, 0, 1, -3, 1, 1, 1, -3, 10, 0] } + expected: true + hidden: + - input: { arr: [1] } + expected: true + - input: { arr: [1, 1, 1] } + expected: true + - input: { arr: [1, 1, 2, 2] } + expected: false + - input: { arr: [1, 2, 3] } + expected: false + description: | Given an array of integers `arr`, return `true` *if the number of occurrences of each value in the array is **unique***, or `false` *otherwise*. diff --git a/backend/data/questions/valid-palindrome-ii.yaml b/backend/data/questions/valid-palindrome-ii.yaml index 5b669f6..e4864c9 100644 --- a/backend/data/questions/valid-palindrome-ii.yaml +++ b/backend/data/questions/valid-palindrome-ii.yaml @@ -9,6 +9,28 @@ categories: patterns: - two-pointers +function_signature: "def valid_palindrome(s: str) -> bool:" + +test_cases: + visible: + - input: { s: "aba" } + expected: true + - input: { s: "abca" } + expected: true + - input: { s: "abc" } + expected: false + hidden: + - input: { s: "a" } + expected: true + - input: { s: "aa" } + expected: true + - input: { s: "ab" } + expected: true + - input: { s: "racecar" } + expected: true + - input: { s: "racecars" } + expected: true + description: | Given a string `s`, return `true` *if the* `s` *can be a palindrome after deleting **at most one** character from it*. diff --git a/backend/data/questions/verifying-an-alien-dictionary.yaml b/backend/data/questions/verifying-an-alien-dictionary.yaml index 01ac534..1825e47 100644 --- a/backend/data/questions/verifying-an-alien-dictionary.yaml +++ b/backend/data/questions/verifying-an-alien-dictionary.yaml @@ -10,6 +10,26 @@ categories: patterns: - two-pointers +function_signature: "def is_alien_sorted(words: list[str], order: str) -> bool:" + +test_cases: + visible: + - input: { words: ["hello", "leetcode"], order: "hlabcdefgijkmnopqrstuvwxyz" } + expected: true + - input: { words: ["word", "world", "row"], order: "worldabcefghijkmnpqstuvxyz" } + expected: false + - input: { words: ["apple", "app"], order: "abcdefghijklmnopqrstuvwxyz" } + expected: false + hidden: + - input: { words: ["a"], order: "abcdefghijklmnopqrstuvwxyz" } + expected: true + - input: { words: ["a", "b", "c"], order: "abcdefghijklmnopqrstuvwxyz" } + expected: true + - input: { words: ["app", "apple"], order: "abcdefghijklmnopqrstuvwxyz" } + expected: true + - input: { words: ["a", "a"], order: "abcdefghijklmnopqrstuvwxyz" } + expected: true + description: | In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different `order`. The `order` of the alphabet is some permutation of lowercase letters.