feat(content): hidden test cases
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 i<sup>th</sup> day.
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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 i<sup>th</sup> type you have. You are also given a 2D array `queries` where `queries[i] = [favoriteType_i, favoriteDay_i, dailyCap_i]`.
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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**.
|
||||
|
||||
|
||||
@@ -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**:
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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`.
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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`.
|
||||
|
||||
|
||||
@@ -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`.
|
||||
|
||||
|
||||
@@ -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**).
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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'`.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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`.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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**:
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.).
|
||||
|
||||
|
||||
@@ -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**.
|
||||
|
||||
|
||||
@@ -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`.
|
||||
|
||||
|
||||
@@ -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**.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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**.
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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 i<sup>th</sup> line are `(i, 0)` and `(i, height[i])`.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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`<sub>`i`</sub>`, b`<sub>`i`</sub>`]` indicates that you **must** take course `b`<sub>`i`</sub> first if you want to take course `a`<sub>`i`</sub>.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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**.
|
||||
|
||||
@@ -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**.
|
||||
|
||||
@@ -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 i<sup>th</sup> 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.
|
||||
|
||||
@@ -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*.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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`<sup>th</sup> smallest value (**1-indexed**) of all the values of the nodes in the tree.
|
||||
|
||||
@@ -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**.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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***.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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*.
|
||||
|
||||
@@ -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*.
|
||||
|
||||
@@ -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**.
|
||||
|
||||
|
||||
@@ -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`.
|
||||
|
||||
|
||||
@@ -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*.
|
||||
|
||||
@@ -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`.
|
||||
|
||||
|
||||
@@ -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*.
|
||||
|
||||
@@ -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**.
|
||||
|
||||
|
||||
@@ -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 i<sup>th</sup> **triplet**. You are also given an integer array `target = [x, y, z]` that describes the **triplet** you want to obtain.
|
||||
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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 i<sup>th</sup> step on a staircase. Once you pay the cost, you can either climb one or two steps.
|
||||
|
||||
@@ -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]`.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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 i<sup>th</sup> 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`.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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*.
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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*.
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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**.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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*.
|
||||
|
||||
|
||||
@@ -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*.
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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**.
|
||||
|
||||
|
||||
@@ -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***.
|
||||
|
||||
|
||||
@@ -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**.
|
||||
|
||||
@@ -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., x<sup>n</sup>).
|
||||
|
||||
|
||||
@@ -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]`.
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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`<sup>th</sup> node from the end of the list and return its head.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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*.
|
||||
|
||||
|
||||
@@ -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*.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user