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 |
|---|---|---|---|---|---|---|---|---|---|
1,354 | construct-target-array-with-multiple-sums | Hard | You are given an array target of n integers. From a starting array arr consisting of n 1's, you may perform the following procedure :
- let x be the sum of all elements currently in your array.
- choose index i, such that 0 <= i < n and set the value of arr at index i to x.
- You may repeat this procedure as many time... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == False\n assert candidate(target = [1, 2, 3, 4, 5]) == False\n assert candidate(target = [1000000000, 1, 1]) == False\n assert candidate(target = [5, 7, 1]) == True\n assert candida... | [
"[9,3,5]",
"[1,1,1,2]",
"[8,5]"
] | [
"Given that the sum is strictly increasing, the largest element in the target must be formed in the last step by adding the total sum in the previous step. Thus, we can simulate the process in a reversed way.",
"Subtract the largest with the rest of the array, and put the new element into the array. Repeat until ... | {
"canonical_parameter_names": [
"target"
],
"leetcode_dataset_entry_point": "Solution().isPossible",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:17:40",
"tests_total": 99,
"tests_dro... | cpp | {
"raw_signature": "bool isPossible(vector<int>& target) {",
"container": "Solution",
"callable": "isPossible",
"parameters": [
{
"name": "target",
"type": "vector<int>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,356 | sort-integers-by-the-number-of-1-bits | Easy | You are given an integer array arr. Sort the integers in the array in ascending order by the number of 1's in their binary representation and in case of two or more integers have the same number of 1's you have to sort them in ascending order.
Return the array after sorting it.
Example 1:
Input: arr = [0,1,2,3,4,5,6... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [3, 7, 8, 9]) == [8, 3, 9, 7]\n assert candidate(arr = [1, 3, 5, 7, 9]) == [1, 3, 5, 9, 7]\n assert candidate(arr = [1, 0, 2, 3, 4]) == [0, 1, 2, 4, 3]\n assert candidate(arr = [3, 8, 3, 6, 5, 7, 9, 2]) == [2, 8, 3, 3, 5, ... | [
"[0,1,2,3,4,5,6,7,8]",
"[1024,512,256,128,64,32,16,8,4,2,1]"
] | [
"Simulate the problem. Count the number of 1's in the binary representation of each integer.",
"Sort by the number of 1's ascending and by the value in case of tie."
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().sortByBits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:17:42",
"tests_total": 96,
"tests_droppe... | cpp | {
"raw_signature": "vector<int> sortByBits(vector<int>& arr) {",
"container": "Solution",
"callable": "sortByBits",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
1,358 | number-of-substrings-containing-all-three-characters | Medium | Given a string s consisting only of characters a, b and c.
Return the number of substrings containing at least one occurrence of all these characters a, b and c.
Example 1:
Input: s = "abcabc"
Output: 10
Explanation: The substrings containing at least one occurrence of the characters a, b and c are "abc", "abca", "a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aaabbbccc\") == 9\n assert candidate(s = \"abcba\") == 5\n assert candidate(s = \"cba\") == 1\n assert candidate(s = \"cbaacb\") == 8\n assert candidate(s = \"bbbacbac\") == 18\n assert candidate(s = \"ccccabc\") == ... | [
"\"abcabc\"",
"\"aaacb\"",
"\"abc\""
] | [
"For each position we simply need to find the first occurrence of a/b/c on or after this position.",
"So we can pre-compute three link-list of indices of each a, b, and c."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().numberOfSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:17:44",
"tests_total": 130,
"tests... | cpp | {
"raw_signature": "int numberOfSubstrings(string s) {",
"container": "Solution",
"callable": "numberOfSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,359 | count-all-valid-pickup-and-delivery-options | Hard | Given n orders, each order consists of a pickup and a delivery service.
Count all valid pickup/delivery possible sequences such that delivery(i) is always after of pickup(i).
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:
Input: n = 1
Output: 1
Explanation: Unique order (P1, D1), Delivery ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3) == 90\n assert candidate(n = 250) == 418733499\n assert candidate(n = 100) == 14159051\n assert candidate(n = 4) == 2520\n assert candidate(n = 2) == 6\n assert candidate(n = 20) == 580270580\n assert candidate(n... | [
"1",
"2",
"3"
] | [
"Use the permutation and combination theory to add one (P, D) pair each time until n pairs."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().countOrders",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:17:47",
"tests_total": 32,
"tests_dropped... | cpp | {
"raw_signature": "int countOrders(int n) {",
"container": "Solution",
"callable": "countOrders",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,360 | number-of-days-between-two-dates | Easy | Write a program to count the number of days between two dates.
The two dates are given as strings, their format is YYYY-MM-DD as shown in the examples.
Example 1:
Input: date1 = "2019-06-29", date2 = "2019-06-30"
Output: 1
Example 2:
Input: date1 = "2020-01-15", date2 = "2019-12-31"
Output: 15
Constraints:
- The... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(date1 = \"2019-02-28\",date2 = \"2019-03-01\") == 1\n assert candidate(date1 = \"2020-01-15\",date2 = \"2019-12-31\") == 15\n assert candidate(date1 = \"2000-03-01\",date2 = \"2000-02-29\") == 1\n assert candidate(date1 = \"2023... | [
"\"2019-06-29\"\n\"2019-06-30\"",
"\"2020-01-15\"\n\"2019-12-31\""
] | [
"Create a function f(date) that counts the number of days from 1900-01-01 to date. How can we calculate the answer ?",
"The answer is just |f(date1) - f(date2)|.",
"How to construct f(date) ?",
"For each year from 1900 to year - 1 sum up 365 or 366 in case of leap years. Then sum up for each month the number ... | {
"canonical_parameter_names": [
"date1",
"date2"
],
"leetcode_dataset_entry_point": "Solution().daysBetweenDates",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:17:49",
"tests_total"... | cpp | {
"raw_signature": "int daysBetweenDates(string date1, string date2) {",
"container": "Solution",
"callable": "daysBetweenDates",
"parameters": [
{
"name": "date1",
"type": "string"
},
{
"name": "date2",
"type": "string"
}
],
"return_type": "int",
"signature_source"... |
1,361 | validate-binary-tree-nodes | Medium | You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one valid binary tree.
If node i has no left child then leftChild[i] will equal -1, similarly for the right child.
Note that the nodes have no... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 2,leftChild = [1, 0],rightChild = [-1, -1]) == False\n assert candidate(n = 3,leftChild = [1, -1, -1],rightChild = [2, -1, -1]) == True\n assert candidate(n = 3,leftChild = [1, 0, -1],rightChild = [-1, -1, -1]) == False\n as... | [
"4\n[1,-1,3,-1]\n[2,-1,-1,-1]",
"4\n[1,-1,3,-1]\n[2,3,-1,-1]",
"2\n[1,0]\n[-1,-1]"
] | [
"Find the parent of each node.",
"A valid tree must have nodes with only one parent and exactly one node with no parent."
] | {
"canonical_parameter_names": [
"n",
"leftChild",
"rightChild"
],
"leetcode_dataset_entry_point": "Solution().validateBinaryTreeNodes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T2... | cpp | {
"raw_signature": "bool validateBinaryTreeNodes(int n, vector<int>& leftChild, vector<int>& rightChild) {",
"container": "Solution",
"callable": "validateBinaryTreeNodes",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "leftChild",
"type": "vector<int>&"
},
... |
1,362 | closest-divisors | Medium | Given an integer num, find the closest two integers in absolute difference whose product equals num + 1 or num + 2.
Return the two integers in any order.
Example 1:
Input: num = 8
Output: [3,3]
Explanation: For num + 1 = 9, the closest divisors are 3 & 3, for num + 2 = 10, the closest divisors are 2 & 5, hence 3 & 3... | {
"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 ... | [
"8",
"123",
"999"
] | [
"Find the divisors of n+1 and n+2.",
"To find the divisors of a number, you only need to iterate to the square root of that number."
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().closestDivisors",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:17:53",
"tests_total": 53,
"tests_d... | cpp | {
"raw_signature": "vector<int> closestDivisors(int num) {",
"container": "Solution",
"callable": "closestDivisors",
"parameters": [
{
"name": "num",
"type": "int"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,363 | largest-multiple-of-three | Hard | Given an array of digits digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order. If there is no answer return an empty string.
Since the answer may not fit in an integer data type, return the answer as a string. Note that the returning answer must not con... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(digits = [5, 5, 5]) == \"555\"\n assert candidate(digits = [3, 3, 3]) == \"333\"\n assert candidate(digits = [3, 3, 3, 3, 3]) == \"33333\"\n assert candidate(digits = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999999999\"\n assert... | [
"[8,1,9]",
"[8,6,7,1,0]",
"[1]"
] | [
"A number is a multiple of three if and only if its sum of digits is a multiple of three.",
"Use dynamic programming.",
"To find the maximum number, try to maximize the number of digits of the number.",
"Sort the digits in descending order to find the maximum number."
] | {
"canonical_parameter_names": [
"digits"
],
"leetcode_dataset_entry_point": "Solution().largestMultipleOfThree",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:17:56",
"tests_total": 72,
... | cpp | {
"raw_signature": "string largestMultipleOfThree(vector<int>& digits) {",
"container": "Solution",
"callable": "largestMultipleOfThree",
"parameters": [
{
"name": "digits",
"type": "vector<int>&"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source... |
1,365 | how-many-numbers-are-smaller-than-the-current-number | Easy | Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i].
Return the answer in an array.
Example 1:
Input: nums = [8,1,2,2,3]
Output: [4,0,1,1,3]
Explanation:
For nums[... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == [0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [8, 1, 2, 2, 3]) == [4, 0, 1, 1, 3]\n assert cand... | [
"[8,1,2,2,3]",
"[6,5,4,8]",
"[7,7,7,7]"
] | [
"Brute force for each array element.",
"In order to improve the time complexity, we can sort the array and get the answer for each array element."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().smallerNumbersThanCurrent",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:17:58",
"tests_total": 110... | cpp | {
"raw_signature": "vector<int> smallerNumbersThanCurrent(vector<int>& nums) {",
"container": "Solution",
"callable": "smallerNumbersThanCurrent",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
... |
1,366 | rank-teams-by-votes | Medium | In a special ranking system, each voter gives a rank from highest to lowest to all teams participating in the competition.
The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, if they tie a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(votes = ['ABC', 'ACB', 'ABC', 'ACB', 'ACB']) == \"ACB\"\n assert candidate(votes = ['WXYZ', 'XYZW']) == \"XWYZ\"\n assert candidate(votes = ['BCA', 'CAB', 'ACB', 'BAC', 'CBA', 'ABC']) == \"ABC\"\n assert candidate(votes = ['A', ... | [
"[\"ABC\",\"ACB\",\"ABC\",\"ACB\",\"ACB\"]",
"[\"WXYZ\",\"XYZW\"]",
"[\"ZMNAGUEDSJYLBOPHRQICWFXTVK\"]"
] | [
"Build array rank where rank[i][j] is the number of votes for team i to be the j-th rank.",
"Sort the teams by rank array. if rank array is the same for two or more teams, sort them by the ID in ascending order."
] | {
"canonical_parameter_names": [
"votes"
],
"leetcode_dataset_entry_point": "Solution().rankTeams",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:00",
"tests_total": 73,
"tests_dropp... | cpp | {
"raw_signature": "string rankTeams(vector<string>& votes) {",
"container": "Solution",
"callable": "rankTeams",
"parameters": [
{
"name": "votes",
"type": "vector<string>&"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,368 | minimum-cost-to-make-at-least-one-valid-path-in-a-grid | Hard | Given an m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be:
- 1 which means go to the cell to the right. (i.e go from grid[i][j] to grid[i][j + 1])
- 2 which means go to the cell to the left. (i.e go from grid[i][j] ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 2\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 1], [3, 4, 1, 2], [4, 1, 2, 3]]) == 3\n assert candidate(grid = [[4, 4, 4], [4, 4, 4], [4, 4, 4]]) == 4\n assert candidate(grid = ... | [
"[[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]",
"[[1,1,3],[3,2,2],[1,1,4]]",
"[[1,2],[4,3]]"
] | [
"Build a graph where grid[i][j] is connected to all the four side-adjacent cells with weighted edge. the weight is 0 if the sign is pointing to the adjacent cell or 1 otherwise.",
"Do BFS from (0, 0) visit all edges with weight = 0 first. the answer is the distance to (m -1, n - 1)."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().minCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:04",
"tests_total": 87,
"tests_dropped"... | cpp | {
"raw_signature": "int minCost(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "minCost",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
1,370 | increasing-decreasing-string | Easy | You are given a string s. Reorder the string using the following algorithm:
1. Remove the smallest character from s and append it to the result.
2. Remove the smallest character from s that is greater than the last appended character, and append it to the result.
3. Repeat step 2 until no more characters can be remove... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"rqy\") == \"qry\"\n assert candidate(s = \"fuvofn\") == \"fnouvf\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"vibhu\") == \"bhiuv\"\n assert candida... | [
"\"aaaabbbbcccc\"",
"\"rat\""
] | [
"Count the frequency of each character.",
"Loop over all character from 'a' to 'z' and append the character if it exists and decrease frequency by 1. Do the same from 'z' to 'a'.",
"Keep repeating until the frequency of all characters is zero."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().sortString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:07",
"tests_total": 69,
"tests_dropped"... | cpp | {
"raw_signature": "string sortString(string s) {",
"container": "Solution",
"callable": "sortString",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,371 | find-the-longest-substring-containing-vowels-in-even-counts | Medium | Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"bcbcbc\") == 6\n assert candidate(s = \"cbacdcdcdbacdbad\") == 14\n assert candidate(s = \"aeiouaeiouaeiouaeiou\") == 20\n assert candidate(s = \"aaaaaeeeeeiioooouuuu\") == 14\n assert candidate(s = \"abcdefghijklmnopqr... | [
"\"eleetminicoworoep\"",
"\"leetcodeisgreat\"",
"\"bcbcbc\""
] | [
"Represent the counts (odd or even) of vowels with a bitmask.",
"Precompute the prefix xor for the bitmask of vowels and then get the longest valid substring."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().findTheLongestSubstring",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:09",
"tests_total": 77,
"t... | cpp | {
"raw_signature": "int findTheLongestSubstring(string s) {",
"container": "Solution",
"callable": "findTheLongestSubstring",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"... |
1,374 | generate-a-string-with-characters-that-have-odd-counts | Easy | Given an integer n, return a string with n characters such that each character in such string occurs an odd number of times.
The returned string must contain only lowercase English letters. If there are multiples valid strings, return any of them.
Example 1:
Input: n = 4
Output: "pppz"
Explanation: "pppz" is a valid... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 250) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | [
"4",
"2",
"7"
] | [
"If n is odd, return a string of size n formed only by 'a', else return string formed with n-1 'a' and 1 'b''."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().generateTheString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:15",
"tests_total": 58,
"tests_d... | cpp | {
"raw_signature": "string generateTheString(int n) {",
"container": "Solution",
"callable": "generateTheString",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,375 | number-of-times-binary-string-is-prefix-aligned | Medium | You have a 1-indexed binary string of length n where all the bits are 0 initially. We will flip all the bits of this binary string (i.e., change them from 0 to 1) one by one. You are given a 1-indexed integer array flips where flips[i] indicates that the bit at index flips[i] will be flipped in the i^th step.
A binary... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(flips = [5, 4, 3, 2, 1]) == 1\n assert candidate(flips = [1, 2, 3, 4, 5]) == 5\n assert candidate(flips = [2, 1, 3, 5, 4]) == 3\n assert candidate(flips = [3, 2, 4, 1, 5]) == 2\n assert candidate(flips = [4, 1, 2, 3]) == 1\n ... | [
"[3,2,4,1,5]",
"[4,1,2,3]"
] | [
"If in the step x all bulb shines then bulbs 1,2,3,..,x should shines too."
] | {
"canonical_parameter_names": [
"flips"
],
"leetcode_dataset_entry_point": "Solution().numTimesAllBlue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:18",
"tests_total": 91,
"tests... | cpp | {
"raw_signature": "int numTimesAllBlue(vector<int>& flips) {",
"container": "Solution",
"callable": "numTimesAllBlue",
"parameters": [
{
"name": "flips",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,376 | time-needed-to-inform-all-employees | Medium | A company has n employees with a unique ID for each employee from 0 to n - 1. The head of the company is the one with headID.
Each employee has one direct manager given in the manager array where manager[i] is the direct manager of the i-th employee, manager[headID] = -1. Also, it is guaranteed that the subordination ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,headID = 2,manager = [2, 2, -1, 2, 2, 2],informTime = [0, 0, 1, 0, 0, 0]) == 1\n assert candidate(n = 15,headID = 0,manager = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],informTime = [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,... | [
"1\n0\n[-1]\n[0]",
"6\n2\n[2,2,-1,2,2,2]\n[0,0,1,0,0,0]"
] | [
"The company can be represented as a tree, headID is always the root.",
"Store for each node the time needed to be informed of the news.",
"Answer is the max time a leaf node needs to be informed."
] | {
"canonical_parameter_names": [
"n",
"headID",
"manager",
"informTime"
],
"leetcode_dataset_entry_point": "Solution().numOfMinutes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T... | cpp | {
"raw_signature": "int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {",
"container": "Solution",
"callable": "numOfMinutes",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "headID",
"type": "int"
},
{
"name": "manage... |
1,377 | frog-position-after-t-seconds | Hard | Given an undirected tree consisting of n vertices numbered from 1 to n. A frog starts jumping from vertex 1. In one second, the frog jumps from its current vertex to another unvisited vertex if they are directly connected. The frog can not jump back to a visited vertex. In case the frog can jump to several vertices, it... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat... | [
"7\n[[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]]\n2\n4",
"7\n[[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]]\n1\n7"
] | [
"Use a variation of DFS with parameters 'curent_vertex' and 'current_time'.",
"Update the probability considering to jump to one of the children vertices."
] | {
"canonical_parameter_names": [
"n",
"edges",
"t",
"target"
],
"leetcode_dataset_entry_point": "Solution().frogPosition",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:23",
... | cpp | {
"raw_signature": "double frogPosition(int n, vector<vector<int>>& edges, int t, int target) {",
"container": "Solution",
"callable": "frogPosition",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
},
{
"name": ... |
1,380 | lucky-numbers-in-a-matrix | Easy | Given an m x n matrix of distinct numbers, return all lucky numbers in the matrix in any order.
A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.
Example 1:
Input: matrix = [[3,7,8],[9,11,13],[15,16,17]]
Output: [15]
Explanation: 15 is the only lucky... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ... | [
"[[3,7,8],[9,11,13],[15,16,17]]",
"[[1,10,4,2],[9,3,8,7],[15,16,17,12]]",
"[[7,8],[1,2]]"
] | [
"Find out and save the minimum of each row and maximum of each column in two lists.",
"Then scan through the whole matrix to identify the elements that satisfy the criteria."
] | {
"canonical_parameter_names": [
"matrix"
],
"leetcode_dataset_entry_point": "Solution().luckyNumbers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:27",
"tests_total": 87,
"tests_d... | cpp | {
"raw_signature": "vector<int> luckyNumbers(vector<vector<int>>& matrix) {",
"container": "Solution",
"callable": "luckyNumbers",
"parameters": [
{
"name": "matrix",
"type": "vector<vector<int>>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_... |
1,383 | maximum-performance-of-a-team | Hard | You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n. speed[i] and efficiency[i] represent the speed and efficiency of the i^th engineer respectively.
Choose at most k different engineers out of the n engineers to form a team with t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,speed = [2, 10, 3, 1, 5, 8],efficiency = [5, 4, 3, 9, 7, 2],k = 2) == 60\n assert candidate(n = 6,speed = [2, 10, 3, 1, 5, 8],efficiency = [5, 4, 3, 9, 7, 2],k = 3) == 68\n assert candidate(n = 5,speed = [4, 1, 12, 7, 8],effi... | [
"6\n[2,10,3,1,5,8]\n[5,4,3,9,7,2]\n2",
"6\n[2,10,3,1,5,8]\n[5,4,3,9,7,2]\n3",
"6\n[2,10,3,1,5,8]\n[5,4,3,9,7,2]\n4"
] | [
"Keep track of the engineers by their efficiency in decreasing order.",
"Starting from one engineer, to build a team, it suffices to bring K-1 more engineers who have higher efficiencies as well as high speeds."
] | {
"canonical_parameter_names": [
"n",
"speed",
"efficiency",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxPerformance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18... | cpp | {
"raw_signature": "int maxPerformance(int n, vector<int>& speed, vector<int>& efficiency, int k) {",
"container": "Solution",
"callable": "maxPerformance",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "speed",
"type": "vector<int>&"
},
{
"name": "e... |
1,385 | find-the-distance-value-between-two-arrays | Easy | Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays.
The distance value is defined as the number of elements arr1[i] such that there is not any element arr2[j] where |arr1[i]-arr2[j]| <= d.
Example 1:
Input: arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2
Output: 2
Ex... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr1 = [10, 20, 30],arr2 = [5, 15, 25],d = 4) == 3\n assert candidate(arr1 = [4, 5, 8],arr2 = [10, 9, 1, 8],d = 2) == 2\n assert candidate(arr1 = [1, 4, 2, 3],arr2 = [-4, -3, 6, 10, 20, 30],d = 3) == 2\n assert candidate(arr1 = ... | [
"[4,5,8]\n[10,9,1,8]\n2",
"[1,4,2,3]\n[-4,-3,6,10,20,30]\n3",
"[2,1,100,3]\n[-5,-2,10,-3,7]\n6"
] | [
"Sort 'arr2' and use binary search to get the closest element for each 'arr1[i]', it gives a time complexity of O(nlogn)."
] | {
"canonical_parameter_names": [
"arr1",
"arr2",
"d"
],
"leetcode_dataset_entry_point": "Solution().findTheDistanceValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:34",
"t... | cpp | {
"raw_signature": "int findTheDistanceValue(vector<int>& arr1, vector<int>& arr2, int d) {",
"container": "Solution",
"callable": "findTheDistanceValue",
"parameters": [
{
"name": "arr1",
"type": "vector<int>&"
},
{
"name": "arr2",
"type": "vector<int>&"
},
{
"... |
1,386 | cinema-seat-allocation | Medium | A cinema has n rows of seats, numbered from 1 to n. Each row has 10 seats, numbered from 1 to 10.
You are given a 2D integer array reservedSeats, where reservedSeats[i] = [row_i, seat_i] means that seat seat_i in row row_i is already reserved.
A four-person group must be assigned to four seats in the same row. The gr... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,reservedSeats = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 8\n assert candidate(n = 4,reservedSeats = [[4, 3], [1, 4], [4, 6], [1, 7]]) == 4\n assert candidate(n = 5,reservedSeats = [[1, 2],... | [
"3\n[[1,2],[1,3],[1,8],[2,6],[3,1],[3,10]]",
"2\n[[2,1],[1,8],[2,6]]",
"4\n[[4,3],[1,4],[4,6],[1,7]]"
] | [
"Note you can allocate at most two four-person groups in one row.",
"Greedily check if you can allocate seats for two groups, one group or none.",
"Process only rows that appear in the input, for other rows you can always allocate seats for two groups."
] | {
"canonical_parameter_names": [
"n",
"reservedSeats"
],
"leetcode_dataset_entry_point": "Solution().maxNumberOfFamilies",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:36",
"tests... | cpp | {
"raw_signature": "int maxNumberOfFamilies(int n, vector<vector<int>>& reservedSeats) {",
"container": "Solution",
"callable": "maxNumberOfFamilies",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "reservedSeats",
"type": "vector<vector<int>>&"
}
],
"retur... |
1,387 | sort-integers-by-the-power-value | Medium | The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
- if x is even then x = x / 2
- if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three inte... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(lo = 1,hi = 10,k = 1) == 1\n assert candidate(lo = 5,hi = 5,k = 1) == 5\n assert candidate(lo = 12,hi = 15,k = 2) == 13\n assert candidate(lo = 1,hi = 10,k = 5) == 5\n assert candidate(lo = 10,hi = 20,k = 5) == 13\n assert... | [
"12\n15\n2",
"7\n11\n4"
] | [
"Use dynamic programming to get the power of each integer of the intervals.",
"Sort all the integers of the interval by the power value and return the k-th in the sorted list."
] | {
"canonical_parameter_names": [
"lo",
"hi",
"k"
],
"leetcode_dataset_entry_point": "Solution().getKth",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:39",
"tests_total": 93,
... | cpp | {
"raw_signature": "int getKth(int lo, int hi, int k) {",
"container": "Solution",
"callable": "getKth",
"parameters": [
{
"name": "lo",
"type": "int"
},
{
"name": "hi",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"si... |
1,388 | pizza-with-3n-slices | Hard | There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows:
- You will pick any pizza slice.
- Your friend Alice will pick the next slice in the anti-clockwise direction of your pick.
- Your friend Bob will pick the next slice in the clockwise direction of your pick.
- R... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(slices = [9, 7, 7, 7, 6, 6]) == 16\n assert candidate(slices = [1000, 1000, 1000, 1000, 1000, 1000]) == 2000\n assert candidate(slices = [10, 1, 1, 1, 1, 1, 1, 1]) == 11\n assert candidate(slices = [9, 8, 7, 6, 5, 4, 3, 2, 1]) =... | [
"[1,2,3,4,5,6]",
"[8,9,8,6,1,1]"
] | [
"By studying the pattern of the operations, we can find out that the problem is equivalent to: Given an integer array with size 3N, select N integers with maximum sum and any selected integers are not next to each other in the array.",
"The first one in the array is considered next to the last one in the array. U... | {
"canonical_parameter_names": [
"slices"
],
"leetcode_dataset_entry_point": "Solution().maxSizeSlices",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:41",
"tests_total": 111,
"tests... | cpp | {
"raw_signature": "int maxSizeSlices(vector<int>& slices) {",
"container": "Solution",
"callable": "maxSizeSlices",
"parameters": [
{
"name": "slices",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
1,389 | create-target-array-in-the-given-order | Easy | Given two arrays of integers nums and index. Your task is to create target array under the following rules:
- Initially target array is empty.
- From left to right read nums[i] and index[i], insert at index index[i] the value nums[i] in target array.
- Repeat the previous step until there are no elements to read in nu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1],index = [0]) == [1]\n assert candidate(nums = [10, 9, 8, 7, 6],index = [0, 1, 1, 1, 1]) == [10, 6, 7, 8, 9]\n assert candidate(nums = [0, 1, 2, 3, 4],index = [0, 1, 2, 2, 1]) == [0, 4, 1, 3, 2]\n assert candidate(nums... | [
"[0,1,2,3,4]\n[0,1,2,2,1]",
"[1,2,3,4,0]\n[0,1,2,3,0]",
"[1]\n[0]"
] | [
"Simulate the process and fill corresponding numbers in the designated spots."
] | {
"canonical_parameter_names": [
"nums",
"index"
],
"leetcode_dataset_entry_point": "Solution().createTargetArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:43",
"tests_total"... | cpp | {
"raw_signature": "vector<int> createTargetArray(vector<int>& nums, vector<int>& index) {",
"container": "Solution",
"callable": "createTargetArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "index",
"type": "vector<int>&"
}
],
"return_ty... |
1,390 | four-divisors | Medium | Given an integer array nums, return the sum of divisors of the integers in that array that have exactly four divisors. If there is no such integer in the array, return 0.
Example 1:
Input: nums = [21,4,7]
Output: 32
Explanation:
21 has 4 divisors: 1, 3, 7, 21
4 has 3 divisors: 1, 2, 4
7 has 2 divisors: 1, 7
The answe... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [101, 103, 107, 109, 113]) == 0\n assert candidate(nums = [2310, 2320, 2330, 2340, 2350]) == 0\n assert candidate(nums = [30, 44, 25, 63]) == 0\n assert candidate(nums = [30, 100, 49]) == 0\n assert candidate(nums = [6... | [
"[21,4,7]",
"[21,21]",
"[1,2,3,4,5]"
] | [
"Find the divisors of each element in the array.",
"You only need to loop to the square root of a number to find its divisors."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().sumFourDivisors",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:45",
"tests_total": 136,
"tests... | cpp | {
"raw_signature": "int sumFourDivisors(vector<int>& nums) {",
"container": "Solution",
"callable": "sumFourDivisors",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
1,391 | check-if-there-is-a-valid-path-in-a-grid | Medium | You are given an m x n grid. Each cell of grid represents a street. The street of grid[i][j] can be:
- 1 which means a street connecting the left cell and the right cell.
- 2 which means a street connecting the upper cell and the lower cell.
- 3 which means a street connecting the left cell and the lower cell.
- 4 whi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[4, 3, 2, 1], [2, 1, 4, 3], [3, 2, 1, 4]]) == False\n assert candidate(grid = [[2], [2], [2]]) == True\n assert candidate(grid = [[1, 1, 2]]) == False\n assert candidate(grid = [[2, 4, 3], [6, 5, 2]]) == True\n assert... | [
"[[3],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2]]",
"[[6,2],[3,2],[2,3],[5,6],[4,4],[3,2],[4,4],[2,2],[1,3],[3,5],[6,6],[3,5]... | [
"Start DFS from the node (0, 0) and follow the path till you stop.",
"When you reach a cell and cannot move anymore check that this cell is (m - 1, n - 1) or not."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().hasValidPath",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:47",
"tests_total": 77,
"tests_dro... | cpp | {
"raw_signature": "bool hasValidPath(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "hasValidPath",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
1,392 | longest-happy-prefix | Hard | A string is called a happy prefix if it is a non-empty prefix which is also a suffix (excluding itself).
Given a string s, return the longest happy prefix of s. Return an empty string "" if no such prefix exists.
Example 1:
Input: s = "level"
Output: "l"
Explanation: s contains 4 prefix excluding itself ("l", "le", ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"prefixprefix\") == \"prefix\"\n assert candidate(s = \"abcdef\") == \"\"\n assert candidate(s = \"aaaaa\") == \"aaaa\"\n assert candidate(s = \"aaaaabaaaa\") == \"aaaa\"\n assert candidate(s = \"a\") == \"\"\n assert... | [
"\"level\"",
"\"ababab\""
] | [
"Use Longest Prefix Suffix (KMP-table) or String Hashing."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().longestPrefix",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:50",
"tests_total": 162,
"tests_drop... | cpp | {
"raw_signature": "string longestPrefix(string s) {",
"container": "Solution",
"callable": "longestPrefix",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,394 | find-lucky-integer-in-an-array | Easy | Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to its value.
Return the largest lucky integer in the array. If there is no lucky integer return -1.
Example 1:
Input: arr = [2,2,3,4]
Output: 2
Explanation: The only lucky number in the array is 2 because frequency... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [1, 1]) == -1\n assert candidate(arr = [5, 5, 4, 4, 4]) == -1\n assert candidate(arr = [5]) == -1\n assert candidate(arr = [5, 5, 5, 5, 5]) == 5\n assert candidate(arr = [2, 2, 3, 4]) == 2\n assert candidate(arr = [3... | [
"[2,2,3,4]",
"[1,2,2,3,3,3]",
"[2,2,2,3,3]"
] | [
"Count the frequency of each integer in the array.",
"Get all lucky numbers and return the largest of them."
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().findLucky",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:52",
"tests_total": 61,
"tests_dropped... | cpp | {
"raw_signature": "int findLucky(vector<int>& arr) {",
"container": "Solution",
"callable": "findLucky",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,395 | count-number-of-teams | Medium | There are n soldiers standing in a line. Each soldier is assigned a unique rating value.
You have to form a team of 3 soldiers amongst them under the following rules:
- Choose 3 soldiers with index (i, j, k) with rating (rating[i], rating[j], rating[k]).
- A team is valid if: (rating[i] < rating[j] < rating[k]) or (r... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(rating = [2, 1, 3]) == 0\n assert candidate(rating = [3, 1, 2, 5, 4]) == 2\n assert candidate(rating = [1, 5, 2, 4, 3]) == 3\n assert candidate(rating = [10, 6, 5, 8]) == 1\n assert candidate(rating = [5, 4, 3, 2, 1]) == 10\n... | [
"[2,5,3,4,1]",
"[2,1,3]",
"[1,2,3,4]"
] | [
"BruteForce, check all possibilities."
] | {
"canonical_parameter_names": [
"rating"
],
"leetcode_dataset_entry_point": "Solution().numTeams",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:54",
"tests_total": 114,
"tests_drop... | cpp | {
"raw_signature": "int numTeams(vector<int>& rating) {",
"container": "Solution",
"callable": "numTeams",
"parameters": [
{
"name": "rating",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,397 | find-all-good-strings | Hard | Given the strings s1 and s2 of size n and the string evil, return the number of good strings.
A good string has size n, it is alphabetically greater than or equal to s1, it is alphabetically smaller than or equal to s2, and it does not contain the string evil as a substring. Since the answer can be a huge number, retu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,s1 = \"apple\",s2 = \"zebra\",evil = \"app\") == 11220078\n assert candidate(n = 3,s1 = \"aaa\",s2 = \"zzz\",evil = \"abc\") == 17575\n assert candidate(n = 5,s1 = \"aaaaa\",s2 = \"zzzzz\",evil = \"abc\") == 11879348\n ass... | [
"2\n\"aa\"\n\"da\"\n\"b\"",
"8\n\"leetcode\"\n\"leetgoes\"\n\"leet\"",
"2\n\"gx\"\n\"gz\"\n\"x\""
] | [
"Use DP with 4 states (pos: Int, posEvil: Int, equalToS1: Bool, equalToS2: Bool) which compute the number of valid strings of size \"pos\" where the maximum common suffix with string \"evil\" has size \"posEvil\". When \"equalToS1\" is \"true\", the current valid string is equal to \"S1\" otherwise it is greater. I... | {
"canonical_parameter_names": [
"n",
"s1",
"s2",
"evil"
],
"leetcode_dataset_entry_point": "Solution().findGoodStrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:57",
... | cpp | {
"raw_signature": "int findGoodStrings(int n, string s1, string s2, string evil) {",
"container": "Solution",
"callable": "findGoodStrings",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "s1",
"type": "string"
},
{
"name": "s2",
"type": "strin... |
1,399 | count-largest-group | Easy | You are given an integer n.
We need to group the numbers from 1 to n according to the sum of its digits. For example, the numbers 14 and 5 belong to the same group, whereas 13 and 3 belong to different groups.
Return the number of groups that have the largest size, i.e. the maximum number of elements.
Example 1:
In... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 200) == 2\n assert candidate(n = 10000) == 1\n assert candidate(n = 9) == 9\n assert candidate(n = 104) == 1\n assert candidate(n = 9999) == 1\n assert candidate(n = 2) == 2\n assert candidate(n = 100) == 1\n ass... | [
"13",
"2"
] | [
"Count the digit sum for each integer in the range and find out the largest groups."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().countLargestGroup",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:18:59",
"tests_total": 45,
"tests_d... | cpp | {
"raw_signature": "int countLargestGroup(int n) {",
"container": "Solution",
"callable": "countLargestGroup",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,400 | construct-k-palindrome-strings | Medium | Given a string s and an integer k, return true if you can use all the characters in s to construct non-empty k palindrome strings or false otherwise.
Example 1:
Input: s = "annabelle", k = 2
Output: true
Explanation: You can construct two palindromes using all characters in s.
Some possible constructions "anna" + "el... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"a\",k = 2) == False\n assert candidate(s = \"aabbcc\",k = 3) == True\n assert candidate(s = \"abcd\",k = 2) == False\n assert candidate(s = \"yzyzyzyzyzyzyzy\",k = 17) == False\n assert candidate(s = \"true\",k = 4) == ... | [
"\"annabelle\"\n2",
"\"leetcode\"\n3",
"\"true\"\n4"
] | [
"If the s.length < k we cannot construct k strings from s and answer is false.",
"If the number of characters that have odd counts is > k then the minimum number of palindrome strings we can construct is > k and answer is false.",
"Otherwise you can construct exactly k palindrome strings and answer is true (why... | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().canConstruct",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:01",
"tests_total": 100,
"te... | cpp | {
"raw_signature": "bool canConstruct(string s, int k) {",
"container": "Solution",
"callable": "canConstruct",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
... |
1,401 | circle-and-rectangle-overlapping | Medium | You are given a circle represented as (radius, xCenter, yCenter) and an axis-aligned rectangle represented as (x1, y1, x2, y2), where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the rectangle.
Return true if the circle and rectangle are overlapped... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(radius = 3,xCenter = -3,yCenter = -4,x1 = -6,y1 = -6,x2 = -2,y2 = -2) == True\n assert candidate(radius = 2,xCenter = -2,yCenter = -2,x1 = -5,y1 = -5,x2 = -3,y2 = -3) == True\n assert candidate(radius = 5,xCenter = 0,yCenter = 0,x1... | [
"1\n0\n0\n1\n-1\n3\n1",
"1\n1\n1\n1\n-3\n2\n-1",
"1\n0\n0\n-1\n0\n0\n1"
] | [
"Locate the closest point of the square to the circle, you can then find the distance from this point to the center of the circle and check if this is less than or equal to the radius."
] | {
"canonical_parameter_names": [
"radius",
"xCenter",
"yCenter",
"x1",
"y1",
"x2",
"y2"
],
"leetcode_dataset_entry_point": "Solution().checkOverlap",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
... | cpp | {
"raw_signature": "bool checkOverlap(int radius, int xCenter, int yCenter, int x1, int y1, int x2, int y2) {",
"container": "Solution",
"callable": "checkOverlap",
"parameters": [
{
"name": "radius",
"type": "int"
},
{
"name": "xCenter",
"type": "int"
},
{
"nam... |
1,402 | reducing-dishes | Hard | A chef has collected data on the satisfaction level of his n dishes. Chef can cook any dish in 1 unit of time.
Like-time coefficient of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. time[i] * satisfaction[i].
Return the maximum sum of like-ti... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(satisfaction = [1, -1, 2, -2, 3, -3]) == 22\n assert candidate(satisfaction = [0]) == 0\n assert candidate(satisfaction = [-1]) == 0\n assert candidate(satisfaction = [-500, -500, -500, -500, -500]) == 0\n assert candidate(sa... | [
"[-1,-8,0,5,-7]",
"[4,3,2]",
"[-1,-4,-5]"
] | [
"Use dynamic programming to find the optimal solution by saving the previous best like-time coefficient and its corresponding element sum.",
"If adding the current element to the previous best like-time coefficient and its corresponding element sum would increase the best like-time coefficient, then go ahead and ... | {
"canonical_parameter_names": [
"satisfaction"
],
"leetcode_dataset_entry_point": "Solution().maxSatisfaction",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:06",
"tests_total": 114,
... | cpp | {
"raw_signature": "int maxSatisfaction(vector<int>& satisfaction) {",
"container": "Solution",
"callable": "maxSatisfaction",
"parameters": [
{
"name": "satisfaction",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leet... |
1,403 | minimum-subsequence-in-non-increasing-order | Easy | Given the array nums, obtain a subsequence of the array whose sum of elements is strictly greater than the sum of the non included elements in such subsequence.
If there are multiple solutions, return the subsequence with minimum size and if there still exist multiple solutions, return the subsequence with the maximum... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 4, 7, 6, 7]) == [7, 7, 6]\n assert candidate(nums = [100, 90, 80, 70, 60]) == [100, 90, 80]\n assert candidate(nums = [100, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [100]\n assert candidate(nums = ... | [
"[4,3,10,9,8]",
"[4,4,7,6,7]"
] | [
"Sort elements and take each element from the largest until accomplish the conditions."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minSubsequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:08",
"tests_total": 60,
"tests_d... | cpp | {
"raw_signature": "vector<int> minSubsequence(vector<int>& nums) {",
"container": "Solution",
"callable": "minSubsequence",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
1,404 | number-of-steps-to-reduce-a-number-in-binary-representation-to-one | Medium | Given the binary representation of an integer as a string s, return the number of steps to reduce it to 1 under the following rules:
-
If the current number is even, you have to divide it by 2.
-
If the current number is odd, you have to add 1 to it.
It is guaranteed that you can always reach one for all test cases.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"11101110111\") == 14\n assert candidate(s = \"1111\") == 5\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010101\") == 95\n assert candidate(s = \"1100110\") == 10\n assert candidate(s... | [
"\"1101\"",
"\"10\"",
"\"1\""
] | [
"Read the string from right to left, if the string ends in '0' then the number is even otherwise it is odd.",
"Simulate the steps described in the binary string."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().numSteps",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:10",
"tests_total": 101,
"tests_dropped":... | cpp | {
"raw_signature": "int numSteps(string s) {",
"container": "Solution",
"callable": "numSteps",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,405 | longest-happy-string | Medium | A string s is called happy if it satisfies the following conditions:
- s only contains the letters 'a', 'b', and 'c'.
- s does not contain any of "aaa", "bbb", or "ccc" as a substring.
- s contains at most a occurrences of the letter 'a'.
- s contains at most b occurrences of the letter 'b'.
- s contains at most c occ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(a = 7,b = 1,c = 0) == \"aabaa\"\n assert candidate(a = 100,b = 100,c = 100) == \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc... | [
"1\n1\n7",
"7\n1\n0"
] | [
"Use a greedy approach.",
"Use the letter with the maximum current limit that can be added without breaking the condition."
] | {
"canonical_parameter_names": [
"a",
"b",
"c"
],
"leetcode_dataset_entry_point": "Solution().longestDiverseString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:12",
"tests_t... | cpp | {
"raw_signature": "string longestDiverseString(int a, int b, int c) {",
"container": "Solution",
"callable": "longestDiverseString",
"parameters": [
{
"name": "a",
"type": "int"
},
{
"name": "b",
"type": "int"
},
{
"name": "c",
"type": "int"
}
],
... |
1,406 | stone-game-iii | Hard | Alice and Bob continue their games with piles of stones. There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.
Alice and Bob take turns, with Alice starting first. On each player's turn, that player can take 1, 2, or 3 stones from the firs... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(stoneValue = [0, 0, 0, 0, 0]) == \"Tie\"\n assert candidate(stoneValue = [1]) == \"Alice\"\n assert candidate(stoneValue = [1, -100, 1, 100]) == \"Tie\"\n assert candidate(stoneValue = [5, 3, 7, 1]) == \"Alice\"\n assert cand... | [
"[1,2,3,7]",
"[1,2,3,-9]",
"[1,2,3,6]"
] | [
"The game can be mapped to minmax game. Alice tries to maximize the total score and Bob tries to minimize it.",
"Use dynamic programming to simulate the game. If the total score was 0 the game is \"Tie\", and if it has positive value then \"Alice\" wins, otherwise \"Bob\" wins."
] | {
"canonical_parameter_names": [
"stoneValue"
],
"leetcode_dataset_entry_point": "Solution().stoneGameIII",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:14",
"tests_total": 102,
"te... | cpp | {
"raw_signature": "string stoneGameIII(vector<int>& stoneValue) {",
"container": "Solution",
"callable": "stoneGameIII",
"parameters": [
{
"name": "stoneValue",
"type": "vector<int>&"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
1,408 | string-matching-in-an-array | Easy | Given an array of string words, return all strings in words that are a substring of another word. You can return the answer in any order.
Example 1:
Input: words = ["mass","as","hero","superhero"]
Output: ["as","hero"]
Explanation: "as" is substring of "mass" and "hero" is substring of "superhero".
["hero","as"] is a... | {
"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 ... | [
"[\"mass\",\"as\",\"hero\",\"superhero\"]",
"[\"leetcode\",\"et\",\"code\"]",
"[\"blue\",\"green\",\"bu\"]"
] | [
"Bruteforce to find if one string is substring of another or use KMP algorithm."
] | {
"canonical_parameter_names": [
"words"
],
"leetcode_dataset_entry_point": "Solution().stringMatching",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:17",
"tests_total": 97,
"tests_... | cpp | {
"raw_signature": "vector<string> stringMatching(vector<string>& words) {",
"container": "Solution",
"callable": "stringMatching",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
}
],
"return_type": "vector<string>",
"signature_source": "leetcode/codeSnippets",
"type_so... |
1,409 | queries-on-a-permutation-with-key | Medium | Given the array queries of positive integers between 1 and m, you have to process all queries[i] (from i=0 to i=queries.length-1) according to the following rules:
- In the beginning, you have the permutation P=[1,2,3,...,m].
- For the current i, find the position of queries[i] in the permutation P (indexing from 0) a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(queries = [3, 1, 2, 1],m = 5) == [2, 1, 2, 1]\n assert candidate(queries = [1, 2, 3],m = 3) == [0, 1, 2]\n assert candidate(queries = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],m = 10) == [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(q... | [
"[3,1,2,1]\n5",
"[4,1,2,2]\n4",
"[7,5,5,8,3]\n8"
] | [
"Create the permutation P=[1,2,...,m], it could be a list for example.",
"For each i, find the position of queries[i] with a simple scan over P and then move this to the beginning."
] | {
"canonical_parameter_names": [
"queries",
"m"
],
"leetcode_dataset_entry_point": "Solution().processQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:19",
"tests_total": 97... | cpp | {
"raw_signature": "vector<int> processQueries(vector<int>& queries, int m) {",
"container": "Solution",
"callable": "processQueries",
"parameters": [
{
"name": "queries",
"type": "vector<int>&"
},
{
"name": "m",
"type": "int"
}
],
"return_type": "vector<int>",
"sig... |
1,411 | number-of-ways-to-paint-n-3-grid | Hard | You have a grid of size n x 3 and you want to paint each cell of the grid with exactly one of the three colors: Red, Yellow, or Green while making sure that no two adjacent cells have the same color (i.e., no two cells that share vertical or horizontal sides have the same color).
Given n the number of rows of the grid... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3) == 246\n assert candidate(n = 1000) == 650420578\n assert candidate(n = 100) == 905790447\n assert candidate(n = 2500) == 80958521\n assert candidate(n = 4) == 1122\n assert candidate(n = 4999) == 134620719\n ass... | [
"1",
"5000"
] | [
"We will use Dynamic programming approach. we will try all possible configuration.",
"Let dp[idx][prev1col][prev2col][prev3col] be the number of ways to color the rows of the grid from idx to n-1 keeping in mind that the previous row (idx - 1) has colors prev1col, prev2col and prev3col. Build the dp array to get ... | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().numOfWays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:23",
"tests_total": 37,
"tests_dropped":... | cpp | {
"raw_signature": "int numOfWays(int n) {",
"container": "Solution",
"callable": "numOfWays",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,413 | minimum-value-to-get-positive-step-by-step-sum | Easy | Given an array of integers nums, you start with an initial positive value startValue.
In each iteration, you calculate the step by step sum of startValue plus elements in nums (from left to right).
Return the minimum positive value of startValue such that the step by step sum is never less than 1.
Example 1:
Input:... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [-1, 1, -1, 1]) == 2\n assert candidate(nums = [100, 100, 100]) == 1\n assert candidate(nums = [-3, 2, -3, 4, 2]) == 5\n assert candidate(nums = [1, -2, -3]) == 5\n assert candidate(nums = [-1]) == 2\n assert candid... | [
"[-3,2,-3,4,2]",
"[1,2]",
"[1,-2,-3]"
] | [
"Find the minimum prefix sum."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minStartValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:26",
"tests_total": 95,
"tests_dr... | cpp | {
"raw_signature": "int minStartValue(vector<int>& nums) {",
"container": "Solution",
"callable": "minStartValue",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,414 | find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k | Medium | Given an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times.
The Fibonacci numbers are defined as:
- F_1 = 1
- F_2 = 1
- F_n = F_{n-1} + F_{n-2} for n > 2.
It is guaranteed that for the given constraints we can always find such Fibo... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(k = 433494437) == 1\n assert candidate(k = 377) == 1\n assert candidate(k = 6765) == 1\n assert candidate(k = 24157817) == 1\n assert candidate(k = 102334155) == 1\n assert candidate(k = 89) == 1\n assert candidate(k = ... | [
"7",
"10",
"19"
] | [
"Generate all Fibonacci numbers up to the limit (they are few).",
"Use greedy solution, taking at every time the greatest Fibonacci number which is smaller than or equal to the current number. Subtract this Fibonacci number from the current number and repeat again the process."
] | {
"canonical_parameter_names": [
"k"
],
"leetcode_dataset_entry_point": "Solution().findMinFibonacciNumbers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:28",
"tests_total": 70,
"t... | cpp | {
"raw_signature": "int findMinFibonacciNumbers(int k) {",
"container": "Solution",
"callable": "findMinFibonacciNumbers",
"parameters": [
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,415 | the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Medium | A happy string is a string that:
- consists only of letters of the set ['a', 'b', 'c'].
- s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed).
For example, strings "abc", "ac", "b" and "abcbabcbcb" are all happy strings and strings "aa", "baa" and "ababbc" are not happy strings.
Given t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,k = 1) == \"ababa\"\n assert candidate(n = 10,k = 100) == \"abacbabacb\"\n assert candidate(n = 1,k = 4) == \"\"\n assert candidate(n = 2,k = 5) == \"ca\"\n assert candidate(n = 5,k = 25) == \"bcaba\"\n assert candid... | [
"1\n3",
"1\n4",
"3\n9"
] | [
"Generate recursively all the happy strings of length n.",
"Sort them in lexicographical order and return the kth string if it exists."
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().getHappyString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:30",
"tests_total": 78,
"t... | cpp | {
"raw_signature": "string getHappyString(int n, int k) {",
"container": "Solution",
"callable": "getHappyString",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",... |
1,416 | restore-the-array | Hard | A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits s and all we know is that all integers in the array were in the range [1, k] and there are no leading zeros in the array.
Given the string s and the integer k, return the number ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"237\",k = 50) == 3\n assert candidate(s = \"111111111111111111111\",k = 11) == 17711\n assert candidate(s = \"123123123\",k = 123) == 100\n assert candidate(s = \"1317\",k = 2000) == 8\n assert candidate(s = \"99999\",k... | [
"\"1000\"\n10000",
"\"1000\"\n10",
"\"1317\"\n2000"
] | [
"Use dynamic programming. Build an array dp where dp[i] is the number of ways you can divide the string starting from index i to the end.",
"Keep in mind that the answer is modulo 10^9 + 7 and take the mod for each operation."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().numberOfArrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:32",
"tests_total": 104,
"... | cpp | {
"raw_signature": "int numberOfArrays(string s, int k) {",
"container": "Solution",
"callable": "numberOfArrays",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",... |
1,417 | reformat-the-string | Easy | You are given an alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits).
You have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type.
Re... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"a1b1\") == \"a1b1\"\n assert candidate(s = \"1229857369\") == \"\"\n assert candidate(s = \"aa1\") == \"a1a\"\n assert candidate(s = \"abc123def456\") == \"a1b2c3d4e5f6\"\n assert candidate(s = \"0123456789abcdefghijklm... | [
"\"a0b1c2\"",
"\"leetcode\"",
"\"1229857369\""
] | [
"Count the number of letters and digits in the string. if cntLetters - cntDigits has any of the values [-1, 0, 1] we have an answer, otherwise we don't have any answer.",
"Build the string anyway as you wish. Keep in mind that you need to start with the type that has more characters if cntLetters ≠ cntDigits."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().reformat",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:34",
"tests_total": 136,
"tests_dropped":... | cpp | {
"raw_signature": "string reformat(string s) {",
"container": "Solution",
"callable": "reformat",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,418 | display-table-of-food-orders-in-a-restaurant | Medium | Given the array orders, which represents the orders that customers have done in a restaurant. More specifically orders[i]=[customerName_i,tableNumber_i,foodItem_i] where customerName_i is the name of the customer, tableNumber_i is the table customer sit at, and foodItem_i is the item customer orders.
Return the restau... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(orders = [['Alice', '2', 'Veggie Delight'], ['Bob', '1', 'Salmon'], ['Charlie', '2', 'Salmon'], ['David', '3', 'Veggie Delight'], ['Eve', '3', 'Salmon']]) == [['Table', 'Salmon', 'Veggie Delight'], ['1', '1', '0'], ['2', '1', '1'], ['3',... | [
"[[\"David\",\"3\",\"Ceviche\"],[\"Corina\",\"10\",\"Beef Burrito\"],[\"David\",\"3\",\"Fried Chicken\"],[\"Carla\",\"5\",\"Water\"],[\"Carla\",\"5\",\"Ceviche\"],[\"Rous\",\"3\",\"Ceviche\"]]",
"[[\"James\",\"12\",\"Fried Chicken\"],[\"Ratesh\",\"12\",\"Fried Chicken\"],[\"Amadeus\",\"12\",\"Fried Chicken\"],[\"... | [
"Keep the frequency of all pairs (tableNumber, foodItem) using a hashmap.",
"Sort rows by tableNumber and columns by foodItem, then process the resulted table."
] | {
"canonical_parameter_names": [
"orders"
],
"leetcode_dataset_entry_point": "Solution().displayTable",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:37",
"tests_total": 53,
"tests_d... | cpp | {
"raw_signature": "vector<vector<string>> displayTable(vector<vector<string>>& orders) {",
"container": "Solution",
"callable": "displayTable",
"parameters": [
{
"name": "orders",
"type": "vector<vector<string>>&"
}
],
"return_type": "vector<vector<string>>",
"signature_source": "leet... |
1,419 | minimum-number-of-frogs-croaking | Medium | You are given the string croakOfFrogs, which represents a combination of the string "croak" from different frogs, that is, multiple frogs can croak at the same time, so multiple "croak" are mixed.
Return the minimum number of different frogs to finish all the croaks in the given string.
A valid "croak" means a frog i... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(croakOfFrogs = \"croakcroakcroak\") == 1\n assert candidate(croakOfFrogs = \"croak\") == 1\n assert candidate(croakOfFrogs = \"cccrroooaaakkk\") == -1\n assert candidate(croakOfFrogs = \"crcoakroak\") == 2\n assert candidate(... | [
"\"croakcroak\"",
"\"crcoakroak\"",
"\"croakcrook\""
] | [
"keep the frequency of all characters from \"croak\" using a hashmap.",
"For each character in the given string, greedily match it to a possible \"croak\"."
] | {
"canonical_parameter_names": [
"croakOfFrogs"
],
"leetcode_dataset_entry_point": "Solution().minNumberOfFrogs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:39",
"tests_total": 197,... | cpp | {
"raw_signature": "int minNumberOfFrogs(string croakOfFrogs) {",
"container": "Solution",
"callable": "minNumberOfFrogs",
"parameters": [
{
"name": "croakOfFrogs",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeS... |
1,420 | build-array-where-you-can-find-the-maximum-exactly-k-comparisons | Hard | You are given three integers n, m and k. Consider the following algorithm to find the maximum element of an array of positive integers:
You should build the array arr which has the following properties:
- arr has exactly n integers.
- 1 <= arr[i] <= m where (0 <= i < n).
- After applying the mentioned algorithm to ar... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 1,m = 1,k = 1) == 1\n assert candidate(n = 4,m = 5,k = 2) == 305\n assert candidate(n = 3,m = 3,k = 0) == 0\n assert candidate(n = 3,m = 5,k = 2) == 60\n assert candidate(n = 5,m = 2,k = 3) == 0\n assert candidate(n = ... | [
"2\n3\n1",
"5\n2\n3",
"9\n1\n1"
] | [
"Use dynamic programming approach. Build dp table where dp[a][b][c] is the number of ways you can start building the array starting from index a where the search_cost = c and the maximum used integer was b.",
"Recursively, solve the small sub-problems first. Optimize your answer by stopping the search if you exce... | {
"canonical_parameter_names": [
"n",
"m",
"k"
],
"leetcode_dataset_entry_point": "Solution().numOfArrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:41",
"tests_total": 10... | cpp | {
"raw_signature": "int numOfArrays(int n, int m, int k) {",
"container": "Solution",
"callable": "numOfArrays",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "m",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",... |
1,422 | maximum-score-after-splitting-a-string | Easy | Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring).
The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring.
Example 1:
Input: s = "01110... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1111\") == 3\n assert candidate(s = \"00111\") == 5\n assert candidate(s = \"100100\") == 3\n assert candidate(s = \"110011\") == 4\n assert candidate(s = \"001001\") == 5\n assert candidate(s = \"11110000\") == 3\n ... | [
"\"011101\"",
"\"00111\"",
"\"1111\""
] | [
"Precompute a prefix sum of ones ('1').",
"Iterate from left to right counting the number of zeros ('0'), then use the precomputed prefix sum for counting ones ('1'). Update the answer."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().maxScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:43",
"tests_total": 143,
"tests_dropped":... | cpp | {
"raw_signature": "int maxScore(string s) {",
"container": "Solution",
"callable": "maxScore",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,423 | maximum-points-you-can-obtain-from-cards | Medium | There are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array cardPoints.
In one step, you can take one card from the beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you ha... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(cardPoints = [5, 2, 1, 2, 5],k = 3) == 12\n assert candidate(cardPoints = [9, 7, 7, 9, 7, 7, 9],k = 7) == 55\n assert candidate(cardPoints = [1, 1000, 1],k = 1) == 1\n assert candidate(cardPoints = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1... | [
"[1,2,3,4,5,6,1]\n3",
"[2,2,2]\n2",
"[9,7,7,9,7,7,9]\n7"
] | [
"Let the sum of all points be total_pts. You need to remove a sub-array from cardPoints with length n - k.",
"Keep a window of size n - k over the array. The answer is max(answer, total_pts - sumOfCurrentWindow)"
] | {
"canonical_parameter_names": [
"cardPoints",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:46",
"tests_total": 78,
... | cpp | {
"raw_signature": "int maxScore(vector<int>& cardPoints, int k) {",
"container": "Solution",
"callable": "maxScore",
"parameters": [
{
"name": "cardPoints",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetc... |
1,424 | diagonal-traverse-ii | Medium | Given a 2D integer array nums, return all elements of nums in diagonal order as shown in the below images.
Example 1:
Input: nums = [[1,2,3],[4,5,6],[7,8,9]]
Output: [1,4,2,7,5,3,8,6,9]
Example 2:
Input: nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]]
Output: [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]
Cons... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [[1]]) == [1]\n assert candidate(nums = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [1, 4, 2, 7, 5, 3, 8, 6, 9]\n assert candidate(nums = [[1, 2, 3], [4, 5], [6]]) == [1, 4, 2, 6, 5, 3]\n assert candidate(nums = [[1, 2, 3, 4, 5... | [
"[[1,2,3],[4,5,6],[7,8,9]]",
"[[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]]"
] | [
"Notice that numbers with equal sums of row and column indexes belong to the same diagonal.",
"Store them in tuples (sum, row, val), sort them, and then regroup the answer."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findDiagonalOrder",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:48",
"tests_total": 70,
"test... | cpp | {
"raw_signature": "vector<int> findDiagonalOrder(vector<vector<int>>& nums) {",
"container": "Solution",
"callable": "findDiagonalOrder",
"parameters": [
{
"name": "nums",
"type": "vector<vector<int>>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
... |
1,425 | constrained-subsequence-sum | Hard | Given an integer array nums and an integer k, return the maximum sum of a non-empty subsequence of that array such that for every two consecutive integers in the subsequence, nums[i] and nums[j], where i < j, the condition j - i <= k is satisfied.
A subsequence of an array is obtained by deleting some number of elemen... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 7, -3, 5],k = 1) == 14\n assert candidate(nums = [10, 2, -10, 5, 20],k = 2) == 37\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 15\n assert candidate(nums = [3, -1, 4, -2, 2, 1],k = 2) == 10\n assert candidat... | [
"[10,2,-10,5,20]\n2",
"[-1,-2,-3]\n1",
"[10,-2,-10,-5,20]\n2"
] | [
"Use dynamic programming.",
"Let dp[i] be the solution for the prefix of the array that ends at index i, if the element at index i is in the subsequence.",
"dp[i] = nums[i] + max(0, dp[i-k], dp[i-k+1], ..., dp[i-1])",
"Use a heap with the sliding window technique to optimize the dp."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().constrainedSubsetSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:50",
"tests_total":... | cpp | {
"raw_signature": "int constrainedSubsetSum(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "constrainedSubsetSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_sou... |
1,431 | kids-with-the-greatest-number-of-candies | Easy | There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the i^th kid has, and an integer extraCandies, denoting the number of extra candies that you have.
Return a boolean array result of length n, where result[i] is true if, after giving the i^th k... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(candies = [4, 2, 1, 1, 2],extraCandies = 1) == [True, False, False, False, False]\n assert candidate(candies = [12, 1, 12],extraCandies = 10) == [True, False, True]\n assert candidate(candies = [50, 50, 50, 50, 50],extraCandies = 5... | [
"[2,3,5,1,3]\n3",
"[4,2,1,1,2]\n1",
"[12,1,12]\n10"
] | [
"For each kid check if candies[i] + extraCandies ≥ maximum in Candies[i]."
] | {
"canonical_parameter_names": [
"candies",
"extraCandies"
],
"leetcode_dataset_entry_point": "Solution().kidsWithCandies",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:19:59",
"test... | cpp | {
"raw_signature": "vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {",
"container": "Solution",
"callable": "kidsWithCandies",
"parameters": [
{
"name": "candies",
"type": "vector<int>&"
},
{
"name": "extraCandies",
"type": "int"
}
],
"return_typ... |
1,432 | max-difference-you-can-get-from-changing-an-integer | Medium | You are given an integer num. You will apply the following steps to num two separate times:
- Pick a digit x (0 <= x <= 9).
- Pick another digit y (0 <= y <= 9). Note y can be equal to x.
- Replace all the occurrences of x in the decimal representation of num by y.
Let a and b be the two results from applying the ope... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = 1001100) == 8008800\n assert candidate(num = 9) == 8\n assert candidate(num = 98789) == 81018\n assert candidate(num = 123456) == 820000\n assert candidate(num = 1000000) == 8000000\n assert candidate(num = 1221) == ... | [
"555",
"9"
] | [
"We need to get the max and min value after changing num and the answer is max - min.",
"Use brute force, try all possible changes and keep the minimum and maximum values."
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().maxDiff",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:01",
"tests_total": 81,
"tests_dropped":... | cpp | {
"raw_signature": "int maxDiff(int num) {",
"container": "Solution",
"callable": "maxDiff",
"parameters": [
{
"name": "num",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,433 | check-if-a-string-can-break-another-string | Medium | Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa. In other words s2 can break s1 or vice-versa.
A string x can break string y (both of size n) if x[i] >= y[i] (in alphabetical order) for all i between 0 and n-1.
Example 1:
I... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s1 = \"same\",s2 = \"same\") == True\n assert candidate(s1 = \"abc\",s2 = \"bca\") == True\n assert candidate(s1 = \"hello\",s2 = \"bello\") == True\n assert candidate(s1 = \"aazz\",s2 = \"zzaa\") == True\n assert candidate(s... | [
"\"abc\"\n\"xya\"",
"\"abe\"\n\"acd\"",
"\"leetcodee\"\n\"interview\""
] | [
"Sort both strings and then check if one of them can break the other."
] | {
"canonical_parameter_names": [
"s1",
"s2"
],
"leetcode_dataset_entry_point": "Solution().checkIfCanBreak",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:04",
"tests_total": 120,
... | cpp | {
"raw_signature": "bool checkIfCanBreak(string s1, string s2) {",
"container": "Solution",
"callable": "checkIfCanBreak",
"parameters": [
{
"name": "s1",
"type": "string"
},
{
"name": "s2",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/... |
1,434 | number-of-ways-to-wear-different-hats-to-each-other | Hard | There are n people and 40 types of hats labeled from 1 to 40.
Given a 2D integer array hats, where hats[i] is a list of all hats preferred by the i^th person.
Return the number of ways that n people can wear different hats from each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:
In... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(hats = [[1, 2], [3, 4], [5, 6]]) == 8\n assert candidate(hats = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]]) == 40\n asse... | [
"[[3,4],[4,5],[5]]",
"[[3,5,1],[3,5]]",
"[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]"
] | [
"Dynamic programming + bitmask.",
"dp(peopleMask, idHat) number of ways to wear different hats given a bitmask (people visited) and used hats from 1 to idHat-1."
] | {
"canonical_parameter_names": [
"hats"
],
"leetcode_dataset_entry_point": "Solution().numberWays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:06",
"tests_total": 83,
"tests_dropp... | cpp | {
"raw_signature": "int numberWays(vector<vector<int>>& hats) {",
"container": "Solution",
"callable": "numberWays",
"parameters": [
{
"name": "hats",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeS... |
1,436 | destination-city | Easy | You are given the array paths, where paths[i] = [cityA_i, cityB_i] means there exists a direct path going from cityA_i to cityB_i. Return the destination city, that is, the city without any path outgoing to another city.
It is guaranteed that the graph of paths forms a line without any loop, therefore, there will be e... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(paths = [['X', 'Y'], ['Y', 'Z'], ['Z', 'W']]) == \"W\"\n assert candidate(paths = [['Paris', 'Berlin'], ['Berlin', 'Madrid'], ['Madrid', 'Rome']]) == \"Rome\"\n assert candidate(paths = [['B', 'C'], ['D', 'B'], ['C', 'A']]) == \"A\... | [
"[[\"London\",\"New York\"],[\"New York\",\"Lima\"],[\"Lima\",\"Sao Paulo\"]]",
"[[\"B\",\"C\"],[\"D\",\"B\"],[\"C\",\"A\"]]",
"[[\"A\",\"Z\"]]"
] | [
"Start in any city and use the path to move to the next city.",
"Eventually, you will reach a city with no path outgoing, this is the destination city."
] | {
"canonical_parameter_names": [
"paths"
],
"leetcode_dataset_entry_point": "Solution().destCity",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:08",
"tests_total": 74,
"tests_droppe... | cpp | {
"raw_signature": "string destCity(vector<vector<string>>& paths) {",
"container": "Solution",
"callable": "destCity",
"parameters": [
{
"name": "paths",
"type": "vector<vector<string>>&"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leet... |
1,437 | check-if-all-1s-are-at-least-length-k-places-away | Easy | Given an binary array nums and an integer k, return true if all 1's are at least k places away from each other, otherwise return false.
Example 1:
Input: nums = [1,0,0,0,1,0,0,1], k = 2
Output: true
Explanation: Each of the 1s are at least 2 places away from each other.
Example 2:
Input: nums = [1,0,0,1,0,1], k = 2... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 0, 0, 0, 0],k = 1) == False\n assert candidate(nums = [0, 1, 0, 1, 0, 1],k = 1) == True\n assert candidate(nums = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],k = 2) == True\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 0, 0, ... | [
"[1,0,0,0,1,0,0,1]\n2",
"[1,0,0,1,0,1]\n2"
] | [
"Each time you find a number 1, check whether or not it is K or more places away from the next one. If it's not, return false."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().kLengthApart",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:10",
"tests_total": 104,
... | cpp | {
"raw_signature": "bool kLengthApart(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "kLengthApart",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcod... |
1,438 | longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit | Medium | Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.
Example 1:
Input: nums = [8,2,4,7], limit = 4
Output: 2
Explanation: All subarrays are:
[8] with maximum a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 6, 8, 9, 10],limit = 2) == 3\n assert candidate(nums = [100, 101, 102, 103, 104],limit = 3) == 4\n assert candidate(nums = [4, 2, 2, 2, 4, 4, 2, 2],limit = 0) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8,... | [
"[8,2,4,7]\n4",
"[10,1,2,4,7,2]\n5",
"[4,2,2,2,4,4,2,2]\n0"
] | [
"Use a sliding window approach keeping the maximum and minimum value using a data structure like a multiset from STL in C++.",
"More specifically, use the two pointer technique, moving the right pointer as far as possible to the right until the subarray is not valid (maxValue - minValue > limit), then moving the ... | {
"canonical_parameter_names": [
"nums",
"limit"
],
"leetcode_dataset_entry_point": "Solution().longestSubarray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:13",
"tests_total": ... | cpp | {
"raw_signature": "int longestSubarray(vector<int>& nums, int limit) {",
"container": "Solution",
"callable": "longestSubarray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "limit",
"type": "int"
}
],
"return_type": "int",
"signature_sourc... |
1,439 | find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows | Hard | You are given an m x n matrix mat that has its rows sorted in non-decreasing order and an integer k.
You are allowed to choose exactly one element from each row to form an array.
Return the k^th smallest array sum among all possible arrays.
Example 1:
Input: mat = [[1,3,11],[2,4,6]], k = 5
Output: 7
Explanation: Ch... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mat = [[1, 10, 10], [1, 4, 5], [2, 3, 6]],k = 7) == 9\n assert candidate(mat = [[1, 2, 3], [4, 5, 6]],k = 9) == 9\n assert candidate(mat = [[1, 3, 11], [2, 4, 6]],k = 5) == 7\n assert candidate(mat = [[1, 3, 11], [2, 4, 6]],k = ... | [
"[[1,3,11],[2,4,6]]\n5",
"[[1,3,11],[2,4,6]]\n9",
"[[1,10,10],[1,4,5],[2,3,6]]\n7"
] | [
"Save all visited sums and corresponding indexes in a priority queue. Then, once you pop the smallest sum so far, you can quickly identify the next m candidates for smallest sum by incrementing each row index by 1."
] | {
"canonical_parameter_names": [
"mat",
"k"
],
"leetcode_dataset_entry_point": "Solution().kthSmallest",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:15",
"tests_total": 85,
"te... | cpp | {
"raw_signature": "int kthSmallest(vector<vector<int>>& mat, int k) {",
"container": "Solution",
"callable": "kthSmallest",
"parameters": [
{
"name": "mat",
"type": "vector<vector<int>>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source"... |
1,441 | build-an-array-with-stack-operations | Medium | You are given an integer array target and an integer n.
You have an empty stack with the two following operations:
- "Push": pushes an integer to the top of the stack.
- "Pop": removes the integer on the top of the stack.
You also have a stream of the integers in the range [1, n].
Use the two stack operations to ma... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(target = [3, 4, 5],n = 5) == ['Push', 'Pop', 'Push', 'Pop', 'Push', 'Push', 'Push']\n assert candidate(target = [3, 4, 6],n = 7) == ['Push', 'Pop', 'Push', 'Pop', 'Push', 'Push', 'Push', 'Pop', 'Push']\n assert candidate(target = [... | [
"[1,3]\n3",
"[1,2,3]\n3",
"[1,2]\n4"
] | [
"Use “Push” for numbers to be kept in target array and [“Push”, “Pop”] for numbers to be discarded."
] | {
"canonical_parameter_names": [
"target",
"n"
],
"leetcode_dataset_entry_point": "Solution().buildArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:17",
"tests_total": 113,
... | cpp | {
"raw_signature": "vector<string> buildArray(vector<int>& target, int n) {",
"container": "Solution",
"callable": "buildArray",
"parameters": [
{
"name": "target",
"type": "vector<int>&"
},
{
"name": "n",
"type": "int"
}
],
"return_type": "vector<string>",
"signatu... |
1,442 | count-triplets-that-can-form-two-arrays-of-equal-xor | Medium | Given an array of integers arr.
We want to select three indices i, j and k where (0 <= i < j <= k < arr.length).
Let's define a and b as follows:
- a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]
- b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]
Note that ^ denotes the bitwise-xor operation.
Return the number of triplets (i, j ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [2, 3, 4, 1, 5, 6, 7, 8, 9]) == 17\n assert candidate(arr = [5, 5, 5, 5, 5, 5]) == 19\n assert candidate(arr = [8, 12, 3, 10]) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 24\n assert candidate(arr = [3... | [
"[2,3,1,6,7]",
"[1,1,1,1,1]"
] | [
"We are searching for sub-array of length ≥ 2 and we need to split it to 2 non-empty arrays so that the xor of the first array is equal to the xor of the second array. This is equivalent to searching for sub-array with xor = 0.",
"Keep the prefix xor of arr in another array, check the xor of all sub-arrays in O(n... | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().countTriplets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:19",
"tests_total": 93,
"tests_dro... | cpp | {
"raw_signature": "int countTriplets(vector<int>& arr) {",
"container": "Solution",
"callable": "countTriplets",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,444 | number-of-ways-of-cutting-a-pizza | Hard | Given a rectangular pizza represented as a rows x cols matrix containing the following characters: 'A' (an apple) and '.' (empty cell) and given the integer k. You have to cut the pizza into k pieces using k-1 cuts.
For each cut you choose the direction: vertical or horizontal, then you choose a cut position at the ce... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(pizza = ['A', 'A', 'A'],k = 3) == 1\n assert candidate(pizza = ['AA', 'AA'],k = 2) == 2\n assert candidate(pizza = ['A.A', 'A.A', 'A.A'],k = 4) == 6\n assert candidate(pizza = ['A.A', 'A.A', 'A.A'],k = 5) == 0\n assert candid... | [
"[\"A..\",\"AAA\",\"...\"]\n3",
"[\"A..\",\"AA.\",\"...\"]\n3",
"[\"A..\",\"A..\",\"...\"]\n1"
] | [
"Note that after each cut the remaining piece of pizza always has the lower right coordinate at (rows-1,cols-1).",
"Use dynamic programming approach with states (row1, col1, c) which computes the number of ways of cutting the pizza using \"c\" cuts where the current piece of pizza has upper left coordinate at (ro... | {
"canonical_parameter_names": [
"pizza",
"k"
],
"leetcode_dataset_entry_point": "Solution().ways",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:21",
"tests_total": 72,
"tests_d... | cpp | {
"raw_signature": "int ways(vector<string>& pizza, int k) {",
"container": "Solution",
"callable": "ways",
"parameters": [
{
"name": "pizza",
"type": "vector<string>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnip... |
1,446 | consecutive-characters | Easy | The power of the string is the maximum length of a non-empty substring that contains only one unique character.
Given a string s, return the power of s.
Example 1:
Input: s = "leetcode"
Output: 2
Explanation: The substring "ee" is of length 2 with the character 'e' only.
Example 2:
Input: s = "abbcccddddeeeeedcba"... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 1\n assert candidate(s = \"tourist\") == 1\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"aabbbbccc\") == 4\n assert candidate(s = \"cccccaaaa\") == 5\n assert candidate(... | [
"\"leetcode\"",
"\"abbcccddddeeeeedcba\""
] | [
"Keep an array power where power[i] is the maximum power of the i-th character.",
"The answer is max(power[i])."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().maxPower",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:23",
"tests_total": 70,
"tests_dropped": ... | cpp | {
"raw_signature": "int maxPower(string s) {",
"container": "Solution",
"callable": "maxPower",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,447 | simplified-fractions | Medium | Given an integer n, return a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator is less-than-or-equal-to n. You can return the answer in any order.
Example 1:
Input: n = 2
Output: ["1/2"]
Explanation: "1/2" is the only unique fraction with a denominator less-than-or-equal-to 2.
Ex... | {
"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 ... | [
"2",
"3",
"4"
] | [
"A fraction is fully simplified if there is no integer that divides cleanly into the numerator and denominator.",
"In other words the greatest common divisor of the numerator and the denominator of a simplified fraction is 1."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().simplifiedFractions",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:26",
"tests_total": 22,
"tests... | cpp | {
"raw_signature": "vector<string> simplifiedFractions(int n) {",
"container": "Solution",
"callable": "simplifiedFractions",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "vector<string>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeS... |
1,449 | form-largest-integer-with-digits-that-add-up-to-target | Hard | Given an array of integers cost and an integer target, return the maximum integer you can paint under the following rules:
- The cost of painting a digit (i + 1) is given by cost[i] (0-indexed).
- The total cost used must be equal to target.
- The integer does not have 0 digits.
Since the answer may be very large, re... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(cost = [5, 3, 7, 5, 2, 6, 8, 9, 1],target = 10) == \"9999999999\"\n assert candidate(cost = [9, 8, 7, 6, 5, 4, 3, 2, 1],target = 20) == \"99999999999999999999\"\n assert candidate(cost = [5, 5, 5, 5, 5, 5, 5, 5, 5],target = 25) == ... | [
"[4,3,2,5,6,7,2,5,5]\n9",
"[7,6,5,5,5,6,8,7,8]\n12",
"[2,4,6,2,4,6,4,4,4]\n5"
] | [
"Use dynamic programming to find the maximum digits to paint given a total cost.",
"Build the largest number possible using this DP table."
] | {
"canonical_parameter_names": [
"cost",
"target"
],
"leetcode_dataset_entry_point": "Solution().largestNumber",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:30",
"tests_total": 1... | cpp | {
"raw_signature": "string largestNumber(vector<int>& cost, int target) {",
"container": "Solution",
"callable": "largestNumber",
"parameters": [
{
"name": "cost",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "string",
"signature_s... |
1,450 | number-of-students-doing-homework-at-a-given-time | Easy | Given two integer arrays startTime and endTime and given an integer queryTime.
The ith student started doing their homework at the time startTime[i] and finished it at time endTime[i].
Return the number of students doing their homework at time queryTime. More formally, return the number of students where queryTime la... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(startTime = [9, 8, 7, 6],endTime = [10, 9, 8, 7],queryTime = 8) == 2\n assert candidate(startTime = [5, 5, 5, 5],endTime = [10, 10, 10, 10],queryTime = 7) == 4\n assert candidate(startTime = [9, 8, 7, 6, 5, 4, 3, 2, 1],endTime = [1... | [
"[1,2,3]\n[3,2,7]\n4",
"[4]\n[4]\n4"
] | [
"Imagine that startTime[i] and endTime[i] form an interval (i.e. [startTime[i], endTime[i]]).",
"The answer is how many times the queryTime laid in those mentioned intervals."
] | {
"canonical_parameter_names": [
"startTime",
"endTime",
"queryTime"
],
"leetcode_dataset_entry_point": "Solution().busyStudent",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:32... | cpp | {
"raw_signature": "int busyStudent(vector<int>& startTime, vector<int>& endTime, int queryTime) {",
"container": "Solution",
"callable": "busyStudent",
"parameters": [
{
"name": "startTime",
"type": "vector<int>&"
},
{
"name": "endTime",
"type": "vector<int>&"
},
{
... |
1,451 | rearrange-words-in-a-sentence | Medium | Given a sentence text (A sentence is a string of space-separated words) in the following format:
- First letter is in upper case.
- Each word in text are separated by a single space.
Your task is to rearrange the words in text such that all words are rearranged in an increasing order of their lengths. If two words ha... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(text = \"A quick brown fox jumps over the lazy dog\") == \"A fox the dog over lazy quick brown jumps\"\n assert candidate(text = \"This is a simple test case\") == \"A is this test case simple\"\n assert candidate(text = \"The weat... | [
"\"Leetcode is cool\"",
"\"Keep calm and code on\"",
"\"To be or not to be\""
] | [
"Store each word and their relative position. Then, sort them by length of words in case of tie by their original order."
] | {
"canonical_parameter_names": [
"text"
],
"leetcode_dataset_entry_point": "Solution().arrangeWords",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:35",
"tests_total": 152,
"tests_dr... | cpp | {
"raw_signature": "string arrangeWords(string text) {",
"container": "Solution",
"callable": "arrangeWords",
"parameters": [
{
"name": "text",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,452 | people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list | Medium | Given the array favoriteCompanies where favoriteCompanies[i] is the list of favorites companies for the ith person (indexed from 0).
Return the indices of people whose list of favorite companies is not a subset of any other list of favorites companies. You must return the indices in increasing order.
Example 1:
Inpu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(favoriteCompanies = [['leetcode'], ['google'], ['facebook'], ['amazon']]) == [0, 1, 2, 3]\n assert candidate(favoriteCompanies = [['apple'], ['apple', 'google'], ['google', 'facebook'], ['apple', 'facebook', 'google']]) == [3]\n as... | [
"[[\"leetcode\",\"google\",\"facebook\"],[\"google\",\"microsoft\"],[\"google\",\"facebook\"],[\"google\"],[\"amazon\"]]",
"[[\"leetcode\",\"google\",\"facebook\"],[\"leetcode\",\"amazon\"],[\"facebook\",\"google\"]]",
"[[\"leetcode\"],[\"google\"],[\"facebook\"],[\"amazon\"]]"
] | [
"Use hashing to convert company names in numbers and then for each list check if this is a subset of any other list.",
"In order to check if a list is a subset of another list, use two pointers technique to get a linear solution for this task. The total complexity will be O(n^2 * m) where n is the number of lists... | {
"canonical_parameter_names": [
"favoriteCompanies"
],
"leetcode_dataset_entry_point": "Solution().peopleIndexes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:37",
"tests_total": 79... | cpp | {
"raw_signature": "vector<int> peopleIndexes(vector<vector<string>>& favoriteCompanies) {",
"container": "Solution",
"callable": "peopleIndexes",
"parameters": [
{
"name": "favoriteCompanies",
"type": "vector<vector<string>>&"
}
],
"return_type": "vector<int>",
"signature_source": "le... |
1,453 | maximum-number-of-darts-inside-of-a-circular-dartboard | Hard | Alice is throwing n darts on a very large wall. You are given an array darts where darts[i] = [x_i, y_i] is the position of the i^th dart that Alice threw on the wall.
Bob knows the positions of the n darts on the wall. He wants to place a dartboard of radius r on the wall so that the maximum number of darts that Alic... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(darts = [[100, 100], [-100, -100], [0, 0]],r = 150) == 3\n assert candidate(darts = [[0, 0], [0, 1], [0, 2], [0, 3]],r = 1) == 3\n assert candidate(darts = [[-3, 0], [3, 0], [2, 6], [5, 4], [0, 9], [7, 8]],r = 5) == 5\n assert c... | [
"[[-2,0],[2,0],[0,2],[0,-2]]\n2",
"[[-3,0],[3,0],[2,6],[5,4],[0,9],[7,8]]\n5"
] | [
"If there is an optimal solution, you can always move the circle so that two points lie on the boundary of the circle.",
"When the radius is fixed, you can find either 0 or 1 or 2 circles that pass two given points at the same time.",
"Loop for each pair of points and find the center of the circle, after that c... | {
"canonical_parameter_names": [
"darts",
"r"
],
"leetcode_dataset_entry_point": "Solution().numPoints",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:39",
"tests_total": 130,
"t... | cpp | {
"raw_signature": "int numPoints(vector<vector<int>>& darts, int r) {",
"container": "Solution",
"callable": "numPoints",
"parameters": [
{
"name": "darts",
"type": "vector<vector<int>>&"
},
{
"name": "r",
"type": "int"
}
],
"return_type": "int",
"signature_source"... |
1,455 | check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence | Easy | Given a sentence that consists of some words separated by a single space, and a searchWord, check if searchWord is a prefix of any word in sentence.
Return the index of the word in sentence (1-indexed) where searchWord is a prefix of this word. If searchWord is a prefix of more than one word, return the index of the f... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(sentence = \"a ab abc abd\",searchWord = \"a\") == 1\n assert candidate(sentence = \"abcde fghij klmno\",searchWord = \"mnop\") == -1\n assert candidate(sentence = \"find prefix quickly\",searchWord = \"qui\") == 3\n assert cand... | [
"\"i love eating burger\"\n\"burg\"",
"\"this problem is an easy problem\"\n\"pro\"",
"\"i am tired\"\n\"you\""
] | [
"First extract the words of the sentence.",
"Check for each word if searchWord occurs at index 0, if so return the index of this word (1-indexed)",
"If searchWord doesn't exist as a prefix of any word return the default value (-1)."
] | {
"canonical_parameter_names": [
"sentence",
"searchWord"
],
"leetcode_dataset_entry_point": "Solution().isPrefixOfWord",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:42",
"tests_... | cpp | {
"raw_signature": "int isPrefixOfWord(string sentence, string searchWord) {",
"container": "Solution",
"callable": "isPrefixOfWord",
"parameters": [
{
"name": "sentence",
"type": "string"
},
{
"name": "searchWord",
"type": "string"
}
],
"return_type": "int",
"signa... |
1,456 | maximum-number-of-vowels-in-a-substring-of-given-length | Medium | Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.
Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.
Example 1:
Input: s = "abciiidef", k = 3
Output: 3
Explanation: The substring "iii" contains 3 vowel letters.
Example 2:
Input: s = "aeiou", k... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aooiiieeec\",k = 6) == 6\n assert candidate(s = \"a\",k = 1) == 1\n assert candidate(s = \"happy\",k = 2) == 1\n assert candidate(s = \"rhythms\",k = 5) == 0\n assert candidate(s = \"fluffy\",k = 2) == 1\n assert can... | [
"\"abciiidef\"\n3",
"\"aeiou\"\n2",
"\"leetcode\"\n3"
] | [
"Keep a window of size k and maintain the number of vowels in it.",
"Keep moving the window and update the number of vowels while moving. Answer is max number of vowels of any window."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxVowels",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:44",
"tests_total": 80,
"tests_... | cpp | {
"raw_signature": "int maxVowels(string s, int k) {",
"container": "Solution",
"callable": "maxVowels",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_s... |
1,458 | max-dot-product-of-two-subsequences | Hard | Given two arrays nums1 and nums2.
Return the maximum dot product between non-empty subsequences of nums1 and nums2 with the same length.
A subsequence of an array is a new array which is formed from the original array by deleting some (can be none) of the characters without disturbing the relative positions of the re... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [-1, 0, 1],nums2 = [-1, 0, 1]) == 2\n assert candidate(nums1 = [2, 1, -2, 5],nums2 = [3, 0, -6]) == 18\n assert candidate(nums1 = [5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5]) == 46\n assert candidate(nums1 = [1, 3, -5, 4],nu... | [
"[2,1,-2,5]\n[3,0,-6]",
"[3,-2]\n[2,-6,7]",
"[-1,-1]\n[1,1]"
] | [
"Use dynamic programming, define DP[i][j] as the maximum dot product of two subsequences starting in the position i of nums1 and position j of nums2."
] | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().maxDotProduct",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:46",
"tests_total": 1... | cpp | {
"raw_signature": "int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "maxDotProduct",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type": "int",
... |
1,460 | make-two-arrays-equal-by-reversing-subarrays | Easy | You are given two integer arrays of equal length target and arr. In one step, you can select any non-empty subarray of arr and reverse it. You are allowed to make any number of steps.
Return true if you can make arr equal to target or false otherwise.
Example 1:
Input: target = [1,2,3,4], arr = [2,4,1,3]
Output: tru... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(target = [4, 3, 2, 1],arr = [1, 2, 3, 4]) == True\n assert candidate(target = [5, 6, 7, 8],arr = [8, 7, 6, 5]) == True\n assert candidate(target = [1, 1, 1, 1],arr = [1, 1, 1, 1]) == True\n assert candidate(target = [1, 3, 5, 7]... | [
"[1,2,3,4]\n[2,4,1,3]",
"[7]\n[7]",
"[3,7,9]\n[3,7,11]"
] | [
"Each element of target should have a corresponding element in arr, and if it doesn't have a corresponding element, return false.",
"To solve it easiely you can sort the two arrays and check if they are equal."
] | {
"canonical_parameter_names": [
"target",
"arr"
],
"leetcode_dataset_entry_point": "Solution().canBeEqual",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:48",
"tests_total": 122,
... | cpp | {
"raw_signature": "bool canBeEqual(vector<int>& target, vector<int>& arr) {",
"container": "Solution",
"callable": "canBeEqual",
"parameters": [
{
"name": "target",
"type": "vector<int>&"
},
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "bool",
"signa... |
1,461 | check-if-a-string-contains-all-binary-codes-of-size-k | Medium | Given a binary string s and an integer k, return true if every binary code of length k is a substring of s. Otherwise, return false.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indices 0, 1, 3 and ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1010101010\",k = 5) == False\n assert candidate(s = \"1010101010\",k = 3) == False\n assert candidate(s = \"0000000\",k = 3) == False\n assert candidate(s = \"00110110\",k = 2) == True\n assert candidate(s = \"00000000\... | [
"\"00110110\"\n2",
"\"0110\"\n1",
"\"0110\"\n2"
] | [
"We need only to check all sub-strings of length k.",
"The number of distinct sub-strings should be exactly 2^k."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().hasAllCodes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:51",
"tests_total": 102,
"tes... | cpp | {
"raw_signature": "bool hasAllCodes(string s, int k) {",
"container": "Solution",
"callable": "hasAllCodes",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"... |
1,462 | course-schedule-iv | Medium | There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [a_i, b_i] indicates that you must take course a_i first if you want to take course b_i.
- For example, the pair [0, 1] indicates that you have to take course 0 befo... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(numCourses = 5,prerequisites = [[0, 1], [1, 2], [2, 3], [3, 4]],queries = [[0, 4], [4, 0]]) == [True, False]\n assert candidate(numCourses = 4,prerequisites = [[0, 1], [1, 2], [2, 3]],queries = [[0, 3], [1, 3], [0, 2]]) == [True, True... | [
"6\n[[4,5],[3,4],[2,3],[1,2],[0,1]]\n[[0,5]]",
"3\n[[0,1],[1,2]]\n[[0,2]]",
"4\n[[0,1],[2,3]]\n[[0,3]]"
] | [
"Imagine if the courses are nodes of a graph. We need to build an array isReachable[i][j].",
"Start a bfs from each course i and assign for each course j you visit isReachable[i][j] = True.",
"Answer the queries from the isReachable array."
] | {
"canonical_parameter_names": [
"numCourses",
"prerequisites",
"queries"
],
"leetcode_dataset_entry_point": "Solution().checkIfPrerequisite",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-0... | cpp | {
"raw_signature": "vector<bool> checkIfPrerequisite(int numCourses, vector<vector<int>>& prerequisites, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "checkIfPrerequisite",
"parameters": [
{
"name": "numCourses",
"type": "int"
},
{
"name": "prerequisites",... |
1,463 | cherry-pickup-ii | Hard | You are given a rows x cols matrix grid representing a field of cherries where grid[i][j] represents the number of cherries that you can collect from the (i, j) cell.
You have two robots that can collect cherries for you:
- Robot #1 is located at the top-left corner (0, 0), and
- Robot #2 is located at the top-right ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 2, 3], [0, 1, 0], [3, 0, 1], [1, 2, 3]]) == 14\n assert candidate(grid = [[5, 0, 0, 5], [0, 4, 4, 0], [0, 4, 4, 0], [5, 0, 0, 5]]) == 36\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, ... | [
"[[3,1,1],[2,5,1],[1,5,5],[2,1,1]]",
"[[1,0,0,0,0,0,1],[2,0,0,0,0,3,0],[2,0,9,0,0,0,0],[0,3,0,5,4,0,0],[1,0,2,3,0,0,6]]"
] | [
"Use dynamic programming, define DP[i][j][k]: The maximum cherries that both robots can take starting on the ith row, and column j and k of Robot 1 and 2 respectively."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().cherryPickup",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:55",
"tests_total": 74,
"tests_dro... | cpp | {
"raw_signature": "int cherryPickup(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "cherryPickup",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
1,464 | maximum-product-of-two-elements-in-an-array | Easy | You are given an array of integers nums.
Choose two different indices i and j of that array.
Return the maximum value of (nums[i] - 1) * (nums[j] - 1).
Example 1:
Input: nums = [3,4,5,2]
Output: 12
Explanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10]) == 81\n assert candidate(nums = [2, 3, 5, 7, 11, 13]) == 120\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 72\n assert candidate(nums = [1, 1000, 2, 999, 3, 998]) == 997002\n assert ca... | [
"[3,4,5,2]",
"[1,5,4,5]",
"[3,7]"
] | [
"Use brute force: two loops to select i and j, then select the maximum value of (nums[i]-1)*(nums[j]-1)."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxProduct",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:20:57",
"tests_total": 96,
"tests_dropp... | cpp | {
"raw_signature": "int maxProduct(vector<int>& nums) {",
"container": "Solution",
"callable": "maxProduct",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,465 | maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts | Medium | You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and verticalCuts where:
- horizontalCuts[i] is the distance from the top of the rectangular cake to the i^th horizontal cut and similarly, and
- verticalCuts[j] is the distance from the left of the rectangular cake to the j^th ver... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(h = 10,w = 10,horizontalCuts = [2, 5, 7],verticalCuts = [2, 5, 7]) == 9\n assert candidate(h = 5,w = 4,horizontalCuts = [3, 1],verticalCuts = [1]) == 6\n assert candidate(h = 5,w = 4,horizontalCuts = [1, 2, 4],verticalCuts = [1, 3]... | [
"5\n4\n[1,2,4]\n[1,3]",
"5\n4\n[3,1]\n[1]",
"5\n4\n[3]\n[3]"
] | [
"Sort the arrays, then compute the maximum difference between two consecutive elements for horizontal cuts and vertical cuts.",
"The answer is the product of these maximum values in horizontal cuts and vertical cuts."
] | {
"canonical_parameter_names": [
"h",
"w",
"horizontalCuts",
"verticalCuts"
],
"leetcode_dataset_entry_point": "Solution().maxArea",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T2... | cpp | {
"raw_signature": "int maxArea(int h, int w, vector<int>& horizontalCuts, vector<int>& verticalCuts) {",
"container": "Solution",
"callable": "maxArea",
"parameters": [
{
"name": "h",
"type": "int"
},
{
"name": "w",
"type": "int"
},
{
"name": "horizontalCuts",
... |
1,466 | reorder-routes-to-make-all-paths-lead-to-the-city-zero | Medium | There are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to orient the roads in one direction because they are too narrow.
Roads are represented by connections where connec... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 7,connections = [[1, 0], [2, 0], [3, 1], [4, 0], [5, 0], [6, 4]]) == 0\n assert candidate(n = 6,connections = [[0, 1], [1, 3], [2, 3], [4, 0], [4, 5]]) == 3\n assert candidate(n = 5,connections = [[1, 0], [1, 2], [3, 2], [3, 4]... | [
"6\n[[0,1],[1,3],[2,3],[4,0],[4,5]]",
"5\n[[1,0],[1,2],[3,2],[3,4]]",
"3\n[[1,0],[2,0]]"
] | [
"Treat the graph as undirected. Start a dfs from the root, if you come across an edge in the forward direction, you need to reverse the edge."
] | {
"canonical_parameter_names": [
"n",
"connections"
],
"leetcode_dataset_entry_point": "Solution().minReorder",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:02",
"tests_total": 57... | cpp | {
"raw_signature": "int minReorder(int n, vector<vector<int>>& connections) {",
"container": "Solution",
"callable": "minReorder",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "connections",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"sig... |
1,467 | probability-of-a-two-boxes-having-the-same-number-of-distinct-balls | Hard | Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat... | [
"[1,1]",
"[2,1,1]",
"[1,2,1,2]"
] | [
"Check how many ways you can distribute the balls between the boxes.",
"Consider that one way you will use (x1, x2, x3, ..., xk) where xi is the number of balls from colour i. The probability of achieving this way randomly is ( (ball1 C x1) * (ball2 C x2) * (ball3 C x3) * ... * (ballk C xk)) / (2n C n).",
"The ... | {
"canonical_parameter_names": [
"balls"
],
"leetcode_dataset_entry_point": "Solution().getProbability",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:04",
"tests_total": 102,
"tests... | cpp | {
"raw_signature": "double getProbability(vector<int>& balls) {",
"container": "Solution",
"callable": "getProbability",
"parameters": [
{
"name": "balls",
"type": "vector<int>&"
}
],
"return_type": "double",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeS... |
1,470 | shuffle-the-array | Easy | Given the array nums consisting of 2n elements in the form [x_1,x_2,...,x_n,y_1,y_2,...,y_n].
Return the array in the form [x_1,y_1,x_2,y_2,...,x_n,y_n].
Example 1:
Input: nums = [2,5,1,3,4,7], n = 3
Output: [2,3,5,4,1,7]
Explanation: Since x_1=2, x_2=5, x_3=1, y_1=3, y_2=4, y_3=7 then the answer is [2,3,5,4,1,7].
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],n = 6) == [5, 11, 6, 12, 7, 13, 8, 14, 9, 15, 10, 16]\n assert candidate(nums = [2, 5, 1, 3, 4, 7],n = 3) == [2, 3, 5, 4, 1, 7]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 7... | [
"[2,5,1,3,4,7]\n3",
"[1,2,3,4,4,3,2,1]\n4",
"[1,1,2,2]\n2"
] | [
"Use two pointers to create the new array of 2n elements. The first starting at the beginning and the other starting at (n+1)th position. Alternate between them and create the new array."
] | {
"canonical_parameter_names": [
"nums",
"n"
],
"leetcode_dataset_entry_point": "Solution().shuffle",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:08",
"tests_total": 71,
"tests... | cpp | {
"raw_signature": "vector<int> shuffle(vector<int>& nums, int n) {",
"container": "Solution",
"callable": "shuffle",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "n",
"type": "int"
}
],
"return_type": "vector<int>",
"signature_source": "lee... |
1,471 | the-k-strongest-values-in-an-array | Medium | Given an array of integers arr and an integer k.
A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the centre of the array.
If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j].
Return a list of the strongest k values in t... | {
"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 ... | [
"[1,2,3,4,5]\n2",
"[1,1,3,5,5]\n2",
"[6,7,11,7,6,8]\n5"
] | [
"Calculate the centre of the array as defined in the statement.",
"Use custom sort function to sort values (Strongest first), then slice the first k."
] | {
"canonical_parameter_names": [
"arr",
"k"
],
"leetcode_dataset_entry_point": "Solution().getStrongest",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:11",
"tests_total": 91,
"t... | cpp | {
"raw_signature": "vector<int> getStrongest(vector<int>& arr, int k) {",
"container": "Solution",
"callable": "getStrongest",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "vector<int>",
"signature_sourc... |
1,473 | paint-house-iii | Hard | There is a row of m houses in a small city, each house must be painted with one of the n colors (labeled from 1 to n), some houses that have been painted last summer should not be painted again.
A neighborhood is a maximal group of continuous houses that are painted with the same color.
- For example: houses = [1,2,2... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(houses = [1, 0, 0, 0, 0],cost = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],m = 5,n = 2,target = 2) == 15\n assert candidate(houses = [0, 0, 0, 0, 0],cost = [[10, 20, 30, 40], [20, 30, 40, 50], [30, 40, 50, 60], [40, 50, 60, 70], [50, 60... | [
"[0,0,0,0,0]\n[[1,10],[10,1],[10,1],[1,10],[5,1]]\n5\n2\n3",
"[0,2,1,2,0]\n[[1,10],[10,1],[10,1],[1,10],[5,1]]\n5\n2\n3",
"[3,1,2,3]\n[[1,1,1],[1,1,1],[1,1,1],[1,1,1]]\n4\n3\n3"
] | [
"Use Dynamic programming.",
"Define dp[i][j][k] as the minimum cost where we have k neighborhoods in the first i houses and the i-th house is painted with the color j."
] | {
"canonical_parameter_names": [
"houses",
"cost",
"m",
"n",
"target"
],
"leetcode_dataset_entry_point": "Solution().minCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:... | cpp | {
"raw_signature": "int minCost(vector<int>& houses, vector<vector<int>>& cost, int m, int n, int target) {",
"container": "Solution",
"callable": "minCost",
"parameters": [
{
"name": "houses",
"type": "vector<int>&"
},
{
"name": "cost",
"type": "vector<vector<int>>&"
},
... |
1,475 | final-prices-with-a-special-discount-in-a-shop | Easy | You are given an integer array prices where prices[i] is the price of the i^th item in a shop.
There is a special discount for items in the shop. If you buy the i^th item, then you will receive a discount equivalent to prices[j] where j is the minimum index such that j > i and prices[j] <= prices[i]. Otherwise, you wi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(prices = [5, 5, 5, 5, 5]) == [0, 0, 0, 0, 5]\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(prices = [8, 4, 6, 2, 3]) == [4, 2, 4, 2, 3]\n assert candidate(price... | [
"[8,4,6,2,3]",
"[1,2,3,4,5]",
"[10,1,1,6]"
] | [
"Use brute force: For the ith item in the shop with a loop find the first position j satisfying the conditions and apply the discount, otherwise, the discount is 0."
] | {
"canonical_parameter_names": [
"prices"
],
"leetcode_dataset_entry_point": "Solution().finalPrices",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:18",
"tests_total": 117,
"tests_d... | cpp | {
"raw_signature": "vector<int> finalPrices(vector<int>& prices) {",
"container": "Solution",
"callable": "finalPrices",
"parameters": [
{
"name": "prices",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
1,477 | find-two-non-overlapping-sub-arrays-each-with-target-sum | Medium | You are given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with a sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [5, 5, 5, 5, 5],target = 10) == 4\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 15) == 5\n assert candidate(arr = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],target = 6) == 6\n assert candidate(arr = [1, 1, 1, 2, 2,... | [
"[3,2,2,4,3]\n3",
"[7,3,4,7]\n7",
"[4,3,2,6,2,3,4]\n6"
] | [
"Let's create two arrays prefix and suffix where prefix[i] is the minimum length of sub-array ends before i and has sum = k, suffix[i] is the minimum length of sub-array starting at or after i and has sum = k.",
"The answer we are searching for is min(prefix[i] + suffix[i]) for all values of i from 0 to n-1 where... | {
"canonical_parameter_names": [
"arr",
"target"
],
"leetcode_dataset_entry_point": "Solution().minSumOfLengths",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:20",
"tests_total": ... | cpp | {
"raw_signature": "int minSumOfLengths(vector<int>& arr, int target) {",
"container": "Solution",
"callable": "minSumOfLengths",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "int",
"signature_sourc... |
1,478 | allocate-mailboxes | Hard | Given the array houses where houses[i] is the location of the i^th house along a street and an integer k, allocate k mailboxes in the street.
Return the minimum total distance between each house and its nearest mailbox.
The test cases are generated so that the answer fits in a 32-bit integer.
Example 1:
Input: hous... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(houses = [10, 5, 17, 1, 18, 2, 12, 9],k = 3) == 8\n assert candidate(houses = [5, 10, 15, 20, 25],k = 2) == 15\n assert candidate(houses = [3, 6, 14, 10],k = 4) == 0\n assert candidate(houses = [3, 6, 14, 16, 25, 28, 30],k = 2) ... | [
"[1,4,8,10,20]\n3",
"[2,3,5,12,18]\n2"
] | [
"If k =1, the minimum distance is obtained allocating the mailbox in the median of the array houses.",
"Generalize this idea, using dynamic programming allocating k mailboxes."
] | {
"canonical_parameter_names": [
"houses",
"k"
],
"leetcode_dataset_entry_point": "Solution().minDistance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:22",
"tests_total": 108,
... | cpp | {
"raw_signature": "int minDistance(vector<int>& houses, int k) {",
"container": "Solution",
"callable": "minDistance",
"parameters": [
{
"name": "houses",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcod... |
1,480 | running-sum-of-1d-array | Easy | Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).
Return the running sum of nums.
Example 1:
Input: nums = [1,2,3,4]
Output: [1,3,6,10]
Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
Example 2:
Input: nums = [1,1,1,1,1]
Output: [1,2,3,4,5]... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [-1, 2, -3, 4, -5]) == [-1, 1, -2, 2, -3]\n assert candidate(nums = [-5]) == [-5]\n assert candidate(nums = [0, -1, 2, -3, 4]) == [0, -1, 1, -2, 2]\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == [1, 0, 1, 0, 1, 0]\n ... | [
"[1,2,3,4]",
"[1,1,1,1,1]",
"[3,1,2,10,1]"
] | [
"Think about how we can calculate the i-th number in the running sum from the (i-1)-th number."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().runningSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:24",
"tests_total": 95,
"tests_dropp... | cpp | {
"raw_signature": "vector<int> runningSum(vector<int>& nums) {",
"container": "Solution",
"callable": "runningSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeS... |
1,481 | least-number-of-unique-integers-after-k-removals | Medium | Given an array of integers arr and an integer k. Find the least number of unique integers after removing exactly k elements.
Example 1:
Input: arr = [5,5,4], k = 1
Output: 1
Explanation: Remove the single 4, only 5 is left.
Example 2:
Input: arr = [4,3,1,1,3,3,2], k = 3
Output: 2
Explanation: Remove 4, 2 and either... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [1, 1, 1, 1, 1],k = 3) == 1\n assert candidate(arr = [1, 2, 3, 4, 5],k = 2) == 3\n assert candidate(arr = [10, 20, 20, 10, 10, 30, 50, 10, 20],k = 4) == 2\n assert candidate(arr = [10, 20, 30, 40, 50, 60],k = 0) == 6\n ... | [
"[5,5,4]\n1",
"[4,3,1,1,3,3,2]\n3"
] | [
"Use a map to count the frequencies of the numbers in the array.",
"An optimal strategy is to remove the numbers with the smallest count first."
] | {
"canonical_parameter_names": [
"arr",
"k"
],
"leetcode_dataset_entry_point": "Solution().findLeastNumOfUniqueInts",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:27",
"tests_tota... | cpp | {
"raw_signature": "int findLeastNumOfUniqueInts(vector<int>& arr, int k) {",
"container": "Solution",
"callable": "findLeastNumOfUniqueInts",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signatu... |
1,482 | minimum-number-of-days-to-make-m-bouquets | Medium | You are given an integer array bloomDay, an integer m and an integer k.
You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.
The garden consists of n flowers, the i^th flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet.
Return the minimum n... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(bloomDay = [1, 10, 3, 10, 2],m = 3,k = 1) == 3\n assert candidate(bloomDay = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],m = 5,k = 2) == 1\n assert candidate(bloomDay = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 5,k = 1) == 5\n assert candidate(blo... | [
"[1,10,3,10,2]\n3\n1",
"[1,10,3,10,2]\n3\n2",
"[7,7,7,7,12,7,7]\n2\n3"
] | [
"If we can make m or more bouquets at day x, then we can still make m or more bouquets at any day y > x.",
"We can check easily if we can make enough bouquets at day x if we can get group adjacent flowers at day x."
] | {
"canonical_parameter_names": [
"bloomDay",
"m",
"k"
],
"leetcode_dataset_entry_point": "Solution().minDays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:29",
"tests_total":... | cpp | {
"raw_signature": "int minDays(vector<int>& bloomDay, int m, int k) {",
"container": "Solution",
"callable": "minDays",
"parameters": [
{
"name": "bloomDay",
"type": "vector<int>&"
},
{
"name": "m",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],... |
1,486 | xor-operation-in-an-array | Easy | You are given an integer n and an integer start.
Define an array nums where nums[i] = start + 2 * i (0-indexed) and n == nums.length.
Return the bitwise XOR of all elements of nums.
Example 1:
Input: n = 5, start = 0
Output: 8
Explanation: Array nums is equal to [0, 2, 4, 6, 8] where (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8.
Where ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,start = 3) == 8\n assert candidate(n = 8,start = 12) == 0\n assert candidate(n = 7,start = 2) == 0\n assert candidate(n = 3,start = 2) == 0\n assert candidate(n = 10,start = 1) == 2\n assert candidate(n = 5,start = 0... | [
"5\n0",
"4\n3"
] | [
"Simulate the process, create an array nums and return the Bitwise XOR of all elements of it."
] | {
"canonical_parameter_names": [
"n",
"start"
],
"leetcode_dataset_entry_point": "Solution().xorOperation",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:33",
"tests_total": 92,
... | cpp | {
"raw_signature": "int xorOperation(int n, int start) {",
"container": "Solution",
"callable": "xorOperation",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "start",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
... |
1,487 | making-file-names-unique | Medium | Given an array of strings names of size n. You will create n folders in your file system such that, at the i^th minute, you will create a folder with the name names[i].
Since two files cannot have the same name, if you enter a folder name that was previously used, the system will have a suffix addition to its name in ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(names = ['doc', 'doc(1)', 'image', 'doc(1)', 'doc']) == ['doc', 'doc(1)', 'image', 'doc(1)(1)', 'doc(2)']\n assert candidate(names = ['abcd', 'abcde', 'abcd(1)', 'abcd', 'abcd(2)', 'abcd(1)(1)']) == ['abcd', 'abcde', 'abcd(1)', 'abcd(... | [
"[\"pes\",\"fifa\",\"gta\",\"pes(2019)\"]",
"[\"gta\",\"gta(1)\",\"gta\",\"avalon\"]",
"[\"onepiece\",\"onepiece(1)\",\"onepiece(2)\",\"onepiece(3)\",\"onepiece\"]"
] | [
"Keep a map of each name and the smallest valid integer that can be appended as a suffix to it.",
"If the name is not present in the map, you can use it without adding any suffixes.",
"If the name is present in the map, append the smallest proper suffix, and add the new name to the map."
] | {
"canonical_parameter_names": [
"names"
],
"leetcode_dataset_entry_point": "Solution().getFolderNames",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:36",
"tests_total": 66,
"tests_... | cpp | {
"raw_signature": "vector<string> getFolderNames(vector<string>& names) {",
"container": "Solution",
"callable": "getFolderNames",
"parameters": [
{
"name": "names",
"type": "vector<string>&"
}
],
"return_type": "vector<string>",
"signature_source": "leetcode/codeSnippets",
"type_so... |
1,488 | avoid-flood-in-the-city | Medium | Your country has 10^9 lakes. Initially, all the lakes are empty, but when it rains over the n^th lake, the n^th lake becomes full of water. If it rains over a lake that is full of water, there will be a flood. Your goal is to avoid floods in any lake.
Given an integer array rains where:
- rains[i] > 0 means there wil... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(rains = [0, 1, 1, 0, 2, 0, 1]) == []\n assert candidate(rains = [1, 2, 0, 1, 2]) == []\n assert candidate(rains = [1, 0, 2, 0, 0, 1, 0, 2]) == [-1, 1, -1, 2, 1, -1, 1, -1]\n assert candidate(rains = [0, 0, 0, 0]) == [1, 1, 1, 1]... | [
"[1,2,3,4]",
"[1,2,0,0,2,1]",
"[1,2,0,1,2]"
] | [
"Keep An array of the last day there was rains over each city.",
"Keep an array of the days you can dry a lake when you face one.",
"When it rains over a lake, check the first possible day you can dry this lake and assign this day to this lake."
] | {
"canonical_parameter_names": [
"rains"
],
"leetcode_dataset_entry_point": "Solution().avoidFlood",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:38",
"tests_total": 242,
"tests_dro... | cpp | {
"raw_signature": "vector<int> avoidFlood(vector<int>& rains) {",
"container": "Solution",
"callable": "avoidFlood",
"parameters": [
{
"name": "rains",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,489 | find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree | Hard | Given a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [a_i, b_i, weight_i] represents a bidirectional and weighted edge between nodes a_i and b_i. A minimum spanning tree (MST) is a subset of the graph's edges that connects all vertices without cycles ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3,edges = [[0, 1, 1], [1, 2, 1], [0, 2, 2]]) == [[0, 1], []]\n assert candidate(n = 5,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 2], [0, 3, 2], [0, 4, 3], [3, 4, 3], [1, 4, 6]]) == [[0, 1], [2, 3, 4, 5]]\n assert candidate(n = 6,edg... | [
"5\n[[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]",
"4\n[[0,1,1],[1,2,1],[2,3,1],[0,3,1]]"
] | [
"Use the Kruskal algorithm to find the minimum spanning tree by sorting the edges and picking edges from ones with smaller weights.",
"Use a disjoint set to avoid adding redundant edges that result in a cycle.",
"To find if one edge is critical, delete that edge and re-run the MST algorithm and see if the weigh... | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().findCriticalAndPseudoCriticalEdges",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:40",
... | cpp | {
"raw_signature": "vector<vector<int>> findCriticalAndPseudoCriticalEdges(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "findCriticalAndPseudoCriticalEdges",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vect... |
1,491 | average-salary-excluding-the-minimum-and-maximum-salary | Easy | You are given an array of unique integers salary where salary[i] is the salary of the i^th employee.
Return the average salary of employees excluding the minimum and maximum salary. Answers within 10^-5 of the actual answer will be accepted.
Example 1:
Input: salary = [4000,3000,1000,2000]
Output: 2500.00000
Explana... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat... | [
"[4000,3000,1000,2000]",
"[1000,2000,3000]"
] | [
"Get the total sum and subtract the minimum and maximum value in the array. Finally divide the result by n - 2."
] | {
"canonical_parameter_names": [
"salary"
],
"leetcode_dataset_entry_point": "Solution().average",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:43",
"tests_total": 99,
"tests_droppe... | cpp | {
"raw_signature": "double average(vector<int>& salary) {",
"container": "Solution",
"callable": "average",
"parameters": [
{
"name": "salary",
"type": "vector<int>&"
}
],
"return_type": "double",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,492 | the-kth-factor-of-n | Medium | You are given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0.
Consider a list of all factors of n sorted in ascending order, return the k^th factor in this list or return -1 if n has less than k factors.
Example 1:
Input: n = 12, k = 3
Output: 3
Explanation: Facto... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 1,k = 1) == 1\n assert candidate(n = 49,k = 3) == 49\n assert candidate(n = 100,k = 5) == 10\n assert candidate(n = 7,k = 2) == 7\n assert candidate(n = 17,k = 2) == 17\n assert candidate(n = 1000,k = 15) == 500\n a... | [
"12\n3",
"7\n2",
"4\n4"
] | [
"The factors of n will be always in the range [1, n].",
"Keep a list of all factors sorted. Loop i from 1 to n and add i if n % i == 0. Return the kth factor if it exist in this list."
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().kthFactor",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:45",
"tests_total": 81,
"tests_... | cpp | {
"raw_signature": "int kthFactor(int n, int k) {",
"container": "Solution",
"callable": "kthFactor",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source"... |
1,493 | longest-subarray-of-1s-after-deleting-one-element | Medium | Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1's in the resulting array. Return 0 if there is no such subarray.
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1]) == 4\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 2\n assert candidate(nums = [0, 0, 0]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n as... | [
"[1,1,0,1]",
"[0,1,1,1,0,1,1,0,1]",
"[1,1,1]"
] | [
"Maintain a sliding window where there is at most one zero in it."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().longestSubarray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:47",
"tests_total": 92,
"tests_... | cpp | {
"raw_signature": "int longestSubarray(vector<int>& nums) {",
"container": "Solution",
"callable": "longestSubarray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
1,494 | parallel-courses-ii | Hard | You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCourse_i, nextCourse_i], representing a prerequisite relationship between course prevCourse_i and course nextCourse_i: course prevCourse_i has to be taken before cour... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,relations = [[2, 1], [3, 1], [1, 4]],k = 2) == 3\n assert candidate(n = 5,relations = [],k = 3) == 2\n assert candidate(n = 5,relations = [[2, 1], [3, 1], [4, 1], [1, 5]],k = 2) == 4\n assert candidate(n = 3,relations = [[... | [
"4\n[[2,1],[3,1],[1,4]]\n2",
"5\n[[2,1],[3,1],[4,1],[1,5]]\n2"
] | [
"Use backtracking with states (bitmask, degrees) where bitmask represents the set of courses, if the ith bit is 1 then the ith course was taken, otherwise, you can take the ith course. Degrees represent the degree for each course (nodes in the graph).",
"Note that you can only take nodes (courses) with degree = 0... | {
"canonical_parameter_names": [
"n",
"relations",
"k"
],
"leetcode_dataset_entry_point": "Solution().minNumberOfSemesters",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:50",
... | cpp | {
"raw_signature": "int minNumberOfSemesters(int n, vector<vector<int>>& relations, int k) {",
"container": "Solution",
"callable": "minNumberOfSemesters",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "relations",
"type": "vector<vector<int>>&"
},
{
... |
1,496 | path-crossing | Easy | Given a string path, where path[i] = 'N', 'S', 'E' or 'W', each representing moving one unit north, south, east, or west, respectively. You start at the origin (0, 0) on a 2D plane and walk on the path specified by path.
Return true if the path crosses itself at any point, that is, if at any time you are on a location... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(path = \"NEESWNWWSNNWNSSSWEWEWEWE\") == True\n assert candidate(path = \"NNNSSSSSSEEEEEEEWWWWWWWWW\") == True\n assert candidate(path = \"NEWSNEWS\") == True\n assert candidate(path = \"EWEWEWEW\") == True\n assert candidate(... | [
"\"NES\"",
"\"NESWW\""
] | [
"Simulate the process while keeping track of visited points.",
"Use a set to store previously visited points."
] | {
"canonical_parameter_names": [
"path"
],
"leetcode_dataset_entry_point": "Solution().isPathCrossing",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:52",
"tests_total": 186,
"tests_... | cpp | {
"raw_signature": "bool isPathCrossing(string path) {",
"container": "Solution",
"callable": "isPathCrossing",
"parameters": [
{
"name": "path",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.