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 |
|---|---|---|---|---|---|---|---|---|---|
994 | rotting-oranges | Medium | You are given an m x n grid where each cell can have one of three values:
- 0 representing an empty cell,
- 1 representing a fresh orange, or
- 2 representing a rotten orange.
Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten.
Return the minimum number of minutes that ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == -1\n assert candidate(grid = [[1, 2, 1, 1, 2, 1, 1]]) == 2\n assert candidate(grid = [[2, 2, 2], [2, 1, 2], [2, 2, 2]]) == 1\n assert candidate(grid = [[2, 1, 1], [0, 1, 1], [1, 0, 1]... | [
"[[2,1,1],[1,1,0],[0,1,1]]",
"[[2,1,1],[0,1,1],[1,0,1]]",
"[[0,2]]"
] | [] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().orangesRotting",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:04",
"tests_total": 96,
"tests_d... | cpp | {
"raw_signature": "int orangesRotting(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "orangesRotting",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
995 | minimum-number-of-k-consecutive-bit-flips | Hard | You are given a binary array nums and an integer k.
A k-bit flip is choosing a subarray of length k from nums and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of k-bit flips required so that there is no 0 in the array. If it is not possible, return ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [0, 0, 1, 1, 0, 1, 1, 0, 1, 0],k = 2) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0],k = 3) == 3\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0],k = 4) == 4\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1],... | [
"[0,1,0]\n1",
"[1,1,0]\n2",
"[0,0,0,1,0,1,1,0]\n3"
] | [] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().minKBitFlips",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:07",
"tests_total": 100,
... | cpp | {
"raw_signature": "int minKBitFlips(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "minKBitFlips",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/... |
996 | number-of-squareful-arrays | Hard | An array is squareful if the sum of every pair of adjacent elements is a perfect square.
Given an integer array nums, return the number of permutations of nums that are squareful.
Two permutations perm1 and perm2 are different if there is some index i such that perm1[i] != perm2[i].
Example 1:
Input: nums = [1,17,8... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [9, 0, 16, 25, 36]) == 0\n assert candidate(nums = [2, 2, 2]) == 1\n assert candidate(nums = [1, 17, 8]) == 2\n assert candidate(nums = [9, 0, 9]) == 1\n assert candidate(nums = [0, 0, 0]) == 1\n assert candidate(nu... | [
"[1,17,8]",
"[2,2,2]"
] | [] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().numSquarefulPerms",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:09",
"tests_total": 109,
"tes... | cpp | {
"raw_signature": "int numSquarefulPerms(vector<int>& nums) {",
"container": "Solution",
"callable": "numSquarefulPerms",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
997 | find-the-town-judge | Easy | In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge.
If the town judge exists, then:
1. The town judge trusts nobody.
2. Everybody (except for the town judge) trusts the town judge.
3. There is exactly one person that satisfies properties 1 and 2.
Y... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,trust = [[1, 3], [1, 4], [2, 3], [2, 4], [4, 3]]) == 3\n assert candidate(n = 1,trust = []) == 1\n assert candidate(n = 5,trust = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]) == -1\n assert candidate(n = 3,trust = [[1, 3], [2... | [
"2\n[[1,2]]",
"3\n[[1,3],[2,3]]",
"3\n[[1,3],[2,3],[3,1]]"
] | [] | {
"canonical_parameter_names": [
"n",
"trust"
],
"leetcode_dataset_entry_point": "Solution().findJudge",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:11",
"tests_total": 86,
"te... | cpp | {
"raw_signature": "int findJudge(int n, vector<vector<int>>& trust) {",
"container": "Solution",
"callable": "findJudge",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "trust",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source"... |
999 | available-captures-for-rook | Easy | You are given an 8 x 8 matrix representing a chessboard. There is exactly one white rook represented by 'R', some number of white bishops 'B', and some number of black pawns 'p'. Empty squares are represented by '.'.
A rook can move any number of squares horizontally or vertically (up, down, left, right) until it reac... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(board = [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', 'p', '.', '.', '.', '.'], ['.', '.', '.', 'p', '.', '.', '.', '.'], ['p', 'p', '.', 'R', '.', 'p', 'B', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', 'B... | [
"[[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"R\",\".\",\".\",\".\",\"p\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\... | [] | {
"canonical_parameter_names": [
"board"
],
"leetcode_dataset_entry_point": "Solution().numRookCaptures",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:16",
"tests_total": 58,
"tests... | cpp | {
"raw_signature": "int numRookCaptures(vector<vector<char>>& board) {",
"container": "Solution",
"callable": "numRookCaptures",
"parameters": [
{
"name": "board",
"type": "vector<vector<char>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
1,000 | minimum-cost-to-merge-stones | Hard | There are n piles of stones arranged in a row. The i^th pile has stones[i] stones.
A move consists of merging exactly k consecutive piles into one pile, and the cost of this move is equal to the total number of stones in these k piles.
Return the minimum cost to merge all piles of stones into one pile. If it is impos... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == -1\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 2) == 135\n assert candidate(stones = [3, 2, 4, 1],k = 3) == -1\n assert candidate(stones = [1, 2, 3, 4, 5],k = 3)... | [
"[3,2,4,1]\n2",
"[3,2,4,1]\n3",
"[3,5,1,2,6]\n3"
] | [] | {
"canonical_parameter_names": [
"stones",
"k"
],
"leetcode_dataset_entry_point": "Solution().mergeStones",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:18",
"tests_total": 235,
... | cpp | {
"raw_signature": "int mergeStones(vector<int>& stones, int k) {",
"container": "Solution",
"callable": "mergeStones",
"parameters": [
{
"name": "stones",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcod... |
1,001 | grid-illumination | Hard | There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.
You are given a 2D array of lamp positions lamps, where lamps[i] = [row_i, col_i] indicates that the lamp at grid[row_i][col_i] is turned on. Even if the same lamp is listed more than once, it is turned on.
When a l... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,lamps = [[0, 0], [4, 4]],queries = [[1, 1], [1, 1]]) == [1, 1]\n assert candidate(n = 5,lamps = [[0, 0], [0, 4]],queries = [[0, 4], [0, 1], [1, 4]]) == [1, 1, 0]\n assert candidate(n = 5,lamps = [[0, 0], [4, 4]],queries = [[1... | [
"5\n[[0,0],[4,4]]\n[[1,1],[1,0]]",
"5\n[[0,0],[4,4]]\n[[1,1],[1,1]]",
"5\n[[0,0],[0,4]]\n[[0,4],[0,1],[1,4]]"
] | [] | {
"canonical_parameter_names": [
"n",
"lamps",
"queries"
],
"leetcode_dataset_entry_point": "Solution().gridIllumination",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:20",
"t... | cpp | {
"raw_signature": "vector<int> gridIllumination(int n, vector<vector<int>>& lamps, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "gridIllumination",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "lamps",
"type": "vector<vector<int>>&"
... |
1,002 | find-common-characters | Easy | Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.
Example 1:
Input: words = ["bella","label","roller"]
Output: ["e","l","l"]
Example 2:
Input: words = ["cool","lock","cook"]
Output: ["c","o"]
Co... | {
"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 ... | [
"[\"bella\",\"label\",\"roller\"]",
"[\"cool\",\"lock\",\"cook\"]"
] | [] | {
"canonical_parameter_names": [
"words"
],
"leetcode_dataset_entry_point": "Solution().commonChars",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:22",
"tests_total": 103,
"tests_dr... | cpp | {
"raw_signature": "vector<string> commonChars(vector<string>& words) {",
"container": "Solution",
"callable": "commonChars",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
}
],
"return_type": "vector<string>",
"signature_source": "leetcode/codeSnippets",
"type_source":... |
1,003 | check-if-word-is-valid-after-substitutions | Medium | Given a string s, determine if it is valid.
A string s is valid if, starting with an empty string t = "", you can transform t into s after performing the following operation any number of times:
- Insert string "abc" into any position in t. More formally, t becomes t_left + "abc" + t_right, where t == t_left + t_righ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aaabbbccc\") == False\n assert candidate(s = \"aababcbccabc\") == False\n assert candidate(s = \"cababc\") == False\n assert candidate(s = \"abcabcabc\") == True\n assert candidate(s = \"aababcbabc\") == False\n asse... | [
"\"aabcbc\"",
"\"abcabcababcc\"",
"\"abccba\""
] | [] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().isValid",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:24",
"tests_total": 140,
"tests_dropped": ... | cpp | {
"raw_signature": "bool isValid(string s) {",
"container": "Solution",
"callable": "isValid",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,004 | max-consecutive-ones-iii | Medium | Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.
Example 1:
Input: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2
Output: 6
Explanation: [1,1,1,0,0,1,1,1,1,1,1]
Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
Exam... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0],k = 2) == 4\n assert candidate(nums = [0, 0, 0, 0],k = 2) == 2\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0],k = 2) == 5\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1... | [
"[1,1,1,0,0,0,1,1,1,1,0]\n2",
"[0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1]\n3"
] | [
"One thing's for sure, we will only flip a zero if it extends an existing window of 1s. Otherwise, there's no point in doing it, right? Think Sliding Window!",
"Since we know this problem can be solved using the sliding window construct, we might as well focus in that direction for hints. Basically, in a given wi... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().longestOnes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:26",
"tests_total": 77,
"t... | cpp | {
"raw_signature": "int longestOnes(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "longestOnes",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/co... |
1,005 | maximize-sum-of-array-after-k-negations | Easy | Given an integer array nums and an integer k, modify the array in the following way:
- choose an index i and replace nums[i] with -nums[i].
You should apply this process exactly k times. You may choose the same index i multiple times.
Return the largest possible sum of the array after modifying it in this way.
Exam... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [-5, -4, -3, -2, -1],k = 5) == 15\n assert candidate(nums = [0, 0, 0, 0],k = 3) == 0\n assert candidate(nums = [4, 2, 3],k = 1) == 5\n assert candidate(nums = [100, -100, 50, -50],k = 3) == 200\n assert candidate(nums ... | [
"[4,2,3]\n1",
"[3,-1,0,2]\n3",
"[2,-3,-1,5,-4]\n2"
] | [] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().largestSumAfterKNegations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:29",
"tests_to... | cpp | {
"raw_signature": "int largestSumAfterKNegations(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "largestSumAfterKNegations",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"sig... |
1,006 | clumsy-factorial | Medium | The factorial of a positive integer n is the product of all positive integers less than or equal to n.
- For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.
We make a clumsy factorial using the integers in decreasing order by swapping out the multiply operations for a fixed rotation of operations wit... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 8) == 9\n assert candidate(n = 3) == 6\n assert candidate(n = 100) == 101\n assert candidate(n = 4) == 7\n assert candidate(n = 10000) == 10001\n assert candidate(n = 9) == 11\n assert candidate(n = 5000) == 5001\n ... | [
"4",
"10"
] | [] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().clumsy",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:31",
"tests_total": 38,
"tests_dropped": 0,... | cpp | {
"raw_signature": "int clumsy(int n) {",
"container": "Solution",
"callable": "clumsy",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,007 | minimum-domino-rotations-for-equal-row | Medium | In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the i^th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i^th domino, so that tops[i] and bottoms[i] swap values.
Return the minimum number of rotations so that all the value... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(tops = [2, 3, 2, 2],bottoms = [1, 2, 2, 2]) == 1\n assert candidate(tops = [2, 3, 2, 1, 2],bottoms = [1, 2, 3, 2, 2]) == 2\n assert candidate(tops = [6, 6, 6, 6, 6, 6],bottoms = [6, 6, 6, 6, 6, 6]) == 0\n assert candidate(tops =... | [
"[2,1,2,4,2,2]\n[5,2,6,2,3,2]",
"[3,5,1,2,3]\n[3,6,3,3,4]"
] | [] | {
"canonical_parameter_names": [
"tops",
"bottoms"
],
"leetcode_dataset_entry_point": "Solution().minDominoRotations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:33",
"tests_tot... | cpp | {
"raw_signature": "int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {",
"container": "Solution",
"callable": "minDominoRotations",
"parameters": [
{
"name": "tops",
"type": "vector<int>&"
},
{
"name": "bottoms",
"type": "vector<int>&"
}
],
"return_type... |
1,009 | complement-of-base-10-integer | Easy | The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.
- For example, The integer 5 is "101" in binary and its complement is "010" which is the integer 2.
Given an integer n, return its complement.
Example 1:
Input: n = 5
Output: 2
E... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 0) == 1\n assert candidate(n = 8) == 7\n assert candidate(n = 100) == 27\n assert candidate(n = 15) == 0\n assert candidate(n = 31) == 0\n assert candidate(n = 123456789) == 10760938\n assert candidate(n = 1) == 0\n... | [
"5",
"7",
"10"
] | [
"A binary number plus its complement will equal 111....111 in binary. Also, N = 0 is a corner case."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().bitwiseComplement",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:37",
"tests_total": 37,
"tests_d... | cpp | {
"raw_signature": "int bitwiseComplement(int n) {",
"container": "Solution",
"callable": "bitwiseComplement",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,010 | pairs-of-songs-with-total-durations-divisible-by-60 | Medium | You are given a list of songs where the i^th song has a duration of time[i] seconds.
Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0.
Example 1:
Input: time = [30,20,150,1... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(time = [1, 3, 5, 7, 9, 11]) == 0\n assert candidate(time = [40, 20, 50, 30, 10]) == 2\n assert candidate(time = [60, 120, 180, 240, 300]) == 10\n assert candidat... | [
"[30,20,150,100,40]",
"[60,60,60]"
] | [
"We only need to consider each song length modulo 60.",
"We can count the number of songs having same (length % 60), and store that in an array of size 60."
] | {
"canonical_parameter_names": [
"time"
],
"leetcode_dataset_entry_point": "Solution().numPairsDivisibleBy60",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:40",
"tests_total": 89,
"... | cpp | {
"raw_signature": "int numPairsDivisibleBy60(vector<int>& time) {",
"container": "Solution",
"callable": "numPairsDivisibleBy60",
"parameters": [
{
"name": "time",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
1,011 | capacity-to-ship-packages-within-d-days | Medium | A conveyor belt has packages that must be shipped from one port to another within days days.
The i^th package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(weights = [10, 50, 100, 100, 50, 10],days = 2) == 160\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],days = 5) == 15\n assert candidate(weights = [10, 50, 100, 100, 50, 10],days = 3) == 160\n assert candidate(weigh... | [
"[1,2,3,4,5,6,7,8,9,10]\n5",
"[3,2,2,4,1,4]\n3",
"[1,2,3,1,1]\n4"
] | [
"Binary search on the answer. We need a function possible(capacity) which returns true if and only if we can do the task in D days."
] | {
"canonical_parameter_names": [
"weights",
"days"
],
"leetcode_dataset_entry_point": "Solution().shipWithinDays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:42",
"tests_total":... | cpp | {
"raw_signature": "int shipWithinDays(vector<int>& weights, int days) {",
"container": "Solution",
"callable": "shipWithinDays",
"parameters": [
{
"name": "weights",
"type": "vector<int>&"
},
{
"name": "days",
"type": "int"
}
],
"return_type": "int",
"signature_sou... |
1,012 | numbers-with-repeated-digits | Hard | Given an integer n, return the number of positive integers in the range [1, n] that have at least one repeated digit.
Example 1:
Input: n = 20
Output: 1
Explanation: The only positive number (<= 20) with at least 1 repeated digit is 11.
Example 2:
Input: n = 100
Output: 10
Explanation: The positive numbers (<= 100)... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 99999) == 67509\n assert candidate(n = 999999999) == 994388229\n assert candidate(n = 9999999) == 9287109\n assert candidate(n = 100) == 10\n assert candidate(n = 56789) == 37493\n assert candidate(n = 1000) == 262\n ... | [
"20",
"100",
"1000"
] | [
"How many numbers with no duplicate digits? How many numbers with K digits and no duplicates?",
"How many numbers with same length as N? How many numbers with same prefix as N?"
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().numDupDigitsAtMostN",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:44",
"tests_total": 59,
"tests... | cpp | {
"raw_signature": "int numDupDigitsAtMostN(int n) {",
"container": "Solution",
"callable": "numDupDigitsAtMostN",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,013 | partition-array-into-three-parts-with-equal-sum | Easy | Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.
Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[arr.length - ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000]) == True\n assert candidate(arr = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == False\n assert candidate(arr = [10, -10, 10, -10, 10, -10, ... | [
"[0,2,1,-6,6,-7,9,1,2,0,1]",
"[0,2,1,-6,6,7,9,-1,2,0,1]",
"[3,3,6,5,-2,2,5,1,-9,4]"
] | [
"If we have three parts with the same sum, what is the sum of each? If you can find the first part, can you find the second part?"
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().canThreePartsEqualSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:46",
"tests_total": 77,
"t... | cpp | {
"raw_signature": "bool canThreePartsEqualSum(vector<int>& arr) {",
"container": "Solution",
"callable": "canThreePartsEqualSum",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
1,014 | best-sightseeing-pair | Medium | You are given an integer array values where values[i] represents the value of the i^th sightseeing spot. Two sightseeing spots i and j have a distance j - i between them.
The score of a pair (i < j) of sightseeing spots is values[i] + values[j] + i - j: the sum of the values of the sightseeing spots, minus the distanc... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(values = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991]) == 1998\n assert candidate(values = [1, 3, 5, 7, 9, 11]) == 19\n assert candidate(values = [10, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 10\n assert candidate(values = [1, 100,... | [
"[8,1,5,2,6]",
"[1,2]"
] | [
"Can you tell the best sightseeing spot in one pass (ie. as you iterate over the input?) What should we store or keep track of as we iterate to do this?"
] | {
"canonical_parameter_names": [
"values"
],
"leetcode_dataset_entry_point": "Solution().maxScoreSightseeingPair",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:48",
"tests_total": 106... | cpp | {
"raw_signature": "int maxScoreSightseeingPair(vector<int>& values) {",
"container": "Solution",
"callable": "maxScoreSightseeingPair",
"parameters": [
{
"name": "values",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
1,015 | smallest-integer-divisible-by-k | Medium | Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.
Return the length of n. If there is no such n, return -1.
Note: n may not fit in a 64-bit signed integer.
Example 1:
Input: k = 1
Output: 1
Explanation: The smal... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(k = 29) == 28\n assert candidate(k = 101) == 4\n assert candidate(k = 83) == 41\n assert candidate(k = 43) == 21\n assert candidate(k = 89) == 44\n assert candidate(k = 17) == 16\n assert candidate(k = 73) == 8\n ass... | [
"1",
"2",
"3"
] | [
"11111 = 1111 * 10 + 1 We only need to store remainders modulo K.",
"If we never get a remainder of 0, why would that happen, and how would we know that?"
] | {
"canonical_parameter_names": [
"k"
],
"leetcode_dataset_entry_point": "Solution().smallestRepunitDivByK",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:51",
"tests_total": 90,
"tes... | cpp | {
"raw_signature": "int smallestRepunitDivByK(int k) {",
"container": "Solution",
"callable": "smallestRepunitDivByK",
"parameters": [
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,016 | binary-string-with-substrings-representing-1-to-n | Medium | Given a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise.
A substring is a contiguous sequence of characters within a string.
Example 1:
Input: s = "0110", n = 3
Output: true
Example 2:
Input: s = "011... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"0110\",n = 3) == True\n assert candidate(s = \"1111111111\",n = 10) == False\n assert candidate(s = \"0000000000\",n = 1) == False\n assert candidate(s = \"0110\",n = 4) == False\n assert candidate(s = \"000000\",n = 1)... | [
"\"0110\"\n3",
"\"0110\"\n4"
] | [
"We only need to check substrings of length at most 30, because 10^9 has 30 bits."
] | {
"canonical_parameter_names": [
"s",
"n"
],
"leetcode_dataset_entry_point": "Solution().queryString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:53",
"tests_total": 96,
"test... | cpp | {
"raw_signature": "bool queryString(string s, int n) {",
"container": "Solution",
"callable": "queryString",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "n",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"... |
1,017 | convert-to-base-2 | Medium | Given an integer n, return a binary string representing its representation in base -2.
Note that the returned string should not have leading zeros unless the string is "0".
Example 1:
Input: n = 2
Output: "110"
Explantion: (-2)^2 + (-2)^1 = 2
Example 2:
Input: n = 3
Output: "111"
Explantion: (-2)^2 + (-2)^1 + (-2)... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3) == \"111\"\n assert candidate(n = 104730) == \"1101110100101101110\"\n assert candidate(n = 100) == \"110100100\"\n assert candidate(n = 1000) == \"10000111000\"\n assert candidate(n = 5) == \"101\"\n assert candida... | [
"2",
"3",
"4"
] | [
"Figure out whether you need the ones digit placed or not, then shift by two."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().baseNeg2",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:55",
"tests_total": 69,
"tests_dropped": ... | cpp | {
"raw_signature": "string baseNeg2(int n) {",
"container": "Solution",
"callable": "baseNeg2",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,018 | binary-prefix-divisible-by-5 | Easy | You are given a binary array nums (0-indexed).
We define x_i as the number whose binary representation is the subarray nums[0..i] (from most-significant-bit to least-significant-bit).
- For example, if nums = [1,0,1], then x_0 = 1, x_1 = 2, and x_2 = 5.
Return an array of booleans answer where answer[i] is true if x... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1]) == [False]\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == [True, False, False, True, True, False, False, True, True, False]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [False, False, False... | [
"[0,1,1]",
"[1,1,1]"
] | [
"If X is the first i digits of the array as a binary number, then 2X + A[i] is the first i+1 digits."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().prefixesDivBy5",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:07:57",
"tests_total": 69,
"tests_d... | cpp | {
"raw_signature": "vector<bool> prefixesDivBy5(vector<int>& nums) {",
"container": "Solution",
"callable": "prefixesDivBy5",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<bool>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leet... |
1,020 | number-of-enclaves | Medium | You are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell.
A move consists of walking from one land cell to another adjacent (4-directionally) land cell or walking off the boundary of the grid.
Return the number of land cells in grid for which we cannot walk off the boundar... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0, 0], [1, 0, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]) == 3\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 = [[0, 1, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0], [0,... | [
"[[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]",
"[[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]]"
] | [
"Can you model this problem as a graph problem? Create n * m + 1 nodes where n * m nodes represents each cell of the map and one extra node to represent the exterior of the map.",
"In the map add edges between neighbors on land cells. And add edges between the exterior and land nodes which are in the boundary. Re... | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().numEnclaves",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:01",
"tests_total": 67,
"tests_drop... | cpp | {
"raw_signature": "int numEnclaves(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "numEnclaves",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,021 | remove-outermost-parentheses | Easy | A valid parentheses string is either empty "", "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation.
- For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings.
A valid parentheses string s is primitive if it is nonempty, and there does n... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"(()(()))()\") == \"()(())\"\n assert candidate(s = \"()\") == \"\"\n assert candidate(s = \"()(()())\") == \"()()\"\n assert candidate(s = \"(()())(())\") == \"()()()\"\n assert candidate(s = \"((()))\") == \"(())\"\n ... | [
"\"(()())(())\"",
"\"(()())(())(()(()))\"",
"\"()()\""
] | [
"Can you find the primitive decomposition? The number of ( and ) characters must be equal."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().removeOuterParentheses",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:04",
"tests_total": 103,
"t... | cpp | {
"raw_signature": "string removeOuterParentheses(string s) {",
"container": "Solution",
"callable": "removeOuterParentheses",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,023 | camelcase-matching | Medium | Given an array of strings queries and a string pattern, return a boolean array answer where answer[i] is true if queries[i] matches pattern, and false otherwise.
A query word queries[i] matches pattern if you can insert lowercase English letters into the pattern so that it equals the query. You may insert a character ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(queries = ['FooBar', 'FooBarTest', 'FootBall', 'FrameBuffer', 'ForceFeedBack'],pattern = \"FB\") == [True, False, True, True, False]\n assert candidate(queries = ['FooBar', 'FooBarTest', 'FootBall', 'FrameBuffer', 'ForceFeedBack'],pat... | [
"[\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"]\n\"FB\"",
"[\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"]\n\"FoBa\"",
"[\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"]\n\"FoBaT\""
] | [
"Given a single pattern and word, how can we solve it?",
"One way to do it is using a DP (pos1, pos2) where pos1 is a pointer to the word and pos2 to the pattern and returns true if we can match the pattern with the given word.",
"We have two scenarios: The first one is when `word[pos1] == pattern[pos2]`, then ... | {
"canonical_parameter_names": [
"queries",
"pattern"
],
"leetcode_dataset_entry_point": "Solution().camelMatch",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:08",
"tests_total": ... | cpp | {
"raw_signature": "vector<bool> camelMatch(vector<string>& queries, string pattern) {",
"container": "Solution",
"callable": "camelMatch",
"parameters": [
{
"name": "queries",
"type": "vector<string>&"
},
{
"name": "pattern",
"type": "string"
}
],
"return_type": "vec... |
1,024 | video-stitching | Medium | You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array clips where clips[i] = [start_i, end_i] indicates that the ith clip started at start_i and ended at end_i.
We ca... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(clips = [[0, 5], [0, 7], [1, 3], [1, 4], [2, 5], [2, 6], [3, 4], [3, 5], [4, 5], [4, 6], [5, 6], [5, 7], [6, 7], [6, 8], [7, 8], [7, 10], [7, 9], [8, 10], [9, 10]],time = 10) == 2\n assert candidate(clips = [[0, 2], [4, 6], [8, 10], [... | [
"[[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]]\n10",
"[[0,1],[1,2]]\n5",
"[[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]]\n9"
] | [
"What if we sort the intervals? Considering the sorted intervals, how can we solve the problem with dynamic programming?",
"Let's consider a DP(pos, limit) where pos represents the position of the current interval we are gonna take the decision and limit is the current covered area from [0 - limit]. This DP retur... | {
"canonical_parameter_names": [
"clips",
"time"
],
"leetcode_dataset_entry_point": "Solution().videoStitching",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:10",
"tests_total": 9... | cpp | {
"raw_signature": "int videoStitching(vector<vector<int>>& clips, int time) {",
"container": "Solution",
"callable": "videoStitching",
"parameters": [
{
"name": "clips",
"type": "vector<vector<int>>&"
},
{
"name": "time",
"type": "int"
}
],
"return_type": "int",
"s... |
1,025 | divisor-game | Easy | Alice and Bob take turns playing a game, with Alice starting first.
Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:
- Choosing any integer x with 0 < x < n and n % x == 0.
- Replacing the number n on the chalkboard with n - x.
Also, if a player cannot ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 8) == True\n assert candidate(n = 3) == False\n assert candidate(n = 4) == True\n assert candidate(n = 9) == False\n assert candidate(n = 6) == True\n assert candidate(n = 2) == True\n assert candidate(n = 1000) == ... | [
"2",
"3"
] | [
"If the current number is even, we can always subtract a 1 to make it odd. If the current number is odd, we must subtract an odd number to make it even."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().divisorGame",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:12",
"tests_total": 51,
"tests_dropped... | cpp | {
"raw_signature": "bool divisorGame(int n) {",
"container": "Solution",
"callable": "divisorGame",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,027 | longest-arithmetic-subsequence | Medium | Given an array nums of integers, return the length of the longest arithmetic subsequence in nums.
Note that:
- A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
- A sequence seq is arithmetic if seq[i + 1] - seq[i] ar... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 11, 11, 11, 15]) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == 8\n assert candidate(nums = [83, 20, 17, 43, 52, 78, 68, 45]) == 2\n assert candidate(nums = [8, 12, 16, 20, 24, 28]) == 6\n ass... | [
"[3,6,9,12]",
"[9,4,7,2,10]",
"[20,1,15,3,10,5,8]"
] | [] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().longestArithSeqLength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:17",
"tests_total": 159,
... | cpp | {
"raw_signature": "int longestArithSeqLength(vector<int>& nums) {",
"container": "Solution",
"callable": "longestArithSeqLength",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
1,029 | two-city-scheduling | Medium | A company is planning to interview 2n people. Given the array costs where costs[i] = [aCost_i, bCost_i], the cost of flying the i^th person to city a is aCost_i, and the cost of flying the i^th person to city b is bCost_i.
Return the minimum cost to fly every person to a city such that exactly n people arrive in each ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(costs = [[30, 20], [200, 300], [50, 400], [20, 30]]) == 300\n assert candidate(costs = [[10, 20], [30, 200], [400, 50], [30, 20]]) == 110\n assert candidate(costs = [[515, 563], [451, 713], [537, 709], [343, 819], [855, 779], [457,... | [
"[[10,20],[30,200],[400,50],[30,20]]",
"[[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]]",
"[[515,563],[451,713],[537,709],[343,819],[855,779],[457,60],[650,359],[631,42]]"
] | [] | {
"canonical_parameter_names": [
"costs"
],
"leetcode_dataset_entry_point": "Solution().twoCitySchedCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:22",
"tests_total": 68,
"test... | cpp | {
"raw_signature": "int twoCitySchedCost(vector<vector<int>>& costs) {",
"container": "Solution",
"callable": "twoCitySchedCost",
"parameters": [
{
"name": "costs",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
1,030 | matrix-cells-in-distance-order | Easy | You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter).
Return the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from the smallest distance to the largest distance. You may ret... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(rows = 5,cols = 7,rCenter = 3,cCenter = 4) == [[3, 4], [2, 4], [3, 5], [4, 4], [3, 3], [1, 4], [2, 5], [2, 3], [3, 6], [4, 5], [4, 3], [3, 2], [0, 4], [1, 5], [1, 3], [2, 6], [2, 2], [4, 6], [4, 2], [3, 1], [0, 5], [0, 3], [1, 6], [1, 2]... | [
"1\n2\n0\n0",
"2\n2\n0\n1",
"2\n3\n1\n2"
] | [] | {
"canonical_parameter_names": [
"rows",
"cols",
"rCenter",
"cCenter"
],
"leetcode_dataset_entry_point": "Solution().allCellsDistOrder",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-... | cpp | {
"raw_signature": "vector<vector<int>> allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {",
"container": "Solution",
"callable": "allCellsDistOrder",
"parameters": [
{
"name": "rows",
"type": "int"
},
{
"name": "cols",
"type": "int"
},
{
"name": ... |
1,031 | maximum-sum-of-two-non-overlapping-subarrays | Medium | Given an integer array nums and two integers firstLen and secondLen, return the maximum sum of elements in two non-overlapping subarrays with lengths firstLen and secondLen.
The array with length firstLen could occur before or after the array with length secondLen, but they have to be non-overlapping.
A subarray is a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1],firstLen = 3,secondLen = 3) == 6\n assert candidate(nums = [0, 6, 5, 2, 2, 5, 1, 9, 4],firstLen = 1,secondLen = 2) == 20\n assert candidate(nums = [2, 1, 5, 6, 0, 9, 5, 0, 3, 8],firstLen = 4,secon... | [
"[0,6,5,2,2,5,1,9,4]\n1\n2",
"[3,8,1,3,2,1,8,9,0]\n3\n2",
"[2,1,5,6,0,9,5,0,3,8]\n4\n3"
] | [
"We can use prefix sums to calculate any subarray sum quickly. For each L length subarray, find the best possible M length subarray that occurs before and after it."
] | {
"canonical_parameter_names": [
"nums",
"firstLen",
"secondLen"
],
"leetcode_dataset_entry_point": "Solution().maxSumTwoNoOverlap",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08... | cpp | {
"raw_signature": "int maxSumTwoNoOverlap(vector<int>& nums, int firstLen, int secondLen) {",
"container": "Solution",
"callable": "maxSumTwoNoOverlap",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "firstLen",
"type": "int"
},
{
"name":... |
1,033 | moving-stones-until-consecutive | Medium | There are three stones in different positions on the X-axis. You are given three integers a, b, and c, the positions of the stones.
In one move, you pick up a stone at an endpoint (i.e., either the lowest or highest position stone), and move it to an unoccupied position between those endpoints. Formally, let's say the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(a = 7,b = 8,c = 10) == [1, 1]\n assert candidate(a = 1,b = 100,c = 50) == [2, 97]\n assert candidate(a = 1,b = 3,c = 100) == [1, 97]\n assert candidate(a = 10,b = 12,c = 14) == [1, 2]\n assert candidate(a = 50,b = 51,c = 53) ... | [
"1\n2\n5",
"4\n3\n2",
"3\n5\n1"
] | [
"For the minimum: We can always do it in at most 2 moves, by moving one stone next to another, then the third stone next to the other two. When can we do it in 1 move? 0 moves? For the maximum: Every move, the maximum position minus the minimum position must decrease by at least 1."
] | {
"canonical_parameter_names": [
"a",
"b",
"c"
],
"leetcode_dataset_entry_point": "Solution().numMovesStones",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:28",
"tests_total":... | cpp | {
"raw_signature": "vector<int> numMovesStones(int a, int b, int c) {",
"container": "Solution",
"callable": "numMovesStones",
"parameters": [
{
"name": "a",
"type": "int"
},
{
"name": "b",
"type": "int"
},
{
"name": "c",
"type": "int"
}
],
"return... |
1,034 | coloring-a-border | Medium | You are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at that location.
Two squares are called adjacent if they are next to each other in any of the 4 directions.
Two squares belong to the same connected component if they hav... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1000, 1000, 1000], [1000, 1, 1000], [1000, 1000, 1000]],row = 1,col = 1,color = 2) == [[1000, 1000, 1000], [1000, 2, 1000], [1000, 1000, 1000]]\n assert candidate(grid = [[1, 1], [1, 2]],row = 0,col = 0,color = 3) == [[3, 3],... | [
"[[1,1],[1,2]]\n0\n0\n3",
"[[1,2,2],[2,3,2]]\n0\n1\n3",
"[[1,1,1],[1,1,1],[1,1,1]]\n1\n1\n2"
] | [
"Use a DFS to find every square in the component. Then for each square, color it if it has a neighbor that is outside the grid or a different color."
] | {
"canonical_parameter_names": [
"grid",
"row",
"col",
"color"
],
"leetcode_dataset_entry_point": "Solution().colorBorder",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:31",... | cpp | {
"raw_signature": "vector<vector<int>> colorBorder(vector<vector<int>>& grid, int row, int col, int color) {",
"container": "Solution",
"callable": "colorBorder",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
},
{
"name": "row",
"type": "int"
},
{
... |
1,035 | uncrossed-lines | Medium | You are given two integer arrays nums1 and nums2. We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines.
We may draw connecting lines: a straight line connecting two numbers nums1[i] and nums2[j] such that:
- nums1[i] == nums2[j], and
- the line we draw does not inter... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [2, 5, 1, 2, 5],nums2 = [10, 5, 2, 1, 5, 2]) == 3\n assert candidate(nums1 = [1, 4, 2],nums2 = [1, 2, 4]) == 2\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3],nums2 = [3, 3, 3, 3, 3, 3, 3]) == 7\n assert candidate(nums1... | [
"[1,4,2]\n[1,2,4]",
"[2,5,1,2,5]\n[10,5,2,1,5,2]",
"[1,3,7,1,7,5]\n[1,9,2,5,1]"
] | [
"Think dynamic programming. Given an oracle dp(i,j) that tells us how many lines A[i:], B[j:] [the sequence A[i], A[i+1], ... and B[j], B[j+1], ...] are uncrossed, can we write this as a recursion?"
] | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().maxUncrossedLines",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:33",
"tests_total... | cpp | {
"raw_signature": "int maxUncrossedLines(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "maxUncrossedLines",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type": "... |
1,036 | escape-a-large-maze | Hard | There is a 1 million by 1 million grid on an XY-plane, and the coordinates of each grid square are (x, y).
We start at the source = [s_x, s_y] square and want to reach the target = [t_x, t_y] square. There is also an array of blocked squares, where each blocked[i] = [x_i, y_i] represents a blocked square with coordina... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(blocked = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]],source = [0, 0],target = [6, 6]) == True\n assert candidate(blocked = [[5, 5]],source = [4, 4],target = [6, 6]) == True\n assert candidate(blocked =... | [
"[[0,1],[1,0]]\n[0,0]\n[0,2]",
"[]\n[0,0]\n[999999,999999]"
] | [
"If we become stuck, there's either a loop around the source or around the target.",
"If there is a loop around say, the source, what is the maximum number of squares it can have?"
] | {
"canonical_parameter_names": [
"blocked",
"source",
"target"
],
"leetcode_dataset_entry_point": "Solution().isEscapePossible",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:35"... | cpp | {
"raw_signature": "bool isEscapePossible(vector<vector<int>>& blocked, vector<int>& source, vector<int>& target) {",
"container": "Solution",
"callable": "isEscapePossible",
"parameters": [
{
"name": "blocked",
"type": "vector<vector<int>>&"
},
{
"name": "source",
"type": "v... |
1,037 | valid-boomerang | Easy | Given an array points where points[i] = [x_i, y_i] represents a point on the X-Y plane, return true if these points are a boomerang.
A boomerang is a set of three points that are all distinct and not in a straight line.
Example 1:
Input: points = [[1,1],[2,3],[3,2]]
Output: true
Example 2:
Input: points = [[1,1],[... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(points = [[1, 1], [2, 2], [1, 3]]) == True\n assert candidate(points = [[1, 1], [2, 5], [3, 9]]) == False\n assert candidate(points = [[1, 1], [2, 3], [3, 2]]) == True\n assert candidate(points = [[5, 5], [6, 6], [7, 7]]) == Fal... | [
"[[1,1],[2,3],[3,2]]",
"[[1,1],[2,2],[3,3]]"
] | [
"3 points form a boomerang if and only if the triangle formed from them has non-zero area."
] | {
"canonical_parameter_names": [
"points"
],
"leetcode_dataset_entry_point": "Solution().isBoomerang",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:37",
"tests_total": 116,
"tests_d... | cpp | {
"raw_signature": "bool isBoomerang(vector<vector<int>>& points) {",
"container": "Solution",
"callable": "isBoomerang",
"parameters": [
{
"name": "points",
"type": "vector<vector<int>>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
1,039 | minimum-score-triangulation-of-polygon | Medium | You have a convex n-sided polygon where each vertex has an integer value. You are given an integer array values where values[i] is the value of the i^th vertex in clockwise order.
Polygon triangulation is a process where you divide a polygon into a set of triangles and the vertices of each triangle must also be vertic... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(values = [10, 1, 1, 10]) == 110\n assert candidate(values = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 328\n assert candidate(values = [3, 1, 2, 4, 5, 6]) == 76\n assert candidate(values = [10, 1, 20, 2, 30, 3, 40, 4]) == 510\n asse... | [
"[1,2,3]",
"[3,7,4,5]",
"[1,3,1,4,1,5]"
] | [
"Without loss of generality, there is a triangle that uses adjacent vertices A[0] and A[N-1] (where N = A.length). Depending on your choice K of it, this breaks down the triangulation into two subproblems A[1:K] and A[K+1:N-1]."
] | {
"canonical_parameter_names": [
"values"
],
"leetcode_dataset_entry_point": "Solution().minScoreTriangulation",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:42",
"tests_total": 111,
... | cpp | {
"raw_signature": "int minScoreTriangulation(vector<int>& values) {",
"container": "Solution",
"callable": "minScoreTriangulation",
"parameters": [
{
"name": "values",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leet... |
1,040 | moving-stones-until-consecutive-ii | Medium | There are some stones in different positions on the X-axis. You are given an integer array stones, the positions of the stones.
Call a stone an endpoint stone if it has the smallest or largest position. In one move, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(stones = [4, 5, 6, 7, 100]) == [2, 92]\n assert candidate(stones = [10, 11, 12, 14, 15, 16]) == [1, 1]\n assert candidate(stones = [3, 6, 9, 12, 15]) == [3, 6]\n assert candidate(stones = [6, 5, 4, 3, 10]) == [2, 3]\n assert ... | [
"[7,4,9]",
"[6,5,4,3,10]"
] | [
"For the minimum, how many stones are already in place? For the maximum, we have to lose either the gap A[1] - A[0] or A[N-1] - A[N-2] (where N = A.length), but every other space can be occupied."
] | {
"canonical_parameter_names": [
"stones"
],
"leetcode_dataset_entry_point": "Solution().numMovesStonesII",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:44",
"tests_total": 140,
"te... | cpp | {
"raw_signature": "vector<int> numMovesStonesII(vector<int>& stones) {",
"container": "Solution",
"callable": "numMovesStonesII",
"parameters": [
{
"name": "stones",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source":... |
1,041 | robot-bounded-in-circle | Medium | On an infinite plane, a robot initially stands at (0, 0) and faces north. Note that:
- The north direction is the positive direction of the y-axis.
- The south direction is the negative direction of the y-axis.
- The east direction is the positive direction of the x-axis.
- The west direction is the negative direction... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(instructions = \"GGLGRGLL\") == True\n assert candidate(instructions = \"LLLL\") == True\n assert candidate(instructions = \"GLLRLLRL\") == True\n assert candidate(instructions = \"GRGL\") == False\n assert candidate(instruct... | [
"\"GGLLGG\"",
"\"GG\"",
"\"GL\""
] | [
"Calculate the final vector of how the robot travels after executing all instructions once - it consists of a change in position plus a change in direction.",
"The robot stays in the circle if and only if (looking at the final vector) it changes direction (ie. doesn't stay pointing north), or it moves 0."
] | {
"canonical_parameter_names": [
"instructions"
],
"leetcode_dataset_entry_point": "Solution().isRobotBounded",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:46",
"tests_total": 140,
... | cpp | {
"raw_signature": "bool isRobotBounded(string instructions) {",
"container": "Solution",
"callable": "isRobotBounded",
"parameters": [
{
"name": "instructions",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
1,042 | flower-planting-with-no-adjacent | Medium | You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [x_i, y_i] describes a bidirectional path between garden x_i to garden y_i. In each garden, you want to plant one of 4 types of flowers.
All gardens have at most 3 paths coming into or leaving it.
Your task is to choose a flower type for eac... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3,paths = [[1, 2], [2, 3], [3, 1]]) == [1, 2, 3]\n assert candidate(n = 6,paths = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 5], [3, 6], [4, 5], [4, 6]]) == [1, 2, 2, 2, 1, 1]\n assert candidate(n = 6,paths = [[1, 2], [2, 3],... | [
"3\n[[1,2],[2,3],[3,1]]",
"4\n[[1,2],[3,4]]",
"4\n[[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]"
] | [
"Since each garden is connected to at most 3 gardens, there's always an available color for each garden. For example, if one garden is next to gardens with colors 1, 3, 4, then color #2 is available."
] | {
"canonical_parameter_names": [
"n",
"paths"
],
"leetcode_dataset_entry_point": "Solution().gardenNoAdj",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:48",
"tests_total": 59,
"... | cpp | {
"raw_signature": "vector<int> gardenNoAdj(int n, vector<vector<int>>& paths) {",
"container": "Solution",
"callable": "gardenNoAdj",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "paths",
"type": "vector<vector<int>>&"
}
],
"return_type": "vector<int>",
... |
1,043 | partition-array-for-maximum-sum | Medium | Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.
Return the largest sum of the given array after partitioning. Test cases are generated so that the answer fits in a 3... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [1],k = 1) == 1\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 1) == 45\n assert candidate(arr = [1, 15, 7, 9, 2, 5, 10],k = 3) == 84\n assert candidate(arr = [10, 20, 30, 40, 50],k = 3) == 190\n assert candid... | [
"[1,15,7,9,2,5,10]\n3",
"[1,4,1,5,7,3,6,1,9,9,3]\n4",
"[1]\n1"
] | [
"Think dynamic programming: dp[i] will be the answer for array A[0], ..., A[i-1].",
"For j = 1 .. k that keeps everything in bounds, dp[i] is the maximum of dp[i-j] + max(A[i-1], ..., A[i-j]) * j ."
] | {
"canonical_parameter_names": [
"arr",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxSumAfterPartitioning",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:50",
"tests_total... | cpp | {
"raw_signature": "int maxSumAfterPartitioning(vector<int>& arr, int k) {",
"container": "Solution",
"callable": "maxSumAfterPartitioning",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature... |
1,044 | longest-duplicate-substring | Hard | Given a string s, consider all duplicated substrings: (contiguous) substrings of s that occur 2 or more times. The occurrences may overlap.
Return any duplicated substring that has the longest possible length. If s does not have a duplicated substring, the answer is "".
Example 1:
Input: s = "banana"
Output: "ana"
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcabcabc\") == \"abcabc\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz... | [
"\"banana\"",
"\"abcd\""
] | [
"Binary search for the length of the answer. (If there's an answer of length 10, then there are answers of length 9, 8, 7, ...)",
"To check whether an answer of length K exists, we can use Rabin-Karp 's algorithm."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().longestDupSubstring",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:53",
"tests_total": 117,
"test... | cpp | {
"raw_signature": "string longestDupSubstring(string s) {",
"container": "Solution",
"callable": "longestDupSubstring",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,046 | last-stone-weight | Easy | You are given an array of integers stones where stones[i] is the weight of the i^th stone.
We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y with x <= y. The result of this smash is:
- If x == y, both st... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(stones = [9, 3, 2, 10, 8]) == 2\n assert candidate(stones = [5, 5, 5, 5, 5]) == 5\n assert candidate(stones = [5, 5, 5, 5, 5]) == 5\n assert candidate(stones = [3, 3, 3, 3, 3]) == 3\n assert candidate(stones = [10, 9, 8, 7, 6... | [
"[2,7,4,1,8,1]",
"[1]"
] | [
"Simulate the process. We can do it with a heap, or by sorting some list of stones every time we take a turn."
] | {
"canonical_parameter_names": [
"stones"
],
"leetcode_dataset_entry_point": "Solution().lastStoneWeight",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:55",
"tests_total": 124,
"tes... | cpp | {
"raw_signature": "int lastStoneWeight(vector<int>& stones) {",
"container": "Solution",
"callable": "lastStoneWeight",
"parameters": [
{
"name": "stones",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
1,047 | remove-all-adjacent-duplicates-in-string | Easy | You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them.
We repeatedly make duplicate removals on s until we no longer can.
Return the final string after all such duplicate removals have been made. It can be proven tha... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"acbbcaa\") == \"a\"\n assert candidate(s = \"aabbaa\") == \"\"\n assert candidate(s = \"abcdef\") == \"abcdef\"\n assert candidate... | [
"\"abbaca\"",
"\"azxxzy\""
] | [
"Use a stack to process everything greedily."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().removeDuplicates",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:08:57",
"tests_total": 42,
"tests_dr... | cpp | {
"raw_signature": "string removeDuplicates(string s) {",
"container": "Solution",
"callable": "removeDuplicates",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,048 | longest-string-chain | Medium | You are given an array of words where each word consists of lowercase English letters.
word_A is a predecessor of word_B if and only if we can insert exactly one letter anywhere in word_A without changing the order of the other characters to make it equal to word_B.
- For example, "abc" is a predecessor of "abac", wh... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['xbc', 'pcxbcf', 'xb', 'cxbc', 'pcxbc']) == 5\n assert candidate(words = ['a', 'b', 'ba', 'bca', 'bda', 'bdca']) == 4\n assert candidate(words = ['abcd', 'abde', 'acde', 'bcde', 'abcde']) == 2\n assert candidate(words =... | [
"[\"a\",\"b\",\"ba\",\"bca\",\"bda\",\"bdca\"]",
"[\"xbc\",\"pcxbcf\",\"xb\",\"cxbc\",\"pcxbc\"]",
"[\"abcd\",\"dbqca\"]"
] | [
"Instead of adding a character, try deleting a character to form a chain in reverse.",
"For each word in order of length, for each word2 which is word with one character removed, length[word2] = max(length[word2], length[word] + 1)."
] | {
"canonical_parameter_names": [
"words"
],
"leetcode_dataset_entry_point": "Solution().longestStrChain",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:00",
"tests_total": 84,
"tests... | cpp | {
"raw_signature": "int longestStrChain(vector<string>& words) {",
"container": "Solution",
"callable": "longestStrChain",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,049 | last-stone-weight-ii | Medium | You are given an array of integers stones where stones[i] is the weight of the i^th stone.
We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:
- If x == y, both stones are destroyed, an... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(stones = [10, 10, 10, 10, 10]) == 10\n assert candidate(stones = [3, 9, 7, 3]) == 2\n assert candidate(stones = [1, 2, 3, 4, 5]) == 1\n assert candidate(stones = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,... | [
"[2,7,4,1,8,1]",
"[31,26,33,21,40]"
] | [
"Think of the final answer as a sum of weights with + or - sign symbols infront of each weight. Actually, all sums with 1 of each sign symbol are possible.",
"Use dynamic programming: for every possible sum with N stones, those sums +x or -x is possible with N+1 stones, where x is the value of the newest stone. (... | {
"canonical_parameter_names": [
"stones"
],
"leetcode_dataset_entry_point": "Solution().lastStoneWeightII",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:02",
"tests_total": 99,
"te... | cpp | {
"raw_signature": "int lastStoneWeightII(vector<int>& stones) {",
"container": "Solution",
"callable": "lastStoneWeightII",
"parameters": [
{
"name": "stones",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,051 | height-checker | Easy | A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the i^th student in line.
You are given an integer array he... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(heights = [1]) == 0\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(heights = [1, 2, 1, 2]) == 2\n assert candidate(heights = [3, 3, 3, 3, 3]) == 0\n assert candidate(heights = [1, 2, 3,... | [
"[1,1,4,2,1,3]",
"[5,1,2,3,4]",
"[1,2,3,4,5]"
] | [
"Build the correct order of heights by sorting another array, then compare the two arrays."
] | {
"canonical_parameter_names": [
"heights"
],
"leetcode_dataset_entry_point": "Solution().heightChecker",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:04",
"tests_total": 115,
"test... | cpp | {
"raw_signature": "int heightChecker(vector<int>& heights) {",
"container": "Solution",
"callable": "heightChecker",
"parameters": [
{
"name": "heights",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,052 | grumpy-bookstore-owner | Medium | There is a bookstore owner that has a store open for n minutes. You are given an integer array customers of length n where customers[i] is the number of the customers that enter the store at the start of the i^th minute and all those customers leave after the end of that minute.
During certain minutes, the bookstore o... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(customers = [3, 1, 4, 2, 2],grumpy = [0, 0, 1, 1, 1],minutes = 1) == 8\n assert candidate(customers = [5, 5, 5, 5, 5],grumpy = [0, 0, 0, 0, 0],minutes = 1) == 25\n assert candidate(customers = [2, 3, 4, 5],grumpy = [1, 0, 1, 1],min... | [
"[1,0,1,2,1,1,7,5]\n[0,1,0,1,0,1,0,1]\n3",
"[1]\n[0]\n1"
] | [
"Say the store owner uses their power in minute 1 to X and we have some answer A. If they instead use their power from minute 2 to X+1, we only have to use data from minutes 1, 2, X and X+1 to update our answer A."
] | {
"canonical_parameter_names": [
"customers",
"grumpy",
"minutes"
],
"leetcode_dataset_entry_point": "Solution().maxSatisfied",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:06",... | cpp | {
"raw_signature": "int maxSatisfied(vector<int>& customers, vector<int>& grumpy, int minutes) {",
"container": "Solution",
"callable": "maxSatisfied",
"parameters": [
{
"name": "customers",
"type": "vector<int>&"
},
{
"name": "grumpy",
"type": "vector<int>&"
},
{
... |
1,053 | previous-permutation-with-one-swap | Medium | Given an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that can be made with exactly one swap. If it cannot be done, then return the same array.
Note that a swap exchanges the positions of two numbers arr[i] and arr[j]
Example 1:
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [10, 9, 8, 7, 6, 5]) == [10, 9, 8, 7, 5, 6]\n assert candidate(arr = [3, 2, 1]) == [3, 1, 2]\n assert candidate(arr = [5, 1, 1, 2, 3]) == [3, 1, 1, 2, 5]\n assert candidate(arr = [5, 4, 3, 2, 1]) == [5, 4, 3, 1, 2]\n as... | [
"[3,2,1]",
"[1,1,5]",
"[1,9,4,6,7]"
] | [
"You need to swap two values, one larger than the other. Where is the larger one located?"
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().prevPermOpt1",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:08",
"tests_total": 140,
"tests_dro... | cpp | {
"raw_signature": "vector<int> prevPermOpt1(vector<int>& arr) {",
"container": "Solution",
"callable": "prevPermOpt1",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,054 | distant-barcodes | Medium | In a warehouse, there is a row of barcodes, where the i^th barcode is barcodes[i].
Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists.
Example 1:
Input: barcodes = [1,1,1,2,2,2]
Output: [2,1,2,1,2,1]
Example 2:
Input: barcodes = [1,1,... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(barcodes = [1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5]) == [1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 2, 5, 2]\n assert candidate(barcodes = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [1, 3, 1, 4, 2, 4, 2, 5, 3, 5]\n assert candidate(barcodes = [2, 2, 1, ... | [
"[1,1,1,2,2,2]",
"[1,1,1,1,2,2,3,3]"
] | [
"We want to always choose the most common or second most common element to write next. What data structure allows us to query this effectively?"
] | {
"canonical_parameter_names": [
"barcodes"
],
"leetcode_dataset_entry_point": "Solution().rearrangeBarcodes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:11",
"tests_total": 96,
"... | cpp | {
"raw_signature": "vector<int> rearrangeBarcodes(vector<int>& barcodes) {",
"container": "Solution",
"callable": "rearrangeBarcodes",
"parameters": [
{
"name": "barcodes",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_so... |
1,061 | lexicographically-smallest-equivalent-string | Medium | You are given two strings of the same length s1 and s2 and a string baseStr.
We say s1[i] and s2[i] are equivalent characters.
- For example, if s1 = "abc" and s2 = "cde", then we have 'a' == 'c', 'b' == 'd', and 'c' == 'e'.
Equivalent characters follow the usual rules of any equivalence relation:
- Reflexivity: 'a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s1 = \"abc\",s2 = \"bcd\",baseStr = \"xyz\") == \"xyz\"\n assert candidate(s1 = \"leetcode\",s2 = \"programs\",baseStr = \"sourcecode\") == \"aauaaaaada\"\n assert candidate(s1 = \"parker\",s2 = \"morris\",baseStr = \"parser\") == ... | [
"\"parker\"\n\"morris\"\n\"parser\"",
"\"hello\"\n\"world\"\n\"hold\"",
"\"leetcode\"\n\"programs\"\n\"sourcecode\""
] | [
"Model these equalities as edges of a graph.",
"Group each connected component of the graph and assign each node of this component to the node with the lowest lexicographically character.",
"Finally convert the string with the precalculated information."
] | {
"canonical_parameter_names": [
"s1",
"s2",
"baseStr"
],
"leetcode_dataset_entry_point": "Solution().smallestEquivalentString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:27"... | cpp | {
"raw_signature": "string smallestEquivalentString(string s1, string s2, string baseStr) {",
"container": "Solution",
"callable": "smallestEquivalentString",
"parameters": [
{
"name": "s1",
"type": "string"
},
{
"name": "s2",
"type": "string"
},
{
"name": "base... |
1,071 | greatest-common-divisor-of-strings | Easy | For two strings s and t, we say "t divides s" if and only if s = t + t + t + ... + t + t (i.e., t is concatenated with itself one or more times).
Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.
Example 1:
Input: str1 = "ABCABC", str2 = "ABC"
Output: "ABC"
Example... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(str1 = \"ABAB\",str2 = \"ABA\") == \"\"\n assert candidate(str1 = \"ABCDEFGH\",str2 = \"XYZ\") == \"\"\n assert candidate(str1 = \"ABCABC\",str2 = \"ABC\") == \"ABC\"\n assert candidate(str1 = \"ABABAB\",str2 = \"ABA\") == \"\"\... | [
"\"ABCABC\"\n\"ABC\"",
"\"ABABAB\"\n\"ABAB\"",
"\"LEET\"\n\"CODE\"",
"\"AAAAAB\"\n\"AAA\""
] | [
"The greatest common divisor must be a prefix of each string, so we can try all prefixes."
] | {
"canonical_parameter_names": [
"str1",
"str2"
],
"leetcode_dataset_entry_point": "Solution().gcdOfStrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:42",
"tests_total": 175,... | cpp | {
"raw_signature": "string gcdOfStrings(string str1, string str2) {",
"container": "Solution",
"callable": "gcdOfStrings",
"parameters": [
{
"name": "str1",
"type": "string"
},
{
"name": "str2",
"type": "string"
}
],
"return_type": "string",
"signature_source": "lee... |
1,072 | flip-columns-for-maximum-number-of-equal-rows | Medium | You are given an m x n binary matrix matrix.
You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from 0 to 1 or vice versa).
Return the maximum number of rows that have all values equal after some number of flips.
Example 1:
Input: matrix = [[0,1... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(matrix = [[0, 1], [1, 0]]) == 2\n assert candidate(matrix = [[1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]]) == 3\n assert candidate(matrix = [[1, 1, 1, 1], [0, 0, 0, 0], [1, 0, 1, 0]]) == 2\n assert candidate(matrix = [[1, 0, 0, 1],... | [
"[[0,1],[1,1]]",
"[[0,1],[1,0]]",
"[[0,0,0],[0,0,1],[1,1,0]]"
] | [
"Flipping a subset of columns is like doing a bitwise XOR of some number K onto each row. We want rows X with X ^ K = all 0s or all 1s. This is the same as X = X^K ^K = (all 0s or all 1s) ^ K, so we want to count rows that have opposite bits set. For example, if K = 1, then we count rows X = (00000...001, or 1111..... | {
"canonical_parameter_names": [
"matrix"
],
"leetcode_dataset_entry_point": "Solution().maxEqualRowsAfterFlips",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:45",
"tests_total": 88,
... | cpp | {
"raw_signature": "int maxEqualRowsAfterFlips(vector<vector<int>>& matrix) {",
"container": "Solution",
"callable": "maxEqualRowsAfterFlips",
"parameters": [
{
"name": "matrix",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"t... |
1,073 | adding-two-negabinary-numbers | Medium | Given two numbers arr1 and arr2 in base -2, return the result of adding them together.
Each number is given in array format: as an array of 0s and 1s, from most significant bit to least significant bit. For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3. A number arr in array, format is a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr1 = [0],arr2 = [0]) == [0]\n assert candidate(arr1 = [1, 0, 1, 0, 1],arr2 = [1, 0, 1, 0, 1]) == [1, 1, 1, 1, 1, 1, 0]\n assert candidate(arr1 = [1, 1, 0],arr2 = [1, 1, 0]) == [1, 0, 0]\n assert candidate(arr1 = [1, 0, 1],arr2... | [
"[1,1,1,1,1]\n[1,0,1]",
"[0]\n[0]",
"[0]\n[1]"
] | [
"We can try to determine the last digit of the answer, then divide everything by 2 and repeat."
] | {
"canonical_parameter_names": [
"arr1",
"arr2"
],
"leetcode_dataset_entry_point": "Solution().addNegabinary",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:47",
"tests_total": 104... | cpp | {
"raw_signature": "vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {",
"container": "Solution",
"callable": "addNegabinary",
"parameters": [
{
"name": "arr1",
"type": "vector<int>&"
},
{
"name": "arr2",
"type": "vector<int>&"
}
],
"return_type": "vect... |
1,074 | number-of-submatrices-that-sum-to-target | Hard | Given a matrix and a target, return the number of non-empty submatrices that sum to target.
A submatrix x1, y1, x2, y2 is the set of all cells matrix[x][y] with x1 <= x <= x2 and y1 <= y <= y2.
Two submatrices (x1, y1, x2, y2) and (x1', y1', x2', y2') are different if they have some coordinate that is different: for ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(matrix = [[1]],target = 1) == 1\n assert candidate(matrix = [[1, 2, 3], [4, 5, 6]],target = 12) == 1\n assert candidate(matrix = [[-1, -1, -1], [-1, -1, -1], [-1, -1, -1]],target = -9) == 1\n assert candidate(matrix = [[0, 0, 0]... | [
"[[0,1,0],[1,1,1],[0,1,0]]\n0",
"[[1,-1],[-1,1]]\n0",
"[[904]]\n0"
] | [
"Using a 2D prefix sum, we can query the sum of any submatrix in O(1) time. Now for each (r1, r2), we can find the largest sum of a submatrix that uses every row in [r1, r2] in linear time using a sliding window."
] | {
"canonical_parameter_names": [
"matrix",
"target"
],
"leetcode_dataset_entry_point": "Solution().numSubmatrixSumTarget",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:49",
"tests... | cpp | {
"raw_signature": "int numSubmatrixSumTarget(vector<vector<int>>& matrix, int target) {",
"container": "Solution",
"callable": "numSubmatrixSumTarget",
"parameters": [
{
"name": "matrix",
"type": "vector<vector<int>>&"
},
{
"name": "target",
"type": "int"
}
],
"retur... |
1,078 | occurrences-after-bigram | Easy | Given two strings first and second, consider occurrences in some text of the form "first second third", where second comes immediately after first, and third comes immediately after second.
Return an array of all the words third for each occurrence of "first second third".
Example 1:
Input: text = "alice is a good g... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(text = \"hello world hello hello world\",first = \"hello\",second = \"world\") == ['hello']\n assert candidate(text = \"repeat repeat repeat repeat\",first = \"repeat\",second = \"repeat\") == ['repeat', 'repeat']\n assert candidat... | [
"\"alice is a good girl she is a good student\"\n\"a\"\n\"good\"",
"\"we will we will rock you\"\n\"we\"\n\"will\""
] | [
"Split the string into words, then look at adjacent triples of words."
] | {
"canonical_parameter_names": [
"text",
"first",
"second"
],
"leetcode_dataset_entry_point": "Solution().findOcurrences",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:51",
"t... | cpp | {
"raw_signature": "vector<string> findOcurrences(string text, string first, string second) {",
"container": "Solution",
"callable": "findOcurrences",
"parameters": [
{
"name": "text",
"type": "string"
},
{
"name": "first",
"type": "string"
},
{
"name": "second"... |
1,079 | letter-tile-possibilities | Medium | You have n tiles, where each tile has one letter tiles[i] printed on it.
Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.
Example 1:
Input: tiles = "AAB"
Output: 8
Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(tiles = \"AAAAAAA\") == 7\n assert candidate(tiles = \"QQQ\") == 3\n assert candidate(tiles = \"ABCDEFG\") == 13699\n assert candidate(tiles = \"ABC\") == 15\n assert candidate(tiles = \"AAB\") == 8\n assert candidate(tile... | [
"\"AAB\"",
"\"AAABBC\"",
"\"V\""
] | [
"Try to build the string with a backtracking DFS by considering what you can put in every position."
] | {
"canonical_parameter_names": [
"tiles"
],
"leetcode_dataset_entry_point": "Solution().numTilePossibilities",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:53",
"tests_total": 74,
"... | cpp | {
"raw_signature": "int numTilePossibilities(string tiles) {",
"container": "Solution",
"callable": "numTilePossibilities",
"parameters": [
{
"name": "tiles",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
1,081 | smallest-subsequence-of-distinct-characters | Medium | Given a string s, return the lexicographically smallest subsequence of s that contains all the distinct characters of s exactly once.
Example 1:
Input: s = "bcabc"
Output: "abc"
Example 2:
Input: s = "cbacdcbc"
Output: "acdb"
Constraints:
- 1 <= s.length <= 1000
- s consists of lowercase English letters.
Note: T... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"rakuqjeiaxeidqqeaeiaxqeaeiaxjeidqq\") == \"rakudeiqxj\"\n assert candidate(s = \"a\") == \"a\"\n assert candidate(s = \"cccaae\") == \"cae\"\n assert candidate(s = \"cbacdcbc\") == \"acdb\"\n assert candidate(s = \"abac... | [
"\"bcabc\"",
"\"cbacdcbc\""
] | [
"Greedily try to add one missing character. How to check if adding some character will not cause problems ? Use bit-masks to check whether you will be able to complete the sub-sequence if you add the character at some index i."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().smallestSubsequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:09:58",
"tests_total": 124,
"test... | cpp | {
"raw_signature": "string smallestSubsequence(string s) {",
"container": "Solution",
"callable": "smallestSubsequence",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,090 | largest-values-from-labels | Medium | You are given n item's value and label as two integer arrays values and labels. You are also given two integers numWanted and useLimit.
Your task is to find a subset of items with the maximum sum of their values such that:
- The number of items is at most numWanted.
- The number of items with the same label is at mos... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(values = [10, 10, 10, 10],labels = [1, 1, 1, 1],numWanted = 3,useLimit = 2) == 20\n assert candidate(values = [10, 10, 10, 10],labels = [1, 2, 3, 4],numWanted = 4,useLimit = 1) == 40\n assert candidate(values = [9, 8, 8, 7, 6],labe... | [
"[5,4,3,2,1]\n[1,1,2,2,3]\n3\n1",
"[5,4,3,2,1]\n[1,3,3,3,2]\n3\n2",
"[9,8,8,7,6]\n[0,0,0,1,1]\n3\n1"
] | [
"Consider the items in order from largest to smallest value, and greedily take the items if they fall under the use_limit. We can keep track of how many items of each label are used by using a hash table."
] | {
"canonical_parameter_names": [
"values",
"labels",
"numWanted",
"useLimit"
],
"leetcode_dataset_entry_point": "Solution().largestValsFromLabels",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at"... | cpp | {
"raw_signature": "int largestValsFromLabels(vector<int>& values, vector<int>& labels, int numWanted, int useLimit) {",
"container": "Solution",
"callable": "largestValsFromLabels",
"parameters": [
{
"name": "values",
"type": "vector<int>&"
},
{
"name": "labels",
"type": "ve... |
1,091 | shortest-path-in-binary-matrix | Medium | Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1.
A clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to the bottom-right cell (i.e., (n - 1, n - 1)) such that:
- All the visited cells of the path are 0.
- A... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 1], [1, 0]]) == 2\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [1, 0, 1, 0, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 1]]) == -1\n assert candidate(grid = [[1]]) == -1\n assert candidate(grid = [[1, 1, 1, 1, ... | [
"[[0,1],[1,0]]",
"[[0,0,0],[1,1,0],[1,1,0]]",
"[[1,0,0],[1,1,0],[1,1,0]]"
] | [
"Do a breadth first search to find the shortest path."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().shortestPathBinaryMatrix",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:13",
"tests_total": 67,
... | cpp | {
"raw_signature": "int shortestPathBinaryMatrix(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "shortestPathBinaryMatrix",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"t... |
1,092 | shortest-common-supersequence | Hard | Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them.
A string s is a subsequence of string t if deleting some number of characters from t (possibly 0) results in the string s.
Example 1:
Input: str1 = "abac",... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(str1 = \"xyz\",str2 = \"xyx\") == \"xyxz\"\n assert candidate(str1 = \"short\",str2 = \"sorts\") == \"shorts\"\n assert candidate(str1 = \"algorithm\",str2 = \"altruistic\") == \"altgoruistichm\"\n assert candidate(str1 = \"ab\"... | [
"\"abac\"\n\"cab\"",
"\"aaaaaaaa\"\n\"aaaaaaaa\""
] | [
"We can find the length of the longest common subsequence between str1[i:] and str2[j:] (for all (i, j)) by using dynamic programming.",
"We can use this information to recover the shortest common supersequence."
] | {
"canonical_parameter_names": [
"str1",
"str2"
],
"leetcode_dataset_entry_point": "Solution().shortestCommonSupersequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:16",
"tes... | cpp | {
"raw_signature": "string shortestCommonSupersequence(string str1, string str2) {",
"container": "Solution",
"callable": "shortestCommonSupersequence",
"parameters": [
{
"name": "str1",
"type": "string"
},
{
"name": "str2",
"type": "string"
}
],
"return_type": "strin... |
1,094 | car-pooling | Medium | There is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).
You are given the integer capacity and an array trips where trips[i] = [numPassengers_i, from_i, to_i] indicates that the i^th trip has numPassengers_i passengers and the locations to pick them up and d... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(trips = [[3, 2, 8], [4, 4, 6], [10, 8, 10]],capacity = 12) == True\n assert candidate(trips = [[3, 2, 7], [2, 7, 9], [4, 1, 3]],capacity = 6) == False\n assert candidate(trips = [[2, 1, 5], [3, 5, 7]],capacity = 5) == True\n ass... | [
"[[2,1,5],[3,3,7]]\n4",
"[[2,1,5],[3,3,7]]\n5"
] | [
"Sort the pickup and dropoff events by location, then process them in order."
] | {
"canonical_parameter_names": [
"trips",
"capacity"
],
"leetcode_dataset_entry_point": "Solution().carPooling",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:20",
"tests_total": 1... | cpp | {
"raw_signature": "bool carPooling(vector<vector<int>>& trips, int capacity) {",
"container": "Solution",
"callable": "carPooling",
"parameters": [
{
"name": "trips",
"type": "vector<vector<int>>&"
},
{
"name": "capacity",
"type": "int"
}
],
"return_type": "bool",
... |
1,096 | brace-expansion-ii | Hard | Under the grammar given below, strings can represent a set of lowercase words. Let R(expr) denote the set of words the expression represents.
The grammar can best be understood through simple examples:
- Single letters represent a singleton set containing that word.
- R("a") = {"a"}
- R("w") = {"w"}
- When we tak... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(expression = \"a\") == ['a']\n assert candidate(expression = \"{a,bc,def}\") == ['a', 'bc', 'def']\n assert candidate(expression = \"a{b{c,d},e{f,g}}\") == ['abc', 'abd', 'aef', 'aeg']\n assert candidate(expression = \"{a,b,c}\"... | [
"\"{a,b}{c,{d,e}}\"",
"\"{{a,z},a{b,c},{ab,z}}\""
] | [
"You can write helper methods to parse the next \"chunk\" of the expression. If you see eg. \"a\", the answer is just the set {a}. If you see \"{\", you parse until you complete the \"}\" (the number of { and } seen are equal) and that becomes a chunk that you find where the appropriate commas are, and parse each i... | {
"canonical_parameter_names": [
"expression"
],
"leetcode_dataset_entry_point": "Solution().braceExpansionII",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:22",
"tests_total": 100,
... | cpp | {
"raw_signature": "vector<string> braceExpansionII(string expression) {",
"container": "Solution",
"callable": "braceExpansionII",
"parameters": [
{
"name": "expression",
"type": "string"
}
],
"return_type": "vector<string>",
"signature_source": "leetcode/codeSnippets",
"type_source... |
1,103 | distribute-candies-to-people | Easy | We distribute some number of candies, to a row of n = num_people people in the following way:
We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person.
Then, we go back to the start of the row, giving n + 1 candies to the first person, n + 2 candie... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(candies = 500000000,num_people = 500) == [1008064, 1008128, 1008192, 1008256, 1008320, 1008384, 1008448, 1008512, 1008576, 1008640, 1008704, 1008768, 1008832, 1008896, 1008960, 1009024, 1009088, 1009152, 1009216, 1009280, 1009344, 100940... | [
"7\n4",
"10\n3"
] | [
"Give candy to everyone each \"turn\" first [until you can't], then give candy to one person per turn."
] | {
"canonical_parameter_names": [
"candies",
"num_people"
],
"leetcode_dataset_entry_point": "Solution().distributeCandies",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:33",
"test... | cpp | {
"raw_signature": "vector<int> distributeCandies(int candies, int num_people) {",
"container": "Solution",
"callable": "distributeCandies",
"parameters": [
{
"name": "candies",
"type": "int"
},
{
"name": "num_people",
"type": "int"
}
],
"return_type": "vector<int>",
... |
1,104 | path-in-zigzag-labelled-binary-tree | Medium | In an infinite binary tree where every node has two children, the nodes are labelled in row order.
In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left.
Given the label of a node in this... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(label = 14) == [1, 3, 4, 14]\n assert candidate(label = 1023) == [1, 3, 4, 15, 16, 63, 64, 255, 256, 1023]\n assert candidate(label = 3) == [1, 3]\n assert candidate(label = 1000000) == [1, 3, 4, 15, 17, 61, 69, 244, 279, 976, 1... | [
"14",
"26"
] | [
"Based on the label of the current node, find what the label must be for the parent of that node."
] | {
"canonical_parameter_names": [
"label"
],
"leetcode_dataset_entry_point": "Solution().pathInZigZagTree",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:36",
"tests_total": 78,
"test... | cpp | {
"raw_signature": "vector<int> pathInZigZagTree(int label) {",
"container": "Solution",
"callable": "pathInZigZagTree",
"parameters": [
{
"name": "label",
"type": "int"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,105 | filling-bookcase-shelves | Medium | You are given an array books where books[i] = [thickness_i, height_i] indicates the thickness and height of the i^th book. You are also given an integer shelfWidth.
We want to place these books in order onto bookcase shelves that have a total width shelfWidth.
We choose some of the books to place on this shelf such t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(books = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],shelfWidth = 1) == 10\n assert candidate(books = [[1, 1], [2, 2], [3, 3]],shelfWidth = 5) == 4\n assert candidate(books = [[10, 1], [2, 2], [3... | [
"[[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]]\n4",
"[[1,3],[2,4],[3,2]]\n6"
] | [
"Use dynamic programming: dp(i) will be the answer to the problem for books[i:]."
] | {
"canonical_parameter_names": [
"books",
"shelfWidth"
],
"leetcode_dataset_entry_point": "Solution().minHeightShelves",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:38",
"tests_t... | cpp | {
"raw_signature": "int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {",
"container": "Solution",
"callable": "minHeightShelves",
"parameters": [
{
"name": "books",
"type": "vector<vector<int>>&"
},
{
"name": "shelfWidth",
"type": "int"
}
],
"return_ty... |
1,106 | parsing-a-boolean-expression | Hard | A boolean expression is an expression that evaluates to either true or false. It can be in one of the following shapes:
- 't' that evaluates to true.
- 'f' that evaluates to false.
- '!(subExpr)' that evaluates to the logical NOT of the inner expression subExpr.
- '&(subExpr_1, subExpr_2, ..., subExpr_n)' that evaluat... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(expression = \"!(!(t))\") == True\n assert candidate(expression = \"|(t,t,t)\") == True\n assert candidate(expression = \"|(f,f,f,t)\") == True\n assert candidate(expression = \"&(t,t,t,t,t,t)\") == True\n assert candidate(ex... | [
"\"&(|(f))\"",
"\"|(f,f,f,t)\"",
"\"!(&(f,t))\""
] | [
"Write a function \"parse\" which calls helper functions \"parse_or\", \"parse_and\", \"parse_not\"."
] | {
"canonical_parameter_names": [
"expression"
],
"leetcode_dataset_entry_point": "Solution().parseBoolExpr",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:40",
"tests_total": 130,
"t... | cpp | {
"raw_signature": "bool parseBoolExpr(string expression) {",
"container": "Solution",
"callable": "parseBoolExpr",
"parameters": [
{
"name": "expression",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"... |
1,108 | defanging-an-ip-address | Easy | Given a valid (IPv4) IP address, return a defanged version of that IP address.
A defanged IP address replaces every period "." with "[.]".
Example 1:
Input: address = "1.1.1.1"
Output: "1[.]1[.]1[.]1"
Example 2:
Input: address = "255.100.50.0"
Output: "255[.]100[.]50[.]0"
Constraints:
- The given address is a va... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(address = \"255.100.50.0\") == \"255[.]100[.]50[.]0\"\n assert candidate(address = \"255.255.255.255\") == \"255[.]255[.]255[.]255\"\n assert candidate(address = \"192.168.1.1\") == \"192[.]168[.]1[.]1\"\n assert candidate(addre... | [
"\"1.1.1.1\"",
"\"255.100.50.0\""
] | [] | {
"canonical_parameter_names": [
"address"
],
"leetcode_dataset_entry_point": "Solution().defangIPaddr",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:42",
"tests_total": 48,
"tests_... | cpp | {
"raw_signature": "string defangIPaddr(string address) {",
"container": "Solution",
"callable": "defangIPaddr",
"parameters": [
{
"name": "address",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,109 | corporate-flight-bookings | Medium | There are n flights that are labeled from 1 to n.
You are given an array of flight bookings bookings, where bookings[i] = [first_i, last_i, seats_i] represents a booking for flights first_i through last_i (inclusive) with seats_i seats reserved for each flight in the range.
Return an array answer of length n, where a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(bookings = [[1, 2, 100], [2, 5, 50], [3, 4, 20]],n = 5) == [100, 150, 70, 70, 50]\n assert candidate(bookings = [[1, 1, 5], [1, 2, 7], [1, 3, 9]],n = 3) == [21, 16, 9]\n assert candidate(bookings = [[1, 4, 5], [4, 5, 6], [2, 5, 3]]... | [
"[[1,2,10],[2,3,20],[2,5,25]]\n5",
"[[1,2,10],[2,2,15]]\n2"
] | [] | {
"canonical_parameter_names": [
"bookings",
"n"
],
"leetcode_dataset_entry_point": "Solution().corpFlightBookings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:45",
"tests_total... | cpp | {
"raw_signature": "vector<int> corpFlightBookings(vector<vector<int>>& bookings, int n) {",
"container": "Solution",
"callable": "corpFlightBookings",
"parameters": [
{
"name": "bookings",
"type": "vector<vector<int>>&"
},
{
"name": "n",
"type": "int"
}
],
"return_ty... |
1,111 | maximum-nesting-depth-of-two-valid-parentheses-strings | Medium | A string is a valid parentheses string (denoted VPS) if and only if it consists of "(" and ")" characters only, and:
- It is the empty string, or
- It can be written as AB (A concatenated with B), where A and B are VPS's, or
- It can be written as (A), where A is a VPS.
We can similarly define the nesting depth depth... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(seq = \"()\") == [0, 0]\n assert candidate(seq = \"(()())\") == [0, 1, 1, 1, 1, 0]\n assert candidate(seq = \"(()(()(())))\") == [0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0]\n assert candidate(seq = \"((())())()\") == [0, 1, 0, 0, 1, 1,... | [
"\"(()())\"",
"\"()(())()\""
] | [] | {
"canonical_parameter_names": [
"seq"
],
"leetcode_dataset_entry_point": "Solution().maxDepthAfterSplit",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:47",
"tests_total": 146,
"tes... | cpp | {
"raw_signature": "vector<int> maxDepthAfterSplit(string seq) {",
"container": "Solution",
"callable": "maxDepthAfterSplit",
"parameters": [
{
"name": "seq",
"type": "string"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,122 | relative-sort-array | Easy | Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.
Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Elements that do not appear in arr2 should be placed at the end of arr1 in ascending order.
Example 1:
Inpu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr1 = [28, 6, 22, 8, 44, 17],arr2 = [22, 28, 8, 6]) == [22, 28, 8, 6, 17, 44]\n assert candidate(arr1 = [1, 2, 3],arr2 = [1, 2, 3, 4, 5]) == [1, 2, 3]\n assert candidate(arr1 = [10, 9, 8, 7, 6],arr2 = [10, 9, 8, 7, 6]) == [10, 9, ... | [
"[2,3,1,3,2,4,6,7,9,2,19]\n[2,1,4,3,9,6]",
"[28,6,22,8,44,17]\n[22,28,8,6]"
] | [
"Using a hashmap, we can map the values of arr2 to their position in arr2.",
"After, we can use a custom sorting function."
] | {
"canonical_parameter_names": [
"arr1",
"arr2"
],
"leetcode_dataset_entry_point": "Solution().relativeSortArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:10:58",
"tests_total":... | cpp | {
"raw_signature": "vector<int> relativeSortArray(vector<int>& arr1, vector<int>& arr2) {",
"container": "Solution",
"callable": "relativeSortArray",
"parameters": [
{
"name": "arr1",
"type": "vector<int>&"
},
{
"name": "arr2",
"type": "vector<int>&"
}
],
"return_type... |
1,124 | longest-well-performing-interval | Medium | We are given hours, a list of the number of hours worked per day for a given employee.
A day is considered to be a tiring day if and only if the number of hours worked is (strictly) greater than 8.
A well-performing interval is an interval of days for which the number of tiring days is strictly larger than the number... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(hours = [9, 7, 9, 7, 9, 7, 9, 7]) == 7\n assert candidate(hours = [8, 9, 9, 10]) == 4\n assert candidate(hours = [9, 9, 9, 9, 9, 9, 9]) == 7\n assert candidate(hours = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(hour... | [
"[9,9,6,0,6,6,9]",
"[6,6,6]"
] | [
"Make a new array A of +1/-1s corresponding to if hours[i] is > 8 or not. The goal is to find the longest subarray with positive sum.",
"Using prefix sums (PrefixSum[i+1] = A[0] + A[1] + ... + A[i]), you need to find for each j, the smallest i < j with PrefixSum[i] + 1 == PrefixSum[j]."
] | {
"canonical_parameter_names": [
"hours"
],
"leetcode_dataset_entry_point": "Solution().longestWPI",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:02",
"tests_total": 99,
"tests_drop... | cpp | {
"raw_signature": "int longestWPI(vector<int>& hours) {",
"container": "Solution",
"callable": "longestWPI",
"parameters": [
{
"name": "hours",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,125 | smallest-sufficient-team | Hard | In a project, you have a list of required skills req_skills, and a list of people. The i^th person people[i] contains a list of skills that the person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can r... | {
"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 ... | [
"[\"java\",\"nodejs\",\"reactjs\"]\n[[\"java\"],[\"nodejs\"],[\"nodejs\",\"reactjs\"]]",
"[\"algorithms\",\"math\",\"java\",\"reactjs\",\"csharp\",\"aws\"]\n[[\"algorithms\",\"math\",\"java\"],[\"algorithms\",\"math\",\"reactjs\"],[\"java\",\"csharp\",\"aws\"],[\"reactjs\",\"csharp\"],[\"csharp\",\"math\"],[\"aws... | [
"Do a bitmask DP.",
"For each person, for each set of skills, we can update our understanding of a minimum set of people needed to perform this set of skills."
] | {
"canonical_parameter_names": [
"req_skills",
"people"
],
"leetcode_dataset_entry_point": "Solution().smallestSufficientTeam",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:05",
"... | cpp | {
"raw_signature": "vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {",
"container": "Solution",
"callable": "smallestSufficientTeam",
"parameters": [
{
"name": "req_skills",
"type": "vector<string>&"
},
{
"name": "people",
"type... |
1,128 | number-of-equivalent-domino-pairs | Easy | Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a == c and b == d), or (a == d and b == c) - that is, one domino can be rotated to be equal to another domino.
Return the number of pairs (i, j) for which 0 <= i < j < dominoes.length, and dominoes[i] is equival... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(dominoes = [[7, 8], [8, 7], [7, 8], [7, 8], [8, 7]]) == 10\n assert candidate(dominoes = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]) == 10\n assert candidate(dominoes = [[1, 2], [2, 1], [3, 4], [5, 6]]) == 1\n assert candidate(dom... | [
"[[1,2],[2,1],[3,4],[5,6]]",
"[[1,2],[1,2],[1,1],[1,2],[2,2]]"
] | [
"For each domino j, find the number of dominoes you've already seen (dominoes i with i < j) that are equivalent.",
"You can keep track of what you've seen using a hashmap."
] | {
"canonical_parameter_names": [
"dominoes"
],
"leetcode_dataset_entry_point": "Solution().numEquivDominoPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:07",
"tests_total": 89,
... | cpp | {
"raw_signature": "int numEquivDominoPairs(vector<vector<int>>& dominoes) {",
"container": "Solution",
"callable": "numEquivDominoPairs",
"parameters": [
{
"name": "dominoes",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"typ... |
1,129 | shortest-path-with-alternating-colors | Medium | You are given an integer n, the number of nodes in a directed graph where the nodes are labeled from 0 to n - 1. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.
You are given two arrays redEdges and blueEdges where:
- redEdges[i] = [a_i, b_i] indicates that there is a directe... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,redEdges = [[0, 1], [1, 2]],blueEdges = [[1, 3]]) == [0, 1, -1, 2]\n assert candidate(n = 4,redEdges = [[0, 1], [0, 2], [0, 3]],blueEdges = [[1, 2], [1, 3], [2, 3]]) == [0, 1, 1, 1]\n assert candidate(n = 2,redEdges = [[0, 0]... | [
"3\n[[0,1],[1,2]]\n[]",
"3\n[[0,1]]\n[[2,1]]"
] | [
"Do a breadth-first search, where the \"nodes\" are actually (Node, color of last edge taken)."
] | {
"canonical_parameter_names": [
"n",
"redEdges",
"blueEdges"
],
"leetcode_dataset_entry_point": "Solution().shortestAlternatingPaths",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20... | cpp | {
"raw_signature": "vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {",
"container": "Solution",
"callable": "shortestAlternatingPaths",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "redEdges",
"type": "v... |
1,130 | minimum-cost-tree-from-leaf-values | Medium | Given an array arr of positive integers, consider all binary trees such that:
- Each node has either 0 or 2 children;
- The values of arr correspond to the values of each leaf in an in-order traversal of the tree.
- The value of each non-leaf node is equal to the product of the largest leaf value in its left and right... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4]) == 20\n assert candidate(arr = [3, 2, 1]) == 8\n assert candidate(arr = [15, 13, 5, 3, 15]) == 500\n assert candidate(arr = [4, 11]) == 44\n assert candidate(arr = [7, 12, 8, 10]) == 284\n assert candid... | [
"[6,2,4]",
"[4,11]"
] | [
"Do a DP, where dp(i, j) is the answer for the subarray arr[i]..arr[j].",
"For each possible way to partition the subarray i <= k < j, the answer is max(arr[i]..arr[k]) * max(arr[k+1]..arr[j]) + dp(i, k) + dp(k+1, j)."
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().mctFromLeafValues",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:12",
"tests_total": 108,
"test... | cpp | {
"raw_signature": "int mctFromLeafValues(vector<int>& arr) {",
"container": "Solution",
"callable": "mctFromLeafValues",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,131 | maximum-of-absolute-value-expression | Medium | Given two arrays of integers with equal lengths, return the maximum value of:
|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|
where the maximum is taken over all 0 <= i, j < arr1.length.
Example 1:
Input: arr1 = [1,2,3,4], arr2 = [-1,4,5,6]
Output: 13
Example 2:
Input: arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr1 = [1, -2, -5, 0, 10],arr2 = [0, -2, -1, -7, -4]) == 20\n assert candidate(arr1 = [1, 3, 5, 7],arr2 = [2, 4, 6, 8]) == 15\n assert candidate(arr1 = [-1, -2, -3, -4, -5],arr2 = [1, 2, 3, 4, 5]) == 12\n assert candidate(arr1 =... | [
"[1,2,3,4]\n[-1,4,5,6]",
"[1,-2,-5,0,10]\n[0,-2,-1,-7,-4]"
] | [
"Use the idea that abs(A) + abs(B) = max(A+B, A-B, -A+B, -A-B)."
] | {
"canonical_parameter_names": [
"arr1",
"arr2"
],
"leetcode_dataset_entry_point": "Solution().maxAbsValExpr",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:15",
"tests_total": 94,... | cpp | {
"raw_signature": "int maxAbsValExpr(vector<int>& arr1, vector<int>& arr2) {",
"container": "Solution",
"callable": "maxAbsValExpr",
"parameters": [
{
"name": "arr1",
"type": "vector<int>&"
},
{
"name": "arr2",
"type": "vector<int>&"
}
],
"return_type": "int",
"sig... |
1,137 | n-th-tribonacci-number | Easy | The Tribonacci sequence T_n is defined as follows:
T_0 = 0, T_1 = 1, T_2 = 1, and T_{n+3} = T_n + T_{n+1} + T_{n+2} for n >= 0.
Given n, return the value of T_n.
Example 1:
Input: n = 4
Output: 4
Explanation:
T_3 = 0 + 1 + 1 = 2
T_4 = 1 + 1 + 2 = 4
Example 2:
Input: n = 25
Output: 1389537
Constraints:
- 0 <= n ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 0) == 0\n assert candidate(n = 3) == 2\n assert candidate(n = 4) == 4\n assert candidate(n = 37) == 2082876103\n assert candidate(n = 2) == 1\n assert candidate(n = 1) == 1\n assert candidate(n = 25) == 1389537\n ... | [
"4",
"25"
] | [
"Make an array F of length 38, and set F[0] = 0, F[1] = F[2] = 1.",
"Now write a loop where you set F[n+3] = F[n] + F[n+1] + F[n+2], and return F[n]."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().tribonacci",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:27",
"tests_total": 18,
"tests_dropped"... | cpp | {
"raw_signature": "int tribonacci(int n) {",
"container": "Solution",
"callable": "tribonacci",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,138 | alphabet-board-path | Medium | On an alphabet board, we start at position (0, 0), corresponding to character board[0][0].
Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"], as shown in the diagram below.
We may make the following moves:
- 'U' moves our position up one row, if the position exists on the board;
- 'D' moves our positi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(target = \"azaz\") == \"!DDDDD!UUUUU!DDDDD!\"\n assert candidate(target = \"zm\") == \"DDDDD!UUURR!\"\n assert candidate(target = \"abcde\") == \"!R!R!R!R!\"\n assert candidate(target = \"leet\") == \"RDD!UURRR!!DDD!\"\n asse... | [
"\"leet\"",
"\"code\""
] | [
"Create a hashmap from letter to position on the board.",
"Now for each letter, try moving there in steps, where at each step you check if it is inside the boundaries of the board."
] | {
"canonical_parameter_names": [
"target"
],
"leetcode_dataset_entry_point": "Solution().alphabetBoardPath",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:29",
"tests_total": 103,
"t... | cpp | {
"raw_signature": "string alphabetBoardPath(string target) {",
"container": "Solution",
"callable": "alphabetBoardPath",
"parameters": [
{
"name": "target",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,139 | largest-1-bordered-square | Medium | Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn't exist in the grid.
Example 1:
Input: grid = [[1,1,1],[1,0,1],[1,1,1]]
Output: 9
Example 2:
Input: grid = [[1,1,0,0]]
Output: 1
Constraints:
- 1 <= grid.length <= ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1], [1, 0, 0, 1]]) == 1\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 25\n assert candidate(grid = [[1, 0], [0, 1]]... | [
"[[1,1,1],[1,0,1],[1,1,1]]",
"[[1,1,0,0]]"
] | [
"For each square, know how many ones are up, left, down, and right of this square. You can find it in O(N^2) using dynamic programming.",
"Now for each square ( O(N^3) ), we can evaluate whether that square is 1-bordered in O(1)."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().largest1BorderedSquare",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:32",
"tests_total": 64,
... | cpp | {
"raw_signature": "int largest1BorderedSquare(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "largest1BorderedSquare",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_... |
1,140 | stone-game-ii | Medium | Alice and Bob continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to end with the most stones.
Alice and Bob take turns, with Alice starting first.
On each player's turn, that player can ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(piles = [1, 2, 3, 4, 5, 100]) == 104\n assert candidate(piles = [10]) == 10\n assert candidate(piles = [100, 100, 100, 100]) == 200\n assert candidate(piles = [1, 2, 3]) == 3\n assert candidate(piles = [1, 100, 1, 100, 1, 100... | [
"[2,7,9,4,4]",
"[1,2,3,4,5,100]"
] | [
"Use dynamic programming: the states are (i, m) for the answer of piles[i:] and that given m."
] | {
"canonical_parameter_names": [
"piles"
],
"leetcode_dataset_entry_point": "Solution().stoneGameII",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:34",
"tests_total": 96,
"tests_dro... | cpp | {
"raw_signature": "int stoneGameII(vector<int>& piles) {",
"container": "Solution",
"callable": "stoneGameII",
"parameters": [
{
"name": "piles",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,143 | longest-common-subsequence | Medium | Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.
A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(text1 = \"a\",text2 = \"b\") == 0\n assert candidate(text1 = \"xyz\",text2 = \"zyx\") == 1\n assert candidate(text1 = \"ezupkr\",text2 = \"ubmrapg\") == 2\n assert candidate(text1 = \"abcde\",text2 = \"ace\") == 3\n assert ca... | [
"\"abcde\"\n\"ace\"",
"\"abc\"\n\"abc\"",
"\"abc\"\n\"def\""
] | [
"Try dynamic programming. DP[i][j] represents the longest common subsequence of text1[0 ... i] & text2[0 ... j].",
"DP[i][j] = DP[i - 1][j - 1] + 1 , if text1[i] == text2[j] DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]) , otherwise"
] | {
"canonical_parameter_names": [
"text1",
"text2"
],
"leetcode_dataset_entry_point": "Solution().longestCommonSubsequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:36",
"test... | cpp | {
"raw_signature": "int longestCommonSubsequence(string text1, string text2) {",
"container": "Solution",
"callable": "longestCommonSubsequence",
"parameters": [
{
"name": "text1",
"type": "string"
},
{
"name": "text2",
"type": "string"
}
],
"return_type": "int",
"s... |
1,144 | decrease-elements-to-make-array-zigzag | Medium | Given an array nums of integers, a move consists of choosing any element and decreasing it by 1.
An array A is a zigzag array if either:
- Every even-indexed element is greater than adjacent elements, ie. A[0] > A[1] < A[2] > A[3] < A[4] > ...
- OR, every odd-indexed element is greater than adjacent elements, ie. A[0... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 3, 2, 1]) == 2\n assert candidate(nums = [1, 3, 2, 2, 3, 1]) == 4\n assert candidate(nums = [1, 1, 1]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 8\n assert candidate(nums = [9, 6, 1, 6, 2])... | [
"[1,2,3]",
"[9,6,1,6,2]"
] | [
"Do each case (even indexed is greater, odd indexed is greater) separately. In say the even case, you should decrease each even-indexed element until it is lower than its immediate neighbors."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().movesToMakeZigzag",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:38",
"tests_total": 148,
"tes... | cpp | {
"raw_signature": "int movesToMakeZigzag(vector<int>& nums) {",
"container": "Solution",
"callable": "movesToMakeZigzag",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
1,147 | longest-chunked-palindrome-decomposition | Hard | You are given a string text. You should split it to k substrings (subtext_1, subtext_2, ..., subtext_k) such that:
- subtext_i is a non-empty string.
- The concatenation of all the substrings is equal to text (i.e., subtext_1 + subtext_2 + ... + subtext_k == text).
- subtext_i == subtext_{k - i + 1} for all valid valu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(text = \"abcabc\") == 2\n assert candidate(text = \"abcabcabc\") == 3\n assert candidate(text = \"level\") == 5\n assert candidate(text = \"zyxzyxzyx\") == 3\n assert candidate(text = \"madam\") == 5\n assert candidate(tex... | [
"\"ghiabcdefhelloadamhelloabcdefghi\"",
"\"merchant\"",
"\"antaprezatepzapreanta\""
] | [
"Using a rolling hash, we can quickly check whether two strings are equal.",
"Use that as the basis of a dp."
] | {
"canonical_parameter_names": [
"text"
],
"leetcode_dataset_entry_point": "Solution().longestDecomposition",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:43",
"tests_total": 181,
"... | cpp | {
"raw_signature": "int longestDecomposition(string text) {",
"container": "Solution",
"callable": "longestDecomposition",
"parameters": [
{
"name": "text",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"... |
1,154 | day-of-the-year | Easy | Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.
Example 1:
Input: date = "2019-01-09"
Output: 9
Explanation: Given date is the 9th day of the year in 2019.
Example 2:
Input: date = "2019-02-10"
Output: 41
Constraints:
- date.length == 10
- dat... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(date = \"2017-03-01\") == 60\n assert candidate(date = \"2019-01-09\") == 9\n assert candidate(date = \"1900-02-28\") == 59\n assert candidate(date = \"2000-03-01\") == 61\n assert candidate(date = \"2018-08-20\") == 232\n ... | [
"\"2019-01-09\"",
"\"2019-02-10\""
] | [
"Have a integer array of how many days there are per month. February gets one extra day if its a leap year. Then, we can manually count the ordinal as day + (number of days in months before this one)."
] | {
"canonical_parameter_names": [
"date"
],
"leetcode_dataset_entry_point": "Solution().dayOfYear",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:54",
"tests_total": 119,
"tests_dropp... | cpp | {
"raw_signature": "int dayOfYear(string date) {",
"container": "Solution",
"callable": "dayOfYear",
"parameters": [
{
"name": "date",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,155 | number-of-dice-rolls-with-target-sum | Medium | You have n dice, and each dice has k faces numbered from 1 to k.
Given three integers n, k, and target, return the number of possible ways (out of the k^n total ways) to roll the dice, so the sum of the face-up numbers equals target. Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:
Input: n =... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 15,k = 10,target = 100) == 794915145\n assert candidate(n = 4,k = 6,target = 12) == 125\n assert candidate(n = 30,k = 30,target = 500) == 222616187\n assert candidate(n = 2,k = 6,target = 7) == 6\n assert candidate(n = 10... | [
"1\n6\n3",
"2\n6\n7",
"30\n30\n500"
] | [
"Use dynamic programming. The states are how many dice are remaining, and what sum total you have rolled so far."
] | {
"canonical_parameter_names": [
"n",
"k",
"target"
],
"leetcode_dataset_entry_point": "Solution().numRollsToTarget",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:56",
"tests_... | cpp | {
"raw_signature": "int numRollsToTarget(int n, int k, int target) {",
"container": "Solution",
"callable": "numRollsToTarget",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
},
{
"name": "target",
"type": "int"
}
],
"... |
1,156 | swap-for-longest-repeated-character-substring | Medium | You are given a string text. You can swap two of the characters in the text.
Return the length of the longest substring with repeated characters.
Example 1:
Input: text = "ababa"
Output: 3
Explanation: We can swap the first 'b' with the last 'a', or the last 'b' with the first 'a'. Then, the longest repeated charact... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(text = \"ababababab\") == 3\n assert candidate(text = \"abababababababab\") == 3\n assert candidate(text = \"ababa\") == 3\n assert candidate(text = \"aaaaa\") == 5\n assert candidate(text = \"zzzzzzzzzz\") == 10\n assert ... | [
"\"bbaababbba\"",
"\"bbabbbbbaaba\"",
"\"abaaaaabbbbbaa\""
] | [
"There are two cases: a block of characters, or two blocks of characters between one different character. By keeping a run-length encoded version of the string, we can easily check these cases."
] | {
"canonical_parameter_names": [
"text"
],
"leetcode_dataset_entry_point": "Solution().maxRepOpt1",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:11:58",
"tests_total": 56,
"tests_dropp... | cpp | {
"raw_signature": "int maxRepOpt1(string text) {",
"container": "Solution",
"callable": "maxRepOpt1",
"parameters": [
{
"name": "text",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,160 | find-words-that-can-be-formed-by-characters | Easy | You are given an array of strings words and a string chars.
A string is good if it can be formed by characters from chars (each character can only be used once for each word in words).
Return the sum of lengths of all good strings in words.
Example 1:
Input: words = ["cat","bt","hat","tree"], chars = "atach"
Output... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['abcd', 'ab', 'bc', 'cd'],chars = \"abcd\") == 10\n assert candidate(words = ['cat', 'bt', 'hat', 'tree'],chars = \"atach\") == 6\n assert candidate(words = ['zxcvbnm', 'asdfghjkl', 'qwertyuiop'],chars = \"qwertyuiopasdfgh... | [
"[\"cat\",\"bt\",\"hat\",\"tree\"]\n\"atach\"",
"[\"hello\",\"world\",\"leetcode\"]\n\"welldonehoneyr\""
] | [
"Solve the problem for each string in words independently.",
"Now try to think in frequency of letters.",
"Count how many times each character occurs in string chars.",
"To form a string using characters from chars, the frequency of each character in chars must be greater than or equal the frequency of that c... | {
"canonical_parameter_names": [
"words",
"chars"
],
"leetcode_dataset_entry_point": "Solution().countCharacters",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:12:00",
"tests_total":... | cpp | {
"raw_signature": "int countCharacters(vector<string>& words, string chars) {",
"container": "Solution",
"callable": "countCharacters",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
},
{
"name": "chars",
"type": "string"
}
],
"return_type": "int",
"s... |
1,162 | as-far-from-land-as-possible | Medium | Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or water exists in the grid, return -1.
The distance used in this problem is the Manhattan distance: th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == -1\n assert candidate(grid = [[1, 0, 1, 0], [0, 0, 0, 0], [1, 0, 1, 0], [0, 0, 0, 0]]) == 2\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 6\n ... | [
"[[1,0,1],[0,0,0],[1,0,1]]",
"[[1,0,0],[0,0,0],[0,0,0]]"
] | [
"Can you think of this problem in a backwards way ?",
"Imagine expanding outward from each land cell. What kind of search does that ?",
"Use BFS starting from all land cells in the same time.",
"When do you reach the furthest water cell?"
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().maxDistance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:12:05",
"tests_total": 62,
"tests_drop... | cpp | {
"raw_signature": "int maxDistance(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "maxDistance",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,163 | last-substring-in-lexicographical-order | Hard | Given a string s, return the last substring of s in lexicographical order.
Example 1:
Input: s = "abab"
Output: "bab"
Explanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lexicographically maximum substring is "bab".
Example 2:
Input: s = "leetcode"
Output: "tcode"
Constraints:
- 1 <=... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abab\") == \"bab\"\n assert candidate(s = \"mississippi\") == \"ssissippi\"\n assert candidate(s = \"abcdabcdabcd\") == \"dabcdabcd\"\n assert candidate(s = \"banana\") == \"nana\"\n assert candidate(s = \"zyxzy\") == \... | [
"\"abab\"",
"\"leetcode\""
] | [
"Assume that the answer is a sub-string from index i to j. If you add the character at index j+1 you get a better answer.",
"The answer is always a suffix of the given string.",
"Since the limits are high, we need an efficient data structure.",
"Use suffix array."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().lastSubstring",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:12:07",
"tests_total": 80,
"tests_dropp... | cpp | {
"raw_signature": "string lastSubstring(string s) {",
"container": "Solution",
"callable": "lastSubstring",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,169 | invalid-transactions | Medium | A transaction is possibly invalid if:
- the amount exceeds $1000, or;
- if it occurs within (and including) 60 minutes of another transaction with the same name in a different city.
You are given an array of strings transaction where transactions[i] consists of comma-separated values representing the name, time (in m... | {
"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 ... | [
"[\"alice,20,800,mtv\",\"alice,50,100,beijing\"]",
"[\"alice,20,800,mtv\",\"alice,50,1200,mtv\"]",
"[\"alice,20,800,mtv\",\"bob,50,1200,mtv\"]"
] | [
"Split each string into four arrays.",
"For each transaction check if it's invalid, you can do this with just a loop with help of the four arrays generated on step 1.",
"At the end you perform O(N ^ 2) operations."
] | {
"canonical_parameter_names": [
"transactions"
],
"leetcode_dataset_entry_point": "Solution().invalidTransactions",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:12:16",
"tests_total": 7... | cpp | {
"raw_signature": "vector<string> invalidTransactions(vector<string>& transactions) {",
"container": "Solution",
"callable": "invalidTransactions",
"parameters": [
{
"name": "transactions",
"type": "vector<string>&"
}
],
"return_type": "vector<string>",
"signature_source": "leetcode/c... |
1,170 | compare-strings-by-frequency-of-the-smallest-character | Medium | Let the function f(s) be the frequency of the lexicographically smallest character in a non-empty string s. For example, if s = "dcce" then f(s) = 2 because the lexicographically smallest character is 'c', which has a frequency of 2.
You are given an array of strings words and another array of query strings queries. F... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(queries = ['ccc'],words = ['a', 'bb', 'ccc', 'dddd']) == [1]\n assert candidate(queries = ['a', 'b', 'c'],words = ['d', 'e', 'f', 'g']) == [0, 0, 0]\n assert candidate(queries = ['abc', 'def'],words = ['ghi', 'jkl']) == [0, 0]\n ... | [
"[\"cbd\"]\n[\"zaaaz\"]",
"[\"bbb\",\"cc\"]\n[\"a\",\"aa\",\"aaa\",\"aaaa\"]"
] | [
"For each string from words calculate the leading count and store it in an array, then sort the integer array.",
"For each string from queries calculate the leading count \"p\" and in base of the sorted array calculated on the step 1 do a binary search to count the number of items greater than \"p\"."
] | {
"canonical_parameter_names": [
"queries",
"words"
],
"leetcode_dataset_entry_point": "Solution().numSmallerByFrequency",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:12:18",
"tests... | cpp | {
"raw_signature": "vector<int> numSmallerByFrequency(vector<string>& queries, vector<string>& words) {",
"container": "Solution",
"callable": "numSmallerByFrequency",
"parameters": [
{
"name": "queries",
"type": "vector<string>&"
},
{
"name": "words",
"type": "vector<string>... |
1,175 | prime-arrangements | Easy | Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.)
(Recall that an integer is prime if and only if it is greater than 1, and cannot be written as a product of two positive integers both smaller than it.)
Since the answer may be large, return the answer modulo 10^9 + 7.... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 30) == 13697484\n assert candidate(n = 99) == 75763854\n assert candidate(n = 75) == 918450925\n assert candidate(n = 20) == 344376809\n assert candidate(n = 2) == 1\n assert candidate(n = 19) == 445364737\n assert ... | [
"5",
"100"
] | [
"Solve the problem for prime numbers and composite numbers separately.",
"Multiply the number of permutations of prime numbers over prime indices with the number of permutations of composite numbers over composite indices.",
"The number of permutations equals the factorial."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().numPrimeArrangements",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:12:23",
"tests_total": 27,
"test... | cpp | {
"raw_signature": "int numPrimeArrangements(int n) {",
"container": "Solution",
"callable": "numPrimeArrangements",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,177 | can-make-palindrome-from-substring | Medium | You are given a string s and array queries where queries[i] = [left_i, right_i, k_i]. We may rearrange the substring s[left_i...right_i] for each query and then choose up to k_i of them to replace with any lowercase English letter.
If the substring is possible to be a palindrome string after the operations above, the ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcd\",queries = [[0, 2, 1], [1, 3, 1]]) == [True, True]\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",queries = [[0, 25, 12], [0, 25, 13], [0, 25, 14]]) == [False, True, True]\n assert candidate(s = \"zaz\",queries =... | [
"\"abcda\"\n[[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]",
"\"lyb\"\n[[0,1,0],[2,2,1]]"
] | [
"Since we can rearrange the substring, all we care about is the frequency of each character in that substring.",
"How to find the character frequencies efficiently ?",
"As a preprocess, calculate the accumulate frequency of all characters for all prefixes of the string.",
"How to check if a substring can be c... | {
"canonical_parameter_names": [
"s",
"queries"
],
"leetcode_dataset_entry_point": "Solution().canMakePaliQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:12:27",
"tests_total"... | cpp | {
"raw_signature": "vector<bool> canMakePaliQueries(string s, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "canMakePaliQueries",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "queries",
"type": "vector<vector<int>>&"
}
],
"retu... |
1,178 | number-of-valid-words-for-each-puzzle | Hard | With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
- word contains the first letter of puzzle.
- For each letter in word, that letter is in puzzle.
- For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage", while
- invalid w... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['apple', 'pleas', 'please'],puzzles = ['aelwxyz', 'aelpxyz', 'aelpsxy', 'saelpxy', 'xaelpsy']) == [0, 1, 3, 2, 0]\n assert candidate(words = ['aaaa', 'asas', 'able', 'ability', 'actt', 'actor', 'access'],puzzles = ['aboveyz',... | [
"[\"aaaa\",\"asas\",\"able\",\"ability\",\"actt\",\"actor\",\"access\"]\n[\"aboveyz\",\"abrodyz\",\"abslute\",\"absoryz\",\"actresz\",\"gaswxyz\"]",
"[\"apple\",\"pleas\",\"please\"]\n[\"aelwxyz\",\"aelpxyz\",\"aelpsxy\",\"saelpxy\",\"xaelpsy\"]"
] | [
"Exploit the fact that the length of the puzzle is only 7.",
"Use bit-masks to represent the word and puzzle strings.",
"For each puzzle, count the number of words whose bit-mask is a sub-mask of the puzzle's bit-mask."
] | {
"canonical_parameter_names": [
"words",
"puzzles"
],
"leetcode_dataset_entry_point": "Solution().findNumOfValidWords",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:12:30",
"tests_t... | cpp | {
"raw_signature": "vector<int> findNumOfValidWords(vector<string>& words, vector<string>& puzzles) {",
"container": "Solution",
"callable": "findNumOfValidWords",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
},
{
"name": "puzzles",
"type": "vector<string>&"
... |
1,184 | distance-between-bus-stops | Easy | A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.
The bus goes along both directions i.e. clockwise and counterclockwise.
Return the shortest distance between the give... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(distance = [7, 10, 1, 12, 11, 14, 5, 0],start = 7,destination = 2) == 17\n assert candidate(distance = [1, 2, 3, 4],start = 0,destination = 2) == 3\n assert candidate(distance = [4, 3, 2],start = 0,destination = 2) == 2\n assert... | [
"[1,2,3,4]\n0\n1",
"[1,2,3,4]\n0\n2",
"[1,2,3,4]\n0\n3"
] | [
"Find the distance between the two stops if the bus moved in clockwise or counterclockwise directions."
] | {
"canonical_parameter_names": [
"distance",
"start",
"destination"
],
"leetcode_dataset_entry_point": "Solution().distanceBetweenBusStops",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-... | cpp | {
"raw_signature": "int distanceBetweenBusStops(vector<int>& distance, int start, int destination) {",
"container": "Solution",
"callable": "distanceBetweenBusStops",
"parameters": [
{
"name": "distance",
"type": "vector<int>&"
},
{
"name": "start",
"type": "int"
},
{... |
1,185 | day-of-the-week | Easy | Given a date, return the corresponding day of the week for that date.
The input is given as three integers representing the day, month and year respectively.
Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.
Note: January 1, 1971 was a Fr... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(day = 31,month = 12,year = 2100) == \"Friday\"\n assert candidate(day = 15,month = 8,year = 1993) == \"Sunday\"\n assert candidate(day = 10,month = 9,year = 2023) == \"Sunday\"\n assert candidate(day = 18,month = 7,year = 1999) ... | [
"31\n8\n2019",
"18\n7\n1999",
"15\n8\n1993"
] | [
"Sum up the number of days for the years before the given year.",
"Handle the case of a leap year.",
"Find the number of days for each month of the given year."
] | {
"canonical_parameter_names": [
"day",
"month",
"year"
],
"leetcode_dataset_entry_point": "Solution().dayOfTheWeek",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:12:44",
"tests_... | cpp | {
"raw_signature": "string dayOfTheWeek(int day, int month, int year) {",
"container": "Solution",
"callable": "dayOfTheWeek",
"parameters": [
{
"name": "day",
"type": "int"
},
{
"name": "month",
"type": "int"
},
{
"name": "year",
"type": "int"
}
],
... |
1,186 | maximum-subarray-sum-with-one-deletion | Medium | Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maximum p... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [-1, 0, -2, 3, 4, -5, 3]) == 10\n assert candidate(arr = [5, -1, 5, -1, 5]) == 14\n assert candidate(arr = [2, 3, -2, 5, -3]) == 10\n assert candidate(arr = [-10000]) == -10000\n assert candidate(arr = [5, -3, -2, 7, 1]... | [
"[1,-2,0,3]",
"[1,-2,-2,3]",
"[-1,-1,-1,-1]"
] | [
"How to solve this problem if no deletions are allowed ?",
"Try deleting each element and find the maximum subarray sum to both sides of that element.",
"To do that efficiently, use the idea of Kadane's algorithm."
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().maximumSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:12:46",
"tests_total": 139,
"tests_dropp... | cpp | {
"raw_signature": "int maximumSum(vector<int>& arr) {",
"container": "Solution",
"callable": "maximumSum",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,187 | make-array-strictly-increasing | Hard | Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing.
In one operation, you can choose two indices 0 <= i < arr1.length and 0 <= j < arr2.length and do the assignment arr1[i] = arr2[j].
If there is no way to make arr1 strictly increasi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr1 = [1, 3, 5, 7],arr2 = [2, 4, 6, 8]) == 0\n assert candidate(arr1 = [1, 5, 3, 6, 7],arr2 = [1, 6, 3, 3]) == -1\n assert candidate(arr1 = [1, 2, 3, 4, 5],arr2 = [6, 7, 8, 9]) == 0\n assert candidate(arr1 = [1, 5, 3, 6, 7],arr... | [
"[1,5,3,6,7]\n[1,3,2,4]",
"[1,5,3,6,7]\n[4,3,1]",
"[1,5,3,6,7]\n[1,6,3,3]"
] | [
"Use dynamic programming.",
"The state would be the index in arr1 and the index of the previous element in arr2 after sorting it and removing duplicates."
] | {
"canonical_parameter_names": [
"arr1",
"arr2"
],
"leetcode_dataset_entry_point": "Solution().makeArrayIncreasing",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:12:48",
"tests_total... | cpp | {
"raw_signature": "int makeArrayIncreasing(vector<int>& arr1, vector<int>& arr2) {",
"container": "Solution",
"callable": "makeArrayIncreasing",
"parameters": [
{
"name": "arr1",
"type": "vector<int>&"
},
{
"name": "arr2",
"type": "vector<int>&"
}
],
"return_type": "... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.