diff --git a/backend/data/questions/add-two-numbers.yaml b/backend/data/questions/add-two-numbers.yaml
index bc04ad6..b1aa5a5 100644
--- a/backend/data/questions/add-two-numbers.yaml
+++ b/backend/data/questions/add-two-numbers.yaml
@@ -24,6 +24,16 @@ test_cases:
expected: [0, 0, 1]
- input: { l1: [5], l2: [5] }
expected: [0, 1]
+ - input: { l1: [9], l2: [1] }
+ expected: [0, 1]
+ - input: { l1: [2, 4, 9], l2: [5, 6, 4, 9] }
+ expected: [7, 0, 4, 0, 1]
+ - input: { l1: [1, 8], l2: [0] }
+ expected: [1, 8]
+ - input: { l1: [9, 9, 9], l2: [1] }
+ expected: [0, 0, 0, 1]
+ - input: { l1: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], l2: [5, 6, 4] }
+ expected: [6, 6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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/best-time-to-buy-and-sell-stock.yaml b/backend/data/questions/best-time-to-buy-and-sell-stock.yaml
index b9f9553..f18bb04 100644
--- a/backend/data/questions/best-time-to-buy-and-sell-stock.yaml
+++ b/backend/data/questions/best-time-to-buy-and-sell-stock.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: 0
- input: { prices: [1] }
expected: 0
+ - input: { prices: [2, 1, 2, 1, 0, 1, 2] }
+ expected: 2
+ - input: { prices: [3, 2, 6, 5, 0, 3] }
+ expected: 4
+ - input: { prices: [1, 2] }
+ expected: 1
description: |
You are given an array `prices` where `prices[i]` is the price of a given stock on the ith day.
diff --git a/backend/data/questions/binary-search.yaml b/backend/data/questions/binary-search.yaml
index 31c9695..8409612 100644
--- a/backend/data/questions/binary-search.yaml
+++ b/backend/data/questions/binary-search.yaml
@@ -28,6 +28,10 @@ test_cases:
expected: 4
- input: { nums: [1, 2, 3, 4, 5], target: 3 }
expected: 2
+ - input: { nums: [-5, -3, -1, 0, 2, 4], target: -3 }
+ expected: 1
+ - input: { nums: [1, 3], target: 2 }
+ expected: -1
description: |
Given an array of integers `nums` which is sorted in ascending order, and an integer `target`, write a function to search `target` in `nums`.
diff --git a/backend/data/questions/booking-concert-tickets-in-groups.yaml b/backend/data/questions/booking-concert-tickets-in-groups.yaml
index 9f4fe3b..816ba97 100644
--- a/backend/data/questions/booking-concert-tickets-in-groups.yaml
+++ b/backend/data/questions/booking-concert-tickets-in-groups.yaml
@@ -9,6 +9,28 @@ categories:
patterns:
- binary-search
+function_signature: "class BookMyShow"
+
+test_cases:
+ visible:
+ - input:
+ operations: ["BookMyShow", "gather", "gather", "scatter", "scatter"]
+ args: [[2, 5], [4, 0], [2, 0], [5, 1], [5, 1]]
+ expected: [null, [0, 0], [], true, false]
+ hidden:
+ - input:
+ operations: ["BookMyShow", "gather", "scatter"]
+ args: [[1, 5], [5, 0], [1, 0]]
+ expected: [null, [0, 0], false]
+ - input:
+ operations: ["BookMyShow", "scatter", "scatter", "gather"]
+ args: [[2, 3], [3, 1], [3, 1], [2, 1]]
+ expected: [null, true, true, []]
+ - input:
+ operations: ["BookMyShow", "gather", "gather", "gather"]
+ args: [[3, 4], [2, 0], [2, 1], [2, 2]]
+ expected: [null, [0, 0], [0, 2], [1, 0]]
+
description: |
A concert hall has `n` rows numbered from `0` to `n - 1`, each with `m` seats, numbered from `0` to `m - 1`. You need to design a ticketing system that can allocate seats in the following cases:
diff --git a/backend/data/questions/brace-expansion-ii.yaml b/backend/data/questions/brace-expansion-ii.yaml
index e862dde..458765a 100644
--- a/backend/data/questions/brace-expansion-ii.yaml
+++ b/backend/data/questions/brace-expansion-ii.yaml
@@ -11,6 +11,28 @@ patterns:
- backtracking
- dfs
+function_signature: "def brace_expansion_ii(expression: str) -> list[str]:"
+
+test_cases:
+ visible:
+ - input: { expression: "{a,b}{c,{d,e}}" }
+ expected: ["ac", "ad", "ae", "bc", "bd", "be"]
+ - input: { expression: "{{a,z},a{b,c},{ab,z}}" }
+ expected: ["a", "ab", "ac", "z"]
+ hidden:
+ - input: { expression: "a" }
+ expected: ["a"]
+ - input: { expression: "{a,b}" }
+ expected: ["a", "b"]
+ - input: { expression: "{a,b}c" }
+ expected: ["ac", "bc"]
+ - input: { expression: "a{b,c}d" }
+ expected: ["abd", "acd"]
+ - input: { expression: "{a}{b}" }
+ expected: ["ab"]
+ - input: { expression: "{{a}}" }
+ expected: ["a"]
+
description: |
Under the grammar given below, strings can represent a set of lowercase words. Let `R(expr)` denote the set of words the expression represents.
diff --git a/backend/data/questions/bricks-falling-when-hit.yaml b/backend/data/questions/bricks-falling-when-hit.yaml
index 23bfcee..908b119 100644
--- a/backend/data/questions/bricks-falling-when-hit.yaml
+++ b/backend/data/questions/bricks-falling-when-hit.yaml
@@ -10,6 +10,24 @@ patterns:
- union-find
- matrix-traversal
+function_signature: "def hit_bricks(grid: list[list[int]], hits: list[list[int]]) -> list[int]:"
+
+test_cases:
+ visible:
+ - input: { grid: [[1, 0, 0, 0], [1, 1, 1, 0]], hits: [[1, 0]] }
+ expected: [2]
+ - input: { grid: [[1, 0, 0, 0], [1, 1, 0, 0]], hits: [[1, 1], [1, 0]] }
+ expected: [0, 0]
+ hidden:
+ - input: { grid: [[1]], hits: [[0, 0]] }
+ expected: [0]
+ - input: { grid: [[1, 1, 1], [0, 1, 0], [0, 0, 0]], hits: [[0, 1]] }
+ expected: [1]
+ - input: { grid: [[1, 0, 1], [1, 1, 1]], hits: [[0, 0], [1, 1]] }
+ expected: [0, 3]
+ - input: { grid: [[1, 1], [1, 1]], hits: [[0, 0]] }
+ expected: [0]
+
description: |
You are given an `m x n` binary `grid`, where each `1` represents a brick and `0` represents an empty space. A brick is **stable** if:
diff --git a/backend/data/questions/build-a-matrix-with-conditions.yaml b/backend/data/questions/build-a-matrix-with-conditions.yaml
index 6f2cc1a..be930b9 100644
--- a/backend/data/questions/build-a-matrix-with-conditions.yaml
+++ b/backend/data/questions/build-a-matrix-with-conditions.yaml
@@ -9,6 +9,22 @@ categories:
patterns:
- topological-sort
+function_signature: "def build_matrix(k: int, row_conditions: list[list[int]], col_conditions: list[list[int]]) -> list[list[int]]:"
+
+test_cases:
+ visible:
+ - input: { k: 3, row_conditions: [[1, 2], [3, 2]], col_conditions: [[2, 1], [3, 2]] }
+ expected: [[3, 0, 0], [0, 0, 1], [0, 2, 0]]
+ - input: { k: 3, row_conditions: [[1, 2], [2, 3], [3, 1], [2, 3]], col_conditions: [[2, 1]] }
+ expected: []
+ hidden:
+ - input: { k: 2, row_conditions: [[1, 2]], col_conditions: [[1, 2]] }
+ expected: [[1, 0], [0, 2]]
+ - input: { k: 2, row_conditions: [[1, 2]], col_conditions: [[2, 1]] }
+ expected: [[0, 1], [2, 0]]
+ - input: { k: 2, row_conditions: [[1, 2], [2, 1]], col_conditions: [[1, 2]] }
+ expected: []
+
description: |
You are given a **positive** integer `k`. You are also given:
diff --git a/backend/data/questions/build-array-where-you-can-find-the-maximum-exactly-k-comparisons.yaml b/backend/data/questions/build-array-where-you-can-find-the-maximum-exactly-k-comparisons.yaml
index 08451c5..2bb278c 100644
--- a/backend/data/questions/build-array-where-you-can-find-the-maximum-exactly-k-comparisons.yaml
+++ b/backend/data/questions/build-array-where-you-can-find-the-maximum-exactly-k-comparisons.yaml
@@ -10,6 +10,26 @@ patterns:
- dynamic-programming
- prefix-sum
+function_signature: "def num_of_arrays(n: int, m: int, k: int) -> int:"
+
+test_cases:
+ visible:
+ - input: { n: 2, m: 3, k: 1 }
+ expected: 6
+ - input: { n: 5, m: 2, k: 3 }
+ expected: 0
+ - input: { n: 9, m: 1, k: 1 }
+ expected: 1
+ hidden:
+ - input: { n: 1, m: 1, k: 1 }
+ expected: 1
+ - input: { n: 1, m: 5, k: 1 }
+ expected: 5
+ - input: { n: 3, m: 3, k: 2 }
+ expected: 18
+ - input: { n: 2, m: 2, k: 2 }
+ expected: 1
+
description: |
You are given three integers `n`, `m` and `k`. Consider the following algorithm to find the maximum element of an array of positive integers:
diff --git a/backend/data/questions/building-boxes.yaml b/backend/data/questions/building-boxes.yaml
index b65cf51..2543ddf 100644
--- a/backend/data/questions/building-boxes.yaml
+++ b/backend/data/questions/building-boxes.yaml
@@ -10,6 +10,30 @@ patterns:
- binary-search
- greedy
+function_signature: "def minimum_boxes(n: int) -> int:"
+
+test_cases:
+ visible:
+ - input: { n: 3 }
+ expected: 3
+ - input: { n: 4 }
+ expected: 3
+ - input: { n: 10 }
+ expected: 6
+ hidden:
+ - input: { n: 1 }
+ expected: 1
+ - input: { n: 2 }
+ expected: 2
+ - input: { n: 5 }
+ expected: 4
+ - input: { n: 6 }
+ expected: 4
+ - input: { n: 7 }
+ expected: 5
+ - input: { n: 20 }
+ expected: 10
+
description: |
You have a cubic storeroom where the width, length, and height of the room are all equal to `n` units. You are asked to place `n` boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes:
diff --git a/backend/data/questions/building-h2o.yaml b/backend/data/questions/building-h2o.yaml
index 37a5582..616cdfb 100644
--- a/backend/data/questions/building-h2o.yaml
+++ b/backend/data/questions/building-h2o.yaml
@@ -8,6 +8,28 @@ categories:
patterns:
- synchronization
+function_signature: "class H2O"
+
+test_cases:
+ visible:
+ - input: { water: "HOH" }
+ expected: "HHO"
+ - input: { water: "OOHHHH" }
+ expected: "HHOHHO"
+ hidden:
+ - input: { water: "HHOOHH" }
+ expected: "HHOOHH"
+ - input: { water: "HOHOHOHOHOHO" }
+ expected: "HHOHHOHHOHHO"
+ - input: { water: "HHO" }
+ expected: "HHO"
+ - input: { water: "OHH" }
+ expected: "HHO"
+ - input: { water: "OOOHHHHHH" }
+ expected: "HHOHHOHHO"
+ - input: { water: "HHHHHHOOO" }
+ expected: "HHOHHOHHO"
+
description: |
There are two kinds of threads: `oxygen` and `hydrogen`. Your goal is to group these threads to form water molecules.
diff --git a/backend/data/questions/can-you-eat-your-favorite-candy-on-your-favorite-day.yaml b/backend/data/questions/can-you-eat-your-favorite-candy-on-your-favorite-day.yaml
index 26ff9ab..3a25142 100644
--- a/backend/data/questions/can-you-eat-your-favorite-candy-on-your-favorite-day.yaml
+++ b/backend/data/questions/can-you-eat-your-favorite-candy-on-your-favorite-day.yaml
@@ -8,6 +8,22 @@ categories:
patterns:
- prefix-sum
+function_signature: "def can_eat(candies_count: list[int], queries: list[list[int]]) -> list[bool]:"
+
+test_cases:
+ visible:
+ - input: { candies_count: [7, 4, 5, 3, 8], queries: [[0, 2, 2], [4, 2, 4], [2, 13, 1000000000]] }
+ expected: [true, false, true]
+ - input: { candies_count: [5, 2, 6, 4, 1], queries: [[3, 1, 2], [4, 10, 3], [3, 10, 100], [4, 100, 30], [1, 3, 1]] }
+ expected: [false, true, true, false, false]
+ hidden:
+ - input: { candies_count: [1], queries: [[0, 0, 1]] }
+ expected: [true]
+ - input: { candies_count: [5, 5], queries: [[0, 0, 5], [1, 4, 1]] }
+ expected: [true, true]
+ - input: { candies_count: [10, 10], queries: [[0, 5, 1], [1, 5, 1]] }
+ expected: [true, true]
+
description: |
You are given a **(0-indexed)** array of positive integers `candiesCount` where `candiesCount[i]` represents the number of candies of the ith type you have. You are also given a 2D array `queries` where `queries[i] = [favoriteType_i, favoriteDay_i, dailyCap_i]`.
diff --git a/backend/data/questions/car-fleet-ii.yaml b/backend/data/questions/car-fleet-ii.yaml
index 3f15d73..9691e37 100644
--- a/backend/data/questions/car-fleet-ii.yaml
+++ b/backend/data/questions/car-fleet-ii.yaml
@@ -10,6 +10,26 @@ categories:
patterns:
- monotonic-stack
+function_signature: "def get_collision_times(cars: list[list[int]]) -> list[float]:"
+
+test_cases:
+ visible:
+ - input: { cars: [[1, 2], [2, 1], [4, 3], [7, 2]] }
+ expected: [1.0, -1.0, 3.0, -1.0]
+ - input: { cars: [[3, 4], [5, 4], [6, 3], [9, 1]] }
+ expected: [2.0, 1.0, 1.5, -1.0]
+ hidden:
+ - input: { cars: [[1, 1]] }
+ expected: [-1.0]
+ - input: { cars: [[1, 2], [2, 1]] }
+ expected: [1.0, -1.0]
+ - input: { cars: [[1, 1], [2, 2], [3, 3]] }
+ expected: [-1.0, -1.0, -1.0]
+ - input: { cars: [[1, 3], [2, 2], [3, 1]] }
+ expected: [1.0, 1.0, -1.0]
+ - input: { cars: [[5, 2], [6, 2], [7, 2]] }
+ expected: [-1.0, -1.0, -1.0]
+
description: |
There are `n` cars traveling at different speeds in the same direction along a one-lane road. You are given an array `cars` of length `n`, where `cars[i] = [position_i, speed_i]` represents:
diff --git a/backend/data/questions/cat-and-mouse-ii.yaml b/backend/data/questions/cat-and-mouse-ii.yaml
index 42fab0c..709313f 100644
--- a/backend/data/questions/cat-and-mouse-ii.yaml
+++ b/backend/data/questions/cat-and-mouse-ii.yaml
@@ -11,6 +11,24 @@ patterns:
- dynamic-programming
- matrix-traversal
+function_signature: "def can_mouse_win(grid: list[str], cat_jump: int, mouse_jump: int) -> bool:"
+
+test_cases:
+ visible:
+ - input: { grid: ["####F", "#C...", "M...."], cat_jump: 1, mouse_jump: 2 }
+ expected: true
+ - input: { grid: ["M.C...F"], cat_jump: 1, mouse_jump: 4 }
+ expected: true
+ - input: { grid: ["M.C...F"], cat_jump: 1, mouse_jump: 3 }
+ expected: false
+ hidden:
+ - input: { grid: ["CM......", "#######.", "........", ".#######", "........", "#######.", "........", "F#######"], cat_jump: 1, mouse_jump: 1 }
+ expected: true
+ - input: { grid: [".M...", "..#..", "#..#.", "C#.#.", "...#F"], cat_jump: 3, mouse_jump: 1 }
+ expected: false
+ - input: { grid: ["C...#", "...#.", "....#", "M....", "....F"], cat_jump: 2, mouse_jump: 5 }
+ expected: false
+
description: |
A game is played by a cat and a mouse named Cat and Mouse.
diff --git a/backend/data/questions/cat-and-mouse.yaml b/backend/data/questions/cat-and-mouse.yaml
index f315344..d05afa1 100644
--- a/backend/data/questions/cat-and-mouse.yaml
+++ b/backend/data/questions/cat-and-mouse.yaml
@@ -10,6 +10,22 @@ patterns:
- dfs
- dynamic-programming
+function_signature: "def cat_mouse_game(graph: list[list[int]]) -> int:"
+
+test_cases:
+ visible:
+ - input: { graph: [[2, 5], [3], [0, 4, 5], [1, 4, 5], [2, 3], [0, 2, 3]] }
+ expected: 0
+ - input: { graph: [[1, 3], [0], [3], [0, 2]] }
+ expected: 1
+ hidden:
+ - input: { graph: [[2, 3], [3, 4], [0, 4], [0, 1], [1, 2]] }
+ expected: 1
+ - input: { graph: [[2, 5], [3], [0, 4, 5], [1, 4, 5], [2, 3], [0, 2, 3]] }
+ expected: 0
+ - input: { graph: [[1], [0, 2, 4], [1, 3], [2], [1]] }
+ expected: 2
+
description: |
A game on an **undirected** graph is played by two players, Mouse and Cat, who alternate turns.
diff --git a/backend/data/questions/change-minimum-characters-to-satisfy-one-of-three-conditions.yaml b/backend/data/questions/change-minimum-characters-to-satisfy-one-of-three-conditions.yaml
index 3931bac..01d9160 100644
--- a/backend/data/questions/change-minimum-characters-to-satisfy-one-of-three-conditions.yaml
+++ b/backend/data/questions/change-minimum-characters-to-satisfy-one-of-three-conditions.yaml
@@ -9,6 +9,28 @@ categories:
patterns:
- prefix-sum
+function_signature: "def min_characters(a: str, b: str) -> int:"
+
+test_cases:
+ visible:
+ - input: { a: "aba", b: "caa" }
+ expected: 2
+ - input: { a: "dabadd", b: "cda" }
+ expected: 3
+ hidden:
+ - input: { a: "a", b: "b" }
+ expected: 0
+ - input: { a: "aaa", b: "aaa" }
+ expected: 0
+ - input: { a: "abc", b: "abc" }
+ expected: 2
+ - input: { a: "a", b: "a" }
+ expected: 0
+ - input: { a: "z", b: "a" }
+ expected: 0
+ - input: { a: "abc", b: "def" }
+ expected: 0
+
description: |
You are given two strings `a` and `b` that consist of lowercase letters. In one operation, you can change any character in `a` or `b` to **any lowercase letter**.
diff --git a/backend/data/questions/check-if-a-parentheses-string-can-be-valid.yaml b/backend/data/questions/check-if-a-parentheses-string-can-be-valid.yaml
index b5bbc46..a240d72 100644
--- a/backend/data/questions/check-if-a-parentheses-string-can-be-valid.yaml
+++ b/backend/data/questions/check-if-a-parentheses-string-can-be-valid.yaml
@@ -9,6 +9,30 @@ categories:
patterns:
- greedy
+function_signature: "def can_be_valid(s: str, locked: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { s: "))()))", locked: "010100" }
+ expected: true
+ - input: { s: "()()", locked: "0000" }
+ expected: true
+ - input: { s: ")", locked: "0" }
+ expected: false
+ hidden:
+ - input: { s: "()", locked: "11" }
+ expected: true
+ - input: { s: ")(", locked: "00" }
+ expected: true
+ - input: { s: "((", locked: "11" }
+ expected: false
+ - input: { s: "))", locked: "11" }
+ expected: false
+ - input: { s: "((()", locked: "0000" }
+ expected: true
+ - input: { s: "((()))", locked: "111111" }
+ expected: true
+
description: |
A parentheses string is a **non-empty** string consisting only of `'('` and `')'`. It is valid if **any** of the following conditions is **true**:
diff --git a/backend/data/questions/check-if-a-string-can-break-another-string.yaml b/backend/data/questions/check-if-a-string-can-break-another-string.yaml
index 3d922c6..23d8f70 100644
--- a/backend/data/questions/check-if-a-string-can-break-another-string.yaml
+++ b/backend/data/questions/check-if-a-string-can-break-another-string.yaml
@@ -9,6 +9,30 @@ categories:
patterns:
- greedy
+function_signature: "def check_if_can_break(s1: str, s2: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { s1: "abc", s2: "xya" }
+ expected: true
+ - input: { s1: "abe", s2: "acd" }
+ expected: false
+ - input: { s1: "leetcodee", s2: "interview" }
+ expected: true
+ hidden:
+ - input: { s1: "aaa", s2: "aaa" }
+ expected: true
+ - input: { s1: "a", s2: "z" }
+ expected: true
+ - input: { s1: "zzz", s2: "aaa" }
+ expected: true
+ - input: { s1: "ab", s2: "ba" }
+ expected: true
+ - input: { s1: "acb", s2: "bca" }
+ expected: true
+ - input: { s1: "xyz", s2: "abc" }
+ expected: true
+
description: |
Given two strings: `s1` and `s2` with the same size, check if some permutation of string `s1` can break some permutation of string `s2` or vice-versa. In other words `s2` can break `s1` or vice-versa.
diff --git a/backend/data/questions/check-if-a-string-contains-all-binary-codes-of-size-k.yaml b/backend/data/questions/check-if-a-string-contains-all-binary-codes-of-size-k.yaml
index f6ea6c8..c29c0c3 100644
--- a/backend/data/questions/check-if-a-string-contains-all-binary-codes-of-size-k.yaml
+++ b/backend/data/questions/check-if-a-string-contains-all-binary-codes-of-size-k.yaml
@@ -9,6 +9,30 @@ categories:
patterns:
- sliding-window
+function_signature: "def has_all_codes(s: str, k: int) -> bool:"
+
+test_cases:
+ visible:
+ - input: { s: "00110110", k: 2 }
+ expected: true
+ - input: { s: "0110", k: 1 }
+ expected: true
+ - input: { s: "0110", k: 2 }
+ expected: false
+ hidden:
+ - input: { s: "0", k: 1 }
+ expected: false
+ - input: { s: "01", k: 1 }
+ expected: true
+ - input: { s: "00110", k: 2 }
+ expected: true
+ - input: { s: "0000000001011100", k: 4 }
+ expected: false
+ - input: { s: "11111111", k: 3 }
+ expected: false
+ - input: { s: "00011100101", k: 3 }
+ expected: true
+
description: |
Given a binary string `s` and an integer `k`, return `true` *if every binary code of length* `k` *is a substring of* `s`. Otherwise, return `false`.
diff --git a/backend/data/questions/check-if-an-original-string-exists-given-two-encoded-strings.yaml b/backend/data/questions/check-if-an-original-string-exists-given-two-encoded-strings.yaml
index a3d6c02..afd5baf 100644
--- a/backend/data/questions/check-if-an-original-string-exists-given-two-encoded-strings.yaml
+++ b/backend/data/questions/check-if-an-original-string-exists-given-two-encoded-strings.yaml
@@ -9,6 +9,28 @@ categories:
patterns:
- dynamic-programming
+function_signature: "def possibly_equals(s1: str, s2: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { s1: "internationalization", s2: "i18n" }
+ expected: true
+ - input: { s1: "l123e", s2: "44" }
+ expected: true
+ - input: { s1: "a5b", s2: "c5b" }
+ expected: false
+ hidden:
+ - input: { s1: "a", s2: "a" }
+ expected: true
+ - input: { s1: "a", s2: "b" }
+ expected: false
+ - input: { s1: "1", s2: "a" }
+ expected: true
+ - input: { s1: "12", s2: "3" }
+ expected: true
+ - input: { s1: "ab", s2: "2" }
+ expected: true
+
description: |
An original string, consisting of lowercase English letters, can be encoded by the following steps:
diff --git a/backend/data/questions/check-if-array-pairs-are-divisible-by-k.yaml b/backend/data/questions/check-if-array-pairs-are-divisible-by-k.yaml
index da07d81..49b13b8 100644
--- a/backend/data/questions/check-if-array-pairs-are-divisible-by-k.yaml
+++ b/backend/data/questions/check-if-array-pairs-are-divisible-by-k.yaml
@@ -10,6 +10,30 @@ categories:
patterns:
- prefix-sum
+function_signature: "def can_arrange(arr: list[int], k: int) -> bool:"
+
+test_cases:
+ visible:
+ - input: { arr: [1, 2, 3, 4, 5, 10, 6, 7, 8, 9], k: 5 }
+ expected: true
+ - input: { arr: [1, 2, 3, 4, 5, 6], k: 7 }
+ expected: true
+ - input: { arr: [1, 2, 3, 4, 5, 6], k: 10 }
+ expected: false
+ hidden:
+ - input: { arr: [-1, 1, -2, 2, -3, 3], k: 3 }
+ expected: true
+ - input: { arr: [0, 0, 0, 0], k: 5 }
+ expected: true
+ - input: { arr: [5, 5], k: 5 }
+ expected: true
+ - input: { arr: [1, 2], k: 4 }
+ expected: false
+ - input: { arr: [-10, 10], k: 2 }
+ expected: true
+ - input: { arr: [3, 3, 3, 3, 3, 3], k: 3 }
+ expected: true
+
description: |
Given an array of integers `arr` of even length `n` and an integer `k`.
diff --git a/backend/data/questions/check-if-binary-string-has-at-most-one-segment-of-ones.yaml b/backend/data/questions/check-if-binary-string-has-at-most-one-segment-of-ones.yaml
index 6443615..faa3413 100644
--- a/backend/data/questions/check-if-binary-string-has-at-most-one-segment-of-ones.yaml
+++ b/backend/data/questions/check-if-binary-string-has-at-most-one-segment-of-ones.yaml
@@ -8,6 +8,30 @@ categories:
patterns:
- two-pointers
+function_signature: "def check_ones_segment(s: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { s: "1001" }
+ expected: false
+ - input: { s: "110" }
+ expected: true
+ hidden:
+ - input: { s: "1" }
+ expected: true
+ - input: { s: "10" }
+ expected: true
+ - input: { s: "11" }
+ expected: true
+ - input: { s: "111" }
+ expected: true
+ - input: { s: "1000" }
+ expected: true
+ - input: { s: "10001" }
+ expected: false
+ - input: { s: "1110" }
+ expected: true
+
description: |
Given a binary string `s` **without leading zeros**, return `true` *if* `s` *contains **at most one contiguous segment of ones***. Otherwise, return `false`.
diff --git a/backend/data/questions/check-if-every-row-and-column-contains-all-numbers.yaml b/backend/data/questions/check-if-every-row-and-column-contains-all-numbers.yaml
index 4f57380..e48d4aa 100644
--- a/backend/data/questions/check-if-every-row-and-column-contains-all-numbers.yaml
+++ b/backend/data/questions/check-if-every-row-and-column-contains-all-numbers.yaml
@@ -9,6 +9,28 @@ categories:
patterns:
- matrix-traversal
+function_signature: "def check_valid(matrix: list[list[int]]) -> bool:"
+
+test_cases:
+ visible:
+ - input: { matrix: [[1, 2, 3], [3, 1, 2], [2, 3, 1]] }
+ expected: true
+ - input: { matrix: [[1, 1, 1], [1, 2, 3], [1, 2, 3]] }
+ expected: false
+ hidden:
+ - input: { matrix: [[1]] }
+ expected: true
+ - input: { matrix: [[1, 2], [2, 1]] }
+ expected: true
+ - input: { matrix: [[1, 2], [1, 2]] }
+ expected: false
+ - input: { matrix: [[2, 1], [1, 2]] }
+ expected: true
+ - input: { matrix: [[1, 2, 3, 4], [2, 3, 4, 1], [3, 4, 1, 2], [4, 1, 2, 3]] }
+ expected: true
+ - input: { matrix: [[1, 2, 3], [2, 3, 1], [3, 1, 3]] }
+ expected: false
+
description: |
An `n x n` matrix is **valid** if every row and every column contains **all** the integers from `1` to `n` (**inclusive**).
diff --git a/backend/data/questions/check-if-it-is-a-good-array.yaml b/backend/data/questions/check-if-it-is-a-good-array.yaml
index 502e27c..12d39be 100644
--- a/backend/data/questions/check-if-it-is-a-good-array.yaml
+++ b/backend/data/questions/check-if-it-is-a-good-array.yaml
@@ -9,6 +9,30 @@ categories:
patterns:
- greedy
+function_signature: "def is_good_array(nums: list[int]) -> bool:"
+
+test_cases:
+ visible:
+ - input: { nums: [12, 5, 7, 23] }
+ expected: true
+ - input: { nums: [29, 6, 10] }
+ expected: true
+ - input: { nums: [3, 6] }
+ expected: false
+ hidden:
+ - input: { nums: [1] }
+ expected: true
+ - input: { nums: [2, 4, 6, 8] }
+ expected: false
+ - input: { nums: [6, 9, 15, 21] }
+ expected: false
+ - input: { nums: [5, 7] }
+ expected: true
+ - input: { nums: [100, 99] }
+ expected: true
+ - input: { nums: [2, 3] }
+ expected: true
+
description: |
Given an array `nums` of positive integers. Your task is to select some subset of `nums`, multiply each element by an integer and add all these numbers.
diff --git a/backend/data/questions/check-if-move-is-legal.yaml b/backend/data/questions/check-if-move-is-legal.yaml
index b65bd6c..ff7d3e9 100644
--- a/backend/data/questions/check-if-move-is-legal.yaml
+++ b/backend/data/questions/check-if-move-is-legal.yaml
@@ -8,6 +8,24 @@ categories:
patterns:
- matrix-traversal
+function_signature: "def check_move(board: list[list[str]], r_move: int, c_move: int, color: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { board: [[".", ".", ".", "B", ".", ".", ".", "."], [".", ".", ".", "W", ".", ".", ".", "."], [".", ".", ".", "W", ".", ".", ".", "."], [".", ".", ".", "W", ".", ".", ".", "."], ["W", "B", "B", ".", "W", "W", "W", "B"], [".", ".", ".", "B", ".", ".", ".", "."], [".", ".", ".", "B", ".", ".", ".", "."], [".", ".", ".", "W", ".", ".", ".", "."]], r_move: 4, c_move: 3, color: "B" }
+ expected: true
+ - input: { board: [[".", ".", ".", ".", ".", ".", ".", "."], [".", "B", ".", ".", "W", ".", ".", "."], [".", ".", "W", ".", ".", ".", ".", "."], [".", ".", ".", "W", "B", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", "B", "W", ".", "."], [".", ".", ".", ".", ".", ".", "W", "."], [".", ".", ".", ".", ".", ".", ".", "B"]], r_move: 4, c_move: 4, color: "W" }
+ expected: false
+ hidden:
+ - input: { board: [[".", ".", "."], [".", "W", "."], [".", ".", "."]], r_move: 0, c_move: 1, color: "B" }
+ expected: false
+ - input: { board: [["B", "W", "."], [".", ".", "."], [".", ".", "."]], r_move: 0, c_move: 2, color: "B" }
+ expected: true
+ - input: { board: [[".", "W", "B"], [".", "W", "."], [".", ".", "."]], r_move: 2, c_move: 1, color: "B" }
+ expected: true
+ - input: { board: [["B", ".", "."], [".", "W", "."], [".", ".", "."]], r_move: 2, c_move: 2, color: "B" }
+ expected: true
+
description: |
You are given a **0-indexed** `8 x 8` grid `board`, where `board[r][c]` represents the cell `(r, c)` on a game board. On the board, free cells are represented by `'.'`, white cells are represented by `'W'`, and black cells are represented by `'B'`.
diff --git a/backend/data/questions/check-if-number-has-equal-digit-count-and-digit-value.yaml b/backend/data/questions/check-if-number-has-equal-digit-count-and-digit-value.yaml
index f732ddf..625b07f 100644
--- a/backend/data/questions/check-if-number-has-equal-digit-count-and-digit-value.yaml
+++ b/backend/data/questions/check-if-number-has-equal-digit-count-and-digit-value.yaml
@@ -9,6 +9,28 @@ categories:
patterns:
- prefix-sum
+function_signature: "def digit_count(num: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { num: "1210" }
+ expected: true
+ - input: { num: "030" }
+ expected: false
+ hidden:
+ - input: { num: "2020" }
+ expected: true
+ - input: { num: "0" }
+ expected: false
+ - input: { num: "10" }
+ expected: false
+ - input: { num: "21200" }
+ expected: true
+ - input: { num: "1111" }
+ expected: false
+ - input: { num: "2100" }
+ expected: true
+
description: |
You are given a **0-indexed** string `num` of length `n` consisting of digits.
diff --git a/backend/data/questions/check-if-number-is-a-sum-of-powers-of-three.yaml b/backend/data/questions/check-if-number-is-a-sum-of-powers-of-three.yaml
index 3b28837..c0b5a35 100644
--- a/backend/data/questions/check-if-number-is-a-sum-of-powers-of-three.yaml
+++ b/backend/data/questions/check-if-number-is-a-sum-of-powers-of-three.yaml
@@ -8,6 +8,32 @@ categories:
patterns:
- greedy
+function_signature: "def check_powers_of_three(n: int) -> bool:"
+
+test_cases:
+ visible:
+ - input: { n: 12 }
+ expected: true
+ - input: { n: 91 }
+ expected: true
+ - input: { n: 21 }
+ expected: false
+ hidden:
+ - input: { n: 1 }
+ expected: true
+ - input: { n: 3 }
+ expected: true
+ - input: { n: 4 }
+ expected: true
+ - input: { n: 2 }
+ expected: false
+ - input: { n: 6 }
+ expected: false
+ - input: { n: 9 }
+ expected: true
+ - input: { n: 10 }
+ expected: true
+
description: |
Given an integer `n`, return `true` *if it is possible to represent* `n` *as the sum of distinct powers of three*. Otherwise, return `false`.
diff --git a/backend/data/questions/check-if-object-instance-of-class.yaml b/backend/data/questions/check-if-object-instance-of-class.yaml
index 129a474..b66b5de 100644
--- a/backend/data/questions/check-if-object-instance-of-class.yaml
+++ b/backend/data/questions/check-if-object-instance-of-class.yaml
@@ -8,6 +8,30 @@ categories:
patterns:
- dfs
+function_signature: "function checkIfInstanceOf(obj, classFunction)"
+
+test_cases:
+ visible:
+ - input: { obj: "new Date()", classFunction: "Date" }
+ expected: true
+ - input: { obj: "5", classFunction: "Number" }
+ expected: true
+ - input: { obj: "Date", classFunction: "Date" }
+ expected: false
+ hidden:
+ - input: { obj: "null", classFunction: "Object" }
+ expected: false
+ - input: { obj: "undefined", classFunction: "Object" }
+ expected: false
+ - input: { obj: "'hello'", classFunction: "String" }
+ expected: true
+ - input: { obj: "[]", classFunction: "Array" }
+ expected: true
+ - input: { obj: "[]", classFunction: "Object" }
+ expected: true
+ - input: { obj: "{}", classFunction: "Object" }
+ expected: true
+
description: |
Write a function that checks if a given value is an instance of a given class or superclass. For this problem, an object is considered an instance of a given class if that object has access to that class's methods.
diff --git a/backend/data/questions/check-if-point-is-reachable.yaml b/backend/data/questions/check-if-point-is-reachable.yaml
index 21204dd..03b078b 100644
--- a/backend/data/questions/check-if-point-is-reachable.yaml
+++ b/backend/data/questions/check-if-point-is-reachable.yaml
@@ -8,6 +8,28 @@ categories:
patterns:
- greedy
+function_signature: "def is_reachable(target_x: int, target_y: int) -> bool:"
+
+test_cases:
+ visible:
+ - input: { target_x: 6, target_y: 9 }
+ expected: false
+ - input: { target_x: 4, target_y: 7 }
+ expected: true
+ hidden:
+ - input: { target_x: 1, target_y: 1 }
+ expected: true
+ - input: { target_x: 2, target_y: 2 }
+ expected: true
+ - input: { target_x: 1, target_y: 2 }
+ expected: true
+ - input: { target_x: 3, target_y: 3 }
+ expected: false
+ - input: { target_x: 8, target_y: 16 }
+ expected: true
+ - input: { target_x: 5, target_y: 10 }
+ expected: false
+
description: |
There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps.
diff --git a/backend/data/questions/check-if-string-is-transformable-with-substring-sort-operations.yaml b/backend/data/questions/check-if-string-is-transformable-with-substring-sort-operations.yaml
index 1cae653..d164b85 100644
--- a/backend/data/questions/check-if-string-is-transformable-with-substring-sort-operations.yaml
+++ b/backend/data/questions/check-if-string-is-transformable-with-substring-sort-operations.yaml
@@ -9,6 +9,28 @@ categories:
patterns:
- greedy
+function_signature: "def is_transformable(s: str, t: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { s: "84532", t: "34852" }
+ expected: true
+ - input: { s: "34521", t: "23415" }
+ expected: true
+ - input: { s: "12345", t: "12435" }
+ expected: false
+ hidden:
+ - input: { s: "1", t: "1" }
+ expected: true
+ - input: { s: "12", t: "12" }
+ expected: true
+ - input: { s: "21", t: "12" }
+ expected: true
+ - input: { s: "12", t: "21" }
+ expected: false
+ - input: { s: "111", t: "111" }
+ expected: true
+
description: |
Given two strings `s` and `t`, transform string `s` into string `t` using the following operation any number of times:
diff --git a/backend/data/questions/check-if-there-is-a-valid-parentheses-string-path.yaml b/backend/data/questions/check-if-there-is-a-valid-parentheses-string-path.yaml
index ce47f6f..0991d59 100644
--- a/backend/data/questions/check-if-there-is-a-valid-parentheses-string-path.yaml
+++ b/backend/data/questions/check-if-there-is-a-valid-parentheses-string-path.yaml
@@ -11,6 +11,26 @@ patterns:
- matrix-traversal
- dfs
+function_signature: "def has_valid_path(grid: list[list[str]]) -> bool:"
+
+test_cases:
+ visible:
+ - input: { grid: [["(", "(", "("], [")", "(", ")"], ["(", "(", ")"], ["(", "(", ")"]] }
+ expected: true
+ - input: { grid: [[")", ")"], ["(", "("]] }
+ expected: false
+ hidden:
+ - input: { grid: [["(", ")"]] }
+ expected: true
+ - input: { grid: [["("]] }
+ expected: false
+ - input: { grid: [[")"]] }
+ expected: false
+ - input: { grid: [["(", "("], [")", ")"]] }
+ expected: true
+ - input: { grid: [["(", ")"], ["(", ")"]] }
+ expected: false
+
description: |
A parentheses string is a **non-empty** string consisting only of `'('` and `')'`. It is **valid** if **any** of the following conditions is **true**:
diff --git a/backend/data/questions/check-if-there-is-a-valid-partition-for-the-array.yaml b/backend/data/questions/check-if-there-is-a-valid-partition-for-the-array.yaml
index 03fcce5..80a544b 100644
--- a/backend/data/questions/check-if-there-is-a-valid-partition-for-the-array.yaml
+++ b/backend/data/questions/check-if-there-is-a-valid-partition-for-the-array.yaml
@@ -9,6 +9,30 @@ categories:
patterns:
- dynamic-programming
+function_signature: "def valid_partition(nums: list[int]) -> bool:"
+
+test_cases:
+ visible:
+ - input: { nums: [4, 4, 4, 5, 6] }
+ expected: true
+ - input: { nums: [1, 1, 1, 2] }
+ expected: false
+ hidden:
+ - input: { nums: [1, 1] }
+ expected: true
+ - input: { nums: [1, 1, 1] }
+ expected: true
+ - input: { nums: [1, 2, 3] }
+ expected: true
+ - input: { nums: [1, 2] }
+ expected: false
+ - input: { nums: [5, 5, 5, 5] }
+ expected: true
+ - input: { nums: [1, 2, 3, 3, 3] }
+ expected: true
+ - input: { nums: [1, 1, 2, 2] }
+ expected: true
+
description: |
You are given a **0-indexed** integer array `nums`. You have to partition the array into one or more **contiguous** subarrays.
diff --git a/backend/data/questions/check-if-there-is-a-valid-path-in-a-grid.yaml b/backend/data/questions/check-if-there-is-a-valid-path-in-a-grid.yaml
index 9642e16..87e7bfd 100644
--- a/backend/data/questions/check-if-there-is-a-valid-path-in-a-grid.yaml
+++ b/backend/data/questions/check-if-there-is-a-valid-path-in-a-grid.yaml
@@ -12,6 +12,30 @@ patterns:
- matrix-traversal
- union-find
+function_signature: "def has_valid_path(grid: list[list[int]]) -> bool:"
+
+test_cases:
+ visible:
+ - input: { grid: [[2, 4, 3], [6, 5, 2]] }
+ expected: true
+ - input: { grid: [[1, 2, 1], [1, 2, 1]] }
+ expected: false
+ - input: { grid: [[1, 1, 2]] }
+ expected: false
+ hidden:
+ - input: { grid: [[1]] }
+ expected: true
+ - input: { grid: [[2]] }
+ expected: true
+ - input: { grid: [[4, 1], [6, 1]] }
+ expected: true
+ - input: { grid: [[1, 1, 1, 1]] }
+ expected: true
+ - input: { grid: [[2], [2], [2]] }
+ expected: true
+ - input: { grid: [[4, 3], [6, 5]] }
+ expected: false
+
description: |
You are given an `m x n` `grid`. Each cell of `grid` represents a street. The street of `grid[i][j]` can be:
diff --git a/backend/data/questions/check-if-word-can-be-placed-in-crossword.yaml b/backend/data/questions/check-if-word-can-be-placed-in-crossword.yaml
index cca327a..856d8be 100644
--- a/backend/data/questions/check-if-word-can-be-placed-in-crossword.yaml
+++ b/backend/data/questions/check-if-word-can-be-placed-in-crossword.yaml
@@ -9,6 +9,30 @@ categories:
patterns:
- matrix-traversal
+function_signature: "def place_word_in_crossword(board: list[list[str]], word: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { board: [["#", " ", "#"], [" ", " ", "#"], ["#", "c", " "]], word: "abc" }
+ expected: true
+ - input: { board: [[" ", "#", "a"], [" ", "#", "c"], [" ", "#", "a"]], word: "ac" }
+ expected: false
+ - input: { board: [["#", " ", "#"], [" ", " ", "#"], ["#", " ", "c"]], word: "ca" }
+ expected: true
+ hidden:
+ - input: { board: [[" "]], word: "a" }
+ expected: true
+ - input: { board: [["a"]], word: "a" }
+ expected: true
+ - input: { board: [["a"]], word: "b" }
+ expected: false
+ - input: { board: [[" ", " ", " "]], word: "abc" }
+ expected: true
+ - input: { board: [[" ", "#", " "]], word: "ab" }
+ expected: false
+ - input: { board: [["a", "b", "c"]], word: "abc" }
+ expected: true
+
description: |
You are given an `m x n` matrix `board`, representing the **current** state of a crossword puzzle. The crossword contains lowercase English letters (from solved words), `' '` to represent any **empty** cells, and `'#'` to represent any **blocked** cells.
diff --git a/backend/data/questions/check-if-word-equals-summation-of-two-words.yaml b/backend/data/questions/check-if-word-equals-summation-of-two-words.yaml
index 55daece..5f67d18 100644
--- a/backend/data/questions/check-if-word-equals-summation-of-two-words.yaml
+++ b/backend/data/questions/check-if-word-equals-summation-of-two-words.yaml
@@ -8,6 +8,26 @@ categories:
patterns:
- greedy
+function_signature: "def is_sum_equal(first_word: str, second_word: str, target_word: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { first_word: "acb", second_word: "cba", target_word: "cdb" }
+ expected: true
+ - input: { first_word: "aaa", second_word: "a", target_word: "aab" }
+ expected: false
+ - input: { first_word: "aaa", second_word: "a", target_word: "aaaa" }
+ expected: true
+ hidden:
+ - input: { first_word: "a", second_word: "a", target_word: "aa" }
+ expected: false
+ - input: { first_word: "j", second_word: "j", target_word: "bi" }
+ expected: true
+ - input: { first_word: "ab", second_word: "cd", target_word: "ef" }
+ expected: false
+ - input: { first_word: "a", second_word: "b", target_word: "b" }
+ expected: true
+
description: |
The **letter value** of a letter is its position in the alphabet **starting from 0** (i.e. `'a' -> 0`, `'b' -> 1`, `'c' -> 2`, etc.).
diff --git a/backend/data/questions/check-if-word-is-valid-after-substitutions.yaml b/backend/data/questions/check-if-word-is-valid-after-substitutions.yaml
index 608a01a..950ac93 100644
--- a/backend/data/questions/check-if-word-is-valid-after-substitutions.yaml
+++ b/backend/data/questions/check-if-word-is-valid-after-substitutions.yaml
@@ -9,6 +9,30 @@ categories:
patterns:
- monotonic-stack
+function_signature: "def is_valid(s: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { s: "aabcbc" }
+ expected: true
+ - input: { s: "abcabcababcc" }
+ expected: true
+ - input: { s: "abccba" }
+ expected: false
+ hidden:
+ - input: { s: "abc" }
+ expected: true
+ - input: { s: "a" }
+ expected: false
+ - input: { s: "ab" }
+ expected: false
+ - input: { s: "abcabc" }
+ expected: true
+ - input: { s: "aabbcc" }
+ expected: false
+ - input: { s: "abcabcabc" }
+ expected: true
+
description: |
Given a string `s`, determine if it is **valid**.
diff --git a/backend/data/questions/check-if-word-occurs-as-prefix.yaml b/backend/data/questions/check-if-word-occurs-as-prefix.yaml
index 459822a..e56ee75 100644
--- a/backend/data/questions/check-if-word-occurs-as-prefix.yaml
+++ b/backend/data/questions/check-if-word-occurs-as-prefix.yaml
@@ -8,6 +8,28 @@ categories:
patterns:
- two-pointers
+function_signature: "def is_prefix_of_word(sentence: str, search_word: str) -> int:"
+
+test_cases:
+ visible:
+ - input: { sentence: "i love eating burger", search_word: "burg" }
+ expected: 4
+ - input: { sentence: "this problem is an easy problem", search_word: "pro" }
+ expected: 2
+ - input: { sentence: "i am tired", search_word: "you" }
+ expected: -1
+ hidden:
+ - input: { sentence: "hello", search_word: "hello" }
+ expected: 1
+ - input: { sentence: "hello world", search_word: "world" }
+ expected: 2
+ - input: { sentence: "a b c", search_word: "a" }
+ expected: 1
+ - input: { sentence: "abc def ghi", search_word: "xyz" }
+ expected: -1
+ - input: { sentence: "hellohello", search_word: "ell" }
+ expected: -1
+
description: |
Given a `sentence` that consists of some words separated by a **single space**, and a `searchWord`, check if `searchWord` is a prefix of any word in `sentence`.
diff --git a/backend/data/questions/check-knight-tour-configuration.yaml b/backend/data/questions/check-knight-tour-configuration.yaml
index 2e4bbfd..09fabae 100644
--- a/backend/data/questions/check-knight-tour-configuration.yaml
+++ b/backend/data/questions/check-knight-tour-configuration.yaml
@@ -9,6 +9,22 @@ categories:
patterns:
- matrix-traversal
+function_signature: "def check_valid_grid(grid: list[list[int]]) -> bool:"
+
+test_cases:
+ visible:
+ - input: { grid: [[0, 11, 16, 5, 20], [17, 4, 19, 10, 15], [12, 1, 8, 21, 6], [3, 18, 23, 14, 9], [24, 13, 2, 7, 22]] }
+ expected: true
+ - input: { grid: [[0, 3, 6], [5, 8, 1], [2, 7, 4]] }
+ expected: false
+ hidden:
+ - input: { grid: [[0, 2, 4], [5, 7, 1], [6, 3, 8]] }
+ expected: false
+ - input: { grid: [[1, 0, 2], [3, 4, 5], [6, 7, 8]] }
+ expected: false
+ - input: { grid: [[0, 5, 4], [3, 2, 7], [6, 1, 8]] }
+ expected: false
+
description: |
There is a knight on an `n x n` chessboard. In a valid configuration, the knight starts **at the top-left cell** of the board and visits every cell on the board **exactly once**.
diff --git a/backend/data/questions/checking-existence-of-edge-length-limited-paths.yaml b/backend/data/questions/checking-existence-of-edge-length-limited-paths.yaml
index 4d5815a..4ed47ae 100644
--- a/backend/data/questions/checking-existence-of-edge-length-limited-paths.yaml
+++ b/backend/data/questions/checking-existence-of-edge-length-limited-paths.yaml
@@ -11,6 +11,24 @@ patterns:
- union-find
- two-pointers
+function_signature: "def distance_limited_paths_exist(n: int, edge_list: list[list[int]], queries: list[list[int]]) -> list[bool]:"
+
+test_cases:
+ visible:
+ - input: { n: 3, edge_list: [[0, 1, 2], [1, 2, 4], [2, 0, 8], [1, 0, 16]], queries: [[0, 1, 2], [0, 2, 5]] }
+ expected: [false, true]
+ - input: { n: 5, edge_list: [[0, 1, 10], [1, 2, 5], [2, 3, 9], [3, 4, 13]], queries: [[0, 4, 14], [1, 4, 13]] }
+ expected: [true, false]
+ hidden:
+ - input: { n: 2, edge_list: [[0, 1, 1]], queries: [[0, 1, 2]] }
+ expected: [true]
+ - input: { n: 2, edge_list: [[0, 1, 5]], queries: [[0, 1, 5]] }
+ expected: [false]
+ - input: { n: 3, edge_list: [[0, 1, 1], [1, 2, 1]], queries: [[0, 2, 2]] }
+ expected: [true]
+ - input: { n: 3, edge_list: [], queries: [[0, 1, 1]] }
+ expected: [false]
+
description: |
An undirected graph of `n` nodes is defined by `edgeList`, where `edgeList[i] = [u_i, v_i, dis_i]` denotes an edge between nodes `u_i` and `v_i` with distance `dis_i`. Note that there may be **multiple** edges between two nodes.
diff --git a/backend/data/questions/climbing-stairs.yaml b/backend/data/questions/climbing-stairs.yaml
index 00acf43..c30cb74 100644
--- a/backend/data/questions/climbing-stairs.yaml
+++ b/backend/data/questions/climbing-stairs.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: 8
- input: { n: 10 }
expected: 89
+ - input: { n: 20 }
+ expected: 10946
+ - input: { n: 6 }
+ expected: 13
+ - input: { n: 15 }
+ expected: 987
description: |
You are climbing a staircase. It takes `n` steps to reach the top.
diff --git a/backend/data/questions/clone-graph.yaml b/backend/data/questions/clone-graph.yaml
index 82e1f42..4875e15 100644
--- a/backend/data/questions/clone-graph.yaml
+++ b/backend/data/questions/clone-graph.yaml
@@ -25,6 +25,14 @@ test_cases:
expected: [[2], [1]]
- input: { adjList: [[2, 3], [1, 3], [1, 2]] }
expected: [[2, 3], [1, 3], [1, 2]]
+ - input: { adjList: [[2, 3, 4], [1, 3], [1, 2, 4], [1, 3]] }
+ expected: [[2, 3, 4], [1, 3], [1, 2, 4], [1, 3]]
+ - input: { adjList: [[2], [1, 3], [2, 4], [3, 5], [4]] }
+ expected: [[2], [1, 3], [2, 4], [3, 5], [4]]
+ - input: { adjList: [[2, 3, 4, 5], [1], [1], [1], [1]] }
+ expected: [[2, 3, 4, 5], [1], [1], [1], [1]]
+ - input: { adjList: [[2], [1, 3], [2]] }
+ expected: [[2], [1, 3], [2]]
description: |
Given a reference of a node in a **connected** undirected graph.
diff --git a/backend/data/questions/coin-change.yaml b/backend/data/questions/coin-change.yaml
index 654186f..f173502 100644
--- a/backend/data/questions/coin-change.yaml
+++ b/backend/data/questions/coin-change.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: 2
- input: { coins: [186, 419, 83, 408], amount: 6249 }
expected: 20
+ - input: { coins: [1, 2, 5], amount: 100 }
+ expected: 20
+ - input: { coins: [3, 7], amount: 5 }
+ expected: -1
+ - input: { coins: [1, 5, 10, 25], amount: 30 }
+ expected: 2
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.yaml b/backend/data/questions/combination-sum.yaml
index 15d701e..ed266cc 100644
--- a/backend/data/questions/combination-sum.yaml
+++ b/backend/data/questions/combination-sum.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: [[1, 1]]
- input: { candidates: [2, 3, 5], target: 5 }
expected: [[2, 3], [5]]
+ - input: { candidates: [2, 7, 6, 3, 5, 1], target: 9 }
+ expected: [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 2, 3], [1, 1, 1, 1, 5], [1, 1, 1, 2, 2, 2], [1, 1, 1, 3, 3], [1, 1, 1, 6], [1, 1, 2, 2, 3], [1, 1, 2, 5], [1, 1, 7], [1, 2, 2, 2, 2], [1, 2, 3, 3], [1, 2, 6], [1, 3, 5], [2, 2, 2, 3], [2, 2, 5], [2, 7], [3, 3, 3], [3, 6]]
+ - input: { candidates: [8, 7, 4, 3], target: 11 }
+ expected: [[3, 4, 4], [3, 8], [4, 7]]
+ - input: { candidates: [5, 10], target: 15 }
+ expected: [[5, 5, 5], [5, 10]]
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/construct-quad-tree.yaml b/backend/data/questions/construct-quad-tree.yaml
index b016ce6..428b833 100644
--- a/backend/data/questions/construct-quad-tree.yaml
+++ b/backend/data/questions/construct-quad-tree.yaml
@@ -11,6 +11,24 @@ patterns:
- matrix-traversal
- dfs
+function_signature: "def construct(grid: list[list[int]]) -> Node:"
+
+test_cases:
+ visible:
+ - input: { grid: [[0, 1], [1, 0]] }
+ expected: [[0, 1], [1, 0], [1, 1], [1, 1], [1, 0]]
+ - input: { grid: [[1, 1], [1, 1]] }
+ expected: [[1, 1]]
+ hidden:
+ - input: { grid: [[0]] }
+ expected: [[1, 0]]
+ - input: { grid: [[1]] }
+ expected: [[1, 1]]
+ - input: { grid: [[0, 0], [0, 0]] }
+ expected: [[1, 0]]
+ - input: { grid: [[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]] }
+ expected: [[0, 1], [1, 1], [1, 0], [1, 0], [1, 1]]
+
description: |
Given a `n * n` matrix `grid` of `0`s and `1`s only. We want to represent `grid` with a Quad-Tree.
diff --git a/backend/data/questions/container-with-most-water.yaml b/backend/data/questions/container-with-most-water.yaml
index 0b4cfc6..39d1b92 100644
--- a/backend/data/questions/container-with-most-water.yaml
+++ b/backend/data/questions/container-with-most-water.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: 36
- input: { height: [1, 2, 4, 3] }
expected: 4
+ - input: { height: [1, 1, 1, 1, 1, 1, 1, 1] }
+ expected: 7
+ - input: { height: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] }
+ expected: 25
+ - input: { height: [1, 3, 2, 5, 25, 24, 5] }
+ expected: 24
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/contains-duplicate.yaml b/backend/data/questions/contains-duplicate.yaml
index 6874524..76b06ec 100644
--- a/backend/data/questions/contains-duplicate.yaml
+++ b/backend/data/questions/contains-duplicate.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: true
- input: { nums: [0, 0] }
expected: true
+ - input: { nums: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
+ expected: false
+ - input: { nums: [1, 2, 3, 4, 5, 1] }
+ expected: true
+ - input: { nums: [1000000000, -1000000000] }
+ expected: false
description: |
Given an integer array `nums`, return `true` if any value appears **at least twice** in the array, and return `false` if every element is distinct.
diff --git a/backend/data/questions/counting-bits.yaml b/backend/data/questions/counting-bits.yaml
index bf7dd7b..fc83812 100644
--- a/backend/data/questions/counting-bits.yaml
+++ b/backend/data/questions/counting-bits.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: [0, 1, 1, 2, 1, 2, 2, 3]
- input: { n: 10 }
expected: [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2]
+ - input: { n: 3 }
+ expected: [0, 1, 1, 2]
+ - input: { n: 15 }
+ expected: [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4]
+ - input: { n: 4 }
+ expected: [0, 1, 1, 2, 1]
description: |
Given an integer `n`, return an array `ans` of length `n + 1` such that for each `i` (`0 <= i <= n`), `ans[i]` is the **number of `1`'s** in the binary representation of `i`.
diff --git a/backend/data/questions/course-schedule.yaml b/backend/data/questions/course-schedule.yaml
index ba5d141..0b9fe1b 100644
--- a/backend/data/questions/course-schedule.yaml
+++ b/backend/data/questions/course-schedule.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: false
- input: { num_courses: 5, prerequisites: [[1, 0], [2, 0], [3, 1], [4, 2]] }
expected: true
+ - input: { num_courses: 3, prerequisites: [[0, 1], [0, 2], [1, 2]] }
+ expected: true
+ - input: { num_courses: 4, prerequisites: [] }
+ expected: true
+ - input: { num_courses: 3, prerequisites: [[0, 1], [1, 2], [2, 0]] }
+ expected: false
description: |
There are a total of `numCourses` courses you have to take, labeled from `0` to `numCourses - 1`. You are given an array `prerequisites` where `prerequisites[i] = [a``i``, b``i``]` indicates that you **must** take course `b``i` first if you want to take course `a``i`.
diff --git a/backend/data/questions/decode-ways.yaml b/backend/data/questions/decode-ways.yaml
index 5c361a2..29528fd 100644
--- a/backend/data/questions/decode-ways.yaml
+++ b/backend/data/questions/decode-ways.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: 1
- input: { s: "11106" }
expected: 2
+ - input: { s: "111" }
+ expected: 3
+ - input: { s: "27" }
+ expected: 1
+ - input: { s: "1234" }
+ expected: 3
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/find-minimum-in-rotated-sorted-array.yaml b/backend/data/questions/find-minimum-in-rotated-sorted-array.yaml
index 0e01e2b..549d9fb 100644
--- a/backend/data/questions/find-minimum-in-rotated-sorted-array.yaml
+++ b/backend/data/questions/find-minimum-in-rotated-sorted-array.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: 1
- input: { nums: [5, 1, 2, 3, 4] }
expected: 1
+ - input: { nums: [2, 3, 4, 5, 1] }
+ expected: 1
+ - input: { nums: [3, 4, 5, 6, 7, 1, 2] }
+ expected: 1
+ - input: { nums: [10, 20, 30, 40, 5] }
+ expected: 5
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 f761281..f26971e 100644
--- a/backend/data/questions/find-the-duplicate-number.yaml
+++ b/backend/data/questions/find-the-duplicate-number.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: 2
- input: { nums: [1, 4, 4, 2, 4] }
expected: 4
+ - input: { nums: [1, 2, 3, 4, 5, 6, 7, 8, 9, 5] }
+ expected: 5
+ - input: { nums: [2, 5, 9, 6, 9, 3, 8, 9, 7, 1] }
+ expected: 9
+ - input: { nums: [1, 1, 2] }
+ expected: 1
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/group-anagrams.yaml b/backend/data/questions/group-anagrams.yaml
index 9b1518b..9117430 100644
--- a/backend/data/questions/group-anagrams.yaml
+++ b/backend/data/questions/group-anagrams.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: [["", ""]]
- input: { strs: ["listen", "silent", "enlist"] }
expected: [["listen", "silent", "enlist"]]
+ - input: { strs: ["a", "b", "c"] }
+ expected: [["a"], ["b"], ["c"]]
+ - input: { strs: ["abc", "def", "ghi"] }
+ expected: [["abc"], ["def"], ["ghi"]]
+ - input: { strs: ["aab", "aba", "baa", "ab", "ba"] }
+ expected: [["aab", "aba", "baa"], ["ab", "ba"]]
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 d939799..de6d7ce 100644
--- a/backend/data/questions/house-robber.yaml
+++ b/backend/data/questions/house-robber.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: 9
- input: { nums: [0, 0, 0, 0] }
expected: 0
+ - input: { nums: [100, 1, 1, 100] }
+ expected: 200
+ - input: { nums: [2, 1, 1, 2] }
+ expected: 4
+ - input: { nums: [1, 3, 1, 3, 100] }
+ expected: 103
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 2926d4e..cf5c160 100644
--- a/backend/data/questions/insert-interval.yaml
+++ b/backend/data/questions/insert-interval.yaml
@@ -25,6 +25,12 @@ test_cases:
expected: [[1, 5], [6, 8]]
- input: { intervals: [[3, 5], [12, 15]], newInterval: [6, 6] }
expected: [[3, 5], [6, 6], [12, 15]]
+ - input: { intervals: [[1, 5]], newInterval: [0, 0] }
+ expected: [[0, 0], [1, 5]]
+ - input: { intervals: [[1, 5]], newInterval: [0, 6] }
+ expected: [[0, 6]]
+ - input: { intervals: [[1, 2], [3, 4], [5, 6]], newInterval: [0, 7] }
+ expected: [[0, 7]]
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/invert-binary-tree.yaml b/backend/data/questions/invert-binary-tree.yaml
index 02cc8f3..0d3a44f 100644
--- a/backend/data/questions/invert-binary-tree.yaml
+++ b/backend/data/questions/invert-binary-tree.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: [1, null, 2]
- input: { root: [1, null, 2] }
expected: [1, 2]
+ - input: { root: [1, 2, 3, 4, 5, 6, 7] }
+ expected: [1, 3, 2, 7, 6, 5, 4]
+ - input: { root: [5, 3, 8, 1, 4, 7, 9] }
+ expected: [5, 8, 3, 9, 7, 4, 1]
+ - input: { root: [1, 2, 3] }
+ expected: [1, 3, 2]
description: |
Given the `root` of a binary tree, invert the tree, and return *its root*.
diff --git a/backend/data/questions/jump-game.yaml b/backend/data/questions/jump-game.yaml
index 2d7ef34..b2f3213 100644
--- a/backend/data/questions/jump-game.yaml
+++ b/backend/data/questions/jump-game.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: false
- input: { nums: [5, 4, 3, 2, 1, 0, 0] }
expected: true
+ - input: { nums: [1, 1, 1, 1, 1] }
+ expected: true
+ - input: { nums: [2, 0, 2, 0, 1] }
+ expected: true
+ - input: { nums: [1, 2, 3] }
+ 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-smallest-element-in-a-bst.yaml b/backend/data/questions/kth-smallest-element-in-a-bst.yaml
index 882dce0..74f1547 100644
--- a/backend/data/questions/kth-smallest-element-in-a-bst.yaml
+++ b/backend/data/questions/kth-smallest-element-in-a-bst.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: 6
- input: { root: [3, 1, 4, null, 2], k: 4 }
expected: 4
+ - input: { root: [5, 3, 6, 2, 4, null, null, 1], k: 1 }
+ expected: 1
+ - input: { root: [5, 3, 6, 2, 4, null, null, 1], k: 4 }
+ expected: 4
+ - input: { root: [41, 37, 44, 24, 39, 42, 48, 1, 35, 38, 40, null, 43, 46, 49, 0, 2, 30, 36, null, null, null, null, null, null, 45, 47, null, null, null, null, null, 4, 29, 32, null, null, null, null, null, null, 3, 9, 26, null, 31, 34, null, null, 7, 11, 25, 27, null, null, 33, null, 6, 8, 10, 16, null, null, null, 28, null, null, 5, null, null, null, null, null, 15, 19, null, null, null, null, 12, null, 18, 20, null, 13, 17, null, null, 22, null, 14, null, null, 21, 23], k: 25 }
+ expected: 24
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/letter-combinations-of-a-phone-number.yaml b/backend/data/questions/letter-combinations-of-a-phone-number.yaml
index 0f1aa84..6e3d21f 100644
--- a/backend/data/questions/letter-combinations-of-a-phone-number.yaml
+++ b/backend/data/questions/letter-combinations-of-a-phone-number.yaml
@@ -25,6 +25,16 @@ test_cases:
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"]
+ - input: { digits: "234" }
+ expected: ["adg", "adh", "adi", "aeg", "aeh", "aei", "afg", "afh", "afi", "bdg", "bdh", "bdi", "beg", "beh", "bei", "bfg", "bfh", "bfi", "cdg", "cdh", "cdi", "ceg", "ceh", "cei", "cfg", "cfh", "cfi"]
+ - input: { digits: "9" }
+ expected: ["w", "x", "y", "z"]
+ - input: { digits: "22" }
+ expected: ["aa", "ab", "ac", "ba", "bb", "bc", "ca", "cb", "cc"]
+ - input: { digits: "8" }
+ expected: ["t", "u", "v"]
+ - input: { digits: "56" }
+ expected: ["jm", "jn", "jo", "km", "kn", "ko", "lm", "ln", "lo"]
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 c6ecb2e..8b53d6d 100644
--- a/backend/data/questions/linked-list-cycle.yaml
+++ b/backend/data/questions/linked-list-cycle.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: false
- input: { head: [1, 2, 3, 4, 5], pos: 4 }
expected: true
+ - input: { head: [1, 2], pos: -1 }
+ expected: false
+ - input: { head: [1], pos: 0 }
+ expected: true
+ - input: { head: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], pos: 0 }
+ 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 f33de19..39ecc8d 100644
--- a/backend/data/questions/longest-common-subsequence.yaml
+++ b/backend/data/questions/longest-common-subsequence.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: 0
- input: { text1: "oxcpqrsvwf", text2: "shmtulqrypy" }
expected: 2
+ - input: { text1: "abcdefg", text2: "bdfxyz" }
+ expected: 3
+ - input: { text1: "aaaa", text2: "aaaa" }
+ expected: 4
+ - input: { text1: "ezupkr", text2: "ubmrapg" }
+ 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-increasing-subsequence.yaml b/backend/data/questions/longest-increasing-subsequence.yaml
index 4c834e0..d1d1053 100644
--- a/backend/data/questions/longest-increasing-subsequence.yaml
+++ b/backend/data/questions/longest-increasing-subsequence.yaml
@@ -30,6 +30,12 @@ test_cases:
expected: 1
- input: { nums: [4, 10, 4, 3, 8, 9] }
expected: 3
+ - input: { nums: [2, 2, 2, 2, 2] }
+ expected: 1
+ - input: { nums: [1, 3, 6, 7, 9, 4, 10, 5, 6] }
+ expected: 6
+ - input: { nums: [3, 5, 6, 2, 5, 4, 19, 5, 6, 7, 12] }
+ expected: 6
description: |
Given an integer array `nums`, return *the length of the longest **strictly increasing subsequence***.
diff --git a/backend/data/questions/longest-substring-without-repeating.yaml b/backend/data/questions/longest-substring-without-repeating.yaml
index 8e0f673..6dbf9c1 100644
--- a/backend/data/questions/longest-substring-without-repeating.yaml
+++ b/backend/data/questions/longest-substring-without-repeating.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: 2
- input: { s: "dvdf" }
expected: 3
+ - input: { s: "abcdefghijklmnopqrstuvwxyz" }
+ expected: 26
+ - input: { s: "aab" }
+ expected: 2
+ - input: { s: "tmmzuxt" }
+ expected: 5
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 b43d7ff..773ce8f 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
@@ -26,6 +26,12 @@ test_cases:
expected: 8
- input: { root: [3, 1, 4, null, 2], p: 1, q: 4 }
expected: 3
+ - input: { root: [6, 2, 8, 0, 4, 7, 9, null, null, 3, 5], p: 0, q: 5 }
+ expected: 2
+ - input: { root: [5, 3, 6, 2, 4], p: 2, q: 4 }
+ expected: 3
+ - input: { root: [2, 1, 3], p: 1, q: 3 }
+ expected: 2
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/majority-element.yaml b/backend/data/questions/majority-element.yaml
index a6e47fb..6c3bc50 100644
--- a/backend/data/questions/majority-element.yaml
+++ b/backend/data/questions/majority-element.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: 2
- input: { nums: [3, 3, 4] }
expected: 3
+ - input: { nums: [1, 1, 1, 1, 2, 3, 4] }
+ expected: 1
+ - input: { nums: [5, 5, 5, 5, 5] }
+ expected: 5
+ - input: { nums: [-1, -1, -1, 2, 2] }
+ expected: -1
description: |
Given an array `nums` of size `n`, return *the majority element*.
diff --git a/backend/data/questions/maximum-depth-of-binary-tree.yaml b/backend/data/questions/maximum-depth-of-binary-tree.yaml
index e3125bd..6afd84f 100644
--- a/backend/data/questions/maximum-depth-of-binary-tree.yaml
+++ b/backend/data/questions/maximum-depth-of-binary-tree.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: 3
- input: { root: [1, 2, null, 3, null, 4] }
expected: 4
+ - input: { root: [1, 2, 3, 4, 5, 6, 7] }
+ expected: 3
+ - input: { root: [1, null, 2, null, 3, null, 4] }
+ expected: 4
+ - input: { root: [1, 2, 3, null, null, null, 4] }
+ expected: 3
description: |
Given the `root` of a binary tree, return *its maximum depth*.
diff --git a/backend/data/questions/maximum-fruits-harvested-after-at-most-k-steps.yaml b/backend/data/questions/maximum-fruits-harvested-after-at-most-k-steps.yaml
index cd620ac..4f0edc4 100644
--- a/backend/data/questions/maximum-fruits-harvested-after-at-most-k-steps.yaml
+++ b/backend/data/questions/maximum-fruits-harvested-after-at-most-k-steps.yaml
@@ -11,6 +11,26 @@ patterns:
- prefix-sum
- two-pointers
+function_signature: "def max_total_fruits(fruits: list[list[int]], start_pos: int, k: int) -> int:"
+
+test_cases:
+ visible:
+ - input: { fruits: [[2, 8], [6, 3], [8, 6]], start_pos: 5, k: 4 }
+ expected: 9
+ - input: { fruits: [[0, 9], [4, 1], [5, 7], [6, 2], [7, 4], [10, 9]], start_pos: 5, k: 4 }
+ expected: 14
+ - input: { fruits: [[0, 3], [6, 4], [8, 5]], start_pos: 3, k: 2 }
+ expected: 0
+ hidden:
+ - input: { fruits: [[0, 10]], start_pos: 0, k: 0 }
+ expected: 10
+ - input: { fruits: [[5, 5]], start_pos: 5, k: 0 }
+ expected: 5
+ - input: { fruits: [[0, 5], [10, 5]], start_pos: 5, k: 5 }
+ expected: 5
+ - input: { fruits: [[1, 1], [2, 2], [3, 3]], start_pos: 2, k: 10 }
+ expected: 6
+
description: |
Fruits are available at some positions on an infinite x-axis. You are given a 2D integer array `fruits` where `fruits[i] = [position_i, amount_i]` depicts `amount_i` fruits at the position `position_i`. `fruits` is already **sorted** by `position_i` in **ascending order**, and each `position_i` is **unique**.
diff --git a/backend/data/questions/maximum-length-of-pair-chain.yaml b/backend/data/questions/maximum-length-of-pair-chain.yaml
index cc7e425..2ff5676 100644
--- a/backend/data/questions/maximum-length-of-pair-chain.yaml
+++ b/backend/data/questions/maximum-length-of-pair-chain.yaml
@@ -11,6 +11,26 @@ patterns:
- greedy
- intervals
+function_signature: "def find_longest_chain(pairs: list[list[int]]) -> int:"
+
+test_cases:
+ visible:
+ - input: { pairs: [[1, 2], [2, 3], [3, 4]] }
+ expected: 2
+ - input: { pairs: [[1, 2], [7, 8], [4, 5]] }
+ expected: 3
+ hidden:
+ - input: { pairs: [[1, 2]] }
+ expected: 1
+ - input: { pairs: [[1, 10], [2, 3], [4, 5]] }
+ expected: 2
+ - input: { pairs: [[-10, -5], [-3, 0], [1, 5]] }
+ expected: 3
+ - input: { pairs: [[1, 5], [2, 3], [4, 6]] }
+ expected: 2
+ - input: { pairs: [[1, 2], [3, 4], [5, 6], [7, 8]] }
+ expected: 4
+
description: |
You are given an array of `n` pairs `pairs` where `pairs[i] = [left_i, right_i]` and `left_i < right_i`.
diff --git a/backend/data/questions/maximum-subarray.yaml b/backend/data/questions/maximum-subarray.yaml
index e12565e..70a020f 100644
--- a/backend/data/questions/maximum-subarray.yaml
+++ b/backend/data/questions/maximum-subarray.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: 10
- input: { nums: [-1, -2, -3, -4] }
expected: -1
+ - input: { nums: [3, -2, 5, -1] }
+ expected: 6
+ - input: { nums: [-2, 1] }
+ expected: 1
+ - input: { nums: [8, -19, 5, -4, 20] }
+ expected: 21
description: |
Given an integer array `nums`, find the subarray with the largest sum, and return *its sum*.
diff --git a/backend/data/questions/maximum-sum-circular-subarray.yaml b/backend/data/questions/maximum-sum-circular-subarray.yaml
index b2409e3..525be32 100644
--- a/backend/data/questions/maximum-sum-circular-subarray.yaml
+++ b/backend/data/questions/maximum-sum-circular-subarray.yaml
@@ -9,6 +9,28 @@ categories:
patterns:
- dynamic-programming
+function_signature: "def max_subarray_sum_circular(nums: list[int]) -> int:"
+
+test_cases:
+ visible:
+ - input: { nums: [1, -2, 3, -2] }
+ expected: 3
+ - input: { nums: [5, -3, 5] }
+ expected: 10
+ - input: { nums: [-3, -2, -3] }
+ expected: -2
+ hidden:
+ - input: { nums: [1] }
+ expected: 1
+ - input: { nums: [-1] }
+ expected: -1
+ - input: { nums: [3, -1, 2, -1] }
+ expected: 4
+ - input: { nums: [3, -2, 2, -3] }
+ expected: 3
+ - input: { nums: [1, 2, 3, 4, 5] }
+ expected: 15
+
description: |
Given a **circular integer array** `nums` of length `n`, return *the maximum possible sum of a non-empty **subarray** of* `nums`.
diff --git a/backend/data/questions/merge-intervals.yaml b/backend/data/questions/merge-intervals.yaml
index adcb06f..96945fd 100644
--- a/backend/data/questions/merge-intervals.yaml
+++ b/backend/data/questions/merge-intervals.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: [[0, 0], [1, 4]]
- input: { intervals: [[1, 4], [2, 3]] }
expected: [[1, 4]]
+ - input: { intervals: [[1, 3], [4, 6], [7, 9]] }
+ expected: [[1, 3], [4, 6], [7, 9]]
+ - input: { intervals: [[1, 10], [2, 3], [4, 5], [6, 7]] }
+ expected: [[1, 10]]
+ - input: { intervals: [[2, 3], [4, 5], [6, 7], [8, 9], [1, 10]] }
+ expected: [[1, 10]]
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-k-sorted-lists.yaml b/backend/data/questions/merge-k-sorted-lists.yaml
index 734a3fd..f290be2 100644
--- a/backend/data/questions/merge-k-sorted-lists.yaml
+++ b/backend/data/questions/merge-k-sorted-lists.yaml
@@ -9,6 +9,26 @@ categories:
patterns:
- heap
+function_signature: "def merge_k_lists(lists: list[ListNode | None]) -> ListNode | None:"
+
+test_cases:
+ visible:
+ - input: { lists: [[1, 4, 5], [1, 3, 4], [2, 6]] }
+ expected: [1, 1, 2, 3, 4, 4, 5, 6]
+ - input: { lists: [] }
+ expected: null
+ - input: { lists: [[]] }
+ expected: null
+ hidden:
+ - input: { lists: [[1]] }
+ expected: [1]
+ - input: { lists: [[1, 2], [3, 4]] }
+ expected: [1, 2, 3, 4]
+ - input: { lists: [[5], [1], [3]] }
+ expected: [1, 3, 5]
+ - input: { lists: [[-1, 0], [-2, 1]] }
+ expected: [-2, -1, 0, 1]
+
description: |
You are given an array of `k` linked-lists `lists`, each linked-list is sorted in **ascending order**.
diff --git a/backend/data/questions/merge-triplets-to-form-target-triplet.yaml b/backend/data/questions/merge-triplets-to-form-target-triplet.yaml
index 438aa34..031743c 100644
--- a/backend/data/questions/merge-triplets-to-form-target-triplet.yaml
+++ b/backend/data/questions/merge-triplets-to-form-target-triplet.yaml
@@ -8,6 +8,26 @@ categories:
patterns:
- greedy
+function_signature: "def merge_triplets(triplets: list[list[int]], target: list[int]) -> bool:"
+
+test_cases:
+ visible:
+ - input: { triplets: [[2, 5, 3], [1, 8, 4], [1, 7, 5]], target: [2, 7, 5] }
+ expected: true
+ - input: { triplets: [[3, 4, 5], [4, 5, 6]], target: [3, 2, 5] }
+ expected: false
+ - input: { triplets: [[2, 5, 3], [2, 3, 4], [1, 2, 5], [5, 2, 3]], target: [5, 5, 5] }
+ expected: true
+ hidden:
+ - input: { triplets: [[1, 1, 1]], target: [1, 1, 1] }
+ expected: true
+ - input: { triplets: [[1, 2, 3]], target: [1, 2, 4] }
+ expected: false
+ - input: { triplets: [[5, 1, 1], [1, 5, 1], [1, 1, 5]], target: [5, 5, 5] }
+ expected: true
+ - input: { triplets: [[6, 1, 1], [1, 5, 5]], target: [5, 5, 5] }
+ expected: false
+
description: |
A **triplet** is an array of three integers. You are given a 2D integer array `triplets`, where `triplets[i] = [a_i, b_i, c_i]` describes the ith **triplet**. You are also given an integer array `target = [x, y, z]` that describes the **triplet** you want to obtain.
diff --git a/backend/data/questions/merge-two-sorted-lists.yaml b/backend/data/questions/merge-two-sorted-lists.yaml
index bab1a86..7d06f01 100644
--- a/backend/data/questions/merge-two-sorted-lists.yaml
+++ b/backend/data/questions/merge-two-sorted-lists.yaml
@@ -24,6 +24,16 @@ test_cases:
expected: [1, 2]
- input: { list1: [5], list2: [1, 2, 4] }
expected: [1, 2, 4, 5]
+ - input: { list1: [1, 3, 5, 7], list2: [2, 4, 6, 8] }
+ expected: [1, 2, 3, 4, 5, 6, 7, 8]
+ - input: { list1: [1, 1, 1], list2: [1, 1, 1] }
+ expected: [1, 1, 1, 1, 1, 1]
+ - input: { list1: [-10, -5, 0, 5], list2: [-7, -3, 2, 8] }
+ expected: [-10, -7, -5, -3, 0, 2, 5, 8]
+ - input: { list1: [1, 2, 3, 4, 5], list2: [] }
+ expected: [1, 2, 3, 4, 5]
+ - input: { list1: [], list2: [1, 2, 3] }
+ expected: [1, 2, 3]
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 ad57130..7296769 100644
--- a/backend/data/questions/min-cost-climbing-stairs.yaml
+++ b/backend/data/questions/min-cost-climbing-stairs.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: 10
- input: { cost: [1, 100] }
expected: 1
+ - input: { cost: [1, 2, 3] }
+ expected: 2
+ - input: { cost: [0, 1, 2, 3, 4, 5] }
+ expected: 6
+ - input: { cost: [5, 5, 5, 5, 5] }
+ expected: 15
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/min-cost-to-connect-all-points.yaml b/backend/data/questions/min-cost-to-connect-all-points.yaml
index a38df97..39e48a6 100644
--- a/backend/data/questions/min-cost-to-connect-all-points.yaml
+++ b/backend/data/questions/min-cost-to-connect-all-points.yaml
@@ -10,6 +10,26 @@ patterns:
- heap
- union-find
+function_signature: "def min_cost_connect_points(points: list[list[int]]) -> int:"
+
+test_cases:
+ visible:
+ - input: { points: [[0, 0], [2, 2], [3, 10], [5, 2], [7, 0]] }
+ expected: 20
+ - input: { points: [[3, 12], [-2, 5], [-4, 1]] }
+ expected: 18
+ hidden:
+ - input: { points: [[0, 0]] }
+ expected: 0
+ - input: { points: [[0, 0], [1, 1]] }
+ expected: 2
+ - input: { points: [[0, 0], [1, 0], [2, 0]] }
+ expected: 2
+ - input: { points: [[-1000000, -1000000], [1000000, 1000000]] }
+ expected: 4000000
+ - input: { points: [[0, 0], [0, 1], [1, 0], [1, 1]] }
+ expected: 3
+
description: |
You are given an array `points` representing integer coordinates of some points on a 2D-plane, where `points[i] = [x_i, y_i]`.
diff --git a/backend/data/questions/min-stack.yaml b/backend/data/questions/min-stack.yaml
index c57baa4..9f506fd 100644
--- a/backend/data/questions/min-stack.yaml
+++ b/backend/data/questions/min-stack.yaml
@@ -8,6 +8,32 @@ categories:
patterns:
- monotonic-stack
+function_signature: "class MinStack"
+
+test_cases:
+ visible:
+ - input:
+ operations: ["MinStack", "push", "push", "push", "getMin", "pop", "top", "getMin"]
+ args: [[], [-2], [0], [-3], [], [], [], []]
+ expected: [null, null, null, null, -3, null, 0, -2]
+ - input:
+ operations: ["MinStack", "push", "push", "getMin", "pop", "getMin"]
+ args: [[], [1], [2], [], [], []]
+ expected: [null, null, null, 1, null, 1]
+ hidden:
+ - input:
+ operations: ["MinStack", "push", "push", "push", "top", "pop", "getMin", "pop", "getMin", "pop", "push", "top", "getMin", "push", "top", "getMin", "pop", "getMin"]
+ args: [[], [2147483646], [2147483646], [2147483647], [], [], [], [], [], [], [2147483647], [], [], [-2147483648], [], [], [], []]
+ expected: [null, null, null, null, 2147483647, null, 2147483646, null, 2147483646, null, null, 2147483647, 2147483647, null, -2147483648, -2147483648, null, 2147483647]
+ - input:
+ operations: ["MinStack", "push", "push", "push", "getMin", "top", "pop", "getMin"]
+ args: [[], [0], [1], [0], [], [], [], []]
+ expected: [null, null, null, null, 0, 0, null, 0]
+ - input:
+ operations: ["MinStack", "push", "getMin", "push", "getMin", "push", "getMin"]
+ args: [[], [5], [], [3], [], [7], []]
+ expected: [null, null, 5, null, 3, null, 3]
+
description: |
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
diff --git a/backend/data/questions/minimum-height-trees.yaml b/backend/data/questions/minimum-height-trees.yaml
index 0e2d88a..edac0ed 100644
--- a/backend/data/questions/minimum-height-trees.yaml
+++ b/backend/data/questions/minimum-height-trees.yaml
@@ -10,6 +10,26 @@ patterns:
- bfs
- tree-traversal
+function_signature: "def find_min_height_trees(n: int, edges: list[list[int]]) -> list[int]:"
+
+test_cases:
+ visible:
+ - input: { n: 4, edges: [[1, 0], [1, 2], [1, 3]] }
+ expected: [1]
+ - input: { n: 6, edges: [[3, 0], [3, 1], [3, 2], [3, 4], [5, 4]] }
+ expected: [3, 4]
+ hidden:
+ - input: { n: 1, edges: [] }
+ expected: [0]
+ - input: { n: 2, edges: [[0, 1]] }
+ expected: [0, 1]
+ - input: { n: 3, edges: [[0, 1], [1, 2]] }
+ expected: [1]
+ - input: { n: 7, edges: [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]] }
+ expected: [3]
+ - input: { n: 8, edges: [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]] }
+ expected: [3, 4]
+
description: |
A tree is an undirected graph in which any two vertices are connected by *exactly* one path. In other words, any connected graph without simple cycles is a tree.
diff --git a/backend/data/questions/minimum-interval-to-include-each-query.yaml b/backend/data/questions/minimum-interval-to-include-each-query.yaml
index 87c5e5e..171008c 100644
--- a/backend/data/questions/minimum-interval-to-include-each-query.yaml
+++ b/backend/data/questions/minimum-interval-to-include-each-query.yaml
@@ -10,6 +10,24 @@ categories:
patterns:
- heap
+function_signature: "def min_interval(intervals: list[list[int]], queries: list[int]) -> list[int]:"
+
+test_cases:
+ visible:
+ - input: { intervals: [[1, 4], [2, 4], [3, 6], [4, 4]], queries: [2, 3, 4, 5] }
+ expected: [3, 3, 1, 4]
+ - input: { intervals: [[2, 3], [2, 5], [1, 8], [20, 25]], queries: [2, 19, 5, 22] }
+ expected: [2, -1, 4, 6]
+ hidden:
+ - input: { intervals: [[1, 1]], queries: [1] }
+ expected: [1]
+ - input: { intervals: [[1, 5]], queries: [0, 6] }
+ expected: [-1, -1]
+ - input: { intervals: [[1, 10], [2, 3]], queries: [2, 5] }
+ expected: [2, 10]
+ - input: { intervals: [[1, 2], [3, 4], [5, 6]], queries: [1, 3, 5, 7] }
+ expected: [2, 2, 2, -1]
+
description: |
You are given a 2D integer array `intervals`, where `intervals[i] = [left_i, right_i]` describes the ith interval starting at `left_i` and ending at `right_i` **(inclusive)**. The **size** of an interval is defined as the number of integers it contains, or more formally `right_i - left_i + 1`.
diff --git a/backend/data/questions/minimum-path-sum.yaml b/backend/data/questions/minimum-path-sum.yaml
index bc2a2fb..79b760c 100644
--- a/backend/data/questions/minimum-path-sum.yaml
+++ b/backend/data/questions/minimum-path-sum.yaml
@@ -10,6 +10,26 @@ patterns:
- dynamic-programming
- matrix-traversal
+function_signature: "def min_path_sum(grid: list[list[int]]) -> int:"
+
+test_cases:
+ visible:
+ - input: { grid: [[1, 3, 1], [1, 5, 1], [4, 2, 1]] }
+ expected: 7
+ - input: { grid: [[1, 2, 3], [4, 5, 6]] }
+ expected: 12
+ hidden:
+ - input: { grid: [[5]] }
+ expected: 5
+ - input: { grid: [[1, 2, 3, 4, 5]] }
+ expected: 15
+ - input: { grid: [[1], [2], [3], [4], [5]] }
+ expected: 15
+ - input: { grid: [[0, 0], [0, 0]] }
+ expected: 0
+ - input: { grid: [[1, 100], [1, 1]] }
+ expected: 3
+
description: |
Given a `m x n` `grid` filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
diff --git a/backend/data/questions/minimum-size-subarray-sum.yaml b/backend/data/questions/minimum-size-subarray-sum.yaml
index 022efe0..b166e0d 100644
--- a/backend/data/questions/minimum-size-subarray-sum.yaml
+++ b/backend/data/questions/minimum-size-subarray-sum.yaml
@@ -11,6 +11,28 @@ patterns:
- binary-search
- prefix-sum
+function_signature: "def min_subarray_len(target: int, nums: list[int]) -> int:"
+
+test_cases:
+ visible:
+ - input: { target: 7, nums: [2, 3, 1, 2, 4, 3] }
+ expected: 2
+ - input: { target: 4, nums: [1, 4, 4] }
+ expected: 1
+ - input: { target: 11, nums: [1, 1, 1, 1, 1, 1, 1, 1] }
+ expected: 0
+ hidden:
+ - input: { target: 5, nums: [5] }
+ expected: 1
+ - input: { target: 6, nums: [5] }
+ expected: 0
+ - input: { target: 15, nums: [1, 2, 3, 4, 5] }
+ expected: 5
+ - input: { target: 100, nums: [1, 1, 1, 1, 1, 1, 1] }
+ expected: 0
+ - input: { target: 3, nums: [1, 1, 1, 1, 1] }
+ expected: 3
+
description: |
Given an array of positive integers `nums` and a positive integer `target`, return *the **minimal length** of a subarray whose sum is greater than or equal to* `target`. If there is no such subarray, return `0` instead.
diff --git a/backend/data/questions/missing-number.yaml b/backend/data/questions/missing-number.yaml
index fb17359..e8728a5 100644
--- a/backend/data/questions/missing-number.yaml
+++ b/backend/data/questions/missing-number.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: 0
- input: { nums: [0, 1, 2, 3, 5] }
expected: 4
+ - input: { nums: [2, 0, 1, 4, 5, 6, 7] }
+ expected: 3
+ - input: { nums: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] }
+ expected: 10
+ - input: { nums: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
+ expected: 0
description: |
Given an array `nums` containing `n` distinct numbers in the range `[0, n]`, return *the only number in the range that is missing from the array*.
diff --git a/backend/data/questions/multiply-strings.yaml b/backend/data/questions/multiply-strings.yaml
index fc75a29..7d40f43 100644
--- a/backend/data/questions/multiply-strings.yaml
+++ b/backend/data/questions/multiply-strings.yaml
@@ -9,6 +9,26 @@ categories:
patterns:
- two-pointers
+function_signature: "def multiply(num1: str, num2: str) -> str:"
+
+test_cases:
+ visible:
+ - input: { num1: "2", num2: "3" }
+ expected: "6"
+ - input: { num1: "123", num2: "456" }
+ expected: "56088"
+ hidden:
+ - input: { num1: "0", num2: "0" }
+ expected: "0"
+ - input: { num1: "999", num2: "0" }
+ expected: "0"
+ - input: { num1: "1", num2: "1" }
+ expected: "1"
+ - input: { num1: "99", num2: "99" }
+ expected: "9801"
+ - input: { num1: "12345", num2: "6789" }
+ expected: "83810205"
+
description: |
Given two non-negative integers `num1` and `num2` represented as strings, return the product of `num1` and `num2`, also represented as a string.
diff --git a/backend/data/questions/number-of-islands.yaml b/backend/data/questions/number-of-islands.yaml
index abca9e2..a1ef022 100644
--- a/backend/data/questions/number-of-islands.yaml
+++ b/backend/data/questions/number-of-islands.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: 3
- input: { grid: [["1", "1"], ["1", "1"]] }
expected: 1
+ - input: { grid: [["1"], ["0"], ["1"], ["0"], ["1"]] }
+ expected: 3
+ - input: { grid: [["0", "0", "0"], ["0", "0", "0"], ["0", "0", "0"]] }
+ expected: 0
+ - input: { grid: [["1", "0", "1"], ["0", "1", "0"], ["1", "0", "1"]] }
+ expected: 5
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/online-stock-span.yaml b/backend/data/questions/online-stock-span.yaml
index f06548b..6b3dfaa 100644
--- a/backend/data/questions/online-stock-span.yaml
+++ b/backend/data/questions/online-stock-span.yaml
@@ -8,6 +8,32 @@ categories:
patterns:
- monotonic-stack
+function_signature: "class StockSpanner"
+
+test_cases:
+ visible:
+ - input:
+ operations: ["StockSpanner", "next", "next", "next", "next", "next", "next", "next"]
+ args: [[], [100], [80], [60], [70], [60], [75], [85]]
+ expected: [null, 1, 1, 1, 2, 1, 4, 6]
+ hidden:
+ - input:
+ operations: ["StockSpanner", "next", "next", "next"]
+ args: [[], [100], [100], [100]]
+ expected: [null, 1, 2, 3]
+ - input:
+ operations: ["StockSpanner", "next", "next", "next", "next"]
+ args: [[], [31], [41], [48], [59]]
+ expected: [null, 1, 2, 3, 4]
+ - input:
+ operations: ["StockSpanner", "next", "next", "next", "next"]
+ args: [[], [100], [90], [80], [70]]
+ expected: [null, 1, 1, 1, 1]
+ - input:
+ operations: ["StockSpanner", "next", "next", "next", "next", "next"]
+ args: [[], [28], [14], [28], [35], [46]]
+ expected: [null, 1, 1, 3, 4, 5]
+
description: |
Design an algorithm that collects daily price quotes for some stock and returns **the span** of that stock's price for the current day.
diff --git a/backend/data/questions/open-the-lock.yaml b/backend/data/questions/open-the-lock.yaml
index 8e59698..217f379 100644
--- a/backend/data/questions/open-the-lock.yaml
+++ b/backend/data/questions/open-the-lock.yaml
@@ -10,6 +10,28 @@ categories:
patterns:
- bfs
+function_signature: "def open_lock(deadends: list[str], target: str) -> int:"
+
+test_cases:
+ visible:
+ - input: { deadends: ["0201", "0101", "0102", "1212", "2002"], target: "0202" }
+ expected: 6
+ - input: { deadends: ["8888"], target: "0009" }
+ expected: 1
+ - input: { deadends: ["8887", "8889", "8878", "8898", "8788", "8988", "7888", "9888"], target: "8888" }
+ expected: -1
+ hidden:
+ - input: { deadends: ["0000"], target: "1111" }
+ expected: -1
+ - input: { deadends: [], target: "0000" }
+ expected: 0
+ - input: { deadends: [], target: "1111" }
+ expected: 4
+ - input: { deadends: ["1111"], target: "1112" }
+ expected: 5
+ - input: { deadends: ["0001", "0010", "0100", "1000"], target: "9999" }
+ expected: 4
+
description: |
You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: `'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'`. The wheels can rotate freely and wrap around: for example we can turn `'9'` to be `'0'`, or `'0'` to be `'9'`. Each move consists of turning **one wheel one slot**.
diff --git a/backend/data/questions/pacific-atlantic-water-flow.yaml b/backend/data/questions/pacific-atlantic-water-flow.yaml
index 2fa214d..28be447 100644
--- a/backend/data/questions/pacific-atlantic-water-flow.yaml
+++ b/backend/data/questions/pacific-atlantic-water-flow.yaml
@@ -23,6 +23,14 @@ test_cases:
expected: [[0, 0], [0, 1], [1, 0], [1, 1]]
- input: { heights: [[1, 2], [4, 3]] }
expected: [[0, 1], [1, 0], [1, 1]]
+ - input: { heights: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] }
+ expected: [[0, 2], [1, 2], [2, 0], [2, 1], [2, 2]]
+ - input: { heights: [[10, 10, 10], [10, 1, 10], [10, 10, 10]] }
+ expected: [[0, 0], [0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1], [2, 2]]
+ - input: { heights: [[3, 3, 3, 3, 3]] }
+ expected: [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4]]
+ - input: { heights: [[3], [3], [3], [3], [3]] }
+ expected: [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0]]
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/palindromic-substrings.yaml b/backend/data/questions/palindromic-substrings.yaml
index 3f38598..a7231ca 100644
--- a/backend/data/questions/palindromic-substrings.yaml
+++ b/backend/data/questions/palindromic-substrings.yaml
@@ -10,6 +10,26 @@ patterns:
- two-pointers
- dynamic-programming
+function_signature: "def count_substrings(s: str) -> int:"
+
+test_cases:
+ visible:
+ - input: { s: "abc" }
+ expected: 3
+ - input: { s: "aaa" }
+ expected: 6
+ hidden:
+ - input: { s: "a" }
+ expected: 1
+ - input: { s: "aa" }
+ expected: 3
+ - input: { s: "ab" }
+ expected: 2
+ - input: { s: "aba" }
+ expected: 4
+ - input: { s: "abba" }
+ expected: 6
+
description: |
Given a string `s`, return *the number of **palindromic substrings** in it*.
diff --git a/backend/data/questions/partition-equal-subset-sum.yaml b/backend/data/questions/partition-equal-subset-sum.yaml
index 2fc14b4..a2d9bbd 100644
--- a/backend/data/questions/partition-equal-subset-sum.yaml
+++ b/backend/data/questions/partition-equal-subset-sum.yaml
@@ -26,6 +26,12 @@ test_cases:
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
+ - input: { nums: [3, 3, 3, 4, 5] }
+ expected: true
+ - input: { nums: [1] }
+ expected: false
+ - input: { nums: [1, 2, 3, 4, 5, 6, 7] }
+ expected: true
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-to-k-equal-sum-subsets.yaml b/backend/data/questions/partition-to-k-equal-sum-subsets.yaml
index 551ab7b..d071419 100644
--- a/backend/data/questions/partition-to-k-equal-sum-subsets.yaml
+++ b/backend/data/questions/partition-to-k-equal-sum-subsets.yaml
@@ -10,6 +10,26 @@ categories:
patterns:
- backtracking
+function_signature: "def can_partition_k_subsets(nums: list[int], k: int) -> bool:"
+
+test_cases:
+ visible:
+ - input: { nums: [4, 3, 2, 3, 5, 2, 1], k: 4 }
+ expected: true
+ - input: { nums: [1, 2, 3, 4], k: 3 }
+ expected: false
+ hidden:
+ - input: { nums: [1], k: 1 }
+ expected: true
+ - input: { nums: [1, 1, 1, 1], k: 4 }
+ expected: true
+ - input: { nums: [1, 1, 1, 1], k: 2 }
+ expected: true
+ - input: { nums: [2, 2, 2, 2, 3, 4, 5], k: 4 }
+ expected: false
+ - input: { nums: [10, 10, 10, 7, 7, 7, 7, 7, 7, 6, 6, 6], k: 3 }
+ expected: true
+
description: |
Given an integer array `nums` and an integer `k`, return `true` if it is possible to divide this array into `k` non-empty subsets whose sums are all equal.
diff --git a/backend/data/questions/path-with-minimum-effort.yaml b/backend/data/questions/path-with-minimum-effort.yaml
index 815e18f..ac5be8e 100644
--- a/backend/data/questions/path-with-minimum-effort.yaml
+++ b/backend/data/questions/path-with-minimum-effort.yaml
@@ -14,6 +14,26 @@ patterns:
- heap
- matrix-traversal
+function_signature: "def minimum_effort_path(heights: list[list[int]]) -> int:"
+
+test_cases:
+ visible:
+ - input: { heights: [[1, 2, 2], [3, 8, 2], [5, 3, 5]] }
+ expected: 2
+ - input: { heights: [[1, 2, 3], [3, 8, 4], [5, 3, 5]] }
+ expected: 1
+ - input: { heights: [[1, 2, 1, 1, 1], [1, 2, 1, 2, 1], [1, 2, 1, 2, 1], [1, 2, 1, 2, 1], [1, 1, 1, 2, 1]] }
+ expected: 0
+ hidden:
+ - input: { heights: [[1]] }
+ expected: 0
+ - input: { heights: [[1, 2]] }
+ expected: 1
+ - input: { heights: [[1], [2]] }
+ expected: 1
+ - input: { heights: [[1, 10, 6, 7, 9, 10, 4, 9]] }
+ expected: 9
+
description: |
You are a hiker preparing for an upcoming hike. You are given `heights`, a 2D array of size `rows x columns`, where `heights[row][col]` represents the height of cell `(row, col)`. You are situated in the top-left cell, `(0, 0)`, and you hope to travel to the bottom-right cell, `(rows-1, columns-1)` (i.e., **0-indexed**). You can move **up**, **down**, **left**, or **right**, and you wish to find a route that requires the minimum **effort**.
diff --git a/backend/data/questions/permutations-ii.yaml b/backend/data/questions/permutations-ii.yaml
index 1754cf9..067206e 100644
--- a/backend/data/questions/permutations-ii.yaml
+++ b/backend/data/questions/permutations-ii.yaml
@@ -10,6 +10,26 @@ categories:
patterns:
- backtracking
+function_signature: "def permute_unique(nums: list[int]) -> list[list[int]]:"
+
+test_cases:
+ visible:
+ - input: { nums: [1, 1, 2] }
+ expected: [[1, 1, 2], [1, 2, 1], [2, 1, 1]]
+ - input: { nums: [1, 2, 3] }
+ expected: [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
+ hidden:
+ - input: { nums: [1] }
+ expected: [[1]]
+ - input: { nums: [1, 1] }
+ expected: [[1, 1]]
+ - input: { nums: [1, 2] }
+ expected: [[1, 2], [2, 1]]
+ - input: { nums: [1, 1, 1] }
+ expected: [[1, 1, 1]]
+ - input: { nums: [0, 1, 0, 0, 9] }
+ expected: [[0, 0, 0, 1, 9], [0, 0, 0, 9, 1], [0, 0, 1, 0, 9], [0, 0, 1, 9, 0], [0, 0, 9, 0, 1], [0, 0, 9, 1, 0], [0, 1, 0, 0, 9], [0, 1, 0, 9, 0], [0, 1, 9, 0, 0], [0, 9, 0, 0, 1], [0, 9, 0, 1, 0], [0, 9, 1, 0, 0], [1, 0, 0, 0, 9], [1, 0, 0, 9, 0], [1, 0, 9, 0, 0], [1, 9, 0, 0, 0], [9, 0, 0, 0, 1], [9, 0, 0, 1, 0], [9, 0, 1, 0, 0], [9, 1, 0, 0, 0]]
+
description: |
Given a collection of numbers, `nums`, that might contain duplicates, return *all possible unique permutations **in any order***.
diff --git a/backend/data/questions/permutations.yaml b/backend/data/questions/permutations.yaml
index 0501d3e..a07ff12 100644
--- a/backend/data/questions/permutations.yaml
+++ b/backend/data/questions/permutations.yaml
@@ -28,6 +28,10 @@ test_cases:
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]]
+ - input: { nums: [9, 8] }
+ expected: [[9, 8], [8, 9]]
+ - input: { nums: [100] }
+ expected: [[100]]
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/powx-n.yaml b/backend/data/questions/powx-n.yaml
index fa6b416..0296524 100644
--- a/backend/data/questions/powx-n.yaml
+++ b/backend/data/questions/powx-n.yaml
@@ -9,6 +9,28 @@ categories:
patterns:
- binary-search
+function_signature: "def my_pow(x: float, n: int) -> float:"
+
+test_cases:
+ visible:
+ - input: { x: 2.0, n: 10 }
+ expected: 1024.0
+ - input: { x: 2.1, n: 3 }
+ expected: 9.261
+ - input: { x: 2.0, n: -2 }
+ expected: 0.25
+ hidden:
+ - input: { x: 1.0, n: 0 }
+ expected: 1.0
+ - input: { x: 5.0, n: 0 }
+ expected: 1.0
+ - input: { x: 2.0, n: 1 }
+ expected: 2.0
+ - input: { x: 2.0, n: -1 }
+ expected: 0.5
+ - input: { x: 0.5, n: 2 }
+ expected: 0.25
+
description: |
Implement `pow(x, n)`, which calculates `x` raised to the power `n` (i.e., xn).
diff --git a/backend/data/questions/product-of-array-except-self.yaml b/backend/data/questions/product-of-array-except-self.yaml
index 1b19194..34a586b 100644
--- a/backend/data/questions/product-of-array-except-self.yaml
+++ b/backend/data/questions/product-of-array-except-self.yaml
@@ -25,6 +25,12 @@ test_cases:
expected: [0, 0]
- input: { nums: [5, -2, 4] }
expected: [-8, 20, -10]
+ - input: { nums: [1, 2, 3, 4, 5] }
+ expected: [120, 60, 40, 30, 24]
+ - input: { nums: [0, 1, 2, 3] }
+ expected: [6, 0, 0, 0]
+ - input: { nums: [-1, -1, -1] }
+ expected: [1, 1, 1]
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/regular-expression-matching.yaml b/backend/data/questions/regular-expression-matching.yaml
index 228d5fe..94001c1 100644
--- a/backend/data/questions/regular-expression-matching.yaml
+++ b/backend/data/questions/regular-expression-matching.yaml
@@ -10,6 +10,28 @@ categories:
patterns:
- dynamic-programming
+function_signature: "def is_match(s: str, p: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { s: "aa", p: "a" }
+ expected: false
+ - input: { s: "aa", p: "a*" }
+ expected: true
+ - input: { s: "ab", p: ".*" }
+ expected: true
+ hidden:
+ - input: { s: "a", p: "a" }
+ expected: true
+ - input: { s: "a", p: "." }
+ expected: true
+ - input: { s: "", p: "a*" }
+ expected: true
+ - input: { s: "aab", p: "c*a*b" }
+ expected: true
+ - input: { s: "mississippi", p: "mis*is*p*." }
+ expected: false
+
description: |
Given an input string `s` and a pattern `p`, implement regular expression matching with support for `'.'` and `'*'` where:
diff --git a/backend/data/questions/remove-nth-node-from-end-of-list.yaml b/backend/data/questions/remove-nth-node-from-end-of-list.yaml
index 73aea55..87abcc8 100644
--- a/backend/data/questions/remove-nth-node-from-end-of-list.yaml
+++ b/backend/data/questions/remove-nth-node-from-end-of-list.yaml
@@ -10,6 +10,26 @@ patterns:
- two-pointers
- fast-slow-pointers
+function_signature: "def remove_nth_from_end(head: ListNode, n: int) -> ListNode:"
+
+test_cases:
+ visible:
+ - input: { head: [1, 2, 3, 4, 5], n: 2 }
+ expected: [1, 2, 3, 5]
+ - input: { head: [1], n: 1 }
+ expected: []
+ - input: { head: [1, 2], n: 1 }
+ expected: [1]
+ hidden:
+ - input: { head: [1, 2], n: 2 }
+ expected: [2]
+ - input: { head: [1, 2, 3], n: 3 }
+ expected: [2, 3]
+ - input: { head: [1, 2, 3, 4, 5], n: 5 }
+ expected: [2, 3, 4, 5]
+ - input: { head: [1, 2, 3, 4, 5], n: 1 }
+ expected: [1, 2, 3, 4]
+
description: |
Given the `head` of a linked list, remove the `n`th node from the end of the list and return its head.
diff --git a/backend/data/questions/reorganize-string.yaml b/backend/data/questions/reorganize-string.yaml
index 990efe9..e7abbca 100644
--- a/backend/data/questions/reorganize-string.yaml
+++ b/backend/data/questions/reorganize-string.yaml
@@ -11,6 +11,26 @@ patterns:
- greedy
- heap
+function_signature: "def reorganize_string(s: str) -> str:"
+
+test_cases:
+ visible:
+ - input: { s: "aab" }
+ expected: "aba"
+ - input: { s: "aaab" }
+ expected: ""
+ hidden:
+ - input: { s: "a" }
+ expected: "a"
+ - input: { s: "aa" }
+ expected: ""
+ - input: { s: "ab" }
+ expected: "ab"
+ - input: { s: "aabb" }
+ expected: "abab"
+ - input: { s: "aaabb" }
+ expected: "ababa"
+
description: |
Given a string `s`, rearrange the characters of `s` so that any two adjacent characters are not the same.
diff --git a/backend/data/questions/reverse-linked-list-ii.yaml b/backend/data/questions/reverse-linked-list-ii.yaml
index 1d70678..fdcd9fb 100644
--- a/backend/data/questions/reverse-linked-list-ii.yaml
+++ b/backend/data/questions/reverse-linked-list-ii.yaml
@@ -8,6 +8,26 @@ categories:
patterns:
- linkedlist-reversal
+function_signature: "def reverse_between(head: ListNode, left: int, right: int) -> ListNode:"
+
+test_cases:
+ visible:
+ - input: { head: [1, 2, 3, 4, 5], left: 2, right: 4 }
+ expected: [1, 4, 3, 2, 5]
+ - input: { head: [5], left: 1, right: 1 }
+ expected: [5]
+ hidden:
+ - input: { head: [1, 2, 3], left: 1, right: 3 }
+ expected: [3, 2, 1]
+ - input: { head: [1, 2, 3], left: 1, right: 2 }
+ expected: [2, 1, 3]
+ - input: { head: [1, 2, 3], left: 2, right: 3 }
+ expected: [1, 3, 2]
+ - input: { head: [1, 2], left: 1, right: 2 }
+ expected: [2, 1]
+ - input: { head: [1, 2, 3, 4, 5], left: 1, right: 5 }
+ expected: [5, 4, 3, 2, 1]
+
description: |
Given the `head` of a singly linked list and two integers `left` and `right` where `left <= right`, reverse the nodes of the list from position `left` to position `right`, and return *the reversed list*.
diff --git a/backend/data/questions/reverse-linked-list.yaml b/backend/data/questions/reverse-linked-list.yaml
index cb41cc6..efcac97 100644
--- a/backend/data/questions/reverse-linked-list.yaml
+++ b/backend/data/questions/reverse-linked-list.yaml
@@ -24,6 +24,16 @@ test_cases:
expected: [1]
- input: { head: [1, 2, 3] }
expected: [3, 2, 1]
+ - input: { head: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
+ expected: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
+ - input: { head: [-5, 0, 5] }
+ expected: [5, 0, -5]
+ - input: { head: [1, 1, 1, 1] }
+ expected: [1, 1, 1, 1]
+ - input: { head: [100, -100] }
+ expected: [-100, 100]
+ - input: { head: [7] }
+ expected: [7]
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 3684abf..ab552c0 100644
--- a/backend/data/questions/rotate-array.yaml
+++ b/backend/data/questions/rotate-array.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: [1]
- input: { nums: [1, 2, 3, 4, 5], k: 5 }
expected: [1, 2, 3, 4, 5]
+ - input: { nums: [1, 2, 3, 4, 5, 6], k: 2 }
+ expected: [5, 6, 1, 2, 3, 4]
+ - input: { nums: [1, 2], k: 3 }
+ expected: [2, 1]
+ - input: { nums: [1], k: 1 }
+ expected: [1]
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/rotting-oranges.yaml b/backend/data/questions/rotting-oranges.yaml
index 6eb2a5b..ea08c3c 100644
--- a/backend/data/questions/rotting-oranges.yaml
+++ b/backend/data/questions/rotting-oranges.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: -1
- input: { grid: [[2, 1, 1], [1, 1, 1], [1, 1, 2]] }
expected: 2
+ - input: { grid: [[2]] }
+ expected: 0
+ - input: { grid: [[1, 2]] }
+ expected: 1
+ - input: { grid: [[2, 1, 1, 1, 1]] }
+ expected: 4
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 5ba5bd4..e57d935 100644
--- a/backend/data/questions/same-tree.yaml
+++ b/backend/data/questions/same-tree.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: false
- input: { p: [1, 2, 3, 4, 5], q: [1, 2, 3, 4, 5] }
expected: true
+ - input: { p: [1], q: [1] }
+ expected: true
+ - input: { p: [1], q: [2] }
+ expected: false
+ - input: { p: [1, 2, 3], q: [1, 2, null] }
+ expected: false
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-a-2d-matrix.yaml b/backend/data/questions/search-a-2d-matrix.yaml
index 97a507f..f525f34 100644
--- a/backend/data/questions/search-a-2d-matrix.yaml
+++ b/backend/data/questions/search-a-2d-matrix.yaml
@@ -10,6 +10,26 @@ patterns:
- binary-search
- matrix-traversal
+function_signature: "def search_matrix(matrix: list[list[int]], target: int) -> bool:"
+
+test_cases:
+ visible:
+ - input: { matrix: [[1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 60]], target: 3 }
+ expected: true
+ - input: { matrix: [[1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 60]], target: 13 }
+ expected: false
+ hidden:
+ - input: { matrix: [[1]], target: 1 }
+ expected: true
+ - input: { matrix: [[1]], target: 0 }
+ expected: false
+ - input: { matrix: [[1, 2, 3]], target: 2 }
+ expected: true
+ - input: { matrix: [[1], [2], [3]], target: 3 }
+ expected: true
+ - input: { matrix: [[1, 2], [3, 4]], target: 5 }
+ expected: false
+
description: |
You are given an `m x n` integer matrix `matrix` with the following two properties:
diff --git a/backend/data/questions/search-in-rotated-sorted-array-ii.yaml b/backend/data/questions/search-in-rotated-sorted-array-ii.yaml
index 01995b6..d705021 100644
--- a/backend/data/questions/search-in-rotated-sorted-array-ii.yaml
+++ b/backend/data/questions/search-in-rotated-sorted-array-ii.yaml
@@ -9,6 +9,26 @@ categories:
patterns:
- binary-search
+function_signature: "def search(nums: list[int], target: int) -> bool:"
+
+test_cases:
+ visible:
+ - input: { nums: [2, 5, 6, 0, 0, 1, 2], target: 0 }
+ expected: true
+ - input: { nums: [2, 5, 6, 0, 0, 1, 2], target: 3 }
+ expected: false
+ hidden:
+ - input: { nums: [1], target: 1 }
+ expected: true
+ - input: { nums: [1], target: 0 }
+ expected: false
+ - input: { nums: [1, 1, 1, 1, 1], target: 1 }
+ expected: true
+ - input: { nums: [1, 0, 1, 1, 1], target: 0 }
+ expected: true
+ - input: { nums: [1, 3, 1, 1, 1], target: 3 }
+ expected: true
+
description: |
There is an integer array `nums` sorted in non-decreasing order (not necessarily with **distinct** values).
diff --git a/backend/data/questions/search-in-rotated-sorted-array.yaml b/backend/data/questions/search-in-rotated-sorted-array.yaml
index 8a610aa..f36db71 100644
--- a/backend/data/questions/search-in-rotated-sorted-array.yaml
+++ b/backend/data/questions/search-in-rotated-sorted-array.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: 0
- input: { nums: [1, 2, 3, 4, 5], target: 3 }
expected: 2
+ - input: { nums: [6, 7, 8, 1, 2, 3, 4, 5], target: 8 }
+ expected: 2
+ - input: { nums: [3, 4, 5, 6, 7, 8, 1, 2], target: 2 }
+ expected: 7
+ - input: { nums: [2, 3, 4, 5, 6, 7, 8, 1], target: 6 }
+ expected: 4
description: |
There is an integer array `nums` sorted in ascending order (with **distinct** values).
diff --git a/backend/data/questions/serialize-and-deserialize-binary-tree.yaml b/backend/data/questions/serialize-and-deserialize-binary-tree.yaml
index 58e6110..293788d 100644
--- a/backend/data/questions/serialize-and-deserialize-binary-tree.yaml
+++ b/backend/data/questions/serialize-and-deserialize-binary-tree.yaml
@@ -11,6 +11,24 @@ patterns:
- dfs
- tree-traversal
+function_signature: "class Codec"
+
+test_cases:
+ visible:
+ - input: { root: [1, 2, 3, null, null, 4, 5] }
+ expected: [1, 2, 3, null, null, 4, 5]
+ - input: { root: [] }
+ expected: []
+ hidden:
+ - input: { root: [1] }
+ expected: [1]
+ - input: { root: [1, 2] }
+ expected: [1, 2]
+ - input: { root: [1, null, 2] }
+ expected: [1, null, 2]
+ - input: { root: [1, 2, 3, 4, 5, 6, 7] }
+ expected: [1, 2, 3, 4, 5, 6, 7]
+
description: |
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.
diff --git a/backend/data/questions/simplify-path.yaml b/backend/data/questions/simplify-path.yaml
index f349754..323460a 100644
--- a/backend/data/questions/simplify-path.yaml
+++ b/backend/data/questions/simplify-path.yaml
@@ -9,6 +9,30 @@ categories:
patterns:
- monotonic-stack
+function_signature: "def simplify_path(path: str) -> str:"
+
+test_cases:
+ visible:
+ - input: { path: "/home/" }
+ expected: "/home"
+ - input: { path: "/home//foo/" }
+ expected: "/home/foo"
+ - input: { path: "/home/user/Documents/../Pictures" }
+ expected: "/home/user/Pictures"
+ hidden:
+ - input: { path: "/../" }
+ expected: "/"
+ - input: { path: "/.../a/../b/c/../d/./" }
+ expected: "/.../b/d"
+ - input: { path: "/a/./b/../../c/" }
+ expected: "/c"
+ - input: { path: "/" }
+ expected: "/"
+ - input: { path: "/a//b////c/d//././/.." }
+ expected: "/a/b/c"
+ - input: { path: "/..hidden" }
+ expected: "/..hidden"
+
description: |
You are given an *absolute* path for a Unix-style file system, which always begins with a slash `'/'`. Your task is to transform this absolute path into its **simplified canonical path**.
diff --git a/backend/data/questions/single-number.yaml b/backend/data/questions/single-number.yaml
index 90b31e9..3650ff4 100644
--- a/backend/data/questions/single-number.yaml
+++ b/backend/data/questions/single-number.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: -2
- input: { nums: [0, 1, 0] }
expected: 1
+ - input: { nums: [1, 2, 3, 2, 1] }
+ expected: 3
+ - input: { nums: [7, 7, 8, 8, 9] }
+ expected: 9
+ - input: { nums: [100] }
+ expected: 100
description: |
Given a **non-empty** array of integers `nums`, every element appears *twice* except for one. Find that single one.
diff --git a/backend/data/questions/sort-an-array.yaml b/backend/data/questions/sort-an-array.yaml
index bf2fb42..c3afe41 100644
--- a/backend/data/questions/sort-an-array.yaml
+++ b/backend/data/questions/sort-an-array.yaml
@@ -10,6 +10,28 @@ categories:
patterns:
- dynamic-programming
+function_signature: "def sort_array(nums: list[int]) -> list[int]:"
+
+test_cases:
+ visible:
+ - input: { nums: [5, 2, 3, 1] }
+ expected: [1, 2, 3, 5]
+ - input: { nums: [5, 1, 1, 2, 0, 0] }
+ expected: [0, 0, 1, 1, 2, 5]
+ hidden:
+ - input: { nums: [1] }
+ expected: [1]
+ - input: { nums: [2, 1] }
+ expected: [1, 2]
+ - input: { nums: [1, 2, 3, 4, 5] }
+ expected: [1, 2, 3, 4, 5]
+ - input: { nums: [5, 4, 3, 2, 1] }
+ expected: [1, 2, 3, 4, 5]
+ - input: { nums: [-1, 0, 1, -5, 3] }
+ expected: [-5, -1, 0, 1, 3]
+ - input: { nums: [3, 3, 3, 3] }
+ expected: [3, 3, 3, 3]
+
description: |
Given an array of integers `nums`, sort the array in ascending order and return it.
diff --git a/backend/data/questions/spiral-matrix-ii.yaml b/backend/data/questions/spiral-matrix-ii.yaml
index daa1100..d273347 100644
--- a/backend/data/questions/spiral-matrix-ii.yaml
+++ b/backend/data/questions/spiral-matrix-ii.yaml
@@ -8,6 +8,22 @@ categories:
patterns:
- matrix-traversal
+function_signature: "def generate_matrix(n: int) -> list[list[int]]:"
+
+test_cases:
+ visible:
+ - input: { n: 3 }
+ expected: [[1, 2, 3], [8, 9, 4], [7, 6, 5]]
+ - input: { n: 1 }
+ expected: [[1]]
+ hidden:
+ - input: { n: 2 }
+ expected: [[1, 2], [4, 3]]
+ - input: { n: 4 }
+ expected: [[1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7]]
+ - input: { n: 5 }
+ expected: [[1, 2, 3, 4, 5], [16, 17, 18, 19, 6], [15, 24, 25, 20, 7], [14, 23, 22, 21, 8], [13, 12, 11, 10, 9]]
+
description: |
Given a positive integer `n`, generate an `n x n` matrix filled with elements from `1` to `n^2` in spiral order.
diff --git a/backend/data/questions/split-array-largest-sum.yaml b/backend/data/questions/split-array-largest-sum.yaml
index 977f422..b59e13c 100644
--- a/backend/data/questions/split-array-largest-sum.yaml
+++ b/backend/data/questions/split-array-largest-sum.yaml
@@ -11,6 +11,26 @@ patterns:
- binary-search
- greedy
+function_signature: "def split_array(nums: list[int], k: int) -> int:"
+
+test_cases:
+ visible:
+ - input: { nums: [7, 2, 5, 10, 8], k: 2 }
+ expected: 18
+ - input: { nums: [1, 2, 3, 4, 5], k: 2 }
+ expected: 9
+ hidden:
+ - input: { nums: [1, 4, 4], k: 3 }
+ expected: 4
+ - input: { nums: [10, 5, 13, 4, 8, 4, 5, 11, 14, 9, 16, 10, 20, 8], k: 8 }
+ expected: 25
+ - input: { nums: [1, 2, 3, 4, 5], k: 1 }
+ expected: 15
+ - input: { nums: [1, 2, 3, 4, 5], k: 5 }
+ expected: 5
+ - input: { nums: [2, 3, 1, 2, 4, 3], k: 5 }
+ expected: 4
+
description: |
Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is **minimized**.
diff --git a/backend/data/questions/stone-game-ii.yaml b/backend/data/questions/stone-game-ii.yaml
index b325056..d550d88 100644
--- a/backend/data/questions/stone-game-ii.yaml
+++ b/backend/data/questions/stone-game-ii.yaml
@@ -10,6 +10,26 @@ patterns:
- dynamic-programming
- prefix-sum
+function_signature: "def stone_game_ii(piles: list[int]) -> int:"
+
+test_cases:
+ visible:
+ - input: { piles: [2, 7, 9, 4, 4] }
+ expected: 10
+ - input: { piles: [1, 2, 3, 4, 5, 100] }
+ expected: 104
+ hidden:
+ - input: { piles: [1] }
+ expected: 1
+ - input: { piles: [1, 2] }
+ expected: 3
+ - input: { piles: [1, 2, 3] }
+ expected: 6
+ - input: { piles: [3, 9, 1, 2] }
+ expected: 12
+ - input: { piles: [8, 9, 5, 4, 5, 4, 1, 1, 9, 3, 1, 10] }
+ expected: 36
+
description: |
Alice and Bob continue their games with piles of stones. There are a number of piles **arranged in a row**, and each pile has a positive integer number of stones `piles[i]`. The objective of the game is to end with the most stones.
diff --git a/backend/data/questions/stone-game-iii.yaml b/backend/data/questions/stone-game-iii.yaml
index 515ef9e..1933025 100644
--- a/backend/data/questions/stone-game-iii.yaml
+++ b/backend/data/questions/stone-game-iii.yaml
@@ -9,6 +9,28 @@ categories:
patterns:
- dynamic-programming
+function_signature: "def stone_game_iii(stone_value: list[int]) -> str:"
+
+test_cases:
+ visible:
+ - input: { stone_value: [1, 2, 3, 7] }
+ expected: "Bob"
+ - input: { stone_value: [1, 2, 3, -9] }
+ expected: "Alice"
+ - input: { stone_value: [1, 2, 3, 6] }
+ expected: "Tie"
+ hidden:
+ - input: { stone_value: [1] }
+ expected: "Alice"
+ - input: { stone_value: [-1, -2, -3] }
+ expected: "Tie"
+ - input: { stone_value: [1, 2, 3, -1, -2, -3, 7] }
+ expected: "Alice"
+ - input: { stone_value: [-1] }
+ expected: "Bob"
+ - input: { stone_value: [5, -2, -3, 4] }
+ expected: "Alice"
+
description: |
Alice and Bob continue their games with piles of stones. There are several stones **arranged in a row**, and each stone has an associated value which is an integer given in the array `stoneValue`.
diff --git a/backend/data/questions/stone-game.yaml b/backend/data/questions/stone-game.yaml
index 799bb58..77c5d93 100644
--- a/backend/data/questions/stone-game.yaml
+++ b/backend/data/questions/stone-game.yaml
@@ -10,6 +10,24 @@ categories:
patterns:
- dynamic-programming
+function_signature: "def stone_game(piles: list[int]) -> bool:"
+
+test_cases:
+ visible:
+ - input: { piles: [5, 3, 4, 5] }
+ expected: true
+ - input: { piles: [3, 7, 2, 3] }
+ expected: true
+ hidden:
+ - input: { piles: [1, 2] }
+ expected: true
+ - input: { piles: [1, 100, 1, 100] }
+ expected: true
+ - input: { piles: [7, 8, 8, 10] }
+ expected: true
+ - input: { piles: [3, 2, 10, 4] }
+ expected: true
+
description: |
Alice and Bob play a game with piles of stones. There are an **even** number of piles arranged in a row, and each pile has a **positive** integer number of stones `piles[i]`.
diff --git a/backend/data/questions/subarray-product-less-than-k.yaml b/backend/data/questions/subarray-product-less-than-k.yaml
index 7577bd9..91f07e2 100644
--- a/backend/data/questions/subarray-product-less-than-k.yaml
+++ b/backend/data/questions/subarray-product-less-than-k.yaml
@@ -9,6 +9,28 @@ categories:
patterns:
- sliding-window
+function_signature: "def num_subarray_product_less_than_k(nums: list[int], k: int) -> int:"
+
+test_cases:
+ visible:
+ - input: { nums: [10, 5, 2, 6], k: 100 }
+ expected: 8
+ - input: { nums: [1, 2, 3], k: 0 }
+ expected: 0
+ hidden:
+ - input: { nums: [1, 1, 1], k: 2 }
+ expected: 6
+ - input: { nums: [10, 9, 10, 4, 3, 8, 3, 3, 6, 2, 10, 10, 9, 3], k: 19 }
+ expected: 18
+ - input: { nums: [1, 2, 3, 4, 5], k: 1 }
+ expected: 0
+ - input: { nums: [100], k: 101 }
+ expected: 1
+ - input: { nums: [100], k: 100 }
+ expected: 0
+ - input: { nums: [1, 1, 1, 1, 1], k: 2 }
+ expected: 15
+
description: |
Given an array of integers `nums` and an integer `k`, return *the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than* `k`.
diff --git a/backend/data/questions/subarray-sum-equals-k.yaml b/backend/data/questions/subarray-sum-equals-k.yaml
index e98f1ab..87d53e4 100644
--- a/backend/data/questions/subarray-sum-equals-k.yaml
+++ b/backend/data/questions/subarray-sum-equals-k.yaml
@@ -26,6 +26,12 @@ test_cases:
expected: 1
- input: { nums: [1, -1, 0], k: 0 }
expected: 3
+ - input: { nums: [3, 4, 7, 2, -3, 1, 4, 2], k: 7 }
+ expected: 4
+ - input: { nums: [0, 0, 0, 0], k: 0 }
+ expected: 10
+ - input: { nums: [1, 2, 3], k: 6 }
+ expected: 1
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/subtree-of-another-tree.yaml b/backend/data/questions/subtree-of-another-tree.yaml
index 16a8959..01ab7a0 100644
--- a/backend/data/questions/subtree-of-another-tree.yaml
+++ b/backend/data/questions/subtree-of-another-tree.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: true
- input: { root: [1, 2, 3], sub_root: [3, 1] }
expected: false
+ - input: { root: [3, 4, 5, 1, null, 2], sub_root: [3, 1, 2] }
+ expected: false
+ - input: { root: [1, 2, 3, 4, 5], sub_root: [2, 4, 5] }
+ expected: true
+ - input: { root: [1], sub_root: [0] }
+ 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/sum-of-two-integers.yaml b/backend/data/questions/sum-of-two-integers.yaml
index 8112e4e..40e5122 100644
--- a/backend/data/questions/sum-of-two-integers.yaml
+++ b/backend/data/questions/sum-of-two-integers.yaml
@@ -8,6 +8,28 @@ categories:
patterns:
- greedy
+function_signature: "def get_sum(a: int, b: int) -> int:"
+
+test_cases:
+ visible:
+ - input: { a: 1, b: 2 }
+ expected: 3
+ - input: { a: 2, b: 3 }
+ expected: 5
+ hidden:
+ - input: { a: -1, b: 1 }
+ expected: 0
+ - input: { a: 0, b: 0 }
+ expected: 0
+ - input: { a: -12, b: -8 }
+ expected: -20
+ - input: { a: 100, b: -100 }
+ expected: 0
+ - input: { a: 1000, b: -1 }
+ expected: 999
+ - input: { a: -1000, b: 1000 }
+ expected: 0
+
description: |
Given two integers `a` and `b`, return *the sum of the two integers without using the operators* `+` *and* `-`.
diff --git a/backend/data/questions/surrounded-regions.yaml b/backend/data/questions/surrounded-regions.yaml
index c89c845..c3c4427 100644
--- a/backend/data/questions/surrounded-regions.yaml
+++ b/backend/data/questions/surrounded-regions.yaml
@@ -11,6 +11,59 @@ patterns:
- bfs
- matrix-traversal
+function_signature: "def solve(board: list[list[str]]) -> None:"
+
+test_cases:
+ visible:
+ - input:
+ board:
+ - ["X", "X", "X", "X"]
+ - ["X", "O", "O", "X"]
+ - ["X", "X", "O", "X"]
+ - ["X", "O", "X", "X"]
+ expected:
+ - ["X", "X", "X", "X"]
+ - ["X", "X", "X", "X"]
+ - ["X", "X", "X", "X"]
+ - ["X", "O", "X", "X"]
+ - input:
+ board:
+ - ["X"]
+ expected:
+ - ["X"]
+ hidden:
+ - input:
+ board:
+ - ["O", "O", "O"]
+ - ["O", "O", "O"]
+ - ["O", "O", "O"]
+ expected:
+ - ["O", "O", "O"]
+ - ["O", "O", "O"]
+ - ["O", "O", "O"]
+ - input:
+ board:
+ - ["X", "X", "X"]
+ - ["X", "O", "X"]
+ - ["X", "X", "X"]
+ expected:
+ - ["X", "X", "X"]
+ - ["X", "X", "X"]
+ - ["X", "X", "X"]
+ - input:
+ board:
+ - ["O", "X", "X", "O", "X"]
+ - ["X", "O", "O", "X", "O"]
+ - ["X", "O", "X", "O", "X"]
+ - ["O", "X", "O", "O", "O"]
+ - ["X", "X", "O", "X", "O"]
+ expected:
+ - ["O", "X", "X", "O", "X"]
+ - ["X", "X", "X", "X", "O"]
+ - ["X", "X", "X", "O", "X"]
+ - ["O", "X", "O", "O", "O"]
+ - ["X", "X", "O", "X", "O"]
+
description: |
You are given an `m x n` matrix `board` containing letters `'X'` and `'O'`. **Capture** all regions that are **surrounded**:
diff --git a/backend/data/questions/swim-in-rising-water.yaml b/backend/data/questions/swim-in-rising-water.yaml
index 3350788..79d1d6e 100644
--- a/backend/data/questions/swim-in-rising-water.yaml
+++ b/backend/data/questions/swim-in-rising-water.yaml
@@ -12,6 +12,24 @@ patterns:
- bfs
- heap
+function_signature: "def swim_in_water(grid: list[list[int]]) -> int:"
+
+test_cases:
+ visible:
+ - input: { grid: [[0, 2], [1, 3]] }
+ expected: 3
+ - input: { grid: [[0, 1, 2, 3, 4], [24, 23, 22, 21, 5], [12, 13, 14, 15, 16], [11, 17, 18, 19, 20], [10, 9, 8, 7, 6]] }
+ expected: 16
+ hidden:
+ - input: { grid: [[0]] }
+ expected: 0
+ - input: { grid: [[3, 2], [0, 1]] }
+ expected: 3
+ - input: { grid: [[0, 1, 2], [5, 4, 3], [6, 7, 8]] }
+ expected: 4
+ - input: { grid: [[7, 5, 3], [2, 0, 6], [1, 4, 8]] }
+ expected: 7
+
description: |
You are given an `n x n` integer matrix `grid` where each value `grid[i][j]` represents the elevation at that point `(i, j)`.
diff --git a/backend/data/questions/three-sum-closest.yaml b/backend/data/questions/three-sum-closest.yaml
index 256eb37..3c86fb2 100644
--- a/backend/data/questions/three-sum-closest.yaml
+++ b/backend/data/questions/three-sum-closest.yaml
@@ -10,6 +10,28 @@ categories:
patterns:
- two-pointers
+function_signature: "def three_sum_closest(nums: list[int], target: int) -> int:"
+
+test_cases:
+ visible:
+ - input: { nums: [-1, 2, 1, -4], target: 1 }
+ expected: 2
+ - input: { nums: [0, 0, 0], target: 1 }
+ expected: 0
+ hidden:
+ - input: { nums: [1, 1, 1, 0], target: -100 }
+ expected: 2
+ - input: { nums: [1, 2, 3, 4, 5], target: 10 }
+ expected: 10
+ - input: { nums: [-1, 0, 1, 1, 55], target: 3 }
+ expected: 2
+ - input: { nums: [1, 1, -1, -1, 3], target: -1 }
+ expected: -1
+ - input: { nums: [-100, -50, 0, 50, 100], target: 1 }
+ expected: 0
+ - input: { nums: [4, 0, 5, -5, 3, 3, 0, -4, -5], target: -2 }
+ expected: -2
+
description: |
Given an integer array `nums` of length `n` and an integer `target`, find three integers in `nums` such that the sum is **closest** to `target`.
diff --git a/backend/data/questions/three-sum.yaml b/backend/data/questions/three-sum.yaml
index 847eaee..ea874ad 100644
--- a/backend/data/questions/three-sum.yaml
+++ b/backend/data/questions/three-sum.yaml
@@ -27,6 +27,12 @@ test_cases:
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]]
+ - input: { nums: [0, 0, 0, 0] }
+ expected: [[0, 0, 0]]
+ - input: { nums: [-1, -1, -1, 2] }
+ expected: [[-1, -1, 2]]
+ - input: { nums: [3, 0, -2, -1, 1, 2] }
+ expected: [[-2, -1, 3], [-2, 0, 2], [-1, 0, 1]]
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 31d40d4..e1f3aa6 100644
--- a/backend/data/questions/top-k-frequent-elements.yaml
+++ b/backend/data/questions/top-k-frequent-elements.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: [5]
- input: { nums: [1, 1, 2, 2, 3, 3, 4], k: 3 }
expected: [1, 2, 3]
+ - input: { nums: [-1, -1, -1, 2, 2, 3], k: 2 }
+ expected: [-1, 2]
+ - input: { nums: [3, 0, 1, 0], k: 1 }
+ expected: [0]
+ - input: { nums: [1, 1, 1, 2, 2, 3], 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 70e69fc..1241b2c 100644
--- a/backend/data/questions/trapping-rain-water.yaml
+++ b/backend/data/questions/trapping-rain-water.yaml
@@ -28,6 +28,12 @@ test_cases:
expected: 0
- input: { height: [5, 4, 1, 2] }
expected: 1
+ - input: { height: [2, 0, 2] }
+ expected: 2
+ - input: { height: [4, 2, 3] }
+ expected: 1
+ - input: { height: [5, 2, 1, 2, 1, 5] }
+ expected: 14
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/two-sum.yaml b/backend/data/questions/two-sum.yaml
index bbde186..5d752eb 100644
--- a/backend/data/questions/two-sum.yaml
+++ b/backend/data/questions/two-sum.yaml
@@ -26,6 +26,14 @@ test_cases:
expected: [2, 4]
- input: { nums: [0, 4, 3, 0], target: 0 }
expected: [0, 3]
+ - input: { nums: [1, 2], target: 3 }
+ expected: [0, 1]
+ - input: { nums: [5, 75, 25], target: 100 }
+ expected: [1, 2]
+ - input: { nums: [1000000000, 1000000000], target: 2000000000 }
+ expected: [0, 1]
+ - input: { nums: [-3, 4, 3, 90], target: 0 }
+ expected: [0, 2]
description: |
Given an array of integers `nums` and an integer `target`, return *indices of the two numbers such that they add up to `target`*.
diff --git a/backend/data/questions/unique-paths.yaml b/backend/data/questions/unique-paths.yaml
index 00e5efd..4ddf55e 100644
--- a/backend/data/questions/unique-paths.yaml
+++ b/backend/data/questions/unique-paths.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: 6
- input: { m: 10, n: 10 }
expected: 48620
+ - input: { m: 1, n: 100 }
+ expected: 1
+ - input: { m: 100, n: 1 }
+ expected: 1
+ - input: { m: 5, n: 5 }
+ expected: 70
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/valid-anagram.yaml b/backend/data/questions/valid-anagram.yaml
index 562544c..75510b6 100644
--- a/backend/data/questions/valid-anagram.yaml
+++ b/backend/data/questions/valid-anagram.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: true
- input: { s: "hello", t: "world" }
expected: false
+ - input: { s: "", t: "" }
+ expected: true
+ - input: { s: "aaa", t: "aaaa" }
+ expected: false
+ - input: { s: "aacc", t: "ccac" }
+ expected: false
description: |
Given two strings `s` and `t`, return `true` if `t` is an *anagram* of `s`, and `false` otherwise.
diff --git a/backend/data/questions/valid-palindrome.yaml b/backend/data/questions/valid-palindrome.yaml
index eb5a05c..6f9398f 100644
--- a/backend/data/questions/valid-palindrome.yaml
+++ b/backend/data/questions/valid-palindrome.yaml
@@ -26,6 +26,14 @@ test_cases:
expected: false
- input: { s: "Aa" }
expected: true
+ - input: { s: "" }
+ expected: true
+ - input: { s: ".,!" }
+ expected: true
+ - input: { s: "0P" }
+ expected: false
+ - input: { s: "Was it a car or a cat I saw?" }
+ expected: true
description: |
A phrase is a **palindrome** if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
diff --git a/backend/data/questions/valid-parenthesis-string.yaml b/backend/data/questions/valid-parenthesis-string.yaml
index 812684c..72185a4 100644
--- a/backend/data/questions/valid-parenthesis-string.yaml
+++ b/backend/data/questions/valid-parenthesis-string.yaml
@@ -11,6 +11,30 @@ patterns:
- greedy
- dynamic-programming
+function_signature: "def check_valid_string(s: str) -> bool:"
+
+test_cases:
+ visible:
+ - input: { s: "()" }
+ expected: true
+ - input: { s: "(*)" }
+ expected: true
+ - input: { s: "(*))" }
+ expected: true
+ hidden:
+ - input: { s: "" }
+ expected: true
+ - input: { s: "(*" }
+ expected: true
+ - input: { s: "(((((*(()((((*((**(((()()*)()()()*((((**)())*)*)))))))(())(()))())((*()()(((()((()*(*)(*)*()(((((*)()" }
+ expected: false
+ - input: { s: "***" }
+ expected: true
+ - input: { s: "(((*)" }
+ expected: false
+ - input: { s: "(*)(*" }
+ expected: true
+
description: |
Given a string `s` containing only three types of characters: `'('`, `')'` and `'*'`, return `true` *if* `s` *is **valid***.
diff --git a/backend/data/questions/valid-sudoku.yaml b/backend/data/questions/valid-sudoku.yaml
index 2918e2f..dfb0db8 100644
--- a/backend/data/questions/valid-sudoku.yaml
+++ b/backend/data/questions/valid-sudoku.yaml
@@ -9,6 +9,72 @@ categories:
patterns:
- matrix-traversal
+function_signature: "def is_valid_sudoku(board: list[list[str]]) -> bool:"
+
+test_cases:
+ visible:
+ - input:
+ board:
+ - ["5", "3", ".", ".", "7", ".", ".", ".", "."]
+ - ["6", ".", ".", "1", "9", "5", ".", ".", "."]
+ - [".", "9", "8", ".", ".", ".", ".", "6", "."]
+ - ["8", ".", ".", ".", "6", ".", ".", ".", "3"]
+ - ["4", ".", ".", "8", ".", "3", ".", ".", "1"]
+ - ["7", ".", ".", ".", "2", ".", ".", ".", "6"]
+ - [".", "6", ".", ".", ".", ".", "2", "8", "."]
+ - [".", ".", ".", "4", "1", "9", ".", ".", "5"]
+ - [".", ".", ".", ".", "8", ".", ".", "7", "9"]
+ expected: true
+ - input:
+ board:
+ - ["8", "3", ".", ".", "7", ".", ".", ".", "."]
+ - ["6", ".", ".", "1", "9", "5", ".", ".", "."]
+ - [".", "9", "8", ".", ".", ".", ".", "6", "."]
+ - ["8", ".", ".", ".", "6", ".", ".", ".", "3"]
+ - ["4", ".", ".", "8", ".", "3", ".", ".", "1"]
+ - ["7", ".", ".", ".", "2", ".", ".", ".", "6"]
+ - [".", "6", ".", ".", ".", ".", "2", "8", "."]
+ - [".", ".", ".", "4", "1", "9", ".", ".", "5"]
+ - [".", ".", ".", ".", "8", ".", ".", "7", "9"]
+ expected: false
+ hidden:
+ - input:
+ board:
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ expected: true
+ - input:
+ board:
+ - ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ expected: true
+ - input:
+ board:
+ - ["1", "1", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ - [".", ".", ".", ".", ".", ".", ".", ".", "."]
+ expected: false
+
description: |
Determine if a `9 x 9` Sudoku board is valid. Only the filled cells need to be validated **according to the following rules**:
diff --git a/backend/data/questions/validate-binary-search-tree.yaml b/backend/data/questions/validate-binary-search-tree.yaml
index f3fd766..a4198f7 100644
--- a/backend/data/questions/validate-binary-search-tree.yaml
+++ b/backend/data/questions/validate-binary-search-tree.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: false
- input: { root: [10, 5, 15, null, null, 6, 20] }
expected: false
+ - input: { root: [] }
+ expected: true
+ - input: { root: [3, 1, 5, 0, 2, 4, 6] }
+ expected: true
+ - input: { root: [1, 1] }
+ 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-ii.yaml b/backend/data/questions/word-break-ii.yaml
index 9110cf1..75c74ac 100644
--- a/backend/data/questions/word-break-ii.yaml
+++ b/backend/data/questions/word-break-ii.yaml
@@ -11,6 +11,24 @@ patterns:
- backtracking
- dynamic-programming
+function_signature: "def word_break(s: str, word_dict: list[str]) -> list[str]:"
+
+test_cases:
+ visible:
+ - input: { s: "catsanddog", word_dict: ["cat", "cats", "and", "sand", "dog"] }
+ expected: ["cat sand dog", "cats and dog"]
+ - input: { s: "catsandog", word_dict: ["cats", "dog", "sand", "and", "cat"] }
+ expected: []
+ hidden:
+ - input: { s: "pineapplepenapple", word_dict: ["apple", "pen", "applepen", "pine", "pineapple"] }
+ expected: ["pine apple pen apple", "pine applepen apple", "pineapple pen apple"]
+ - input: { s: "a", word_dict: ["a"] }
+ expected: ["a"]
+ - input: { s: "ab", word_dict: ["a", "b"] }
+ expected: ["a b"]
+ - input: { s: "aaaa", word_dict: ["a", "aa"] }
+ expected: ["a a a a", "a a aa", "a aa a", "aa a a", "aa aa"]
+
description: |
Given a string `s` and a dictionary of strings `wordDict`, add spaces in `s` to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in **any order**.
diff --git a/backend/data/questions/word-break.yaml b/backend/data/questions/word-break.yaml
index 0d27fb5..ecf6364 100644
--- a/backend/data/questions/word-break.yaml
+++ b/backend/data/questions/word-break.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: true
- input: { s: "cars", word_dict: ["car", "ca", "rs"] }
expected: true
+ - input: { s: "abcd", word_dict: ["a", "abc", "b", "cd"] }
+ expected: true
+ - input: { s: "bb", word_dict: ["a", "b", "bbb", "bbbb"] }
+ expected: true
+ - input: { s: "goalspecial", word_dict: ["go", "goal", "goals", "special"] }
+ 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-search-ii.yaml b/backend/data/questions/word-search-ii.yaml
index a462a05..2ac7180 100644
--- a/backend/data/questions/word-search-ii.yaml
+++ b/backend/data/questions/word-search-ii.yaml
@@ -12,6 +12,32 @@ patterns:
- backtracking
- matrix-traversal
+function_signature: "def find_words(board: list[list[str]], words: list[str]) -> list[str]:"
+
+test_cases:
+ visible:
+ - input:
+ board: [["o", "a", "a", "n"], ["e", "t", "a", "e"], ["i", "h", "k", "r"], ["i", "f", "l", "v"]]
+ words: ["oath", "pea", "eat", "rain"]
+ expected: ["eat", "oath"]
+ - input:
+ board: [["a", "b"], ["c", "d"]]
+ words: ["abcb"]
+ expected: []
+ hidden:
+ - input:
+ board: [["a"]]
+ words: ["a"]
+ expected: ["a"]
+ - input:
+ board: [["a", "b"], ["c", "d"]]
+ words: ["ab", "cb", "ad", "bd", "ac", "ca", "da", "bc", "db", "adcb", "dabc", "abb", "acb"]
+ expected: ["ab", "ac", "bd", "ca", "db"]
+ - input:
+ board: [["o", "a", "b", "n"], ["o", "t", "a", "e"], ["a", "h", "k", "r"], ["a", "f", "l", "v"]]
+ words: ["oa", "oaa"]
+ expected: ["oa", "oaa"]
+
description: |
Given an `m x n` `board` of characters and a list of strings `words`, return *all words on the board*.
diff --git a/backend/data/questions/word-search.yaml b/backend/data/questions/word-search.yaml
index daaec7f..1f50a76 100644
--- a/backend/data/questions/word-search.yaml
+++ b/backend/data/questions/word-search.yaml
@@ -27,6 +27,12 @@ test_cases:
expected: false
- input: { board: [["A", "B"], ["C", "D"]], word: "ABDC" }
expected: true
+ - input: { board: [["A"]], word: "B" }
+ expected: false
+ - input: { board: [["A", "A", "A"], ["A", "A", "A"], ["A", "A", "A"]], word: "AAAAAAAAA" }
+ expected: true
+ - input: { board: [["C", "A", "A"], ["A", "A", "A"], ["B", "C", "D"]], word: "AAB" }
+ expected: true
description: |
Given an `m × n` grid of characters `board` and a string `word`, return `true` if `word` exists in the grid.