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 `"