question_id int64 3.24k 3.51k | task_id stringclasses 201
values | difficulty stringclasses 3
values | problem_description stringclasses 201
values | canonical_tests dict | metadata dict | language stringclasses 9
values | interface dict |
|---|---|---|---|---|---|---|---|
3,243 | shortest-distance-after-road-addition-queries-i | Medium | You are given an integer n and a 2D integer array queries.
There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0 <= i < n - 1.
queries[i] = [ui, vi] represents the addition of a new unidirectional road from city ui to city vi. After each query, you ne... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 7,queries = [[0, 5], [1, 6], [2, 4]]) == [2, 2, 2]\n assert candidate(n = 8,queries = [[1, 5], [2, 6], [3, 7], [0, 4], [0, 6], [0, 7]]) == [4, 4, 4, 4, 2, 1]\n assert candidate(n = 6,queries = [[1, 3], [2, 5], [0, 3]]) == [4, 3... | {
"canonical_parameter_names": [
"n",
"queries"
],
"leetcode_dataset_entry_point": "Solution().shortestDistanceAfterQueries",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "shortestDistanceAfterQueries",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "queries",
"type": "vector<vector<int>>&"
}... |
3,244 | shortest-distance-after-road-addition-queries-ii | Hard | You are given an integer n and a 2D integer array queries.
There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0 <= i < n - 1.
queries[i] = [ui, vi] represents the addition of a new unidirectional road from city ui to city vi. After each query, you ne... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 7,queries = [[3, 6], [1, 3], [0, 1], [0, 6]]) == [4, 3, 3, 1]\n assert candidate(n = 8,queries = [[2, 7], [0, 2], [4, 6], [0, 4]]) == [3, 2, 2, 1]\n assert candidate(n = 5,queries = [[2, 4], [0, 2], [0, 4]]) == [3, 2, 1]\n a... | {
"canonical_parameter_names": [
"n",
"queries"
],
"leetcode_dataset_entry_point": "Solution().shortestDistanceAfterQueries",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "shortestDistanceAfterQueries",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "queries",
"type": "vector<vector<int>>&"
}... |
3,248 | snake-in-matrix | Easy | There is a snake in an n x n matrix grid and can move in four possible directions. Each cell in the grid is identified by the position: grid[i][j] = (i * n) + j.
The snake starts at cell 0 and follows a sequence of commands.
You are given an integer n representing the size of the grid and an array of strings commands w... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 2,commands = ['RIGHT', 'DOWN']) == 3\n assert candidate(n = 5,commands = ['RIGHT', 'DOWN', 'RIGHT', 'DOWN', 'RIGHT', 'DOWN']) == 18\n assert candidate(n = 10,commands = ['UP', 'LEFT', 'DOWN', 'RIGHT', 'UP', 'LEFT', 'DOWN', 'RIG... | {
"canonical_parameter_names": [
"n",
"commands"
],
"leetcode_dataset_entry_point": "Solution().finalPositionOfSnake",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "int finalPositionOfSnake(int n, vector<string>& commands) {",
"container": "Solution",
"callable": "finalPositionOfSnake",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "commands",
"type": "vector<string>&"
}
],
"return_type": "int",
... |
3,249 | count-the-number-of-good-nodes | Medium | There is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
A node is good if all the subtrees rooted at its children have the same size.
Ret... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 5], [1, 6], [2, 7], [3, 8]]) == 6\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [1, 4], [0, 5], [5, 6], [6, 7], [7, 8], [0, 9], [9, 10], [9, 12], [10, 11]]) == 12\n assert candidat... | {
"canonical_parameter_names": [
"edges"
],
"leetcode_dataset_entry_point": "Solution().countGoodNodes",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "int countGoodNodes(vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "countGoodNodes",
"parameters": [
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leet... |
3,250 | find-the-count-of-monotonic-pairs-i | Hard | You are given an array of positive integers nums of length n.
We call a pair of non-negative integer arrays (arr1, arr2) monotonic if:
The lengths of both arrays are n.
arr1 is monotonically non-decreasing, in other words, arr1[0] <= arr1[1] <= ... <= arr1[n - 1].
arr2 is monotonically non-increasing, in other words, ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [50, 1, 50, 1, 50]) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3]) == 84\n assert candidate(nums = [10, 20, 30, 40, 50]) == 3003\n assert candidate(nums = [5, 5, 5, 5]) == 126\n assert candidate(nums = [1, 2, 3, 4,... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countOfPairs",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "int countOfPairs(vector<int>& nums) {",
"container": "Solution",
"callable": "countOfPairs",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,251 | find-the-count-of-monotonic-pairs-ii | Hard | You are given an array of positive integers nums of length n.
We call a pair of non-negative integer arrays (arr1, arr2) monotonic if:
The lengths of both arrays are n.
arr1 is monotonically non-decreasing, in other words, arr1[0] <= arr1[1] <= ... <= arr1[n - 1].
arr2 is monotonically non-increasing, in other words, ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 3, 2]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 659632782\n assert candidate(nums = [1, 1, 1, 1, ... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countOfPairs",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "int countOfPairs(vector<int>& nums) {",
"container": "Solution",
"callable": "countOfPairs",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,254 | find-the-power-of-k-size-subarrays-i | Medium | You are given an array of integers nums of length n and a positive integer k.
The power of an array is defined as:
Its maximum element if all of its elements are consecutive and sorted in ascending order.
-1 otherwise.
You need to find the power of all subarrays of nums of size k.
Return an integer array results of s... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == [5]\n assert candidate(nums = [2, 2, 2, 2, 2],k = 4) == [-1, -1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11],k = 5) == [-1, -1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5],k = 4) == [-1, -1, ... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().resultsArray",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "vector<int> resultsArray(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "resultsArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "vector<int>",
"signature_sou... |
3,255 | find-the-power-of-k-size-subarrays-ii | Medium | You are given an array of integers nums of length n and a positive integer k.
The power of an array is defined as:
Its maximum element if all of its elements are consecutive and sorted in ascending order.
-1 otherwise.
You need to find the power of all subarrays of nums of size k.
Return an integer array results of s... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100, 101, 102, 103, 104, 105],k = 2) == [101, 102, 103, 104, 105]\n assert candidate(nums = [2, 2, 2, 2, 2],k = 4) == [-1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, ... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().resultsArray",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "vector<int> resultsArray(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "resultsArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "vector<int>",
"signature_sou... |
3,256 | maximum-value-sum-by-placing-three-rooks-i | Hard | You are given a m x n 2D array board representing a chessboard, where board[i][j] represents the value of the cell (i, j).
Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other.
Return the maximum sum of the cell values on which t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(board = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]) == 150\n assert candidate(board = [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]) == -15\n assert candidate(board = [[-3, 1, 1, 1], [-3, 1, -3, 1], [-3, 2, 1, 1]]) == 4\n assert ca... | {
"canonical_parameter_names": [
"board"
],
"leetcode_dataset_entry_point": "Solution().maximumValueSum",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "long long maximumValueSum(vector<vector<int>>& board) {",
"container": "Solution",
"callable": "maximumValueSum",
"parameters": [
{
"name": "board",
"type": "vector<vector<int>>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_... |
3,257 | maximum-value-sum-by-placing-three-rooks-ii | Hard | You are given a m x n 2D array board representing a chessboard, where board[i][j] represents the value of the cell (i, j).
Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other.
Return the maximum sum of the cell values on which t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(board = [[5, -2, 3, 7], [1, 8, -1, 2], [-4, 4, -3, 6], [3, 7, 5, -9]]) == 20\n assert candidate(board = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 3\n assert candidate(board = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [1... | {
"canonical_parameter_names": [
"board"
],
"leetcode_dataset_entry_point": "Solution().maximumValueSum",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "long long maximumValueSum(vector<vector<int>>& board) {",
"container": "Solution",
"callable": "maximumValueSum",
"parameters": [
{
"name": "board",
"type": "vector<vector<int>>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_... |
3,258 | count-substrings-that-satisfy-k-constraint-i | Easy | You are given a binary string s and an integer k.
A binary string satisfies the k-constraint if either of the following conditions holds:
The number of 0's in the string is at most k.
The number of 1's in the string is at most k.
Return an integer denoting the number of substrings of s that satisfy the k-constraint.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"0101010101\",k = 5) == 55\n assert candidate(s = \"11111\",k = 1) == 15\n assert candidate(s = \"00000\",k = 2) == 15\n assert candidate(s = \"101010101010\",k = 4) == 72\n assert candidate(s = \"100100100\",k = 3) == 4... | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().countKConstraintSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "int countKConstraintSubstrings(string s, int k) {",
"container": "Solution",
"callable": "countKConstraintSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": ... |
3,259 | maximum-energy-boost-from-two-drinks | Medium | You are given two integer arrays energyDrinkA and energyDrinkB of the same length n by a futuristic sports scientist. These arrays represent the energy boosts per hour provided by two different energy drinks, A and B, respectively.
You want to maximize your total energy boost by drinking one energy drink per hour. Howe... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(energyDrinkA = [1, 1, 1, 1, 1, 1],energyDrinkB = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(energyDrinkA = [1, 100000, 1],energyDrinkB = [100000, 1, 100000]) == 200001\n assert candidate(energyDrinkA = [4, 1, 1],energyDrinkB = [1,... | {
"canonical_parameter_names": [
"energyDrinkA",
"energyDrinkB"
],
"leetcode_dataset_entry_point": "Solution().maxEnergyBoost",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "long long maxEnergyBoost(vector<int>& energyDrinkA, vector<int>& energyDrinkB) {",
"container": "Solution",
"callable": "maxEnergyBoost",
"parameters": [
{
"name": "energyDrinkA",
"type": "vector<int>&"
},
{
"name": "energyDrinkB",
"type": "vector<int>&"
... |
3,260 | find-the-largest-palindrome-divisible-by-k | Hard | You are given two positive integers n and k.
An integer x is called k-palindromic if:
x is a palindrome.
x is divisible by k.
Return the largest integer having n digits (as a string) that is k-palindromic.
Note that the integer must not have leading zeros.
Example 1:
Input: n = 3, k = 5
Output: "595"
Explanation:
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 1,k = 4) == \"8\"\n assert candidate(n = 6,k = 9) == \"999999\"\n assert candidate(n = 6,k = 7) == \"999999\"\n assert candidate(n = 3,k = 5) == \"595\"\n assert candidate(n = 5,k = 6) == \"89898\"\n assert candidate(n... | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().largestPalindrome",
"problem_source": "newfacade/LeetCodeDataset",
"interface_source": "leetcode/codeSnippets"
} | cpp | {
"raw_signature": "string largestPalindrome(int n, int k) {",
"container": "Solution",
"callable": "largestPalindrome",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnip... |
End of preview. Expand in Data Studio
LeetCode multilingual benchmark dataset
Post-interface rows for the msl-multilingual-self-learning benchmark, flattened to
one row per (problem, language). Each row has the single interface for its
language (python, cpp, go, java, rust, javascript, typescript, php, ruby), plus
the shared canonical_tests (a Python check(candidate) oracle), problem_description,
and metadata. Stored as data/<split>/<lang>-NNN.jsonl (row-boundary shards so
every file stays under HF's ~10 MiB per-file ceiling); HF globs them into a single
split.
Splits
train: 2274 problems x 9 languages (2641 in source; 367 lack complete interfaces).test: 201 problems x 9 languages = 1809 rows (held-out eval).
Load
from datasets import load_dataset
train = load_dataset("neulab/leetcode", split="train") # one Dataset, all rows
test = load_dataset("neulab/leetcode", split="test") # one Dataset, 1809 rows
python_rows = test.filter(lambda r: r["language"] == "python")
- Downloads last month
- -