question_id int64 1 3.24k | task_id stringlengths 3 77 | difficulty stringclasses 3
values | problem_description stringlengths 193 3.69k | canonical_tests dict | public_tests listlengths 1 5 | hints listlengths 0 8 | metadata dict | language stringclasses 9
values | interface dict |
|---|---|---|---|---|---|---|---|---|---|
3,206 | alternating-groups-i | Easy | There is a circle of red and blue tiles. You are given an array of integers colors. The color of tile i is represented by colors[i]:
- colors[i] == 0 means that tile i is red.
- colors[i] == 1 means that tile i is blue.
Every 3 contiguous tiles in the circle with alternating colors (the middle tile has a different co... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(colors = [1, 1, 1, 0, 0, 0, 1, 1, 1]) == 0\n assert candidate(colors = [1, 0, 0, 0, 1, 1, 1, 0]) == 2\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0]) == 7\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1]) == 1\n ass... | [
"[1,1,1]",
"[0,1,0,0,1]"
] | [
"For each tile, check that the previous and the next tile have different colors from that tile or not."
] | {
"canonical_parameter_names": [
"colors"
],
"leetcode_dataset_entry_point": "Solution().numberOfAlternatingGroups",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:16:51",
"tests_total": 1... | typescript | {
"raw_signature": "function numberOfAlternatingGroups(colors: number[]): number {",
"container": null,
"callable": "numberOfAlternatingGroups",
"parameters": [
{
"name": "colors",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_sou... |
3,207 | maximum-points-after-enemy-battles | Medium | You are given an integer array enemyEnergies denoting the energy values of various enemies.
You are also given an integer currentEnergy denoting the amount of energy you have initially.
You start with 0 points, and all the enemies are unmarked initially.
You can perform either of the following operations zero or mul... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(enemyEnergies = [1, 1, 1, 1, 1],currentEnergy = 1) == 5\n assert candidate(enemyEnergies = [5, 5, 5, 5, 5],currentEnergy = 15) == 7\n assert candidate(enemyEnergies = [2],currentEnergy = 10) == 5\n assert candidate(enemyEnergies... | [
"[3,2,2]\n2",
"[2]\n10"
] | [
"The problem can be solved greedily.",
"Mark all the others except the smallest one first.",
"Use the smallest one to increase the energy.",
"Note that the initial energy should be no less than the smallest enemy."
] | {
"canonical_parameter_names": [
"enemyEnergies",
"currentEnergy"
],
"leetcode_dataset_entry_point": "Solution().maximumPoints",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:16:54",
... | typescript | {
"raw_signature": "function maximumPoints(enemyEnergies: number[], currentEnergy: number): number {",
"container": null,
"callable": "maximumPoints",
"parameters": [
{
"name": "enemyEnergies",
"type": "number[]"
},
{
"name": "currentEnergy",
"type": "number"
}
],
"re... |
3,208 | alternating-groups-ii | Medium | There is a circle of red and blue tiles. You are given an array of integers colors and an integer k. The color of tile i is represented by colors[i]:
- colors[i] == 0 means that tile i is red.
- colors[i] == 1 means that tile i is blue.
An alternating group is every k contiguous tiles in the circle with alternating c... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(colors = [1, 1, 0, 1],k = 4) == 0\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0],k = 3) == 8\n assert candidate(colors = [0, 1, 0, 0, 1, 0, 1],k = 6) == 2\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1],k = 3) == 7... | [
"[0,1,0,1,0]\n3",
"[0,1,0,0,1,0,1]\n6",
"[1,1,0,1]\n4"
] | [
"Try to find a tile that has the same color as its next tile (if it exists).",
"Then try to find maximal alternating groups by starting a single for loop from that tile."
] | {
"canonical_parameter_names": [
"colors",
"k"
],
"leetcode_dataset_entry_point": "Solution().numberOfAlternatingGroups",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:16:56",
"tests_... | typescript | {
"raw_signature": "function numberOfAlternatingGroups(colors: number[], k: number): number {",
"container": null,
"callable": "numberOfAlternatingGroups",
"parameters": [
{
"name": "colors",
"type": "number[]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "n... |
3,209 | number-of-subarrays-with-and-value-of-k | Hard | Given an array of integers nums and an integer k, return the number of subarrays of nums where the bitwise AND of the elements of the subarray equals k.
Example 1:
Input: nums = [1,1,1], k = 1
Output: 6
Explanation:
All subarrays contain only 1's.
Example 2:
Input: nums = [1,1,2], k = 1
Output: 3
Explanation:
Subar... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 15\n assert candidate(nums = [10, 9, 8, 7, 6],k = 10) == 1\n assert candidate(nums = [5, 5, 5, 5],k = 5) == 10\n assert candidate(nums = [3, 3, 3, 3, 3, 3],k = 3) == 21\n assert candidate(nums... | [
"[1,1,1]\n1",
"[1,1,2]\n1",
"[1,2,3]\n2"
] | [
"Let’s say we want to count the number of pairs (l, r) such that nums[l] & nums[l + 1] & … & nums[r] == k.",
"Fix the left index l.",
"Note that if you increase r for a fixed l, then the AND value of the subarray either decreases or remains unchanged.",
"Therefore, consider using binary search.",
"To calcul... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().countSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:16:59",
"tests_total": 127,
... | typescript | {
"raw_signature": "function countSubarrays(nums: number[], k: number): number {",
"container": null,
"callable": "countSubarrays",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_sourc... |
3,210 | find-the-encrypted-string | Easy | You are given a string s and an integer k. Encrypt the string using the following algorithm:
- For each character c in s, replace c with the k^th character after c in the string (in a cyclic manner).
Return the encrypted string.
Example 1:
Input: s = "dart", k = 3
Output: "tdar"
Explanation:
- For i = 0, the 3^rd c... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"hello\",k = 10) == \"hello\"\n assert candidate(s = \"abc\",k = 2) == \"cab\"\n assert candidate(s = \"hello\",k = 7) == \"llohe\"\n assert candidate(s = \"abcdef\",k = 2) == \"cdefab\"\n assert candidate(s = \"world\",... | [
"\"dart\"\n3",
"\"aaa\"\n1"
] | [
"Make a new string such that for each character in s, character i will correspond to (i + k) % s.length character in the original string."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().getEncryptedString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:01",
"tests_total": 88,
... | typescript | {
"raw_signature": "function getEncryptedString(s: string, k: number): string {",
"container": null,
"callable": "getEncryptedString",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "string",
"signature_source"... |
3,211 | generate-binary-strings-without-adjacent-zeros | Medium | You are given a positive integer n.
A binary string x is valid if all substrings of x of length 2 contain at least one "1".
Return all valid strings with length n, in any order.
Example 1:
Input: n = 3
Output: ["010","011","101","110","111"]
Explanation:
The valid strings of length 3 are: "010", "011", "101", "110"... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ... | [
"3",
"1"
] | [
"If we have a string s of length x, we can generate all strings of length x + 1.",
"If s has 0 as the last character, we can only append 1, whereas if the last character is 1, we can append both 0 and 1.",
"We can use recursion and backtracking to generate all such strings."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().validStrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:03",
"tests_total": 12,
"tests_droppe... | typescript | {
"raw_signature": "function validStrings(n: number): string[] {",
"container": null,
"callable": "validStrings",
"parameters": [
{
"name": "n",
"type": "number"
}
],
"return_type": "string[]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,212 | count-submatrices-with-equal-frequency-of-x-and-y | Medium | Given a 2D character matrix grid, where grid[i][j] is either 'X', 'Y', or '.', return the number of submatrices that contain:
- grid[0][0]
- an equal frequency of 'X' and 'Y'.
- at least one 'X'.
Example 1:
Input: grid = [["X","Y","."],["Y",".","."]]
Output: 3
Explanation:
Example 2:
Input: grid = [["X","X"],["X",... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [['X', 'Y', 'X'], ['Y', 'X', 'Y'], ['X', 'Y', 'X']]) == 5\n assert candidate(grid = [['.', '.'], ['.', '.']]) == 0\n assert candidate(grid = [['X', 'X'], ['X', 'Y']]) == 0\n assert candidate(grid = [['X', 'X', 'Y', 'Y'], ... | [
"[[\"X\",\"Y\",\".\"],[\"Y\",\".\",\".\"]]",
"[[\"X\",\"X\"],[\"X\",\"Y\"]]",
"[[\".\",\".\"],[\".\",\".\"]]"
] | [
"Replace ’X’ with 1, ’Y’ with -1 and ’.’ with 0.",
"You need to find how many submatrices grid[0..x][0..y] have a sum of 0 and at least one ’X’.",
"Use prefix sum to calculate submatrices sum."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().numberOfSubmatrices",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:06",
"tests_total": 45,
"te... | typescript | {
"raw_signature": "function numberOfSubmatrices(grid: string[][]): number {",
"container": null,
"callable": "numberOfSubmatrices",
"parameters": [
{
"name": "grid",
"type": "string[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetc... |
3,213 | construct-string-with-minimum-cost | Hard | You are given a string target, an array of strings words, and an integer array costs, both arrays of the same length.
Imagine an empty string s.
You can perform the following operation any number of times (including zero):
- Choose an index i in the range [0, words.length - 1].
- Append words[i] to s.
- The cost of ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(target = \"xyz\",words = ['x', 'y', 'z'],costs = [1, 2, 3]) == 6\n assert candidate(target = \"abcd\",words = ['a', 'b', 'c', 'd'],costs = [1, 1, 1, 1]) == 4\n assert candidate(target = \"zzzz\",words = ['zz', 'zzzz'],costs = [2, 1... | [
"\"abcdef\"\n[\"abdef\",\"abc\",\"d\",\"def\",\"ef\"]\n[100,1,1,10,5]",
"\"aaaa\"\n[\"z\",\"zz\",\"zzz\"]\n[1,10,100]"
] | [
"Use Dynamic Programming along with Aho-Corasick or Hashing."
] | {
"canonical_parameter_names": [
"target",
"words",
"costs"
],
"leetcode_dataset_entry_point": "Solution().minimumCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:09",
"tes... | typescript | {
"raw_signature": "function minimumCost(target: string, words: string[], costs: number[]): number {",
"container": null,
"callable": "minimumCost",
"parameters": [
{
"name": "target",
"type": "string"
},
{
"name": "words",
"type": "string[]"
},
{
"name": "costs... |
3,216 | lexicographically-smallest-string-after-a-swap | Easy | Given a string s containing only digits, return the lexicographically smallest string that can be obtained after swapping adjacent digits in s with the same parity at most once.
Digits have the same parity if both are odd or both are even. For example, 5 and 9, as well as 2 and 4, have the same parity, while 6 and 9 d... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"9876543210\") == \"9876543210\"\n assert candidate(s = \"1324\") == \"1324\"\n assert candidate(s = \"111222333\") == \"111222333\"\n assert candidate(s = \"1352468709\") == \"1352468709\"\n assert candidate(s = \"21212... | [
"\"45320\"",
"\"001\""
] | [
"Try all possible swaps satisfying the constraints and find the one that results in the lexicographically smallest string."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().getSmallestString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:14",
"tests_total": 124,
"tests_... | typescript | {
"raw_signature": "function getSmallestString(s: string): string {",
"container": null,
"callable": "getSmallestString",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
... |
3,218 | minimum-cost-for-cutting-cake-i | Medium | There is an m x n cake that needs to be cut into 1 x 1 pieces.
You are given integers m, n, and two arrays:
- horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizontal line i.
- verticalCut of size n - 1, where verticalCut[j] represents the cost to cut along the vertical line... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(m = 5,n = 4,horizontalCut = [1, 2, 3, 4],verticalCut = [2, 4, 6]) == 49\n assert candidate(m = 4,n = 3,horizontalCut = [2, 5, 7],verticalCut = [3, 8]) == 47\n assert candidate(m = 2,n = 2,horizontalCut = [7],verticalCut = [4]) == 1... | [
"3\n2\n[1,3]\n[5]",
"2\n2\n[7]\n[4]"
] | [
"The intended solution uses Dynamic Programming.",
"Let dp[sx][sy][tx][ty] denote the minimum cost to cut the rectangle into 1 x 1 pieces.",
"Iterate on the row or column on which you will perform the next cut, after the cut, the current rectangle will be decomposed into two sub-rectangles."
] | {
"canonical_parameter_names": [
"m",
"n",
"horizontalCut",
"verticalCut"
],
"leetcode_dataset_entry_point": "Solution().minimumCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30... | typescript | {
"raw_signature": "function minimumCost(m: number, n: number, horizontalCut: number[], verticalCut: number[]): number {",
"container": null,
"callable": "minimumCost",
"parameters": [
{
"name": "m",
"type": "number"
},
{
"name": "n",
"type": "number"
},
{
"name... |
3,219 | minimum-cost-for-cutting-cake-ii | Hard | There is an m x n cake that needs to be cut into 1 x 1 pieces.
You are given integers m, n, and two arrays:
- horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizontal line i.
- verticalCut of size n - 1, where verticalCut[j] represents the cost to cut along the vertical line... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(m = 2,n = 2,horizontalCut = [7],verticalCut = [4]) == 15\n assert candidate(m = 4,n = 3,horizontalCut = [1, 2, 3],verticalCut = [1, 2]) == 17\n assert candidate(m = 3,n = 3,horizontalCut = [1, 2],verticalCut = [1, 2]) == 11\n as... | [
"3\n2\n[1,3]\n[5]",
"2\n2\n[7]\n[4]"
] | [
"The intended solution uses a Greedy approach.",
"At each step, we will perform a cut on the line with the highest cost.",
"If you perform a horizontal cut, can you count the contribution that it adds to each row cut that comes afterward?"
] | {
"canonical_parameter_names": [
"m",
"n",
"horizontalCut",
"verticalCut"
],
"leetcode_dataset_entry_point": "Solution().minimumCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30... | typescript | {
"raw_signature": "function minimumCost(m: number, n: number, horizontalCut: number[], verticalCut: number[]): number {",
"container": null,
"callable": "minimumCost",
"parameters": [
{
"name": "m",
"type": "number"
},
{
"name": "n",
"type": "number"
},
{
"name... |
3,222 | find-the-winning-player-in-coin-game | Easy | You are given two positive integers x and y, denoting the number of coins with values 75 and 10 respectively.
Alice and Bob are playing a game. Each turn, starting with Alice, the player must pick up coins with a total value 115. If the player is unable to do so, they lose the game.
Return the name of the player who ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(x = 100,y = 1) == \"Bob\"\n assert candidate(x = 1,y = 100) == \"Alice\"\n assert candidate(x = 1,y = 10) == \"Alice\"\n assert candidate(x = 4,y = 11) == \"Bob\"\n assert candidate(x = 2,y = 7) == \"Alice\"\n assert candi... | [
"2\n7",
"4\n11"
] | [
"The only way to make 115 is to use one coin of value 75 and four coins of value 10. Each turn uses up these many coins.",
"Hence the number of turns is min(x, y / 4).",
"Determine the winner from its parity."
] | {
"canonical_parameter_names": [
"x",
"y"
],
"leetcode_dataset_entry_point": "Solution().winningPlayer",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:27",
"tests_total": 104,
"t... | typescript | {
"raw_signature": "function winningPlayer(x: number, y: number): string {",
"container": null,
"callable": "winningPlayer",
"parameters": [
{
"name": "x",
"type": "number"
},
{
"name": "y",
"type": "number"
}
],
"return_type": "string",
"signature_source": "leetcod... |
3,223 | minimum-length-of-string-after-operations | Medium | You are given a string s.
You can perform the following process on s any number of times:
- Choose an index i in the string such that there is at least one character to the left of index i that is equal to s[i], and at least one character to the right that is also equal to s[i].
- Delete the closest occurrence of s[i... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"zzzzyzyzyyzzyzz\") == 3\n assert candidate(s = \"abcba\") == 5\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"abaacbcbb\") == 5\n assert candidate(s = \"aabbaa\") == 4\n assert ... | [
"\"abaacbcbb\"",
"\"aa\""
] | [
"Only the frequency of each character matters in finding the final answer.",
"If a character occurs less than 3 times, we cannot perform any process with it.",
"Suppose there is a character that occurs at least 3 times in the string, we can repeatedly delete two of these characters until there are at most 2 occ... | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().minimumLength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:29",
"tests_total": 47,
"tests_dropp... | typescript | {
"raw_signature": "function minimumLength(s: string): number {",
"container": null,
"callable": "minimumLength",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,224 | minimum-array-changes-to-make-differences-equal | Medium | You are given an integer array nums of size n where n is even, and an integer k.
You can perform some changes on the array, where in one change you can replace any element in the array with any integer in the range from 0 to k.
You need to perform some changes (possibly none) such that the final array satisfies the f... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995],k = 100000) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5],k = 10) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8],k = 8) == 3\n assert candidate(nums = [1, 3, 5, 7,... | [
"[1,0,1,2,4,3]\n4",
"[0,1,2,3,3,6,5,4]\n6"
] | [
"There are at most k + 1 possible values of the integer X.",
"How do we calculate the minimum number of changes efficiently if we fix the value of X before applying any changes?"
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().minChanges",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:32",
"tests_total": 101,
"t... | typescript | {
"raw_signature": "function minChanges(nums: number[], k: number): number {",
"container": null,
"callable": "minChanges",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_source": "lee... |
3,225 | maximum-score-from-grid-operations | Hard | You are given a 2D matrix grid of size n x n. Initially, all cells of the grid are colored white. In one operation, you can select any cell of indices (i, j), and color black all the cells of the j^th column starting from the top row down to the i^th row.
The grid score is the sum of all grid[i][j] such that cell (i, ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 3, 0, 0], [0, 1, 0, 0, 0], [5, 0, 0, 3, 0], [0, 0, 0, 0, 2]]) == 11\n assert candidate(grid = [[10, 9, 0, 0, 15], [7, 1, 0, 8, 0], [5, 20, 0, 11, 0], [0, 0, 0, 1, 2], [8, 12, 1, 10, 3]]) == 94\n asse... | [
"[[0,0,0,0,0],[0,0,3,0,0],[0,1,0,0,0],[5,0,0,3,0],[0,0,0,0,2]]",
"[[10,9,0,0,15],[7,1,0,8,0],[5,20,0,11,0],[0,0,0,1,2],[8,12,1,10,3]]"
] | [
"Use dynamic programming.",
"Solve the problem in O(N^4) using a 3-states dp.",
"Let dp[i][lastHeight][beforeLastHeight] denote the maximum score if the grid was limited to column i, and the height of column i - 1 is lastHeight and the height of column i - 2 is beforeLastHeight.",
"The third state, beforeLast... | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().maximumScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:34",
"tests_total": 75,
"tests_dro... | typescript | {
"raw_signature": "function maximumScore(grid: number[][]): number {",
"container": null,
"callable": "maximumScore",
"parameters": [
{
"name": "grid",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippe... |
3,226 | number-of-bit-changes-to-make-two-integers-equal | Easy | You are given two positive integers n and k.
You can choose any bit in the binary representation of n that is equal to 1 and change it to 0.
Return the number of changes needed to make n equal to k. If it is impossible, return -1.
Example 1:
Input: n = 13, k = 4
Output: 2
Explanation:
Initially, the binary represen... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 1,k = 2) == -1\n assert candidate(n = 31,k = 1) == 4\n assert candidate(n = 15,k = 9) == 2\n assert candidate(n = 8,k = 8) == 0\n assert candidate(n = 1000000,k = 999999) == -1\n assert candidate(n = 7,k = 11) == -1\n ... | [
"13\n4",
"21\n21",
"14\n13"
] | [
"Find the binary representations of n and k.",
"Any bit that is equal to 1 in n and equal to 0 in k needs to be changed."
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().minChanges",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:37",
"tests_total": 91,
"tests... | typescript | {
"raw_signature": "function minChanges(n: number, k: number): number {",
"container": null,
"callable": "minChanges",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_source": "leetcode/code... |
3,227 | vowels-game-in-a-string | Medium | Alice and Bob are playing a game on a string.
You are given a string s, Alice and Bob will take turns playing the following game where Alice starts first:
- On Alice's turn, she has to remove any non-empty substring from s that contains an odd number of vowels.
- On Bob's turn, he has to remove any non-empty substrin... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"b\") == False\n assert candidate(s = \"bcbcbc\") == False\n assert candidate(s = \"leetcodeisfun\") == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(s = \"uoiea\") == True\n a... | [
"\"leetcoder\"",
"\"bbcd\""
] | [
"If there are no vowels in the initial string, then Bob wins.",
"If the number of vowels in the initial string is odd, then Alice can remove the whole string on her first turn and win.",
"What if the number of vowels in the initial string is even? What’s the optimal play for Alice’s first turn?"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().doesAliceWin",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:39",
"tests_total": 121,
"tests_dropp... | typescript | {
"raw_signature": "function doesAliceWin(s: string): boolean {",
"container": null,
"callable": "doesAliceWin",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "boolean",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,228 | maximum-number-of-operations-to-move-ones-to-the-end | Medium | You are given a binary string s.
You can perform the following operation on the string any number of times:
- Choose any index i from the string where i + 1 < s.length such that s[i] == '1' and s[i + 1] == '0'.
- Move the character s[i] to the right until it reaches the end of the string or another '1'. For example, ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"00111\") == 0\n assert candidate(s = \"101100110\") == 9\n assert candidate(s = \"000111000\") == 3\n assert candidate(s = \"11110000\") == 4\n assert candidate(s = \"010101010\") == 10\n assert candidate(s = \"10010... | [
"\"1001101\"",
"\"00111\""
] | [
"It is optimal to perform the operation on the lowest index possible each time.",
"Traverse the string from left to right and perform the operation every time it is possible."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().maxOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:42",
"tests_total": 107,
"tests_drop... | typescript | {
"raw_signature": "function maxOperations(s: string): number {",
"container": null,
"callable": "maxOperations",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,229 | minimum-operations-to-make-array-equal-to-target | Hard | You are given two positive integer arrays nums and target, of the same length.
In a single operation, you can select any subarray of nums and increment each element within that subarray by 1 or decrement each element within that subarray by 1.
Return the minimum number of operations required to make nums equal to the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 100000000, 1],target = [100000000, 1, 100000000]) == 299999997\n assert candidate(nums = [1, 3, 2],target = [2, 1, 4]) == 5\n assert candidate(nums = [3, 5, 1, 2],target = [4, 6, 2, 4]) == 2\n assert candidate(nums = ... | [
"[3,5,1,2]\n[4,6,2,4]",
"[1,3,2]\n[2,1,4]"
] | [
"Change nums'[i] = nums[i] - target[i], so our goal is to make nums' into all 0s.",
"Divide and conquer."
] | {
"canonical_parameter_names": [
"nums",
"target"
],
"leetcode_dataset_entry_point": "Solution().minimumOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:45",
"tests_total... | typescript | {
"raw_signature": "function minimumOperations(nums: number[], target: number[]): number {",
"container": null,
"callable": "minimumOperations",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "target",
"type": "number[]"
}
],
"return_type": "number"... |
3,232 | find-if-digit-game-can-be-won | Easy | You are given an array of positive integers nums.
Alice and Bob are playing a game. In the game, Alice can choose either all single-digit numbers or all double-digit numbers from nums, and the rest of the numbers are given to Bob. Alice wins if the sum of her numbers is strictly greater than the sum of Bob's numbers.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [9, 9, 9, 10, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 14]) == True\n assert candidate(nums = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n ... | [
"[1,2,3,4,10]",
"[1,2,3,4,5,14]",
"[5,5,5,25]"
] | [
"Alice wins if the sum of all single-digit numbers and the sum of all double-digit numbers are different."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().canAliceWin",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:50",
"tests_total": 121,
"tests_dro... | typescript | {
"raw_signature": "function canAliceWin(nums: number[]): boolean {",
"container": null,
"callable": "canAliceWin",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "boolean",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
... |
3,233 | find-the-count-of-numbers-which-are-not-special | Medium | You are given 2 positive integers l and r. For any number x, all positive divisors of x except x are called the proper divisors of x.
A number is called special if it has exactly 2 proper divisors. For example:
- The number 4 is special because it has proper divisors 1 and 2.
- The number 6 is not special because it ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(l = 100,r = 200) == 99\n assert candidate(l = 5,r = 7) == 3\n assert candidate(l = 20,r = 50) == 29\n assert candidate(l = 1,r = 10) == 8\n assert candidate(l = 100,r = 150) == 50\n assert candidate(l = 4,r = 16) == 11\n ... | [
"5\n7",
"4\n16"
] | [
"A special number must be a square of a prime number.",
"We need to find all primes in the range [sqrt(l), sqrt(r)].",
"Use sieve to find primes till sqrt(10^9)."
] | {
"canonical_parameter_names": [
"l",
"r"
],
"leetcode_dataset_entry_point": "Solution().nonSpecialCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:52",
"tests_total": 77,
"... | typescript | {
"raw_signature": "function nonSpecialCount(l: number, r: number): number {",
"container": null,
"callable": "nonSpecialCount",
"parameters": [
{
"name": "l",
"type": "number"
},
{
"name": "r",
"type": "number"
}
],
"return_type": "number",
"signature_source": "lee... |
3,234 | count-the-number-of-substrings-with-dominant-ones | Medium | You are given a binary string s.
Return the number of substrings with dominant ones.
A string has dominant ones if the number of ones in the string is greater than or equal to the square of the number of zeros in the string.
Example 1:
Input: s = "00011"
Output: 5
Explanation:
The substrings with dominant ones are ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1111\") == 10\n assert candidate(s = \"100100100\") == 8\n assert candidate(s = \"1111010101\") == 33\n assert candidate(s = \"000111000\") == 12\n assert candidate(s = \"11110000\") == 15\n assert candidate(s = \"00... | [
"\"00011\"",
"\"101101\""
] | [
"Let us fix the starting index l of the substring and count the number of indices r such that l <= r and the substring s[l..r] has dominant ones.",
"A substring with dominant ones has at most sqrt(n) zeros.",
"We cannot iterate over every r and check if the s[l..r] has dominant ones. Instead, we iterate over th... | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().numberOfSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:54",
"tests_total": 165,
"tests... | typescript | {
"raw_signature": "function numberOfSubstrings(s: string): number {",
"container": null,
"callable": "numberOfSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets... |
3,235 | check-if-the-rectangle-corner-is-reachable | Hard | You are given two positive integers xCorner and yCorner, and a 2D array circles, where circles[i] = [x_i, y_i, r_i] denotes a circle with center at (x_i, y_i) and radius r_i.
There is a rectangle in the coordinate plane with its bottom left corner at the origin and top right corner at the coordinate (xCorner, yCorner)... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(xCorner = 10,yCorner = 10,circles = [[1, 1, 1], [9, 9, 1]]) == False\n assert candidate(xCorner = 1000000000,yCorner = 1000000000,circles = [[500000000, 500000000, 499999999]]) == True\n assert candidate(xCorner = 5,yCorner = 5,cir... | [
"3\n4\n[[2,1,1]]",
"3\n3\n[[1,1,2]]",
"3\n3\n[[2,1,1],[1,2,1]]",
"4\n4\n[[5,5,1]]"
] | [
"Create a graph with n + 4 vertices.",
"Vertices 0 to n - 1 represent the circles, vertex n represents upper edge, vertex n + 1 represents right edge, vertex n + 2 represents lower edge, and vertex n + 3 represents left edge.",
"Add an edge between these vertices if they intersect or touch.",
"Answer will be ... | {
"canonical_parameter_names": [
"xCorner",
"yCorner",
"circles"
],
"leetcode_dataset_entry_point": "Solution().canReachCorner",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:17:56"... | typescript | {
"raw_signature": "function canReachCorner(xCorner: number, yCorner: number, circles: number[][]): boolean {",
"container": null,
"callable": "canReachCorner",
"parameters": [
{
"name": "xCorner",
"type": "number"
},
{
"name": "yCorner",
"type": "number"
},
{
"... |
3,238 | find-the-number-of-winning-players | Easy | You are given an integer n representing the number of players in a game and a 2D array pick where pick[i] = [x_i, y_i] represents that the player x_i picked a ball of color y_i.
Player i wins the game if they pick strictly more than i balls of the same color. In other words,
- Player 0 wins if they pick any ball.
- P... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 10,pick = [[0, 0], [1, 1], [1, 1], [2, 2], [2, 2], [2, 2], [3, 3], [3, 3], [3, 3], [3, 3]]) == 4\n assert candidate(n = 10,pick = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 1\n assert ... | [
"4\n[[0,0],[1,0],[1,0],[2,1],[2,1],[2,0]]",
"5\n[[1,1],[1,2],[1,3],[1,4]]",
"5\n[[1,1],[2,4],[2,4],[2,4]]"
] | [
"Keep track of the number of balls of each color for each user using hashing.",
"Find the maximum color that occurred for each player."
] | {
"canonical_parameter_names": [
"n",
"pick"
],
"leetcode_dataset_entry_point": "Solution().winningPlayerCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:02",
"tests_total": 6... | typescript | {
"raw_signature": "function winningPlayerCount(n: number, pick: number[][]): number {",
"container": null,
"callable": "winningPlayerCount",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "pick",
"type": "number[][]"
}
],
"return_type": "number",
"sig... |
3,239 | minimum-number-of-flips-to-make-binary-grid-palindromic-i | Medium | You are given an m x n binary matrix grid.
A row or column is considered palindromic if its values read the same forward and backward.
You can flip any number of cells in grid from 0 to 1, or from 1 to 0.
Return the minimum number of cells that need to be flipped to make either all rows palindromic or all columns pa... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 0, 1, 1], [1, 1, 0, 0], [1, 0, 1, 0]]) == 2\n assert candidate(grid = [[1], [0]]) == 0\n assert candidate(grid = [[0, 1], [0, 1], [0, 0]]) == 1\n assert candidate(grid = [[1, 1, 0], [0, 1, 0], [0, 1, 1]]) == 2\n a... | [
"[[1,0,0],[0,0,0],[0,0,1]]",
"[[0,1],[0,1],[0,0]]",
"[[1],[0]]"
] | [
"We need to perform the operation only when the equivalent element of i from the back is not equal."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().minFlips",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:05",
"tests_total": 77,
"tests_dropped... | typescript | {
"raw_signature": "function minFlips(grid: number[][]): number {",
"container": null,
"callable": "minFlips",
"parameters": [
{
"name": "grid",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,240 | minimum-number-of-flips-to-make-binary-grid-palindromic-ii | Medium | You are given an m x n binary matrix grid.
A row or column is considered palindromic if its values read the same forward and backward.
You can flip any number of cells in grid from 0 to 1, or from 1 to 0.
Return the minimum number of cells that need to be flipped to make all rows and columns palindromic, and the tot... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]]) == 0\n assert candidate(grid = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]) == 3\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1]]) == 1\n assert candidate(grid = ... | [
"[[1,0,0],[0,1,0],[0,0,1]]",
"[[0,1],[0,1],[0,0]]",
"[[1],[1]]"
] | [
"For each (x, y), find (m - 1 - x, y), (m - 1 - x, n - 1 - y), and (x, n - 1 - y); they should be the same.",
"Note that we need to specially handle the middle row (column) if the number of rows (columns) is odd."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().minFlips",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:07",
"tests_total": 88,
"tests_dropped... | typescript | {
"raw_signature": "function minFlips(grid: number[][]): number {",
"container": null,
"callable": "minFlips",
"parameters": [
{
"name": "grid",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,241 | time-taken-to-mark-all-nodes | Hard | There exists an undirected tree with n nodes numbered 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [u_i, v_i] indicates that there is an edge between nodes u_i and v_i in the tree.
Initially, all nodes are unmarked. For each node i:
- If i is odd, the node will get marked at ti... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(edges = [[0, 1], [0, 2]]) == [2, 4, 3]\n assert candidate(edges = [[3, 1], [3, 0], [1, 2]]) == [4, 3, 4, 3]\n assert candidate(edges = [[1, 0], [2, 0], [3, 0], [4, 1], [5, 2]]) == [3, 5, 5, 5, 6, 7]\n assert candidate(edges = [[... | [
"[[0,1],[0,2]]",
"[[0,1]]",
"[[2,4],[0,1],[2,3],[0,2]]"
] | [
"Can we use dp on trees?",
"Store the two most distant children for each node.",
"When re-rooting the tree, keep a variable for distance to the root node."
] | {
"canonical_parameter_names": [
"edges"
],
"leetcode_dataset_entry_point": "Solution().timeTaken",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:10",
"tests_total": 54,
"tests_dropp... | typescript | {
"raw_signature": "function timeTaken(edges: number[][]): number[] {",
"container": null,
"callable": "timeTaken",
"parameters": [
{
"name": "edges",
"type": "number[][]"
}
],
"return_type": "number[]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippe... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.