From 85fea3a4bbc3c022f8b6e505b65170b0a4d767c9 Mon Sep 17 00:00:00 2001 From: Kai Chappell Date: Sun, 13 Jul 2025 19:25:39 +0100 Subject: [PATCH] feat(content): more test cases --- backend/data/questions/add-two-numbers.yaml | 16 ++++++++++++ .../data/questions/asteroid-collision.yaml | 18 +++++++++++++ .../questions/backspace-string-compare.yaml | 20 ++++++++++++++ .../data/questions/basic-calculator-ii.yaml | 20 ++++++++++++++ .../binary-tree-level-order-traversal.yaml | 18 +++++++++++++ backend/data/questions/burst-balloons.yaml | 22 ++++++++++++++++ backend/data/questions/candy.yaml | 24 +++++++++++++++++ backend/data/questions/clone-graph.yaml | 16 ++++++++++++ backend/data/questions/coin-change-ii.yaml | 24 +++++++++++++++++ backend/data/questions/coin-change.yaml | 20 ++++++++++++++ .../data/questions/combination-sum-ii.yaml | 22 ++++++++++++++++ backend/data/questions/combination-sum.yaml | 18 +++++++++++++ backend/data/questions/combinations.yaml | 16 ++++++++++++ .../questions/container-with-most-water.yaml | 18 +++++++++++++ .../data/questions/course-schedule-ii.yaml | 22 ++++++++++++++++ backend/data/questions/course-schedule.yaml | 18 +++++++++++++ .../data/questions/daily-temperatures.yaml | 24 +++++++++++++++++ backend/data/questions/decode-string.yaml | 26 +++++++++++++++++++ backend/data/questions/decode-ways.yaml | 20 ++++++++++++++ .../questions/diameter-of-binary-tree.yaml | 20 ++++++++++++++ backend/data/questions/edit-distance.yaml | 26 +++++++++++++++++++ .../evaluate-reverse-polish-notation.yaml | 22 ++++++++++++++++ .../find-minimum-in-rotated-sorted-array.yaml | 20 ++++++++++++++ .../questions/find-the-duplicate-number.yaml | 18 +++++++++++++ backend/data/questions/four-sum.yaml | 16 ++++++++++++ backend/data/questions/gas-station.yaml | 20 ++++++++++++++ .../data/questions/generate-parentheses.yaml | 14 ++++++++++ backend/data/questions/group-anagrams.yaml | 18 +++++++++++++ backend/data/questions/house-robber.yaml | 18 +++++++++++++ backend/data/questions/insert-interval.yaml | 18 +++++++++++++ backend/data/questions/integer-break.yaml | 26 +++++++++++++++++++ .../data/questions/invert-binary-tree.yaml | 18 +++++++++++++ backend/data/questions/jump-game-ii.yaml | 24 +++++++++++++++++ backend/data/questions/jump-game.yaml | 18 +++++++++++++ .../kth-largest-element-in-an-array.yaml | 24 +++++++++++++++++ .../kth-smallest-element-in-a-bst.yaml | 18 +++++++++++++ .../largest-rectangle-in-histogram.yaml | 26 +++++++++++++++++++ ...letter-combinations-of-a-phone-number.yaml | 16 ++++++++++++ backend/data/questions/linked-list-cycle.yaml | 18 +++++++++++++ .../questions/longest-common-subsequence.yaml | 18 +++++++++++++ .../longest-consecutive-sequence.yaml | 18 +++++++++++++ .../longest-increasing-subsequence.yaml | 20 ++++++++++++++ .../longest-palindromic-substring.yaml | 18 +++++++++++++ .../longest-substring-without-repeating.yaml | 20 ++++++++++++++ ...mmon-ancestor-of-a-binary-search-tree.yaml | 18 +++++++++++++ .../maximum-depth-of-binary-tree.yaml | 18 +++++++++++++ .../questions/maximum-product-subarray.yaml | 26 +++++++++++++++++++ .../median-of-two-sorted-arrays.yaml | 18 +++++++++++++ backend/data/questions/merge-intervals.yaml | 18 +++++++++++++ .../data/questions/merge-sorted-array.yaml | 18 +++++++++++++ .../questions/merge-two-sorted-lists.yaml | 16 ++++++++++++ .../questions/min-cost-climbing-stairs.yaml | 18 +++++++++++++ .../questions/minimum-window-substring.yaml | 20 ++++++++++++++ .../data/questions/network-delay-time.yaml | 20 ++++++++++++++ backend/data/questions/number-of-islands.yaml | 18 +++++++++++++ .../pacific-atlantic-water-flow.yaml | 14 ++++++++++ .../questions/palindrome-partitioning.yaml | 22 ++++++++++++++++ .../questions/partition-equal-subset-sum.yaml | 18 +++++++++++++ backend/data/questions/partition-labels.yaml | 24 +++++++++++++++++ backend/data/questions/perfect-squares.yaml | 26 +++++++++++++++++++ .../data/questions/permutation-in-string.yaml | 20 ++++++++++++++ backend/data/questions/permutations.yaml | 20 ++++++++++++++ .../product-of-array-except-self.yaml | 18 +++++++++++++ .../data/questions/reconstruct-itinerary.yaml | 16 ++++++++++++ .../data/questions/redundant-connection.yaml | 18 +++++++++++++ .../remove-duplicates-from-sorted-array.yaml | 18 +++++++++++++ backend/data/questions/remove-element.yaml | 18 +++++++++++++ backend/data/questions/reorder-list.yaml | 20 ++++++++++++++ backend/data/questions/reverse-integer.yaml | 26 +++++++++++++++++++ .../data/questions/reverse-linked-list.yaml | 16 ++++++++++++ backend/data/questions/rotate-array.yaml | 18 +++++++++++++ backend/data/questions/rotate-image.yaml | 16 ++++++++++++ backend/data/questions/rotting-oranges.yaml | 18 +++++++++++++ backend/data/questions/same-tree.yaml | 18 +++++++++++++ .../search-in-rotated-sorted-array.yaml | 20 ++++++++++++++ backend/data/questions/set-matrix-zeroes.yaml | 16 ++++++++++++ .../questions/sliding-window-maximum.yaml | 24 +++++++++++++++++ backend/data/questions/sort-colors.yaml | 18 +++++++++++++ backend/data/questions/spiral-matrix.yaml | 18 +++++++++++++ .../data/questions/subarray-sum-equals-k.yaml | 18 +++++++++++++ backend/data/questions/subsets-ii.yaml | 20 ++++++++++++++ backend/data/questions/subsets.yaml | 22 ++++++++++++++++ .../questions/subtree-of-another-tree.yaml | 18 +++++++++++++ backend/data/questions/target-sum.yaml | 26 +++++++++++++++++++ backend/data/questions/task-scheduler.yaml | 22 ++++++++++++++++ backend/data/questions/three-sum.yaml | 18 +++++++++++++ .../questions/top-k-frequent-elements.yaml | 18 +++++++++++++ .../data/questions/trapping-rain-water.yaml | 18 +++++++++++++ backend/data/questions/unique-paths-ii.yaml | 24 +++++++++++++++++ backend/data/questions/unique-paths.yaml | 18 +++++++++++++ .../validate-binary-search-tree.yaml | 18 +++++++++++++ backend/data/questions/word-break.yaml | 18 +++++++++++++ backend/data/questions/word-ladder.yaml | 22 ++++++++++++++++ backend/data/questions/word-search.yaml | 18 +++++++++++++ 94 files changed, 1840 insertions(+) diff --git a/backend/data/questions/add-two-numbers.yaml b/backend/data/questions/add-two-numbers.yaml index 645a082..bc04ad6 100644 --- a/backend/data/questions/add-two-numbers.yaml +++ b/backend/data/questions/add-two-numbers.yaml @@ -9,6 +9,22 @@ categories: patterns: - two-pointers +function_signature: "def add_two_numbers(l1: ListNode | None, l2: ListNode | None) -> ListNode | None:" + +test_cases: + visible: + - input: { l1: [2, 4, 3], l2: [5, 6, 4] } + expected: [7, 0, 8] + - input: { l1: [0], l2: [0] } + expected: [0] + - input: { l1: [9, 9, 9, 9, 9, 9, 9], l2: [9, 9, 9, 9] } + expected: [8, 9, 9, 9, 0, 0, 0, 1] + hidden: + - input: { l1: [1], l2: [9, 9] } + expected: [0, 0, 1] + - input: { l1: [5], l2: [5] } + expected: [0, 1] + description: | You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, 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/asteroid-collision.yaml b/backend/data/questions/asteroid-collision.yaml index e5dab40..9a51ad5 100644 --- a/backend/data/questions/asteroid-collision.yaml +++ b/backend/data/questions/asteroid-collision.yaml @@ -9,6 +9,24 @@ categories: patterns: - monotonic-stack +function_signature: "def asteroid_collision(asteroids: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { asteroids: [5, 10, -5] } + expected: [5, 10] + - input: { asteroids: [8, -8] } + expected: [] + - input: { asteroids: [10, 2, -5] } + expected: [10] + hidden: + - input: { asteroids: [-2, -1, 1, 2] } + expected: [-2, -1, 1, 2] + - input: { asteroids: [1, -1, -2, -2] } + expected: [-2, -2] + - input: { asteroids: [1, -2, -2, -2] } + expected: [-2, -2, -2] + description: | We are given an array `asteroids` of integers representing asteroids in a row. The indices of the asteroids in the array represent their relative position in space. diff --git a/backend/data/questions/backspace-string-compare.yaml b/backend/data/questions/backspace-string-compare.yaml index 944fc93..a6fd149 100644 --- a/backend/data/questions/backspace-string-compare.yaml +++ b/backend/data/questions/backspace-string-compare.yaml @@ -10,6 +10,26 @@ categories: patterns: - two-pointers +function_signature: "def backspace_compare(s: str, t: str) -> bool:" + +test_cases: + visible: + - input: { s: "ab#c", t: "ad#c" } + expected: true + - input: { s: "ab##", t: "c#d#" } + expected: true + - input: { s: "a#c", t: "b" } + expected: false + hidden: + - input: { s: "a", t: "a" } + expected: true + - input: { s: "###", t: "" } + expected: true + - input: { s: "a##b", t: "b" } + expected: true + - input: { s: "xywrrmp", t: "xywrrmu#p" } + expected: true + description: | Given two strings `s` and `t`, return `true` *if they are equal when both are typed into empty text editors*. `'#'` means a backspace character. diff --git a/backend/data/questions/basic-calculator-ii.yaml b/backend/data/questions/basic-calculator-ii.yaml index 36b3fac..b44fe14 100644 --- a/backend/data/questions/basic-calculator-ii.yaml +++ b/backend/data/questions/basic-calculator-ii.yaml @@ -10,6 +10,26 @@ categories: patterns: - monotonic-stack +function_signature: "def calculate(s: str) -> int:" + +test_cases: + visible: + - input: { s: "3+2*2" } + expected: 7 + - input: { s: " 3/2 " } + expected: 1 + - input: { s: " 3+5 / 2 " } + expected: 5 + hidden: + - input: { s: "42" } + expected: 42 + - input: { s: "1+1+1" } + expected: 3 + - input: { s: "2*3*4" } + expected: 24 + - input: { s: "14-3/2" } + expected: 13 + description: | Given a string `s` which represents an expression, *evaluate this expression and return its value*. diff --git a/backend/data/questions/binary-tree-level-order-traversal.yaml b/backend/data/questions/binary-tree-level-order-traversal.yaml index a4d2ecd..8f8e2e8 100644 --- a/backend/data/questions/binary-tree-level-order-traversal.yaml +++ b/backend/data/questions/binary-tree-level-order-traversal.yaml @@ -10,6 +10,24 @@ patterns: - bfs - tree-traversal +function_signature: "def level_order(root: TreeNode | None) -> list[list[int]]:" + +test_cases: + visible: + - input: { root: [3, 9, 20, null, null, 15, 7] } + expected: [[3], [9, 20], [15, 7]] + - input: { root: [1] } + expected: [[1]] + - input: { root: [] } + expected: [] + hidden: + - input: { root: [1, 2, 3, 4, 5] } + expected: [[1], [2, 3], [4, 5]] + - input: { root: [1, 2, null, 3] } + expected: [[1], [2], [3]] + - input: { root: [1, null, 2, null, 3] } + expected: [[1], [2], [3]] + description: | Given the `root` of a binary tree, return *the level order traversal of its nodes' values*. (i.e., from left to right, level by level). diff --git a/backend/data/questions/burst-balloons.yaml b/backend/data/questions/burst-balloons.yaml index dee4a11..c4366ce 100644 --- a/backend/data/questions/burst-balloons.yaml +++ b/backend/data/questions/burst-balloons.yaml @@ -9,6 +9,28 @@ categories: patterns: - dynamic-programming +function_signature: "def max_coins(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [3, 1, 5, 8] } + expected: 167 + - input: { nums: [1, 5] } + expected: 10 + hidden: + - input: { nums: [1] } + expected: 1 + - input: { nums: [9, 76, 64, 21] } + expected: 116718 + - input: { nums: [5, 7, 8] } + expected: 329 + - input: { nums: [7, 9, 8, 0, 7, 1, 3, 5, 5, 2, 3] } + expected: 1654 + - input: { nums: [35, 16, 83, 87, 32, 45, 81, 26] } + expected: 1310780 + - input: { nums: [8, 2, 6, 8, 9, 8, 1, 4, 1, 5, 3, 0, 7, 7, 0, 4, 2, 2, 5] } + expected: 3630 + description: | You are given `n` balloons, indexed from `0` to `n - 1`. Each balloon is painted with a number on it represented by an array `nums`. You are asked to burst all the balloons. diff --git a/backend/data/questions/candy.yaml b/backend/data/questions/candy.yaml index dca1c9e..d386dc5 100644 --- a/backend/data/questions/candy.yaml +++ b/backend/data/questions/candy.yaml @@ -8,6 +8,30 @@ categories: patterns: - greedy +function_signature: "def candy(ratings: list[int]) -> int:" + +test_cases: + visible: + - input: { ratings: [1, 0, 2] } + expected: 5 + - input: { ratings: [1, 2, 2] } + expected: 4 + hidden: + - input: { ratings: [1] } + expected: 1 + - input: { ratings: [1, 2, 3, 4, 5] } + expected: 15 + - input: { ratings: [5, 4, 3, 2, 1] } + expected: 15 + - input: { ratings: [1, 3, 2, 2, 1] } + expected: 7 + - input: { ratings: [1, 2, 3, 1, 0] } + expected: 9 + - input: { ratings: [1, 3, 4, 5, 2] } + expected: 11 + - input: { ratings: [1, 1, 1, 1] } + expected: 4 + description: | There are `n` children standing in a line. Each child is assigned a rating value given in the integer array `ratings`. diff --git a/backend/data/questions/clone-graph.yaml b/backend/data/questions/clone-graph.yaml index 0e73abd..82e1f42 100644 --- a/backend/data/questions/clone-graph.yaml +++ b/backend/data/questions/clone-graph.yaml @@ -10,6 +10,22 @@ patterns: - dfs - bfs +function_signature: "def clone_graph(node: Node | None) -> Node | None:" + +test_cases: + visible: + - input: { adjList: [[2, 4], [1, 3], [2, 4], [1, 3]] } + expected: [[2, 4], [1, 3], [2, 4], [1, 3]] + - input: { adjList: [[]] } + expected: [[]] + - input: { adjList: [] } + expected: [] + hidden: + - input: { adjList: [[2], [1]] } + expected: [[2], [1]] + - input: { adjList: [[2, 3], [1, 3], [1, 2]] } + expected: [[2, 3], [1, 3], [1, 2]] + description: | Given a reference of a node in a **connected** undirected graph. diff --git a/backend/data/questions/coin-change-ii.yaml b/backend/data/questions/coin-change-ii.yaml index 5bd55cc..e9b9c67 100644 --- a/backend/data/questions/coin-change-ii.yaml +++ b/backend/data/questions/coin-change-ii.yaml @@ -9,6 +9,30 @@ categories: patterns: - dynamic-programming +function_signature: "def change(amount: int, coins: list[int]) -> int:" + +test_cases: + visible: + - input: { amount: 5, coins: [1, 2, 5] } + expected: 4 + - input: { amount: 3, coins: [2] } + expected: 0 + - input: { amount: 10, coins: [10] } + expected: 1 + hidden: + - input: { amount: 0, coins: [1, 2, 5] } + expected: 1 + - input: { amount: 1, coins: [1] } + expected: 1 + - input: { amount: 100, coins: [1, 5, 10, 25] } + expected: 242 + - input: { amount: 7, coins: [2, 3, 5] } + expected: 2 + - input: { amount: 500, coins: [1, 2, 5] } + expected: 12701 + - input: { amount: 4, coins: [1, 2, 3] } + expected: 4 + description: | You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money. diff --git a/backend/data/questions/coin-change.yaml b/backend/data/questions/coin-change.yaml index a917376..654186f 100644 --- a/backend/data/questions/coin-change.yaml +++ b/backend/data/questions/coin-change.yaml @@ -9,6 +9,26 @@ categories: patterns: - dynamic-programming +function_signature: "def coin_change(coins: list[int], amount: int) -> int:" + +test_cases: + visible: + - input: { coins: [1, 2, 5], amount: 11 } + expected: 3 + - input: { coins: [2], amount: 3 } + expected: -1 + - input: { coins: [1], amount: 0 } + expected: 0 + hidden: + - input: { coins: [1], amount: 1 } + expected: 1 + - input: { coins: [1, 3, 4], amount: 6 } + expected: 2 + - input: { coins: [2, 5, 10], amount: 7 } + expected: 2 + - input: { coins: [186, 419, 83, 408], amount: 6249 } + expected: 20 + description: | You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money. diff --git a/backend/data/questions/combination-sum-ii.yaml b/backend/data/questions/combination-sum-ii.yaml index 7f5482b..5d3e394 100644 --- a/backend/data/questions/combination-sum-ii.yaml +++ b/backend/data/questions/combination-sum-ii.yaml @@ -9,6 +9,28 @@ categories: patterns: - backtracking +function_signature: "def combination_sum2(candidates: list[int], target: int) -> list[list[int]]:" + +test_cases: + visible: + - input: { candidates: [10, 1, 2, 7, 6, 1, 5], target: 8 } + expected: [[1, 1, 6], [1, 2, 5], [1, 7], [2, 6]] + - input: { candidates: [2, 5, 2, 1, 2], target: 5 } + expected: [[1, 2, 2], [5]] + hidden: + - input: { candidates: [1], target: 1 } + expected: [[1]] + - input: { candidates: [1], target: 2 } + expected: [] + - input: { candidates: [1, 1, 1, 1, 1], target: 3 } + expected: [[1, 1, 1]] + - input: { candidates: [3, 1, 3, 5, 1, 1], target: 8 } + expected: [[1, 1, 1, 5], [1, 1, 3, 3], [3, 5]] + - input: { candidates: [2, 3, 6, 7], target: 7 } + expected: [[7]] + - input: { candidates: [4, 4, 2, 1, 4, 2, 2, 1, 3], target: 6 } + expected: [[1, 1, 2, 2], [1, 1, 4], [1, 2, 3], [2, 2, 2], [2, 4]] + description: | Given a collection of candidate numbers (`candidates`) and a target number (`target`), find all unique combinations in `candidates` where the candidate numbers sum to `target`. diff --git a/backend/data/questions/combination-sum.yaml b/backend/data/questions/combination-sum.yaml index 5fb5ff9..15d701e 100644 --- a/backend/data/questions/combination-sum.yaml +++ b/backend/data/questions/combination-sum.yaml @@ -9,6 +9,24 @@ categories: patterns: - backtracking +function_signature: "def combination_sum(candidates: list[int], target: int) -> list[list[int]]:" + +test_cases: + visible: + - input: { candidates: [2, 3, 6, 7], target: 7 } + expected: [[2, 2, 3], [7]] + - input: { candidates: [2, 3, 5], target: 8 } + expected: [[2, 2, 2, 2], [2, 3, 3], [3, 5]] + - input: { candidates: [2], target: 1 } + expected: [] + hidden: + - input: { candidates: [1], target: 1 } + expected: [[1]] + - input: { candidates: [1], target: 2 } + expected: [[1, 1]] + - input: { candidates: [2, 3, 5], target: 5 } + expected: [[2, 3], [5]] + description: | Given an array of **distinct** integers `candidates` and a target integer `target`, return *a list of all **unique combinations** of* `candidates` *where the chosen numbers sum to* `target`. You may return the combinations in **any order**. diff --git a/backend/data/questions/combinations.yaml b/backend/data/questions/combinations.yaml index c519477..5c5c178 100644 --- a/backend/data/questions/combinations.yaml +++ b/backend/data/questions/combinations.yaml @@ -9,6 +9,22 @@ categories: patterns: - backtracking +function_signature: "def combine(n: int, k: int) -> list[list[int]]:" + +test_cases: + visible: + - input: { n: 4, k: 2 } + expected: [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]] + - input: { n: 1, k: 1 } + expected: [[1]] + hidden: + - input: { n: 5, k: 3 } + expected: [[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 3, 4], [1, 3, 5], [1, 4, 5], [2, 3, 4], [2, 3, 5], [2, 4, 5], [3, 4, 5]] + - input: { n: 3, k: 1 } + expected: [[1], [2], [3]] + - input: { n: 2, k: 2 } + expected: [[1, 2]] + description: | Given two integers `n` and `k`, return *all possible combinations of* `k` *numbers chosen from the range* `[1, n]`. diff --git a/backend/data/questions/container-with-most-water.yaml b/backend/data/questions/container-with-most-water.yaml index 1d162cb..0b4cfc6 100644 --- a/backend/data/questions/container-with-most-water.yaml +++ b/backend/data/questions/container-with-most-water.yaml @@ -10,6 +10,24 @@ patterns: - two-pointers - greedy +function_signature: "def max_area(height: list[int]) -> int:" + +test_cases: + visible: + - input: { height: [1, 8, 6, 2, 5, 4, 8, 3, 7] } + expected: 49 + - input: { height: [1, 1] } + expected: 1 + hidden: + - input: { height: [4, 3, 2, 1, 4] } + expected: 16 + - input: { height: [1, 2, 1] } + expected: 2 + - input: { height: [2, 3, 10, 5, 7, 8, 9] } + expected: 36 + - input: { height: [1, 2, 4, 3] } + expected: 4 + description: | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the ith line are `(i, 0)` and `(i, height[i])`. diff --git a/backend/data/questions/course-schedule-ii.yaml b/backend/data/questions/course-schedule-ii.yaml index 550fc24..686ca51 100644 --- a/backend/data/questions/course-schedule-ii.yaml +++ b/backend/data/questions/course-schedule-ii.yaml @@ -9,6 +9,28 @@ patterns: - bfs - dfs +function_signature: "def find_order(num_courses: int, prerequisites: list[list[int]]) -> list[int]:" + +test_cases: + visible: + - input: { num_courses: 2, prerequisites: [[1, 0]] } + expected: [0, 1] + - input: { num_courses: 4, prerequisites: [[1, 0], [2, 0], [3, 1], [3, 2]] } + expected: [0, 1, 2, 3] + - input: { num_courses: 1, prerequisites: [] } + expected: [0] + hidden: + - input: { num_courses: 2, prerequisites: [[1, 0], [0, 1]] } + expected: [] + - input: { num_courses: 3, prerequisites: [] } + expected: [0, 1, 2] + - input: { num_courses: 3, prerequisites: [[0, 1], [0, 2], [1, 2]] } + expected: [2, 1, 0] + - input: { num_courses: 4, prerequisites: [[3, 0], [0, 1]] } + expected: [1, 2, 0, 3] + - input: { num_courses: 2, prerequisites: [] } + expected: [0, 1] + description: | There are a total of `numCourses` courses you have to take, labelled from `0` to `numCourses - 1`. You are given an array `prerequisites` where `prerequisites[i] = [a_i, b_i]` indicates that you **must** take course `b_i` first if you want to take course `a_i`. diff --git a/backend/data/questions/course-schedule.yaml b/backend/data/questions/course-schedule.yaml index 0c4def5..ba5d141 100644 --- a/backend/data/questions/course-schedule.yaml +++ b/backend/data/questions/course-schedule.yaml @@ -9,6 +9,24 @@ patterns: - dfs - bfs +function_signature: "def can_finish(num_courses: int, prerequisites: list[list[int]]) -> bool:" + +test_cases: + visible: + - input: { num_courses: 2, prerequisites: [[1, 0]] } + expected: true + - input: { num_courses: 2, prerequisites: [[1, 0], [0, 1]] } + expected: false + - input: { num_courses: 3, prerequisites: [[1, 0], [2, 1]] } + expected: true + hidden: + - input: { num_courses: 1, prerequisites: [] } + expected: true + - input: { num_courses: 4, prerequisites: [[1, 0], [2, 1], [3, 2], [1, 3]] } + expected: false + - input: { num_courses: 5, prerequisites: [[1, 0], [2, 0], [3, 1], [4, 2]] } + expected: true + description: | There are a total of `numCourses` courses you have to take, labeled from `0` to `numCourses - 1`. You are given an array `prerequisites` where `prerequisites[i] = [a``i``, b``i``]` indicates that you **must** take course `b``i` first if you want to take course `a``i`. diff --git a/backend/data/questions/daily-temperatures.yaml b/backend/data/questions/daily-temperatures.yaml index 1a8f33c..df4f966 100644 --- a/backend/data/questions/daily-temperatures.yaml +++ b/backend/data/questions/daily-temperatures.yaml @@ -9,6 +9,30 @@ categories: patterns: - monotonic-stack +function_signature: "def daily_temperatures(temperatures: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { temperatures: [73, 74, 75, 71, 69, 72, 76, 73] } + expected: [1, 1, 4, 2, 1, 1, 0, 0] + - input: { temperatures: [30, 40, 50, 60] } + expected: [1, 1, 1, 0] + - input: { temperatures: [30, 60, 90] } + expected: [1, 1, 0] + hidden: + - input: { temperatures: [50] } + expected: [0] + - input: { temperatures: [90, 80, 70, 60] } + expected: [0, 0, 0, 0] + - input: { temperatures: [60, 70, 80, 90] } + expected: [1, 1, 1, 0] + - input: { temperatures: [55, 55, 55, 55] } + expected: [0, 0, 0, 0] + - input: { temperatures: [40, 35, 32, 37, 50] } + expected: [4, 2, 1, 1, 0] + - input: { temperatures: [89, 62, 70, 58, 47, 47, 46, 76, 100, 70] } + expected: [8, 1, 5, 4, 3, 2, 1, 1, 0, 0] + description: | Given an array of integers `temperatures` represents the daily temperatures, return *an array* `answer` *such that* `answer[i]` *is the number of days you have to wait after the* ith *day to get a warmer temperature*. diff --git a/backend/data/questions/decode-string.yaml b/backend/data/questions/decode-string.yaml index 75633d3..c45a44e 100644 --- a/backend/data/questions/decode-string.yaml +++ b/backend/data/questions/decode-string.yaml @@ -10,6 +10,32 @@ categories: patterns: - monotonic-stack +function_signature: "def decode_string(s: str) -> str:" + +test_cases: + visible: + - input: { s: "3[a]2[bc]" } + expected: "aaabcbc" + - input: { s: "3[a2[c]]" } + expected: "accaccacc" + - input: { s: "2[abc]3[cd]ef" } + expected: "abcabccdcdcdef" + hidden: + - input: { s: "abc" } + expected: "abc" + - input: { s: "10[a]" } + expected: "aaaaaaaaaa" + - input: { s: "2[2[2[b]]]" } + expected: "bbbbbbbb" + - input: { s: "1[ab]" } + expected: "ab" + - input: { s: "2[xy3[z]]" } + expected: "xyzzzxyzzz" + - input: { s: "2[a2[b]]" } + expected: "abbabb" + - input: { s: "100[x]" } + expected: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + description: | Given an encoded string, return its decoded string. diff --git a/backend/data/questions/decode-ways.yaml b/backend/data/questions/decode-ways.yaml index c5d374b..5c361a2 100644 --- a/backend/data/questions/decode-ways.yaml +++ b/backend/data/questions/decode-ways.yaml @@ -9,6 +9,26 @@ categories: patterns: - dynamic-programming +function_signature: "def num_decodings(s: str) -> int:" + +test_cases: + visible: + - input: { s: "12" } + expected: 2 + - input: { s: "226" } + expected: 3 + - input: { s: "06" } + expected: 0 + hidden: + - input: { s: "1" } + expected: 1 + - input: { s: "10" } + expected: 1 + - input: { s: "2101" } + expected: 1 + - input: { s: "11106" } + expected: 2 + description: | You have intercepted a secret message encoded as a string of numbers. The message is **decoded** via the following mapping: diff --git a/backend/data/questions/diameter-of-binary-tree.yaml b/backend/data/questions/diameter-of-binary-tree.yaml index 480f686..f8d9807 100644 --- a/backend/data/questions/diameter-of-binary-tree.yaml +++ b/backend/data/questions/diameter-of-binary-tree.yaml @@ -10,6 +10,26 @@ patterns: - dfs - tree-traversal +function_signature: "def diameter_of_binary_tree(root: TreeNode) -> int:" + +test_cases: + visible: + - input: { root: [1, 2, 3, 4, 5] } + expected: 3 + - input: { root: [1, 2] } + expected: 1 + hidden: + - input: { root: [1] } + expected: 0 + - input: { root: [1, 2, 3] } + expected: 2 + - input: { root: [1, 2, null, 3, null, 4] } + expected: 3 + - input: { root: [1, 2, 3, 4, 5, 6, 7] } + expected: 4 + - input: { root: [4, -7, -3, null, null, -9, -3, 9, -7, -4, null, 6, null, -6, -6, null, null, 0, 6, 5, null, 9, null, null, -1, -4, null, null, null, -2] } + expected: 8 + description: | Given the `root` of a binary tree, return *the length of the **diameter** of the tree*. diff --git a/backend/data/questions/edit-distance.yaml b/backend/data/questions/edit-distance.yaml index 65c47af..2f1fad4 100644 --- a/backend/data/questions/edit-distance.yaml +++ b/backend/data/questions/edit-distance.yaml @@ -9,6 +9,32 @@ categories: patterns: - dynamic-programming +function_signature: "def min_distance(word1: str, word2: str) -> int:" + +test_cases: + visible: + - input: { word1: "horse", word2: "ros" } + expected: 3 + - input: { word1: "intention", word2: "execution" } + expected: 5 + - input: { word1: "abc", word2: "abc" } + expected: 0 + hidden: + - input: { word1: "", word2: "" } + expected: 0 + - input: { word1: "abc", word2: "" } + expected: 3 + - input: { word1: "", word2: "xyz" } + expected: 3 + - input: { word1: "a", word2: "b" } + expected: 1 + - input: { word1: "kitten", word2: "sitting" } + expected: 3 + - input: { word1: "saturday", word2: "sunday" } + expected: 3 + - input: { word1: "algorithm", word2: "altruistic" } + expected: 6 + description: | Given two strings `word1` and `word2`, return *the minimum number of operations required to convert `word1` to `word2`*. diff --git a/backend/data/questions/evaluate-reverse-polish-notation.yaml b/backend/data/questions/evaluate-reverse-polish-notation.yaml index 44a3d65..28c3bf0 100644 --- a/backend/data/questions/evaluate-reverse-polish-notation.yaml +++ b/backend/data/questions/evaluate-reverse-polish-notation.yaml @@ -10,6 +10,28 @@ categories: patterns: - monotonic-stack +function_signature: "def eval_rpn(tokens: list[str]) -> int:" + +test_cases: + visible: + - input: { tokens: ["2", "1", "+", "3", "*"] } + expected: 9 + - input: { tokens: ["4", "13", "5", "/", "+"] } + expected: 6 + - input: { tokens: ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"] } + expected: 22 + hidden: + - input: { tokens: ["3"] } + expected: 3 + - input: { tokens: ["1", "2", "+"] } + expected: 3 + - input: { tokens: ["5", "1", "2", "+", "4", "*", "+", "3", "-"] } + expected: 14 + - input: { tokens: ["15", "7", "1", "1", "+", "-", "/", "3", "*", "2", "1", "1", "+", "+", "-"] } + expected: 5 + - input: { tokens: ["-78", "-33", "196", "+", "-19", "-", "115", "+", "-", "-99", "/", "-18", "8", "*", "-86", "-", "-", "16", "/", "26", "-14", "-", "-", "47", "-", "101", "-", "163", "*", "143", "-", "0", "-", "171", "+", "120", "*", "-60", "+", "156", "/", "173", "/", "-24", "11", "+", "21", "/", "*", "44", "*", "180", "70", "-", "-40", "*", "86", "132", "-", "-", "-126", "/", "-3", "170", "-", "-","-95", "-", "-", "153", "/", "-", "11", "+", "-60", "191", "-", "/", "-", "27", "/", "21", "/", "+", "/", "-89", "218", "-", "-", "7", "-", "-", "-27", "31", "*", "/", "23", "-", "-88", "123", "-", "-38", "/", "*", "-90", "-83", "/", "+", "-20", "+", "-31", "/", "-116", "79", "-", "*", "*", "238", "-69", "*", "-", "-", "192", "-", "/", "-", "170", "-", "59", "*", "37", "*", "-", "/", "-64", "139", "-", "-", "-58", "-", "25", "-11", "/", "/", "-", "-15", "*", "-", "39", "/", "-", "20", "-175", "/", "-114", "*", "-40", "*", "*", "17", "+", "+", "-10", "-", "*", "56", "/", "-", "-43", "-", "-104", "-", "+", "179", "/", "169", "-50", "-", "-52", "-10", "-", "+", "-", "247", "-192", "+", "-24", "-117", "-", "-51", "-", "/", "-", "+", "/", "*"] } + expected: 2 + description: | You are given an array of strings `tokens` that represents an arithmetic expression in a [Reverse Polish Notation](http://en.wikipedia.org/wiki/Reverse_Polish_notation). diff --git a/backend/data/questions/find-minimum-in-rotated-sorted-array.yaml b/backend/data/questions/find-minimum-in-rotated-sorted-array.yaml index 4b8b822..0e01e2b 100644 --- a/backend/data/questions/find-minimum-in-rotated-sorted-array.yaml +++ b/backend/data/questions/find-minimum-in-rotated-sorted-array.yaml @@ -9,6 +9,26 @@ categories: patterns: - binary-search +function_signature: "def find_min(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [3, 4, 5, 1, 2] } + expected: 1 + - input: { nums: [4, 5, 6, 7, 0, 1, 2] } + expected: 0 + - input: { nums: [11, 13, 15, 17] } + expected: 11 + hidden: + - input: { nums: [1] } + expected: 1 + - input: { nums: [2, 1] } + expected: 1 + - input: { nums: [1, 2, 3, 4, 5] } + expected: 1 + - input: { nums: [5, 1, 2, 3, 4] } + expected: 1 + description: | Suppose an array of length `n` sorted in ascending order is **rotated** between `1` and `n` times. For example, the array `nums = [0,1,2,4,5,6,7]` might become: diff --git a/backend/data/questions/find-the-duplicate-number.yaml b/backend/data/questions/find-the-duplicate-number.yaml index 8da3dad..f761281 100644 --- a/backend/data/questions/find-the-duplicate-number.yaml +++ b/backend/data/questions/find-the-duplicate-number.yaml @@ -10,6 +10,24 @@ patterns: - fast-slow-pointers - binary-search +function_signature: "def find_duplicate(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [1, 3, 4, 2, 2] } + expected: 2 + - input: { nums: [3, 1, 3, 4, 2] } + expected: 3 + - input: { nums: [3, 3, 3, 3, 3] } + expected: 3 + hidden: + - input: { nums: [1, 1] } + expected: 1 + - input: { nums: [2, 2, 2, 2, 2] } + expected: 2 + - input: { nums: [1, 4, 4, 2, 4] } + expected: 4 + description: | Given an array of integers `nums` containing `n + 1` integers where each integer is in the range `[1, n]` inclusive. diff --git a/backend/data/questions/four-sum.yaml b/backend/data/questions/four-sum.yaml index f885d70..cdfafde 100644 --- a/backend/data/questions/four-sum.yaml +++ b/backend/data/questions/four-sum.yaml @@ -10,6 +10,22 @@ categories: patterns: - two-pointers +function_signature: "def four_sum(nums: list[int], target: int) -> list[list[int]]:" + +test_cases: + visible: + - input: { nums: [1, 0, -1, 0, -2, 2], target: 0 } + expected: [[-2, -1, 1, 2], [-2, 0, 0, 2], [-1, 0, 0, 1]] + - input: { nums: [2, 2, 2, 2, 2], target: 8 } + expected: [[2, 2, 2, 2]] + hidden: + - input: { nums: [0, 0, 0, 0], target: 0 } + expected: [[0, 0, 0, 0]] + - input: { nums: [1, 2, 3, 4], target: 10 } + expected: [[1, 2, 3, 4]] + - input: { nums: [1, 2, 3, 4], target: 100 } + expected: [] + description: | Given an array `nums` of `n` integers, return *an array of all the **unique** quadruplets* `[nums[a], nums[b], nums[c], nums[d]]` such that: diff --git a/backend/data/questions/gas-station.yaml b/backend/data/questions/gas-station.yaml index 148946d..df7a0fd 100644 --- a/backend/data/questions/gas-station.yaml +++ b/backend/data/questions/gas-station.yaml @@ -8,6 +8,26 @@ categories: patterns: - greedy +function_signature: "def can_complete_circuit(gas: list[int], cost: list[int]) -> int:" + +test_cases: + visible: + - input: { gas: [1, 2, 3, 4, 5], cost: [3, 4, 5, 1, 2] } + expected: 3 + - input: { gas: [2, 3, 4], cost: [3, 4, 3] } + expected: -1 + hidden: + - input: { gas: [5, 1, 2, 3, 4], cost: [4, 4, 1, 5, 1] } + expected: 4 + - input: { gas: [3], cost: [3] } + expected: 0 + - input: { gas: [1, 2], cost: [2, 1] } + expected: 1 + - input: { gas: [5, 8, 2, 8], cost: [6, 5, 6, 6] } + expected: 3 + - input: { gas: [3, 3, 4], cost: [3, 4, 4] } + expected: -1 + description: | There are `n` gas stations along a circular route, where the amount of gas at the ith station is `gas[i]`. diff --git a/backend/data/questions/generate-parentheses.yaml b/backend/data/questions/generate-parentheses.yaml index ebe5811..810993c 100644 --- a/backend/data/questions/generate-parentheses.yaml +++ b/backend/data/questions/generate-parentheses.yaml @@ -9,6 +9,20 @@ categories: patterns: - backtracking +function_signature: "def generate_parenthesis(n: int) -> list[str]:" + +test_cases: + visible: + - input: { n: 3 } + expected: ["((()))", "(()())", "(())()", "()(())", "()()()"] + - input: { n: 1 } + expected: ["()"] + hidden: + - input: { n: 2 } + expected: ["(())", "()()"] + - input: { n: 4 } + expected: ["(((())))", "((()()))", "((())())", "((()))()", "(()(()))", "(()()())", "(()())()", "(())(())", "(())()()", "()((()))", "()(()())", "()(())()", "()()(())", "()()()()"] + description: | Given `n` pairs of parentheses, write a function to *generate all combinations of well-formed parentheses*. diff --git a/backend/data/questions/group-anagrams.yaml b/backend/data/questions/group-anagrams.yaml index b927bc1..9b1518b 100644 --- a/backend/data/questions/group-anagrams.yaml +++ b/backend/data/questions/group-anagrams.yaml @@ -10,6 +10,24 @@ categories: patterns: - hashing +function_signature: "def group_anagrams(strs: list[str]) -> list[list[str]]:" + +test_cases: + visible: + - input: { strs: ["eat", "tea", "tan", "ate", "nat", "bat"] } + expected: [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]] + - input: { strs: [""] } + expected: [[""]] + - input: { strs: ["a"] } + expected: [["a"]] + hidden: + - input: { strs: ["abc", "bca", "cab", "xyz", "zyx"] } + expected: [["abc", "bca", "cab"], ["xyz", "zyx"]] + - input: { strs: ["", ""] } + expected: [["", ""]] + - input: { strs: ["listen", "silent", "enlist"] } + expected: [["listen", "silent", "enlist"]] + description: | Given an array of strings `strs`, group the **anagrams** together. You can return the answer in **any order**. diff --git a/backend/data/questions/house-robber.yaml b/backend/data/questions/house-robber.yaml index c17e5fd..d939799 100644 --- a/backend/data/questions/house-robber.yaml +++ b/backend/data/questions/house-robber.yaml @@ -9,6 +9,24 @@ categories: patterns: - dynamic-programming +function_signature: "def rob(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [1, 2, 3, 1] } + expected: 4 + - input: { nums: [2, 7, 9, 3, 1] } + expected: 12 + hidden: + - input: { nums: [1] } + expected: 1 + - input: { nums: [2, 1] } + expected: 2 + - input: { nums: [1, 2, 3, 4, 5] } + expected: 9 + - input: { nums: [0, 0, 0, 0] } + expected: 0 + description: | You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and **it will automatically contact the police if two adjacent houses were broken into on the same night**. diff --git a/backend/data/questions/insert-interval.yaml b/backend/data/questions/insert-interval.yaml index 955dddf..2926d4e 100644 --- a/backend/data/questions/insert-interval.yaml +++ b/backend/data/questions/insert-interval.yaml @@ -8,6 +8,24 @@ categories: patterns: - intervals +function_signature: "def insert(intervals: list[list[int]], newInterval: list[int]) -> list[list[int]]:" + +test_cases: + visible: + - input: { intervals: [[1, 3], [6, 9]], newInterval: [2, 5] } + expected: [[1, 5], [6, 9]] + - input: { intervals: [[1, 2], [3, 5], [6, 7], [8, 10], [12, 16]], newInterval: [4, 8] } + expected: [[1, 2], [3, 10], [12, 16]] + - input: { intervals: [], newInterval: [5, 7] } + expected: [[5, 7]] + hidden: + - input: { intervals: [[1, 5]], newInterval: [2, 3] } + expected: [[1, 5]] + - input: { intervals: [[1, 5]], newInterval: [6, 8] } + expected: [[1, 5], [6, 8]] + - input: { intervals: [[3, 5], [12, 15]], newInterval: [6, 6] } + expected: [[3, 5], [6, 6], [12, 15]] + description: | You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [start_i, end_i]` represent the start and the end of the ith interval and `intervals` is sorted in ascending order by `start_i`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another interval. diff --git a/backend/data/questions/integer-break.yaml b/backend/data/questions/integer-break.yaml index 7ce9513..adde7c2 100644 --- a/backend/data/questions/integer-break.yaml +++ b/backend/data/questions/integer-break.yaml @@ -10,6 +10,32 @@ patterns: - dynamic-programming - greedy +function_signature: "def integer_break(n: int) -> int:" + +test_cases: + visible: + - input: { n: 2 } + expected: 1 + - input: { n: 10 } + expected: 36 + hidden: + - input: { n: 3 } + expected: 2 + - input: { n: 4 } + expected: 4 + - input: { n: 5 } + expected: 6 + - input: { n: 6 } + expected: 9 + - input: { n: 7 } + expected: 12 + - input: { n: 8 } + expected: 18 + - input: { n: 11 } + expected: 54 + - input: { n: 58 } + expected: 1549681956 + description: | Given an integer `n`, break it into the sum of `k` **positive integers**, where `k >= 2`, and maximize the product of those integers. diff --git a/backend/data/questions/invert-binary-tree.yaml b/backend/data/questions/invert-binary-tree.yaml index 2fad6af..02cc8f3 100644 --- a/backend/data/questions/invert-binary-tree.yaml +++ b/backend/data/questions/invert-binary-tree.yaml @@ -11,6 +11,24 @@ patterns: - dfs - bfs +function_signature: "def invert_tree(root: TreeNode | None) -> TreeNode | None:" + +test_cases: + visible: + - input: { root: [4, 2, 7, 1, 3, 6, 9] } + expected: [4, 7, 2, 9, 6, 3, 1] + - input: { root: [2, 1, 3] } + expected: [2, 3, 1] + - input: { root: [] } + expected: [] + hidden: + - input: { root: [1] } + expected: [1] + - input: { root: [1, 2] } + expected: [1, null, 2] + - input: { root: [1, null, 2] } + expected: [1, 2] + description: | Given the `root` of a binary tree, invert the tree, and return *its root*. diff --git a/backend/data/questions/jump-game-ii.yaml b/backend/data/questions/jump-game-ii.yaml index ef438dd..d01fb6c 100644 --- a/backend/data/questions/jump-game-ii.yaml +++ b/backend/data/questions/jump-game-ii.yaml @@ -9,6 +9,30 @@ categories: patterns: - greedy +function_signature: "def jump(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [2, 3, 1, 1, 4] } + expected: 2 + - input: { nums: [2, 3, 0, 1, 4] } + expected: 2 + - input: { nums: [1] } + expected: 0 + hidden: + - input: { nums: [1, 2, 3] } + expected: 2 + - input: { nums: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 0] } + expected: 2 + - input: { nums: [1, 1, 1, 1, 1] } + expected: 4 + - input: { nums: [5, 6, 4, 4, 6, 9, 4, 4, 7, 4, 4, 8, 2, 6, 8, 1, 5, 9, 6, 5, 2, 7, 9, 7, 9, 6, 9, 4, 1, 6, 8, 8, 4, 4, 2, 0, 3, 8, 5] } + expected: 5 + - input: { nums: [7, 0, 9, 6, 9, 6, 1, 7, 9, 0, 1, 2, 9, 0, 3] } + expected: 2 + - input: { nums: [2, 1] } + expected: 1 + description: | You are given a **0-indexed** array of integers `nums` of length `n`. You are initially positioned at index `0`. diff --git a/backend/data/questions/jump-game.yaml b/backend/data/questions/jump-game.yaml index 005f42d..2d7ef34 100644 --- a/backend/data/questions/jump-game.yaml +++ b/backend/data/questions/jump-game.yaml @@ -10,6 +10,24 @@ patterns: - greedy - dynamic-programming +function_signature: "def can_jump(nums: list[int]) -> bool:" + +test_cases: + visible: + - input: { nums: [2, 3, 1, 1, 4] } + expected: true + - input: { nums: [3, 2, 1, 0, 4] } + expected: false + hidden: + - input: { nums: [0] } + expected: true + - input: { nums: [2, 0, 0] } + expected: true + - input: { nums: [1, 0, 1, 0] } + expected: false + - input: { nums: [5, 4, 3, 2, 1, 0, 0] } + expected: true + description: | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position. diff --git a/backend/data/questions/kth-largest-element-in-an-array.yaml b/backend/data/questions/kth-largest-element-in-an-array.yaml index 8ab2aff..6b7f43b 100644 --- a/backend/data/questions/kth-largest-element-in-an-array.yaml +++ b/backend/data/questions/kth-largest-element-in-an-array.yaml @@ -11,6 +11,30 @@ patterns: - heap - binary-search +function_signature: "def find_kth_largest(nums: list[int], k: int) -> int:" + +test_cases: + visible: + - input: { nums: [3, 2, 1, 5, 6, 4], k: 2 } + expected: 5 + - input: { nums: [3, 2, 3, 1, 2, 4, 5, 5, 6], k: 4 } + expected: 4 + - input: { nums: [1], k: 1 } + expected: 1 + hidden: + - input: { nums: [7, 7, 7, 7], k: 2 } + expected: 7 + - input: { nums: [1, 2, 3, 4, 5], k: 5 } + expected: 1 + - input: { nums: [1, 2, 3, 4, 5], k: 1 } + expected: 5 + - input: { nums: [-1, -2, -3, -4], k: 1 } + expected: -1 + - input: { nums: [5, 2, 4, 1, 3, 6, 0], k: 3 } + expected: 4 + - input: { nums: [99, 99], k: 1 } + expected: 99 + description: | Given an integer array `nums` and an integer `k`, return *the* `k`th *largest element in the array*. diff --git a/backend/data/questions/kth-smallest-element-in-a-bst.yaml b/backend/data/questions/kth-smallest-element-in-a-bst.yaml index dfc953d..882dce0 100644 --- a/backend/data/questions/kth-smallest-element-in-a-bst.yaml +++ b/backend/data/questions/kth-smallest-element-in-a-bst.yaml @@ -10,6 +10,24 @@ patterns: - dfs - tree-traversal +function_signature: "def kth_smallest(root: TreeNode | None, k: int) -> int:" + +test_cases: + visible: + - input: { root: [3, 1, 4, null, 2], k: 1 } + expected: 1 + - input: { root: [5, 3, 6, 2, 4, null, null, 1], k: 3 } + expected: 3 + - input: { root: [1], k: 1 } + expected: 1 + hidden: + - input: { root: [2, 1, 3], k: 2 } + expected: 2 + - input: { root: [5, 3, 6, 2, 4, null, null, 1], k: 6 } + expected: 6 + - input: { root: [3, 1, 4, null, 2], k: 4 } + expected: 4 + description: | Given the `root` of a binary search tree, and an integer `k`, return the `k`th smallest value (**1-indexed**) of all the values of the nodes in the tree. diff --git a/backend/data/questions/largest-rectangle-in-histogram.yaml b/backend/data/questions/largest-rectangle-in-histogram.yaml index d5e6417..7c9e6aa 100644 --- a/backend/data/questions/largest-rectangle-in-histogram.yaml +++ b/backend/data/questions/largest-rectangle-in-histogram.yaml @@ -9,6 +9,32 @@ categories: patterns: - monotonic-stack +function_signature: "def largest_rectangle_area(heights: list[int]) -> int:" + +test_cases: + visible: + - input: { heights: [2, 1, 5, 6, 2, 3] } + expected: 10 + - input: { heights: [2, 4] } + expected: 4 + - input: { heights: [1, 1] } + expected: 2 + hidden: + - input: { heights: [1] } + expected: 1 + - input: { heights: [0] } + expected: 0 + - input: { heights: [2, 1, 2] } + expected: 3 + - input: { heights: [1, 2, 3, 4, 5] } + expected: 9 + - input: { heights: [5, 4, 3, 2, 1] } + expected: 9 + - input: { heights: [3, 6, 5, 7, 4, 8, 1, 0] } + expected: 20 + - input: { heights: [4, 2, 0, 3, 2, 5] } + expected: 6 + description: | Given an array of integers `heights` representing the histogram's bar height where the width of each bar is `1`, return *the area of the largest rectangle in the histogram*. diff --git a/backend/data/questions/letter-combinations-of-a-phone-number.yaml b/backend/data/questions/letter-combinations-of-a-phone-number.yaml index 1fb3509..0f1aa84 100644 --- a/backend/data/questions/letter-combinations-of-a-phone-number.yaml +++ b/backend/data/questions/letter-combinations-of-a-phone-number.yaml @@ -10,6 +10,22 @@ categories: patterns: - backtracking +function_signature: "def letter_combinations(digits: str) -> list[str]:" + +test_cases: + visible: + - input: { digits: "23" } + expected: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"] + - input: { digits: "" } + expected: [] + - input: { digits: "2" } + expected: ["a", "b", "c"] + hidden: + - input: { digits: "7" } + expected: ["p", "q", "r", "s"] + - input: { digits: "79" } + expected: ["pw", "px", "py", "pz", "qw", "qx", "qy", "qz", "rw", "rx", "ry", "rz", "sw", "sx", "sy", "sz"] + description: | Given a string containing digits from `2-9` inclusive, return all possible letter combinations that the number could represent. Return the answer in **any order**. diff --git a/backend/data/questions/linked-list-cycle.yaml b/backend/data/questions/linked-list-cycle.yaml index 4fc5d78..c6ecb2e 100644 --- a/backend/data/questions/linked-list-cycle.yaml +++ b/backend/data/questions/linked-list-cycle.yaml @@ -10,6 +10,24 @@ categories: patterns: - fast-slow-pointers +function_signature: "def has_cycle(head: ListNode | None) -> bool:" + +test_cases: + visible: + - input: { head: [3, 2, 0, -4], pos: 1 } + expected: true + - input: { head: [1, 2], pos: 0 } + expected: true + - input: { head: [1], pos: -1 } + expected: false + hidden: + - input: { head: [], pos: -1 } + expected: false + - input: { head: [1, 2, 3, 4, 5], pos: -1 } + expected: false + - input: { head: [1, 2, 3, 4, 5], pos: 4 } + expected: true + description: | Given `head`, the head of a linked list, determine if the linked list has a cycle in it. diff --git a/backend/data/questions/longest-common-subsequence.yaml b/backend/data/questions/longest-common-subsequence.yaml index 0b4291f..f33de19 100644 --- a/backend/data/questions/longest-common-subsequence.yaml +++ b/backend/data/questions/longest-common-subsequence.yaml @@ -9,6 +9,24 @@ categories: patterns: - dynamic-programming +function_signature: "def longest_common_subsequence(text1: str, text2: str) -> int:" + +test_cases: + visible: + - input: { text1: "abcde", text2: "ace" } + expected: 3 + - input: { text1: "abc", text2: "abc" } + expected: 3 + - input: { text1: "abc", text2: "def" } + expected: 0 + hidden: + - input: { text1: "a", text2: "a" } + expected: 1 + - input: { text1: "a", text2: "b" } + expected: 0 + - input: { text1: "oxcpqrsvwf", text2: "shmtulqrypy" } + expected: 2 + description: | Given two strings `text1` and `text2`, return *the length of their longest **common subsequence***. If there is no **common subsequence**, return `0`. diff --git a/backend/data/questions/longest-consecutive-sequence.yaml b/backend/data/questions/longest-consecutive-sequence.yaml index 5766c46..395272c 100644 --- a/backend/data/questions/longest-consecutive-sequence.yaml +++ b/backend/data/questions/longest-consecutive-sequence.yaml @@ -9,6 +9,24 @@ categories: patterns: - union-find +function_signature: "def longest_consecutive(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [100, 4, 200, 1, 3, 2] } + expected: 4 + - input: { nums: [0, 3, 7, 2, 5, 8, 4, 6, 0, 1] } + expected: 9 + hidden: + - input: { nums: [] } + expected: 0 + - input: { nums: [1, 0, 1, 2] } + expected: 3 + - input: { nums: [9, 1, 4, 7, 3, -1, 0, 5, 8, -1, 6] } + expected: 7 + - input: { nums: [1] } + expected: 1 + description: | Given an unsorted array of integers `nums`, return *the length of the longest consecutive elements sequence*. diff --git a/backend/data/questions/longest-increasing-subsequence.yaml b/backend/data/questions/longest-increasing-subsequence.yaml index aaab516..4c834e0 100644 --- a/backend/data/questions/longest-increasing-subsequence.yaml +++ b/backend/data/questions/longest-increasing-subsequence.yaml @@ -11,6 +11,26 @@ patterns: - dynamic-programming - binary-search +function_signature: "def length_of_lis(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [10, 9, 2, 5, 3, 7, 101, 18] } + expected: 4 + - input: { nums: [0, 1, 0, 3, 2, 3] } + expected: 4 + - input: { nums: [7, 7, 7, 7, 7, 7, 7] } + expected: 1 + hidden: + - input: { nums: [1] } + expected: 1 + - input: { nums: [1, 2, 3, 4, 5] } + expected: 5 + - input: { nums: [5, 4, 3, 2, 1] } + expected: 1 + - input: { nums: [4, 10, 4, 3, 8, 9] } + expected: 3 + description: | Given an integer array `nums`, return *the length of the longest **strictly increasing subsequence***. diff --git a/backend/data/questions/longest-palindromic-substring.yaml b/backend/data/questions/longest-palindromic-substring.yaml index 36c9a04..ef59bb3 100644 --- a/backend/data/questions/longest-palindromic-substring.yaml +++ b/backend/data/questions/longest-palindromic-substring.yaml @@ -10,6 +10,24 @@ patterns: - two-pointers - dynamic-programming +function_signature: "def longest_palindrome(s: str) -> str:" + +test_cases: + visible: + - input: { s: "babad" } + expected: "bab" + - input: { s: "cbbd" } + expected: "bb" + hidden: + - input: { s: "a" } + expected: "a" + - input: { s: "ac" } + expected: "a" + - input: { s: "racecar" } + expected: "racecar" + - input: { s: "aacabdkacaa" } + expected: "aca" + description: | Given a string `s`, return *the longest palindromic substring* in `s`. diff --git a/backend/data/questions/longest-substring-without-repeating.yaml b/backend/data/questions/longest-substring-without-repeating.yaml index 1b52d46..8e0f673 100644 --- a/backend/data/questions/longest-substring-without-repeating.yaml +++ b/backend/data/questions/longest-substring-without-repeating.yaml @@ -9,6 +9,26 @@ categories: patterns: - sliding-window +function_signature: "def length_of_longest_substring(s: str) -> int:" + +test_cases: + visible: + - input: { s: "abcabcbb" } + expected: 3 + - input: { s: "bbbbb" } + expected: 1 + - input: { s: "pwwkew" } + expected: 3 + hidden: + - input: { s: "" } + expected: 0 + - input: { s: " " } + expected: 1 + - input: { s: "au" } + expected: 2 + - input: { s: "dvdf" } + expected: 3 + description: | Given a string `s`, find the length of the **longest substring** without repeating characters. diff --git a/backend/data/questions/lowest-common-ancestor-of-a-binary-search-tree.yaml b/backend/data/questions/lowest-common-ancestor-of-a-binary-search-tree.yaml index bb54833..b43d7ff 100644 --- a/backend/data/questions/lowest-common-ancestor-of-a-binary-search-tree.yaml +++ b/backend/data/questions/lowest-common-ancestor-of-a-binary-search-tree.yaml @@ -9,6 +9,24 @@ patterns: - tree-traversal - binary-search +function_signature: "def lowest_common_ancestor(root: TreeNode, p: TreeNode, q: TreeNode) -> TreeNode:" + +test_cases: + visible: + - input: { root: [6, 2, 8, 0, 4, 7, 9, null, null, 3, 5], p: 2, q: 8 } + expected: 6 + - input: { root: [6, 2, 8, 0, 4, 7, 9, null, null, 3, 5], p: 2, q: 4 } + expected: 2 + - input: { root: [2, 1], p: 2, q: 1 } + expected: 2 + hidden: + - input: { root: [6, 2, 8, 0, 4, 7, 9, null, null, 3, 5], p: 3, q: 5 } + expected: 4 + - input: { root: [6, 2, 8, 0, 4, 7, 9, null, null, 3, 5], p: 7, q: 9 } + expected: 8 + - input: { root: [3, 1, 4, null, 2], p: 1, q: 4 } + expected: 3 + description: | Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST. diff --git a/backend/data/questions/maximum-depth-of-binary-tree.yaml b/backend/data/questions/maximum-depth-of-binary-tree.yaml index e9cb624..e3125bd 100644 --- a/backend/data/questions/maximum-depth-of-binary-tree.yaml +++ b/backend/data/questions/maximum-depth-of-binary-tree.yaml @@ -11,6 +11,24 @@ patterns: - bfs - tree-traversal +function_signature: "def max_depth(root: TreeNode | None) -> int:" + +test_cases: + visible: + - input: { root: [3, 9, 20, null, null, 15, 7] } + expected: 3 + - input: { root: [1, null, 2] } + expected: 2 + - input: { root: [] } + expected: 0 + hidden: + - input: { root: [1] } + expected: 1 + - input: { root: [1, 2, 3, 4, 5] } + expected: 3 + - input: { root: [1, 2, null, 3, null, 4] } + expected: 4 + description: | Given the `root` of a binary tree, return *its maximum depth*. diff --git a/backend/data/questions/maximum-product-subarray.yaml b/backend/data/questions/maximum-product-subarray.yaml index 6843952..0488aed 100644 --- a/backend/data/questions/maximum-product-subarray.yaml +++ b/backend/data/questions/maximum-product-subarray.yaml @@ -9,6 +9,32 @@ categories: patterns: - dynamic-programming +function_signature: "def max_product(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [2, 3, -2, 4] } + expected: 6 + - input: { nums: [-2, 0, -1] } + expected: 0 + - input: { nums: [2, -5, -2, -4, 3] } + expected: 24 + hidden: + - input: { nums: [0] } + expected: 0 + - input: { nums: [-2] } + expected: -2 + - input: { nums: [1, 2, 3, 4] } + expected: 24 + - input: { nums: [-1, -2, -3] } + expected: 6 + - input: { nums: [0, 2] } + expected: 2 + - input: { nums: [-2, 3, -4] } + expected: 24 + - input: { nums: [2, -1, 1, 1] } + expected: 2 + description: | Given an integer array `nums`, find a subarray that has the largest product, and return *the product*. diff --git a/backend/data/questions/median-of-two-sorted-arrays.yaml b/backend/data/questions/median-of-two-sorted-arrays.yaml index c82d6fd..02901bd 100644 --- a/backend/data/questions/median-of-two-sorted-arrays.yaml +++ b/backend/data/questions/median-of-two-sorted-arrays.yaml @@ -9,6 +9,24 @@ categories: patterns: - binary-search +function_signature: "def find_median_sorted_arrays(nums1: list[int], nums2: list[int]) -> float:" + +test_cases: + visible: + - input: { nums1: [1, 3], nums2: [2] } + expected: 2.0 + - input: { nums1: [1, 2], nums2: [3, 4] } + expected: 2.5 + hidden: + - input: { nums1: [], nums2: [1] } + expected: 1.0 + - input: { nums1: [2], nums2: [] } + expected: 2.0 + - input: { nums1: [1, 2, 3], nums2: [4, 5, 6] } + expected: 3.5 + - input: { nums1: [1, 3], nums2: [2, 4] } + expected: 2.5 + description: | Given two sorted arrays `nums1` and `nums2` of size `m` and `n` respectively, return **the median** of the two sorted arrays. diff --git a/backend/data/questions/merge-intervals.yaml b/backend/data/questions/merge-intervals.yaml index 13d687c..adcb06f 100644 --- a/backend/data/questions/merge-intervals.yaml +++ b/backend/data/questions/merge-intervals.yaml @@ -9,6 +9,24 @@ categories: patterns: - intervals +function_signature: "def merge(intervals: list[list[int]]) -> list[list[int]]:" + +test_cases: + visible: + - input: { intervals: [[1, 3], [2, 6], [8, 10], [15, 18]] } + expected: [[1, 6], [8, 10], [15, 18]] + - input: { intervals: [[1, 4], [4, 5]] } + expected: [[1, 5]] + - input: { intervals: [[1, 4], [0, 4]] } + expected: [[0, 4]] + hidden: + - input: { intervals: [[1, 4]] } + expected: [[1, 4]] + - input: { intervals: [[1, 4], [0, 0]] } + expected: [[0, 0], [1, 4]] + - input: { intervals: [[1, 4], [2, 3]] } + expected: [[1, 4]] + description: | Given an array of `intervals` where `intervals[i] = [start_i, end_i]`, merge all overlapping intervals, and return *an array of the non-overlapping intervals that cover all the intervals in the input*. diff --git a/backend/data/questions/merge-sorted-array.yaml b/backend/data/questions/merge-sorted-array.yaml index 6ba95a1..3d2ae23 100644 --- a/backend/data/questions/merge-sorted-array.yaml +++ b/backend/data/questions/merge-sorted-array.yaml @@ -10,6 +10,24 @@ categories: patterns: - two-pointers +function_signature: "def merge(nums1: list[int], m: int, nums2: list[int], n: int) -> list[int]:" + +test_cases: + visible: + - input: { nums1: [1, 2, 3, 0, 0, 0], m: 3, nums2: [2, 5, 6], n: 3 } + expected: [1, 2, 2, 3, 5, 6] + - input: { nums1: [1], m: 1, nums2: [], n: 0 } + expected: [1] + - input: { nums1: [0], m: 0, nums2: [1], n: 1 } + expected: [1] + hidden: + - input: { nums1: [4, 5, 6, 0, 0, 0], m: 3, nums2: [1, 2, 3], n: 3 } + expected: [1, 2, 3, 4, 5, 6] + - input: { nums1: [1, 2, 3, 0, 0, 0], m: 3, nums2: [4, 5, 6], n: 3 } + expected: [1, 2, 3, 4, 5, 6] + - input: { nums1: [2, 0], m: 1, nums2: [1], n: 1 } + expected: [1, 2] + description: | You are given two integer arrays `nums1` and `nums2`, sorted in **non-decreasing order**, and two integers `m` and `n`, representing the number of elements in `nums1` and `nums2` respectively. diff --git a/backend/data/questions/merge-two-sorted-lists.yaml b/backend/data/questions/merge-two-sorted-lists.yaml index bfa0097..bab1a86 100644 --- a/backend/data/questions/merge-two-sorted-lists.yaml +++ b/backend/data/questions/merge-two-sorted-lists.yaml @@ -9,6 +9,22 @@ categories: patterns: - two-pointers +function_signature: "def merge_two_lists(list1: ListNode | None, list2: ListNode | None) -> ListNode | None:" + +test_cases: + visible: + - input: { list1: [1, 2, 4], list2: [1, 3, 4] } + expected: [1, 1, 2, 3, 4, 4] + - input: { list1: [], list2: [] } + expected: [] + - input: { list1: [], list2: [0] } + expected: [0] + hidden: + - input: { list1: [1], list2: [2] } + expected: [1, 2] + - input: { list1: [5], list2: [1, 2, 4] } + expected: [1, 2, 4, 5] + description: | You are given the heads of two sorted linked lists `list1` and `list2`. diff --git a/backend/data/questions/min-cost-climbing-stairs.yaml b/backend/data/questions/min-cost-climbing-stairs.yaml index a953f3d..ad57130 100644 --- a/backend/data/questions/min-cost-climbing-stairs.yaml +++ b/backend/data/questions/min-cost-climbing-stairs.yaml @@ -9,6 +9,24 @@ categories: patterns: - dynamic-programming +function_signature: "def min_cost_climbing_stairs(cost: list[int]) -> int:" + +test_cases: + visible: + - input: { cost: [10, 15, 20] } + expected: 15 + - input: { cost: [1, 100, 1, 1, 1, 100, 1, 1, 100, 1] } + expected: 6 + - input: { cost: [0, 0, 0, 0] } + expected: 0 + hidden: + - input: { cost: [1, 2] } + expected: 1 + - input: { cost: [10, 15] } + expected: 10 + - input: { cost: [1, 100] } + expected: 1 + description: | You are given an integer array `cost` where `cost[i]` is the cost of the ith step on a staircase. Once you pay the cost, you can either climb one or two steps. diff --git a/backend/data/questions/minimum-window-substring.yaml b/backend/data/questions/minimum-window-substring.yaml index a377ae5..c9fd6e5 100644 --- a/backend/data/questions/minimum-window-substring.yaml +++ b/backend/data/questions/minimum-window-substring.yaml @@ -9,6 +9,26 @@ categories: patterns: - sliding-window +function_signature: "def min_window(s: str, t: str) -> str:" + +test_cases: + visible: + - input: { s: "ADOBECODEBANC", t: "ABC" } + expected: "BANC" + - input: { s: "a", t: "a" } + expected: "a" + - input: { s: "a", t: "aa" } + expected: "" + hidden: + - input: { s: "ab", t: "a" } + expected: "a" + - input: { s: "ab", t: "b" } + expected: "b" + - input: { s: "bba", t: "ab" } + expected: "ba" + - input: { s: "abc", t: "cba" } + expected: "abc" + description: | Given two strings `s` and `t` of lengths `m` and `n` respectively, return *the **minimum window substring*** of `s` such that every character in `t` (**including duplicates**) is included in the window. diff --git a/backend/data/questions/network-delay-time.yaml b/backend/data/questions/network-delay-time.yaml index db60456..572228d 100644 --- a/backend/data/questions/network-delay-time.yaml +++ b/backend/data/questions/network-delay-time.yaml @@ -10,6 +10,26 @@ patterns: - bfs - heap +function_signature: "def network_delay_time(times: list[list[int]], n: int, k: int) -> int:" + +test_cases: + visible: + - input: { times: [[2, 1, 1], [2, 3, 1], [3, 4, 1]], n: 4, k: 2 } + expected: 2 + - input: { times: [[1, 2, 1]], n: 2, k: 1 } + expected: 1 + - input: { times: [[1, 2, 1]], n: 2, k: 2 } + expected: -1 + hidden: + - input: { times: [[1, 2, 1], [2, 3, 2], [1, 3, 4]], n: 3, k: 1 } + expected: 3 + - input: { times: [[1, 2, 1], [2, 1, 3]], n: 2, k: 2 } + expected: 3 + - input: { times: [[1, 2, 1], [2, 3, 7], [1, 3, 4], [2, 1, 2]], n: 3, k: 1 } + expected: 4 + - input: { times: [[3, 5, 78], [2, 1, 1], [1, 3, 0], [4, 3, 59], [5, 3, 85], [5, 2, 22], [2, 4, 23], [1, 4, 43], [4, 5, 75], [5, 1, 15], [1, 5, 91], [4, 1, 16], [3, 2, 98], [3, 4, 22], [5, 4, 31], [1, 2, 0], [2, 5, 4], [4, 2, 51], [3, 1, 36], [2, 3, 59]], n: 5, k: 5 } + expected: 31 + description: | You are given a network of `n` nodes, labeled from `1` to `n`. You are also given `times`, a list of travel times as directed edges `times[i] = (u_i, v_i, w_i)`, where `u_i` is the source node, `v_i` is the target node, and `w_i` is the time it takes for a signal to travel from source to target. diff --git a/backend/data/questions/number-of-islands.yaml b/backend/data/questions/number-of-islands.yaml index efe417e..abca9e2 100644 --- a/backend/data/questions/number-of-islands.yaml +++ b/backend/data/questions/number-of-islands.yaml @@ -11,6 +11,24 @@ patterns: - bfs - matrix-traversal +function_signature: "def num_islands(grid: list[list[str]]) -> int:" + +test_cases: + visible: + - input: { grid: [["1", "1", "1", "1", "0"], ["1", "1", "0", "1", "0"], ["1", "1", "0", "0", "0"], ["0", "0", "0", "0", "0"]] } + expected: 1 + - input: { grid: [["1", "1", "0", "0", "0"], ["1", "1", "0", "0", "0"], ["0", "0", "1", "0", "0"], ["0", "0", "0", "1", "1"]] } + expected: 3 + hidden: + - input: { grid: [["1"]] } + expected: 1 + - input: { grid: [["0"]] } + expected: 0 + - input: { grid: [["1", "0", "1", "0", "1"]] } + expected: 3 + - input: { grid: [["1", "1"], ["1", "1"]] } + expected: 1 + description: | Given an `m × n` 2D binary grid `grid` which represents a map of `'1'`s (land) and `'0'`s (water), return *the number of islands*. diff --git a/backend/data/questions/pacific-atlantic-water-flow.yaml b/backend/data/questions/pacific-atlantic-water-flow.yaml index e4f8aad..2fa214d 100644 --- a/backend/data/questions/pacific-atlantic-water-flow.yaml +++ b/backend/data/questions/pacific-atlantic-water-flow.yaml @@ -10,6 +10,20 @@ patterns: - dfs - matrix-traversal +function_signature: "def pacific_atlantic(heights: list[list[int]]) -> list[list[int]]:" + +test_cases: + visible: + - input: { heights: [[1, 2, 2, 3, 5], [3, 2, 3, 4, 4], [2, 4, 5, 3, 1], [6, 7, 1, 4, 5], [5, 1, 1, 2, 4]] } + expected: [[0, 4], [1, 3], [1, 4], [2, 2], [3, 0], [3, 1], [4, 0]] + - input: { heights: [[1]] } + expected: [[0, 0]] + hidden: + - input: { heights: [[1, 1], [1, 1]] } + expected: [[0, 0], [0, 1], [1, 0], [1, 1]] + - input: { heights: [[1, 2], [4, 3]] } + expected: [[0, 1], [1, 0], [1, 1]] + description: | There is an `m x n` rectangular island that borders both the **Pacific Ocean** and **Atlantic Ocean**. The **Pacific Ocean** touches the island's left and top edges, and the **Atlantic Ocean** touches the island's right and bottom edges. diff --git a/backend/data/questions/palindrome-partitioning.yaml b/backend/data/questions/palindrome-partitioning.yaml index 6b9878c..624a3c3 100644 --- a/backend/data/questions/palindrome-partitioning.yaml +++ b/backend/data/questions/palindrome-partitioning.yaml @@ -11,6 +11,28 @@ patterns: - backtracking - dynamic-programming +function_signature: "def partition(s: str) -> list[list[str]]:" + +test_cases: + visible: + - input: { s: "aab" } + expected: [["a", "a", "b"], ["aa", "b"]] + - input: { s: "a" } + expected: [["a"]] + hidden: + - input: { s: "aa" } + expected: [["a", "a"], ["aa"]] + - input: { s: "abc" } + expected: [["a", "b", "c"]] + - input: { s: "aba" } + expected: [["a", "b", "a"], ["aba"]] + - input: { s: "aabb" } + expected: [["a", "a", "b", "b"], ["a", "a", "bb"], ["aa", "b", "b"], ["aa", "bb"]] + - input: { s: "abba" } + expected: [["a", "b", "b", "a"], ["a", "bb", "a"], ["abba"]] + - input: { s: "racecar" } + expected: [["r", "a", "c", "e", "c", "a", "r"], ["r", "a", "cec", "a", "r"], ["r", "aceca", "r"], ["racecar"]] + description: | Given a string `s`, partition `s` such that every substring of the partition is a **palindrome**. diff --git a/backend/data/questions/partition-equal-subset-sum.yaml b/backend/data/questions/partition-equal-subset-sum.yaml index 794e1b3..2fc14b4 100644 --- a/backend/data/questions/partition-equal-subset-sum.yaml +++ b/backend/data/questions/partition-equal-subset-sum.yaml @@ -9,6 +9,24 @@ categories: patterns: - dynamic-programming +function_signature: "def can_partition(nums: list[int]) -> bool:" + +test_cases: + visible: + - input: { nums: [1, 5, 11, 5] } + expected: true + - input: { nums: [1, 2, 3, 5] } + expected: false + - input: { nums: [1, 2, 5] } + expected: false + hidden: + - input: { nums: [1, 1] } + expected: true + - input: { nums: [2, 2, 1, 1] } + expected: true + - input: { nums: [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 99, 97] } + expected: false + description: | Given an integer array `nums`, return `true` *if you can partition the array into two subsets such that the sum of the elements in both subsets is equal* or `false` *otherwise*. diff --git a/backend/data/questions/partition-labels.yaml b/backend/data/questions/partition-labels.yaml index d3dab7d..f36d042 100644 --- a/backend/data/questions/partition-labels.yaml +++ b/backend/data/questions/partition-labels.yaml @@ -11,6 +11,30 @@ patterns: - greedy - two-pointers +function_signature: "def partition_labels(s: str) -> list[int]:" + +test_cases: + visible: + - input: { s: "ababcbacadefegdehijhklij" } + expected: [9, 7, 8] + - input: { s: "eccbbbbdec" } + expected: [10] + - input: { s: "abc" } + expected: [1, 1, 1] + hidden: + - input: { s: "a" } + expected: [1] + - input: { s: "aaa" } + expected: [3] + - input: { s: "abab" } + expected: [4] + - input: { s: "caedbdedda" } + expected: [1, 9] + - input: { s: "qiejxqfnqceocmy" } + expected: [13, 1, 1] + - input: { s: "vhaagbqkaq" } + expected: [1, 8, 1] + description: | You are given a string `s`. We want to partition the string into as many parts as possible so that each letter appears in **at most one part**. diff --git a/backend/data/questions/perfect-squares.yaml b/backend/data/questions/perfect-squares.yaml index fda05cb..2dc977a 100644 --- a/backend/data/questions/perfect-squares.yaml +++ b/backend/data/questions/perfect-squares.yaml @@ -10,6 +10,32 @@ patterns: - dynamic-programming - bfs +function_signature: "def num_squares(n: int) -> int:" + +test_cases: + visible: + - input: { n: 12 } + expected: 3 + - input: { n: 13 } + expected: 2 + - input: { n: 1 } + expected: 1 + hidden: + - input: { n: 4 } + expected: 1 + - input: { n: 2 } + expected: 2 + - input: { n: 3 } + expected: 3 + - input: { n: 7 } + expected: 4 + - input: { n: 100 } + expected: 1 + - input: { n: 99 } + expected: 3 + - input: { n: 48 } + expected: 3 + description: | Given an integer `n`, return *the least number of perfect square numbers that sum to* `n`. diff --git a/backend/data/questions/permutation-in-string.yaml b/backend/data/questions/permutation-in-string.yaml index c4d62de..257bc85 100644 --- a/backend/data/questions/permutation-in-string.yaml +++ b/backend/data/questions/permutation-in-string.yaml @@ -10,6 +10,26 @@ categories: patterns: - sliding-window +function_signature: "def check_inclusion(s1: str, s2: str) -> bool:" + +test_cases: + visible: + - input: { s1: "ab", s2: "eidbaooo" } + expected: true + - input: { s1: "ab", s2: "eidboaoo" } + expected: false + - input: { s1: "adc", s2: "dcda" } + expected: true + hidden: + - input: { s1: "a", s2: "a" } + expected: true + - input: { s1: "ab", s2: "a" } + expected: false + - input: { s1: "abc", s2: "ccccbbbbaaaa" } + expected: false + - input: { s1: "hello", s2: "ooolleoooleh" } + expected: false + description: | Given two strings `s1` and `s2`, return `true` if `s2` contains a permutation of `s1`, or `false` otherwise. diff --git a/backend/data/questions/permutations.yaml b/backend/data/questions/permutations.yaml index 6ef3e25..0501d3e 100644 --- a/backend/data/questions/permutations.yaml +++ b/backend/data/questions/permutations.yaml @@ -9,6 +9,26 @@ categories: patterns: - backtracking +function_signature: "def permute(nums: list[int]) -> list[list[int]]:" + +test_cases: + visible: + - input: { nums: [1, 2, 3] } + expected: [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] + - input: { nums: [0, 1] } + expected: [[0, 1], [1, 0]] + - input: { nums: [1] } + expected: [[1]] + hidden: + - input: { nums: [5, 4] } + expected: [[5, 4], [4, 5]] + - input: { nums: [-1, 0, 1] } + expected: [[-1, 0, 1], [-1, 1, 0], [0, -1, 1], [0, 1, -1], [1, -1, 0], [1, 0, -1]] + - input: { nums: [1, 2, 3, 4] } + expected: [[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2], [2, 1, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 1, 3], [2, 4, 3, 1], [3, 1, 2, 4], [3, 1, 4, 2], [3, 2, 1, 4], [3, 2, 4, 1], [3, 4, 1, 2], [3, 4, 2, 1], [4, 1, 2, 3], [4, 1, 3, 2], [4, 2, 1, 3], [4, 2, 3, 1], [4, 3, 1, 2], [4, 3, 2, 1]] + - input: { nums: [0] } + expected: [[0]] + description: | Given an array `nums` of distinct integers, return *all the possible permutations*. You can return the answer in **any order**. diff --git a/backend/data/questions/product-of-array-except-self.yaml b/backend/data/questions/product-of-array-except-self.yaml index 9b2bc35..1b19194 100644 --- a/backend/data/questions/product-of-array-except-self.yaml +++ b/backend/data/questions/product-of-array-except-self.yaml @@ -8,6 +8,24 @@ categories: patterns: - prefix-sum +function_signature: "def product_except_self(nums: list[int]) -> list[int]:" + +test_cases: + visible: + - input: { nums: [1, 2, 3, 4] } + expected: [24, 12, 8, 6] + - input: { nums: [-1, 1, 0, -3, 3] } + expected: [0, 0, 9, 0, 0] + hidden: + - input: { nums: [2, 3] } + expected: [3, 2] + - input: { nums: [1, 1, 1, 1] } + expected: [1, 1, 1, 1] + - input: { nums: [0, 0] } + expected: [0, 0] + - input: { nums: [5, -2, 4] } + expected: [-8, 20, -10] + description: | Given an integer array `nums`, return an array `answer` such that `answer[i]` is equal to the product of all the elements of `nums` except `nums[i]`. diff --git a/backend/data/questions/reconstruct-itinerary.yaml b/backend/data/questions/reconstruct-itinerary.yaml index dd54df2..0f86862 100644 --- a/backend/data/questions/reconstruct-itinerary.yaml +++ b/backend/data/questions/reconstruct-itinerary.yaml @@ -8,6 +8,22 @@ categories: patterns: - dfs +function_signature: "def find_itinerary(tickets: list[list[str]]) -> list[str]:" + +test_cases: + visible: + - input: { tickets: [["MUC", "LHR"], ["JFK", "MUC"], ["SFO", "SJC"], ["LHR", "SFO"]] } + expected: ["JFK", "MUC", "LHR", "SFO", "SJC"] + - input: { tickets: [["JFK", "SFO"], ["JFK", "ATL"], ["SFO", "ATL"], ["ATL", "JFK"], ["ATL", "SFO"]] } + expected: ["JFK", "ATL", "JFK", "SFO", "ATL", "SFO"] + hidden: + - input: { tickets: [["JFK", "KUL"], ["JFK", "NRT"], ["NRT", "JFK"]] } + expected: ["JFK", "NRT", "JFK", "KUL"] + - input: { tickets: [["EZE", "AXA"], ["TIA", "ANU"], ["ANU", "JFK"], ["JFK", "ANU"], ["ANU", "EZE"], ["TIA", "ANU"], ["AXA", "TIA"], ["TIA", "JFK"], ["ANU", "TIA"], ["JFK", "TIA"]] } + expected: ["JFK", "ANU", "EZE", "AXA", "TIA", "ANU", "JFK", "TIA", "ANU", "TIA", "JFK"] + - input: { tickets: [["JFK", "A"], ["A", "B"], ["B", "JFK"]] } + expected: ["JFK", "A", "B", "JFK"] + description: | You are given a list of airline `tickets` where `tickets[i] = [from_i, to_i]` represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it. diff --git a/backend/data/questions/redundant-connection.yaml b/backend/data/questions/redundant-connection.yaml index 730ff99..4e53232 100644 --- a/backend/data/questions/redundant-connection.yaml +++ b/backend/data/questions/redundant-connection.yaml @@ -9,6 +9,24 @@ patterns: - union-find - dfs +function_signature: "def find_redundant_connection(edges: list[list[int]]) -> list[int]:" + +test_cases: + visible: + - input: { edges: [[1, 2], [1, 3], [2, 3]] } + expected: [2, 3] + - input: { edges: [[1, 2], [2, 3], [3, 4], [1, 4], [1, 5]] } + expected: [1, 4] + hidden: + - input: { edges: [[1, 2], [2, 3], [3, 1]] } + expected: [3, 1] + - input: { edges: [[1, 4], [3, 4], [1, 3], [1, 2], [4, 5]] } + expected: [1, 3] + - input: { edges: [[1, 5], [3, 4], [3, 5], [4, 5], [2, 4]] } + expected: [4, 5] + - input: { edges: [[9, 10], [5, 8], [2, 6], [1, 5], [3, 8], [4, 9], [8, 10], [4, 10], [6, 8], [7, 9]] } + expected: [4, 10] + description: | In this problem, a tree is an **undirected graph** that is connected and has no cycles. diff --git a/backend/data/questions/remove-duplicates-from-sorted-array.yaml b/backend/data/questions/remove-duplicates-from-sorted-array.yaml index f193bf0..c83de10 100644 --- a/backend/data/questions/remove-duplicates-from-sorted-array.yaml +++ b/backend/data/questions/remove-duplicates-from-sorted-array.yaml @@ -9,6 +9,24 @@ categories: patterns: - two-pointers +function_signature: "def remove_duplicates(nums: list[int]) -> int:" + +test_cases: + visible: + - input: { nums: [1, 1, 2] } + expected: 2 + - input: { nums: [0, 0, 1, 1, 1, 2, 2, 3, 3, 4] } + expected: 5 + - input: { nums: [1, 2, 3] } + expected: 3 + hidden: + - input: { nums: [1] } + expected: 1 + - input: { nums: [1, 1, 1, 1, 1] } + expected: 1 + - input: { nums: [-1, 0, 0, 1, 1, 2] } + expected: 4 + description: | Given an integer array `nums` sorted in **non-decreasing order**, remove the duplicates *in-place* such that each unique element appears only **once**. The **relative order** of the elements should be kept the **same**. diff --git a/backend/data/questions/remove-element.yaml b/backend/data/questions/remove-element.yaml index a218f32..40dd602 100644 --- a/backend/data/questions/remove-element.yaml +++ b/backend/data/questions/remove-element.yaml @@ -9,6 +9,24 @@ categories: patterns: - two-pointers +function_signature: "def remove_element(nums: list[int], val: int) -> int:" + +test_cases: + visible: + - input: { nums: [3, 2, 2, 3], val: 3 } + expected: 2 + - input: { nums: [0, 1, 2, 2, 3, 0, 4, 2], val: 2 } + expected: 5 + - input: { nums: [1], val: 1 } + expected: 0 + hidden: + - input: { nums: [], val: 0 } + expected: 0 + - input: { nums: [1, 2, 3, 4, 5], val: 6 } + expected: 5 + - input: { nums: [4, 4, 4, 4], val: 4 } + expected: 0 + description: | Given an integer array `nums` and an integer `val`, remove all occurrences of `val` in `nums` **in-place**. The order of the elements may be changed. Then return *the number of elements in* `nums` *which are not equal to* `val`. diff --git a/backend/data/questions/reorder-list.yaml b/backend/data/questions/reorder-list.yaml index 1126c70..f501da6 100644 --- a/backend/data/questions/reorder-list.yaml +++ b/backend/data/questions/reorder-list.yaml @@ -10,6 +10,26 @@ patterns: - fast-slow-pointers - linkedlist-reversal +function_signature: "def reorder_list(head: ListNode) -> None:" + +test_cases: + visible: + - input: { head: [1, 2, 3, 4] } + expected: [1, 4, 2, 3] + - input: { head: [1, 2, 3, 4, 5] } + expected: [1, 5, 2, 4, 3] + hidden: + - input: { head: [1] } + expected: [1] + - input: { head: [1, 2] } + expected: [1, 2] + - input: { head: [1, 2, 3] } + expected: [1, 3, 2] + - input: { head: [1, 2, 3, 4, 5, 6] } + expected: [1, 6, 2, 5, 3, 4] + - input: { head: [1, 2, 3, 4, 5, 6, 7] } + expected: [1, 7, 2, 6, 3, 5, 4] + description: | You are given the head of a singly linked-list. The list can be represented as: diff --git a/backend/data/questions/reverse-integer.yaml b/backend/data/questions/reverse-integer.yaml index 04ff7ee..bfb0a52 100644 --- a/backend/data/questions/reverse-integer.yaml +++ b/backend/data/questions/reverse-integer.yaml @@ -8,6 +8,32 @@ categories: patterns: - greedy +function_signature: "def reverse(x: int) -> int:" + +test_cases: + visible: + - input: { x: 123 } + expected: 321 + - input: { x: -123 } + expected: -321 + - input: { x: 120 } + expected: 21 + hidden: + - input: { x: 0 } + expected: 0 + - input: { x: -120 } + expected: -21 + - input: { x: 1534236469 } + expected: 0 + - input: { x: -2147483648 } + expected: 0 + - input: { x: 2147483647 } + expected: 0 + - input: { x: 1463847412 } + expected: 2147483641 + - input: { x: -1 } + expected: -1 + description: | Given a signed 32-bit integer `x`, return `x` *with its digits reversed*. If reversing `x` causes the value to go outside the signed 32-bit integer range `[-2^31, 2^31 - 1]`, then return `0`. diff --git a/backend/data/questions/reverse-linked-list.yaml b/backend/data/questions/reverse-linked-list.yaml index 66c7cfb..cb41cc6 100644 --- a/backend/data/questions/reverse-linked-list.yaml +++ b/backend/data/questions/reverse-linked-list.yaml @@ -9,6 +9,22 @@ categories: patterns: - linkedlist-reversal +function_signature: "def reverse_list(head: ListNode | None) -> ListNode | None:" + +test_cases: + visible: + - input: { head: [1, 2, 3, 4, 5] } + expected: [5, 4, 3, 2, 1] + - input: { head: [1, 2] } + expected: [2, 1] + - input: { head: [] } + expected: [] + hidden: + - input: { head: [1] } + expected: [1] + - input: { head: [1, 2, 3] } + expected: [3, 2, 1] + description: | Given the `head` of a singly linked list, reverse the list, and return *the reversed list*. diff --git a/backend/data/questions/rotate-array.yaml b/backend/data/questions/rotate-array.yaml index 910e910..3684abf 100644 --- a/backend/data/questions/rotate-array.yaml +++ b/backend/data/questions/rotate-array.yaml @@ -10,6 +10,24 @@ categories: patterns: - two-pointers +function_signature: "def rotate(nums: list[int], k: int) -> list[int]:" + +test_cases: + visible: + - input: { nums: [1, 2, 3, 4, 5, 6, 7], k: 3 } + expected: [5, 6, 7, 1, 2, 3, 4] + - input: { nums: [-1, -100, 3, 99], k: 2 } + expected: [3, 99, -1, -100] + - input: { nums: [1, 2], k: 1 } + expected: [2, 1] + hidden: + - input: { nums: [1, 2, 3], k: 4 } + expected: [3, 1, 2] + - input: { nums: [1], k: 0 } + expected: [1] + - input: { nums: [1, 2, 3, 4, 5], k: 5 } + expected: [1, 2, 3, 4, 5] + description: | Given an integer array `nums`, rotate the array to the right by `k` steps, where `k` is non-negative. diff --git a/backend/data/questions/rotate-image.yaml b/backend/data/questions/rotate-image.yaml index dff1843..b1346c7 100644 --- a/backend/data/questions/rotate-image.yaml +++ b/backend/data/questions/rotate-image.yaml @@ -9,6 +9,22 @@ categories: patterns: - matrix-manipulation +function_signature: "def rotate(matrix: list[list[int]]) -> None:" + +test_cases: + visible: + - input: { matrix: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] } + expected: [[7, 4, 1], [8, 5, 2], [9, 6, 3]] + - input: { matrix: [[5, 1, 9, 11], [2, 4, 8, 10], [13, 3, 6, 7], [15, 14, 12, 16]] } + expected: [[15, 13, 2, 5], [14, 3, 4, 1], [12, 6, 8, 9], [16, 7, 10, 11]] + hidden: + - input: { matrix: [[1]] } + expected: [[1]] + - input: { matrix: [[1, 2], [3, 4]] } + expected: [[3, 1], [4, 2]] + - input: { matrix: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] } + expected: [[13, 9, 5, 1], [14, 10, 6, 2], [15, 11, 7, 3], [16, 12, 8, 4]] + description: | You are given an `n × n` 2D matrix representing an image. Rotate the image by **90 degrees** (clockwise). diff --git a/backend/data/questions/rotting-oranges.yaml b/backend/data/questions/rotting-oranges.yaml index c71c341..6eb2a5b 100644 --- a/backend/data/questions/rotting-oranges.yaml +++ b/backend/data/questions/rotting-oranges.yaml @@ -10,6 +10,24 @@ patterns: - bfs - matrix-traversal +function_signature: "def oranges_rotting(grid: list[list[int]]) -> int:" + +test_cases: + visible: + - input: { grid: [[2, 1, 1], [1, 1, 0], [0, 1, 1]] } + expected: 4 + - input: { grid: [[2, 1, 1], [0, 1, 1], [1, 0, 1]] } + expected: -1 + - input: { grid: [[0, 2]] } + expected: 0 + hidden: + - input: { grid: [[0]] } + expected: 0 + - input: { grid: [[1]] } + expected: -1 + - input: { grid: [[2, 1, 1], [1, 1, 1], [1, 1, 2]] } + expected: 2 + description: | You are given an `m x n` `grid` where each cell can have one of three values: diff --git a/backend/data/questions/same-tree.yaml b/backend/data/questions/same-tree.yaml index 3672ca0..5ba5bd4 100644 --- a/backend/data/questions/same-tree.yaml +++ b/backend/data/questions/same-tree.yaml @@ -10,6 +10,24 @@ patterns: - dfs - tree-traversal +function_signature: "def is_same_tree(p: TreeNode | None, q: TreeNode | None) -> bool:" + +test_cases: + visible: + - input: { p: [1, 2, 3], q: [1, 2, 3] } + expected: true + - input: { p: [1, 2], q: [1, null, 2] } + expected: false + - input: { p: [1, 2, 1], q: [1, 1, 2] } + expected: false + hidden: + - input: { p: [], q: [] } + expected: true + - input: { p: [1], q: [] } + expected: false + - input: { p: [1, 2, 3, 4, 5], q: [1, 2, 3, 4, 5] } + expected: true + description: | Given the roots of two binary trees `p` and `q`, write a function to check if they are the same or not. diff --git a/backend/data/questions/search-in-rotated-sorted-array.yaml b/backend/data/questions/search-in-rotated-sorted-array.yaml index 8441c9c..8a610aa 100644 --- a/backend/data/questions/search-in-rotated-sorted-array.yaml +++ b/backend/data/questions/search-in-rotated-sorted-array.yaml @@ -9,6 +9,26 @@ categories: patterns: - binary-search +function_signature: "def search(nums: list[int], target: int) -> int:" + +test_cases: + visible: + - input: { nums: [4, 5, 6, 7, 0, 1, 2], target: 0 } + expected: 4 + - input: { nums: [4, 5, 6, 7, 0, 1, 2], target: 3 } + expected: -1 + - input: { nums: [1], target: 0 } + expected: -1 + hidden: + - input: { nums: [1], target: 1 } + expected: 0 + - input: { nums: [3, 1], target: 1 } + expected: 1 + - input: { nums: [5, 1, 3], target: 5 } + expected: 0 + - input: { nums: [1, 2, 3, 4, 5], target: 3 } + expected: 2 + description: | There is an integer array `nums` sorted in ascending order (with **distinct** values). diff --git a/backend/data/questions/set-matrix-zeroes.yaml b/backend/data/questions/set-matrix-zeroes.yaml index fd4af40..5c319b0 100644 --- a/backend/data/questions/set-matrix-zeroes.yaml +++ b/backend/data/questions/set-matrix-zeroes.yaml @@ -9,6 +9,22 @@ categories: patterns: - matrix-traversal +function_signature: "def set_zeroes(matrix: list[list[int]]) -> None:" + +test_cases: + visible: + - input: { matrix: [[1, 1, 1], [1, 0, 1], [1, 1, 1]] } + expected: [[1, 0, 1], [0, 0, 0], [1, 0, 1]] + - input: { matrix: [[0, 1, 2, 0], [3, 4, 5, 2], [1, 3, 1, 5]] } + expected: [[0, 0, 0, 0], [0, 4, 5, 0], [0, 3, 1, 0]] + hidden: + - input: { matrix: [[1, 2, 3], [4, 5, 6]] } + expected: [[1, 2, 3], [4, 5, 6]] + - input: { matrix: [[0]] } + expected: [[0]] + - input: { matrix: [[1, 0, 3]] } + expected: [[0, 0, 0]] + description: | Given an `m x n` integer matrix `matrix`, if an element is `0`, set its entire row and column to `0`'s. diff --git a/backend/data/questions/sliding-window-maximum.yaml b/backend/data/questions/sliding-window-maximum.yaml index f6fcb3e..49089b1 100644 --- a/backend/data/questions/sliding-window-maximum.yaml +++ b/backend/data/questions/sliding-window-maximum.yaml @@ -11,6 +11,30 @@ patterns: - sliding-window - monotonic-stack +function_signature: "def max_sliding_window(nums: list[int], k: int) -> list[int]:" + +test_cases: + visible: + - input: { nums: [1, 3, -1, -3, 5, 3, 6, 7], k: 3 } + expected: [3, 3, 5, 5, 6, 7] + - input: { nums: [1], k: 1 } + expected: [1] + - input: { nums: [1, -1], k: 1 } + expected: [1, -1] + hidden: + - input: { nums: [9, 11], k: 2 } + expected: [11] + - input: { nums: [4, 3, 2, 1], k: 2 } + expected: [4, 3, 2] + - input: { nums: [1, 2, 3, 4], k: 2 } + expected: [2, 3, 4] + - input: { nums: [7, 7, 7, 7], k: 3 } + expected: [7, 7] + - input: { nums: [1, 3, 1, 2, 0, 5], k: 3 } + expected: [3, 3, 2, 5] + - input: { nums: [-7, -8, 7, 5, 7, 1, 6, 0], k: 4 } + expected: [7, 7, 7, 7, 7] + description: | You are given an array of integers `nums`, there is a sliding window of size `k` which is moving from the very left of the array to the very right. You can only see the `k` numbers in the window. Each time the sliding window moves right by one position. diff --git a/backend/data/questions/sort-colors.yaml b/backend/data/questions/sort-colors.yaml index ec46ffc..5f8b71b 100644 --- a/backend/data/questions/sort-colors.yaml +++ b/backend/data/questions/sort-colors.yaml @@ -10,6 +10,24 @@ categories: patterns: - two-pointers +function_signature: "def sort_colors(nums: list[int]) -> None:" + +test_cases: + visible: + - input: { nums: [2, 0, 2, 1, 1, 0] } + expected: [0, 0, 1, 1, 2, 2] + - input: { nums: [2, 0, 1] } + expected: [0, 1, 2] + hidden: + - input: { nums: [0] } + expected: [0] + - input: { nums: [1, 0] } + expected: [0, 1] + - input: { nums: [2, 2, 2, 1, 1, 0, 0] } + expected: [0, 0, 1, 1, 2, 2, 2] + - input: { nums: [1, 2, 0] } + expected: [0, 1, 2] + description: | Given an array `nums` with `n` objects colored red, white, or blue, sort them **in-place** so that objects of the same color are adjacent, with the colors in the order red, white, and blue. diff --git a/backend/data/questions/spiral-matrix.yaml b/backend/data/questions/spiral-matrix.yaml index 9477c1f..60abaf3 100644 --- a/backend/data/questions/spiral-matrix.yaml +++ b/backend/data/questions/spiral-matrix.yaml @@ -8,6 +8,24 @@ categories: patterns: - matrix-traversal +function_signature: "def spiral_order(matrix: list[list[int]]) -> list[int]:" + +test_cases: + visible: + - input: { matrix: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] } + expected: [1, 2, 3, 6, 9, 8, 7, 4, 5] + - input: { matrix: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] } + expected: [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7] + hidden: + - input: { matrix: [[1]] } + expected: [1] + - input: { matrix: [[1, 2, 3, 4]] } + expected: [1, 2, 3, 4] + - input: { matrix: [[1], [2], [3]] } + expected: [1, 2, 3] + - input: { matrix: [[1, 2], [3, 4]] } + expected: [1, 2, 4, 3] + description: | Given an `m x n` `matrix`, return *all elements of the matrix in spiral order*. diff --git a/backend/data/questions/subarray-sum-equals-k.yaml b/backend/data/questions/subarray-sum-equals-k.yaml index 0d28346..e98f1ab 100644 --- a/backend/data/questions/subarray-sum-equals-k.yaml +++ b/backend/data/questions/subarray-sum-equals-k.yaml @@ -9,6 +9,24 @@ categories: patterns: - prefix-sum +function_signature: "def subarray_sum(nums: list[int], k: int) -> int:" + +test_cases: + visible: + - input: { nums: [1, 1, 1], k: 2 } + expected: 2 + - input: { nums: [1, 2, 3], k: 3 } + expected: 2 + hidden: + - input: { nums: [1], k: 1 } + expected: 1 + - input: { nums: [1], k: 0 } + expected: 0 + - input: { nums: [-1, -1, 1], k: 0 } + expected: 1 + - input: { nums: [1, -1, 0], k: 0 } + expected: 3 + description: | Given an array of integers `nums` and an integer `k`, return *the total number of subarrays whose sum equals to* `k`. diff --git a/backend/data/questions/subsets-ii.yaml b/backend/data/questions/subsets-ii.yaml index cd5434c..ab1e3a9 100644 --- a/backend/data/questions/subsets-ii.yaml +++ b/backend/data/questions/subsets-ii.yaml @@ -10,6 +10,26 @@ categories: patterns: - backtracking +function_signature: "def subsets_with_dup(nums: list[int]) -> list[list[int]]:" + +test_cases: + visible: + - input: { nums: [1, 2, 2] } + expected: [[], [1], [1, 2], [1, 2, 2], [2], [2, 2]] + - input: { nums: [0] } + expected: [[], [0]] + hidden: + - input: { nums: [4, 4, 4, 1, 4] } + expected: [[], [1], [1, 4], [1, 4, 4], [1, 4, 4, 4], [1, 4, 4, 4, 4], [4], [4, 4], [4, 4, 4], [4, 4, 4, 4]] + - input: { nums: [1, 1] } + expected: [[], [1], [1, 1]] + - input: { nums: [1, 2, 3] } + expected: [[], [1], [1, 2], [1, 2, 3], [1, 3], [2], [2, 3], [3]] + - input: { nums: [5, 5, 5] } + expected: [[], [5], [5, 5], [5, 5, 5]] + - input: { nums: [3, 1, 2, 1] } + expected: [[], [1], [1, 1], [1, 1, 2], [1, 1, 2, 3], [1, 1, 3], [1, 2], [1, 2, 3], [1, 3], [2], [2, 3], [3]] + description: | Given an integer array `nums` that may contain duplicates, return *all possible subsets* (the power set). diff --git a/backend/data/questions/subsets.yaml b/backend/data/questions/subsets.yaml index 6394379..d710dd0 100644 --- a/backend/data/questions/subsets.yaml +++ b/backend/data/questions/subsets.yaml @@ -9,6 +9,28 @@ categories: patterns: - backtracking +function_signature: "def subsets(nums: list[int]) -> list[list[int]]:" + +test_cases: + visible: + - input: { nums: [1, 2, 3] } + expected: [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]] + - input: { nums: [0] } + expected: [[], [0]] + - input: { nums: [1, 2] } + expected: [[], [1], [2], [1, 2]] + hidden: + - input: { nums: [] } + expected: [[]] + - input: { nums: [5, 10, 15] } + expected: [[], [5], [10], [5, 10], [15], [5, 15], [10, 15], [5, 10, 15]] + - input: { nums: [-1, 0, 1] } + expected: [[], [-1], [0], [-1, 0], [1], [-1, 1], [0, 1], [-1, 0, 1]] + - input: { nums: [1, 2, 3, 4] } + expected: [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3], [4], [1, 4], [2, 4], [1, 2, 4], [3, 4], [1, 3, 4], [2, 3, 4], [1, 2, 3, 4]] + - input: { nums: [9] } + expected: [[], [9]] + description: | Given an integer array `nums` of **unique** elements, return *all possible subsets* (the power set). diff --git a/backend/data/questions/subtree-of-another-tree.yaml b/backend/data/questions/subtree-of-another-tree.yaml index 8c56a4a..16a8959 100644 --- a/backend/data/questions/subtree-of-another-tree.yaml +++ b/backend/data/questions/subtree-of-another-tree.yaml @@ -10,6 +10,24 @@ patterns: - dfs - tree-traversal +function_signature: "def is_subtree(root: TreeNode | None, sub_root: TreeNode | None) -> bool:" + +test_cases: + visible: + - input: { root: [3, 4, 5, 1, 2], sub_root: [4, 1, 2] } + expected: true + - input: { root: [3, 4, 5, 1, 2, null, null, null, null, 0], sub_root: [4, 1, 2] } + expected: false + - input: { root: [1, 1], sub_root: [1] } + expected: true + hidden: + - input: { root: [1], sub_root: [1] } + expected: true + - input: { root: [1, 2, 3], sub_root: [2] } + expected: true + - input: { root: [1, 2, 3], sub_root: [3, 1] } + expected: false + description: | Given the roots of two binary trees `root` and `subRoot`, return `true` if there is a subtree of `root` with the same structure and node values of `subRoot` and `false` otherwise. diff --git a/backend/data/questions/target-sum.yaml b/backend/data/questions/target-sum.yaml index 93fc02a..c52b044 100644 --- a/backend/data/questions/target-sum.yaml +++ b/backend/data/questions/target-sum.yaml @@ -10,6 +10,32 @@ patterns: - dynamic-programming - backtracking +function_signature: "def find_target_sum_ways(nums: list[int], target: int) -> int:" + +test_cases: + visible: + - input: { nums: [1, 1, 1, 1, 1], target: 3 } + expected: 5 + - input: { nums: [1], target: 1 } + expected: 1 + - input: { nums: [1, 2, 1], target: 0 } + expected: 2 + hidden: + - input: { nums: [1], target: 2 } + expected: 0 + - input: { nums: [0, 0, 0, 0, 0], target: 0 } + expected: 32 + - input: { nums: [2, 3, 5], target: 0 } + expected: 0 + - input: { nums: [1, 0], target: 1 } + expected: 2 + - input: { nums: [1, 2, 3, 4, 5], target: 3 } + expected: 3 + - input: { nums: [100], target: -200 } + expected: 0 + - input: { nums: [7, 9, 3, 8, 0, 2, 4, 8, 3, 9], target: 0 } + expected: 0 + description: | You are given an integer array `nums` and an integer `target`. diff --git a/backend/data/questions/task-scheduler.yaml b/backend/data/questions/task-scheduler.yaml index b224d97..c6e9733 100644 --- a/backend/data/questions/task-scheduler.yaml +++ b/backend/data/questions/task-scheduler.yaml @@ -11,6 +11,28 @@ patterns: - greedy - heap +function_signature: "def least_interval(tasks: list[str], n: int) -> int:" + +test_cases: + visible: + - input: { tasks: ["A", "A", "A", "B", "B", "B"], n: 2 } + expected: 8 + - input: { tasks: ["A", "C", "A", "B", "D", "B"], n: 1 } + expected: 6 + - input: { tasks: ["A", "A", "A", "B", "B", "B"], n: 3 } + expected: 10 + hidden: + - input: { tasks: ["A", "A", "A", "B", "B", "B"], n: 0 } + expected: 6 + - input: { tasks: ["A", "A", "A", "A", "A", "A", "B", "C", "D", "E", "F", "G"], n: 2 } + expected: 16 + - input: { tasks: ["A"], n: 5 } + expected: 1 + - input: { tasks: ["A", "B", "C", "D", "E", "A", "B", "C", "D", "E"], n: 4 } + expected: 10 + - input: { tasks: ["A", "A", "B", "B", "C", "C", "D", "D"], n: 3 } + expected: 8 + description: | You are given an array of CPU `tasks`, each labelled with a letter from A to Z, and a number `n`. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed in any order, but there's a constraint: there has to be a gap of **at least** `n` intervals between two tasks with the same label. diff --git a/backend/data/questions/three-sum.yaml b/backend/data/questions/three-sum.yaml index f557b16..847eaee 100644 --- a/backend/data/questions/three-sum.yaml +++ b/backend/data/questions/three-sum.yaml @@ -10,6 +10,24 @@ categories: patterns: - two-pointers +function_signature: "def three_sum(nums: list[int]) -> list[list[int]]:" + +test_cases: + visible: + - input: { nums: [-1, 0, 1, 2, -1, -4] } + expected: [[-1, -1, 2], [-1, 0, 1]] + - input: { nums: [0, 1, 1] } + expected: [] + - input: { nums: [0, 0, 0] } + expected: [[0, 0, 0]] + hidden: + - input: { nums: [-2, 0, 1, 1, 2] } + expected: [[-2, 0, 2], [-2, 1, 1]] + - input: { nums: [1, 2, -2, -1] } + expected: [] + - input: { nums: [-4, -2, -2, -2, 0, 1, 2, 2, 2, 3, 3, 4, 4, 6, 6] } + expected: [[-4, -2, 6], [-4, 0, 4], [-4, 1, 3], [-4, 2, 2], [-2, -2, 4], [-2, 0, 2]] + description: | Given an integer array `nums`, return all the triplets `[nums[i], nums[j], nums[k]]` such that `i != j`, `i != k`, and `j != k`, and `nums[i] + nums[j] + nums[k] == 0`. diff --git a/backend/data/questions/top-k-frequent-elements.yaml b/backend/data/questions/top-k-frequent-elements.yaml index 0771a21..31d40d4 100644 --- a/backend/data/questions/top-k-frequent-elements.yaml +++ b/backend/data/questions/top-k-frequent-elements.yaml @@ -11,6 +11,24 @@ categories: patterns: - heap +function_signature: "def top_k_frequent(nums: list[int], k: int) -> list[int]:" + +test_cases: + visible: + - input: { nums: [1, 1, 1, 2, 2, 3], k: 2 } + expected: [1, 2] + - input: { nums: [1], k: 1 } + expected: [1] + - input: { nums: [4, 1, -1, 2, -1, 2, 3], k: 2 } + expected: [-1, 2] + hidden: + - input: { nums: [1, 2], k: 2 } + expected: [1, 2] + - input: { nums: [5, 5, 5, 5, 5], k: 1 } + expected: [5] + - input: { nums: [1, 1, 2, 2, 3, 3, 4], k: 3 } + expected: [1, 2, 3] + description: | Given an integer array `nums` and an integer `k`, return *the* `k` *most frequent elements*. You may return the answer in **any order**. diff --git a/backend/data/questions/trapping-rain-water.yaml b/backend/data/questions/trapping-rain-water.yaml index bba2a3b..70e69fc 100644 --- a/backend/data/questions/trapping-rain-water.yaml +++ b/backend/data/questions/trapping-rain-water.yaml @@ -11,6 +11,24 @@ patterns: - two-pointers - monotonic-stack +function_signature: "def trap(height: list[int]) -> int:" + +test_cases: + visible: + - input: { height: [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1] } + expected: 6 + - input: { height: [4, 2, 0, 3, 2, 5] } + expected: 9 + hidden: + - input: { height: [0, 0, 0] } + expected: 0 + - input: { height: [3, 0, 3] } + expected: 3 + - input: { height: [1, 2, 3, 4, 5] } + expected: 0 + - input: { height: [5, 4, 1, 2] } + expected: 1 + description: | Given `n` non-negative integers representing an elevation map where the width of each bar is `1`, compute how much water it can trap after raining. diff --git a/backend/data/questions/unique-paths-ii.yaml b/backend/data/questions/unique-paths-ii.yaml index b645d7d..5604f34 100644 --- a/backend/data/questions/unique-paths-ii.yaml +++ b/backend/data/questions/unique-paths-ii.yaml @@ -10,6 +10,30 @@ patterns: - dynamic-programming - matrix-traversal +function_signature: "def unique_paths_with_obstacles(obstacle_grid: list[list[int]]) -> int:" + +test_cases: + visible: + - input: { obstacle_grid: [[0, 0, 0], [0, 1, 0], [0, 0, 0]] } + expected: 2 + - input: { obstacle_grid: [[0, 1], [0, 0]] } + expected: 1 + - input: { obstacle_grid: [[0, 0], [0, 0]] } + expected: 2 + hidden: + - input: { obstacle_grid: [[1]] } + expected: 0 + - input: { obstacle_grid: [[0]] } + expected: 1 + - input: { obstacle_grid: [[1, 0]] } + expected: 0 + - input: { obstacle_grid: [[0, 0, 0, 0], [0, 0, 0, 0]] } + expected: 4 + - input: { obstacle_grid: [[0, 1, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] } + expected: 0 + - input: { obstacle_grid: [[0, 0, 0], [0, 0, 0], [0, 0, 1]] } + expected: 0 + description: | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time. diff --git a/backend/data/questions/unique-paths.yaml b/backend/data/questions/unique-paths.yaml index 31583e0..00e5efd 100644 --- a/backend/data/questions/unique-paths.yaml +++ b/backend/data/questions/unique-paths.yaml @@ -10,6 +10,24 @@ categories: patterns: - dynamic-programming +function_signature: "def unique_paths(m: int, n: int) -> int:" + +test_cases: + visible: + - input: { m: 3, n: 7 } + expected: 28 + - input: { m: 3, n: 2 } + expected: 3 + - input: { m: 1, n: 1 } + expected: 1 + hidden: + - input: { m: 7, n: 3 } + expected: 28 + - input: { m: 3, n: 3 } + expected: 6 + - input: { m: 10, n: 10 } + expected: 48620 + description: | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time. diff --git a/backend/data/questions/validate-binary-search-tree.yaml b/backend/data/questions/validate-binary-search-tree.yaml index e4a2b05..f3fd766 100644 --- a/backend/data/questions/validate-binary-search-tree.yaml +++ b/backend/data/questions/validate-binary-search-tree.yaml @@ -10,6 +10,24 @@ patterns: - dfs - tree-traversal +function_signature: "def is_valid_bst(root: TreeNode | None) -> bool:" + +test_cases: + visible: + - input: { root: [2, 1, 3] } + expected: true + - input: { root: [5, 1, 4, null, null, 3, 6] } + expected: false + - input: { root: [1] } + expected: true + hidden: + - input: { root: [5, 4, 6, null, null, 3, 7] } + expected: false + - input: { root: [2, 2, 2] } + expected: false + - input: { root: [10, 5, 15, null, null, 6, 20] } + expected: false + description: | Given the `root` of a binary tree, determine if it is a valid **binary search tree (BST)**. diff --git a/backend/data/questions/word-break.yaml b/backend/data/questions/word-break.yaml index eb1f0a1..0d27fb5 100644 --- a/backend/data/questions/word-break.yaml +++ b/backend/data/questions/word-break.yaml @@ -10,6 +10,24 @@ categories: patterns: - dynamic-programming +function_signature: "def word_break(s: str, word_dict: list[str]) -> bool:" + +test_cases: + visible: + - input: { s: "leetcode", word_dict: ["leet", "code"] } + expected: true + - input: { s: "applepenapple", word_dict: ["apple", "pen"] } + expected: true + - input: { s: "catsandog", word_dict: ["cats", "dog", "sand", "and", "cat"] } + expected: false + hidden: + - input: { s: "a", word_dict: ["a"] } + expected: true + - input: { s: "aaaaaaa", word_dict: ["aaaa", "aaa"] } + expected: true + - input: { s: "cars", word_dict: ["car", "ca", "rs"] } + expected: true + description: | Given a string `s` and a dictionary of strings `wordDict`, return `true` if `s` can be segmented into a space-separated sequence of one or more dictionary words. diff --git a/backend/data/questions/word-ladder.yaml b/backend/data/questions/word-ladder.yaml index d7cd98b..77537e4 100644 --- a/backend/data/questions/word-ladder.yaml +++ b/backend/data/questions/word-ladder.yaml @@ -10,6 +10,28 @@ categories: patterns: - bfs +function_signature: "def ladder_length(begin_word: str, end_word: str, word_list: list[str]) -> int:" + +test_cases: + visible: + - input: { begin_word: "hit", end_word: "cog", word_list: ["hot", "dot", "dog", "lot", "log", "cog"] } + expected: 5 + - input: { begin_word: "hit", end_word: "cog", word_list: ["hot", "dot", "dog", "lot", "log"] } + expected: 0 + hidden: + - input: { begin_word: "a", end_word: "c", word_list: ["a", "b", "c"] } + expected: 2 + - input: { begin_word: "hot", end_word: "dog", word_list: ["hot", "dog"] } + expected: 0 + - input: { begin_word: "hot", end_word: "dog", word_list: ["hot", "dog", "dot"] } + expected: 3 + - input: { begin_word: "leet", end_word: "code", word_list: ["lest", "leet", "lose", "code", "lode", "robe", "lost"] } + expected: 0 + - input: { begin_word: "cat", end_word: "dog", word_list: ["cat", "bat", "bet", "bot", "dot", "dog"] } + expected: 6 + - input: { begin_word: "red", end_word: "tax", word_list: ["ted", "tex", "red", "tax", "tad", "den", "rex", "pee"] } + expected: 4 + description: | A **transformation sequence** from word `beginWord` to word `endWord` using a dictionary `wordList` is a sequence of words `beginWord -> s1 -> s2 -> ... -> sk` such that: diff --git a/backend/data/questions/word-search.yaml b/backend/data/questions/word-search.yaml index e711082..daaec7f 100644 --- a/backend/data/questions/word-search.yaml +++ b/backend/data/questions/word-search.yaml @@ -10,6 +10,24 @@ patterns: - backtracking - dfs +function_signature: "def exist(board: list[list[str]], word: str) -> bool:" + +test_cases: + visible: + - input: { board: [["A", "B", "C", "E"], ["S", "F", "C", "S"], ["A", "D", "E", "E"]], word: "ABCCED" } + expected: true + - input: { board: [["A", "B", "C", "E"], ["S", "F", "C", "S"], ["A", "D", "E", "E"]], word: "SEE" } + expected: true + - input: { board: [["A", "B", "C", "E"], ["S", "F", "C", "S"], ["A", "D", "E", "E"]], word: "ABCB" } + expected: false + hidden: + - input: { board: [["A"]], word: "A" } + expected: true + - input: { board: [["A", "B"], ["C", "D"]], word: "ABCD" } + expected: false + - input: { board: [["A", "B"], ["C", "D"]], word: "ABDC" } + expected: true + description: | Given an `m × n` grid of characters `board` and a string `word`, return `true` if `word` exists in the grid.