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 |
|---|---|---|---|---|---|---|---|---|---|
2,808 | minimum-seconds-to-equalize-a-circular-array | Medium | You are given a 0-indexed array nums containing n integers.
At each second, you perform the following operation on the array:
- For every index i in the range [0, n - 1], replace nums[i] with either nums[i], nums[(i - 1 + n) % n], or nums[(i + 1) % n].
Note that all the elements get replaced simultaneously.
Return ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 20, 10, 20, 10]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 1]) == 2\n assert candidate(nums = [10, 10, 1, 10, 10]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(nums ... | [
"[1,2,1,2]",
"[2,1,3,3,2]",
"[5,5,5,5]"
] | [
"For every possible x - the final value of the array, calculate the number of seconds needed to make all elements equal to x.",
"Notice that if you take two consecutive occurrences (i, j) of x, then the number of operations to make segment [i + 1, j - 1] equal to x is floor((j - i) / 2)"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minimumSeconds",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:03:42",
"tests_total": 116,
"tests_... | cpp | {
"raw_signature": "int minimumSeconds(vector<int>& nums) {",
"container": "Solution",
"callable": "minimumSeconds",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"... |
2,809 | minimum-time-to-make-array-sum-at-most-x | Hard | You are given two 0-indexed integer arrays nums1 and nums2 of equal length. Every second, for all indices 0 <= i < nums1.length, value of nums1[i] is incremented by nums2[i]. After this is done, you can do the following operation:
- Choose an index 0 <= i < nums1.length and make nums1[i] = 0.
You are also given an in... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 3],nums2 = [1, 2, 3],x = 4) == 3\n assert candidate(nums1 = [5, 3, 8],nums2 = [2, 1, 4],x = 15) == 1\n assert candidate(nums1 = [5, 5, 5],nums2 = [1, 1, 1],x = 15) == 0\n assert candidate(nums1 = [10, 10, 10],nums... | [
"[1,2,3]\n[1,2,3]\n4",
"[1,2,3]\n[3,3,3]\n4"
] | [
"It can be proven that in the optimal solution, for each index i, we only need to set nums1[i] to 0 at most once. (If we have to set it twice, we can simply remove the earlier set and all the operations “shift left” by 1.)",
"It can also be proven that if we select several indexes i_1, i_2, ..., i_k and set nums1... | {
"canonical_parameter_names": [
"nums1",
"nums2",
"x"
],
"leetcode_dataset_entry_point": "Solution().minimumTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:03:45",
"tests_to... | cpp | {
"raw_signature": "int minimumTime(vector<int>& nums1, vector<int>& nums2, int x) {",
"container": "Solution",
"callable": "minimumTime",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
},
{
"name": "x",
... |
2,810 | faulty-keyboard | Easy | Your laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as expected.
You are given a 0-indexed string s, and you type each character of s using your faulty keyboard.
Return the final string that will be present on your la... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"string\") == \"rtsng\"\n assert candidate(s = \"aibcdie\") == \"dcbae\"\n assert candidate(s = \"noicanoati\") == \"taonacno\"\n assert candidate(s = \"abcide\") == \"cbade\"\n assert candidate(s = \"poiinter\") == \"po... | [
"\"string\"",
"\"poiinter\""
] | [
"Try to build a new string by traversing the given string and reversing whenever you get the character ‘i’."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().finalString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:03:47",
"tests_total": 171,
"tests_droppe... | cpp | {
"raw_signature": "string finalString(string s) {",
"container": "Solution",
"callable": "finalString",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,811 | check-if-it-is-possible-to-split-array | Medium | You are given an array nums of length n and an integer m. You need to determine if it is possible to split the array into n arrays of size 1 by performing a series of steps.
An array is called good if:
- The length of the array is one, or
- The sum of the elements of the array is greater than or equal to m.
In each ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40],m = 50) == True\n assert candidate(nums = [2, 3, 3, 2, 3],m = 6) == True\n assert candidate(nums = [50, 50],m = 100) == True\n assert candidate(nums = [1, 2, 3, 4, 5],m = 9) == True\n assert candidate(... | [
"[2, 2, 1]\n4",
"[2, 1, 3]\n5",
"[2, 3, 3, 2, 3]\n6"
] | [
"It can be proven that if you can split more than one element as a subarray, then you can split exactly one element."
] | {
"canonical_parameter_names": [
"nums",
"m"
],
"leetcode_dataset_entry_point": "Solution().canSplitArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:03:49",
"tests_total": 113,
... | cpp | {
"raw_signature": "bool canSplitArray(vector<int>& nums, int m) {",
"container": "Solution",
"callable": "canSplitArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "m",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetc... |
2,812 | find-the-safest-path-in-a-grid | Medium | You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:
- A cell containing a thief if grid[r][c] = 1
- An empty cell if grid[r][c] = 0
You are initially positioned at cell (0, 0). In one move, you can move to any adjacent cell in the grid, including cells containing thieves.
The safeness fa... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 0]]) == 3\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 1]]) == 0\n assert candi... | [
"[[1,0,0],[0,0,0],[0,0,1]]",
"[[0,0,1],[0,0,0],[0,0,0]]",
"[[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]"
] | [
"Consider using both BFS and binary search together.",
"Launch a BFS starting from all the cells containing thieves to calculate d[x][y] which is the smallest Manhattan distance from (x, y) to the nearest grid that contains thieves.",
"To check if the bottom-right cell of the grid can be reached through a path ... | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().maximumSafenessFactor",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:03:51",
"tests_total": 66,
"... | cpp | {
"raw_signature": "int maximumSafenessFactor(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "maximumSafenessFactor",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_so... |
2,813 | maximum-elegance-of-a-k-length-subsequence | Hard | You are given a 0-indexed 2D integer array items of length n and an integer k.
items[i] = [profit_i, category_i], where profit_i and category_i denote the profit and category of the i^th item respectively.
Let's define the elegance of a subsequence of items as total_profit + distinct_categories^2, where total_profit ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(items = [[10, 1], [9, 1], [8, 1], [7, 1], [6, 1]],k = 2) == 20\n assert candidate(items = [[9, 1], [7, 2], [5, 3], [3, 4], [1, 5]],k = 4) == 40\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]],k = 3) == 129\... | [
"[[3,2],[5,1],[10,1]]\n2",
"[[3,1],[3,1],[2,2],[5,3]]\n3",
"[[1,1],[2,1],[3,1]]\n3"
] | [
"Greedy algorithm.",
"Sort items in non-increasing order of profits.",
"Select the first k items (the top k most profitable items). Keep track of the items as the candidate set.",
"For the remaining n - k items sorted in non-increasing order of profits, try replacing an item in the candidate set using the cur... | {
"canonical_parameter_names": [
"items",
"k"
],
"leetcode_dataset_entry_point": "Solution().findMaximumElegance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:03:54",
"tests_total":... | cpp | {
"raw_signature": "long long findMaximumElegance(vector<vector<int>>& items, int k) {",
"container": "Solution",
"callable": "findMaximumElegance",
"parameters": [
{
"name": "items",
"type": "vector<vector<int>>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "... |
2,815 | max-pair-sum-in-an-array | Easy | You are given an integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the largest digit in both numbers is equal.
For example, 2373 is made up of three distinct digits: 2, 3, and 7, where 7 is the largest among them.
Return the maximum sum or -1 if no such pair exists.
Exampl... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [123, 321, 213, 132]) == 534\n assert candidate(nums = [100, 200, 300, 400]) == -1\n assert candidate(nums = [55, 44, 33, 22, 11]) == -1\n assert candidate(nums = [99, 88, 77, 66, 55]) == -1\n assert candidate(nums = [... | [
"[112,131,411]",
"[2536,1613,3366,162]",
"[51,71,17,24,42]"
] | [
"Find the largest and second largest element with maximum digits equal to x where 1<=x<=9."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:03:59",
"tests_total": 126,
"tests_dropped"... | cpp | {
"raw_signature": "int maxSum(vector<int>& nums) {",
"container": "Solution",
"callable": "maxSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,817 | minimum-absolute-difference-between-elements-with-constraint | Medium | You are given a 0-indexed integer array nums and an integer x.
Find the minimum absolute difference between two elements in the array that are at least x indices apart.
In other words, find two indices i and j such that abs(i - j) >= x and abs(nums[i] - nums[j]) is minimized.
Return an integer denoting the minimum a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1],x = 2) == 0\n assert candidate(nums = [10, 5, 3, 9, 2],x = 2) == 1\n assert candidate(nums = [1, 1, 1, 1, 1],x = 0) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7],x = 3) == 0\n assert candid... | [
"[4,3,2,4]\n2",
"[5,3,2,10,15]\n1",
"[1,2,3,4]\n3"
] | [
"Let's only consider the cases where i < j, as the problem is symmetric.",
"For an index j, we are interested in an index i in the range [0, j - x] that minimizes abs(nums[i] - nums[j]).",
"For every index j, while going from left to right, add nums[j - x] to a set (C++ set, Java TreeSet, and Python sorted set)... | {
"canonical_parameter_names": [
"nums",
"x"
],
"leetcode_dataset_entry_point": "Solution().minAbsoluteDifference",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:04",
"tests_total"... | cpp | {
"raw_signature": "int minAbsoluteDifference(vector<int>& nums, int x) {",
"container": "Solution",
"callable": "minAbsoluteDifference",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "x",
"type": "int"
}
],
"return_type": "int",
"signature_s... |
2,824 | count-pairs-whose-sum-is-less-than-target | Easy | Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target.
Example 1:
Input: nums = [-1,1,2,3,1], target = 2
Output: 3
Explanation: There are 3 pairs of indices that satisfy the conditions in the statement:
- (0, 1) si... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],target = 15) == 10\n assert candidate(nums = [1, 3, 5, 7, 9],target = 10) == 4\n assert candidate(nums = [1, 1, 1, 1, 1],target = 3) == 10\n assert candidate(nums = [0, 0, 0, 0, 0],target = 0) == 0\n as... | [
"[-1,1,2,3,1]\n2",
"[-6,2,5,-2,-7,-1,3]\n-2"
] | [
"The constraints are small enough for a brute-force solution to pass"
] | {
"canonical_parameter_names": [
"nums",
"target"
],
"leetcode_dataset_entry_point": "Solution().countPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:09",
"tests_total": 112,... | cpp | {
"raw_signature": "int countPairs(vector<int>& nums, int target) {",
"container": "Solution",
"callable": "countPairs",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "int",
"signature_source": "lee... |
2,825 | make-string-a-subsequence-using-cyclic-increments | Medium | You are given two 0-indexed strings str1 and str2.
In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.
Return true if it is possible to make str2 a subsequen... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(str1 = \"aaa\",str2 = \"a\") == True\n assert candidate(str1 = \"hello\",str2 = \"heo\") == True\n assert candidate(str1 = \"abcd\",str2 = \"bd\") == True\n assert candidate(str1 = \"zyxwvutsrqponmlkjihgfedcba\",str2 = \"abcdefg... | [
"\"abc\"\n\"ad\"",
"\"zc\"\n\"ad\"",
"\"ab\"\n\"d\""
] | [
"Consider the indices we will increment separately.",
"We can maintain two pointers: pointer i for str1 and pointer j for str2, while ensuring they remain within the bounds of the strings.",
"If both str1[i] and str2[j] match, or if incrementing str1[i] matches str2[j], we increase both pointers; otherwise, we ... | {
"canonical_parameter_names": [
"str1",
"str2"
],
"leetcode_dataset_entry_point": "Solution().canMakeSubsequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:11",
"tests_total"... | cpp | {
"raw_signature": "bool canMakeSubsequence(string str1, string str2) {",
"container": "Solution",
"callable": "canMakeSubsequence",
"parameters": [
{
"name": "str1",
"type": "string"
},
{
"name": "str2",
"type": "string"
}
],
"return_type": "bool",
"signature_sourc... |
2,826 | sorting-three-groups | Medium | You are given an integer array nums. Each element in nums is 1, 2 or 3. In each operation, you can remove an element from nums. Return the minimum number of operations to make nums non-decreasing.
Example 1:
Input: nums = [2,1,3,2,1]
Output: 3
Explanation:
One of the optimal solutions is to remove nums[0], nums[2] an... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 3, 2, 2, 1]) == 3\n assert candidate(nums = [3, 3, 3, 2, 2, 2, 1, 1, 1]) == 6\n assert candidate(nums = [1, 2, 3, 1, 2, 3]) == 2\n assert candidate(nums = [1, 1, 1]) == 0\n assert candidate(nums = [3, 3, 3, 2, 2... | [
"[2,1,3,2,1]",
"[1,3,2,1,3,3]",
"[2,2,2,2,3,3]"
] | [
"The problem asks to change the array nums to make it sorted (i.e., all the 1s are on the left of 2s, and all the 2s are on the left of 3s.).",
"We can try all the possibilities to make nums indices range in [0, i) to 0 and [i, j) to 1 and [j, n) to 2. Note the ranges are left-close and right-open; each might be ... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minimumOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:13",
"tests_total": 131,
"tes... | cpp | {
"raw_signature": "int minimumOperations(vector<int>& nums) {",
"container": "Solution",
"callable": "minimumOperations",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
2,827 | number-of-beautiful-integers-in-the-range | Hard | You are given positive integers low, high, and k.
A number is beautiful if it meets both of the following conditions:
- The count of even digits in the number is equal to the count of odd digits.
- The number is divisible by k.
Return the number of beautiful integers in the range [low, high].
Example 1:
Input: low... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(low = 100,high = 200,k = 4) == 0\n assert candidate(low = 100,high = 200,k = 5) == 0\n assert candidate(low = 10,high = 20,k = 3) == 2\n assert candidate(low = 1,high = 10,k = 1) == 1\n assert candidate(low = 100,high = 200,k... | [
"10\n20\n3",
"1\n10\n1",
"5\n5\n2"
] | [
"The intended solution uses Dynamic Programming.",
"Let f(n) denote number of beautiful integers in the range [1…n] , then the answer is f(r) - f(l-1) ."
] | {
"canonical_parameter_names": [
"low",
"high",
"k"
],
"leetcode_dataset_entry_point": "Solution().numberOfBeautifulIntegers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:16",
... | cpp | {
"raw_signature": "int numberOfBeautifulIntegers(int low, int high, int k) {",
"container": "Solution",
"callable": "numberOfBeautifulIntegers",
"parameters": [
{
"name": "low",
"type": "int"
},
{
"name": "high",
"type": "int"
},
{
"name": "k",
"type": "i... |
2,828 | check-if-a-string-is-an-acronym-of-words | Easy | Given an array of strings words and a string s, determine if s is an acronym of words.
The string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, "ab" can be formed from ["apple", "banana"], but it can't be formed from ["bear",... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['different', 'words', 'here'],s = \"dwh\") == True\n assert candidate(words = ['dog', 'cat'],s = \"dc\") == True\n assert candidate(words = ['single'],s = \"s\") == True\n assert candidate(words = ['make', 'america', 'g... | [
"[\"alice\",\"bob\",\"charlie\"]\n\"abc\"",
"[\"an\",\"apple\"]\n\"a\"",
"[\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"]\n\"ngguoy\""
] | [
"Concatenate the first characters of the strings in words, and compare the resulting concatenation to s."
] | {
"canonical_parameter_names": [
"words",
"s"
],
"leetcode_dataset_entry_point": "Solution().isAcronym",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:18",
"tests_total": 129,
"t... | cpp | {
"raw_signature": "bool isAcronym(vector<string>& words, string s) {",
"container": "Solution",
"callable": "isAcronym",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
},
{
"name": "s",
"type": "string"
}
],
"return_type": "bool",
"signature_source": ... |
2,829 | determine-the-minimum-sum-of-a-k-avoiding-array | Medium | You are given two integers, n and k.
An array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.
Return the minimum possible sum of a k-avoiding array of length n.
Example 1:
Input: n = 5, k = 4
Output: 18
Explanation: Consider the k-avoid... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,k = 8) == 10\n assert candidate(n = 3,k = 5) == 8\n assert candidate(n = 10,k = 15) == 76\n assert candidate(n = 4,k = 7) == 13\n assert candidate(n = 7,k = 10) == 36\n assert candidate(n = 2,k = 6) == 3\n assert ... | [
"5\n4",
"2\n6"
] | [
"Try to start with the smallest possible integers.",
"Check if the current number can be added to the array.",
"To check if the current number can be added, keep track of already added numbers in a set.",
"If the number i is added to the array, then i + k can not be added."
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().minimumSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:20",
"tests_total": 77,
"tests... | cpp | {
"raw_signature": "int minimumSum(int n, int k) {",
"container": "Solution",
"callable": "minimumSum",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_sourc... |
2,830 | maximize-the-profit-as-the-salesman | Medium | You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.
Additionally, you are given a 2D integer array offers where offers[i] = [start_i, end_i, gold_i], indicating that i^th buyer wants to buy all the houses from start_i to end_i for gold_i amount of gold.
As a salesm... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 10,offers = [[0, 4, 10], [1, 5, 15], [3, 7, 20], [8, 9, 5]]) == 25\n assert candidate(n = 10,offers = [[0, 4, 10], [1, 5, 11], [2, 6, 12]]) == 12\n assert candidate(n = 10,offers = [[0, 1, 1], [2, 3, 2], [4, 5, 3], [6, 7, 4], [... | [
"5\n[[0,0,1],[0,2,2],[1,3,2]]",
"5\n[[0,0,1],[0,2,10],[1,3,2]]"
] | [
"The intended solution uses a dynamic programming approach to solve the problem.",
"Sort the array offers by start_i.",
"Let dp[i] = { the maximum amount of gold if the sold houses are in the range [0 … i] }."
] | {
"canonical_parameter_names": [
"n",
"offers"
],
"leetcode_dataset_entry_point": "Solution().maximizeTheProfit",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:23",
"tests_total": ... | cpp | {
"raw_signature": "int maximizeTheProfit(int n, vector<vector<int>>& offers) {",
"container": "Solution",
"callable": "maximizeTheProfit",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "offers",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
... |
2,831 | find-the-longest-equal-subarray | Medium | You are given a 0-indexed integer array nums and an integer k.
A subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.
Return the length of the longest possible equal subarray after deleting at most k elements from nums.
A subarray is a contiguous, possibly emp... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3],k = 3) == 4\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3],k = 4) == 3\n assert candidate(nums = [1, 2, 2, 1, 2, 2],k = 2) == 4\n assert candidate(nums = [10, 1, 2, 2, 1, 3, 3, 3, 3, ... | [
"[1,3,2,3,1,3]\n3",
"[1,1,2,2,1,1]\n2"
] | [
"For each number x in nums, create a sorted list indices_x of all indices i such that nums[i] == x.",
"On every indices_x, execute a sliding window technique.",
"For each indices_x, find i, j such that (indices_x[j] - indices_x[i]) - (j - i) <= k and j - i + 1 is maximized.",
"The answer would be the maximum ... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().longestEqualSubarray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:25",
"tests_total":... | cpp | {
"raw_signature": "int longestEqualSubarray(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "longestEqualSubarray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_sou... |
2,833 | furthest-point-from-origin | Easy | You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.
In the i^th move, you can choose one of the following directions:
- move to the left if moves[i] = 'L' or moves[i] = '_'
- move to the right if mov... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(moves = \"________R\") == 9\n assert candidate(moves = \"L_RL__R\") == 3\n assert candidate(moves = \"L_____R\") == 5\n assert candidate(moves = \"R_L_R_L\") == 3\n assert candidate(moves = \"L________\") == 9\n assert can... | [
"\"L_RL__R\"",
"\"_R__LL_\"",
"\"_______\""
] | [
"In an optimal answer, all occurrences of '_’ will be replaced with the same character.",
"Replace all characters of '_’ with the character that occurs the most."
] | {
"canonical_parameter_names": [
"moves"
],
"leetcode_dataset_entry_point": "Solution().furthestDistanceFromOrigin",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:30",
"tests_total": 1... | cpp | {
"raw_signature": "int furthestDistanceFromOrigin(string moves) {",
"container": "Solution",
"callable": "furthestDistanceFromOrigin",
"parameters": [
{
"name": "moves",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
2,834 | find-the-minimum-possible-sum-of-a-beautiful-array | Medium | You are given positive integers n and target.
An array nums is beautiful if it meets the following conditions:
- nums.length == n.
- nums consists of pairwise distinct positive integers.
- There doesn't exist two distinct indices, i and j, in the range [0, n - 1], such that nums[i] + nums[j] == target.
Return the mi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 2,target = 3) == 4\n assert candidate(n = 100,target = 100) == 7500\n assert candidate(n = 5,target = 8) == 18\n assert candidate(n = 1,target = 1) == 1\n assert candidate(n = 1000000000,target = 1000000000) == 750000042\... | [
"2\n3",
"3\n3",
"1\n1"
] | [
"Greedily try to add the smallest possible number in the array nums, such that nums contains distinct positive integers, and there are no two indices i and j with nums[i] + nums[j] == target."
] | {
"canonical_parameter_names": [
"n",
"target"
],
"leetcode_dataset_entry_point": "Solution().minimumPossibleSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:32",
"tests_total":... | cpp | {
"raw_signature": "int minimumPossibleSum(int n, int target) {",
"container": "Solution",
"callable": "minimumPossibleSum",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/co... |
2,835 | minimum-operations-to-form-subsequence-with-target-sum | Hard | You are given a 0-indexed array nums consisting of non-negative powers of 2, and an integer target.
In one operation, you must apply the following changes to the array:
- Choose any element of the array nums[i] such that nums[i] > 1.
- Remove nums[i] from the array.
- Add two occurrences of nums[i] / 2 to the end of ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 4, 8, 16],target = 31) == -1\n assert candidate(nums = [32, 16, 8, 4, 2, 1],target = 63) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],target = 4) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1... | [
"[1,2,8]\n7",
"[1,32,1,2]\n12",
"[1,32,1]\n35"
] | [
"if target > sum(nums[i]) , return -1. Otherwise, an answer exists",
"Solve the problem for each set bit of target, independently, from least significant to most significant bit.",
"For each set bit of target from least to most significant, let X = sum(nums[i]) for nums[i] <= 2^bit.",
"if X >= 2^bit, repeated... | {
"canonical_parameter_names": [
"nums",
"target"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:34",
"tests_total": 1... | cpp | {
"raw_signature": "int minOperations(vector<int>& nums, int target) {",
"container": "Solution",
"callable": "minOperations",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "int",
"signature_source"... |
2,836 | maximize-value-of-function-in-a-ball-passing-game | Hard | You are given an integer array receiver of length n and an integer k. n players are playing a ball-passing game.
You choose the starting player, i. The game proceeds as follows: player i passes the ball to player receiver[i], who then passes it to receiver[receiver[i]], and so on, for k passes in total. The game's sco... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(receiver = [4, 3, 2, 1, 0],k = 10) == 24\n assert candidate(receiver = [4, 3, 2, 1, 0],k = 5) == 12\n assert candidate(receiver = [3, 3, 3, 3],k = 10) == 33\n assert candidate(receiver = [0, 2, 1, 0],k = 5) == 9\n assert cand... | [
"[2,0,1]\n4",
"[1,1,1,2,3]\n3"
] | [
"We can solve the problem using binary lifting.",
"For each player with id x and for every i in the range [0, ceil(log_2k)], we can determine the last receiver's id and compute the sum of player ids who receive the ball after 2^i passes, starting from x.",
"Let last_receiver[x][i] = the last receiver's id after... | {
"canonical_parameter_names": [
"receiver",
"k"
],
"leetcode_dataset_entry_point": "Solution().getMaxFunctionValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:37",
"tests_tota... | cpp | {
"raw_signature": "long long getMaxFunctionValue(vector<int>& receiver, long long k) {",
"container": "Solution",
"callable": "getMaxFunctionValue",
"parameters": [
{
"name": "receiver",
"type": "vector<int>&"
},
{
"name": "k",
"type": "long long"
}
],
"return_type":... |
2,839 | check-if-strings-can-be-made-equal-with-operations-i | Easy | You are given two strings s1 and s2, both of length 4, consisting of lowercase English letters.
You can apply the following operation on any of the two strings any number of times:
- Choose any two indices i and j such that j - i = 2, then swap the two characters at those indices in the string.
Return true if you ca... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s1 = \"abcd\",s2 = \"cdab\") == True\n assert candidate(s1 = \"acbd\",s2 = \"bdac\") == True\n assert candidate(s1 = \"abab\",s2 = \"abcd\") == False\n assert candidate(s1 = \"abdc\",s2 = \"cdab\") == False\n assert candidate... | [
"\"abcd\"\n\"cdab\"",
"\"abcd\"\n\"dacb\""
] | [
"Since the strings are very small you can try a brute-force approach.",
"There are only 2 different swaps that are possible in a string."
] | {
"canonical_parameter_names": [
"s1",
"s2"
],
"leetcode_dataset_entry_point": "Solution().canBeEqual",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:42",
"tests_total": 63,
"tes... | cpp | {
"raw_signature": "bool canBeEqual(string s1, string s2) {",
"container": "Solution",
"callable": "canBeEqual",
"parameters": [
{
"name": "s1",
"type": "string"
},
{
"name": "s2",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippe... |
2,840 | check-if-strings-can-be-made-equal-with-operations-ii | Medium | You are given two strings s1 and s2, both of length n, consisting of lowercase English letters.
You can apply the following operation on any of the two strings any number of times:
- Choose any two indices i and j such that i < j and the difference j - i is even, then swap the two characters at those indices in the s... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s1 = \"aabbcc\",s2 = \"bbaacc\") == True\n assert candidate(s1 = \"abcdabcd\",s2 = \"dcbadcba\") == False\n assert candidate(s1 = \"abcdba\",s2 = \"cabdab\") == True\n assert candidate(s1 = \"a\",s2 = \"a\") == True\n assert ... | [
"\"abcdba\"\n\"cabdab\"",
"\"abe\"\n\"bea\""
] | [
"Characters in two positions can be swapped if and only if the two positions have the same parity.",
"To be able to make the two strings equal, the characters at even and odd positions in the strings should be the same."
] | {
"canonical_parameter_names": [
"s1",
"s2"
],
"leetcode_dataset_entry_point": "Solution().checkStrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:44",
"tests_total": 127,
"... | cpp | {
"raw_signature": "bool checkStrings(string s1, string s2) {",
"container": "Solution",
"callable": "checkStrings",
"parameters": [
{
"name": "s1",
"type": "string"
},
{
"name": "s2",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSn... |
2,841 | maximum-sum-of-almost-unique-subarray | Medium | You are given an integer array nums and two positive integers m and k.
Return the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0.
A subarray of nums is almost unique if it contains at least m distinct elements.
A subarray is a contiguous non-empty sequence of... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],m = 2,k = 3) == 24\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],m = 4,k = 5) == 35\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],m = 5,k = 5) == 0\n assert candidate(nums = ... | [
"[2,6,7,3,1,7]\n3\n4",
"[5,9,9,2,4,5,4]\n1\n3",
"[1,2,1,2,1,2,1]\n3\n3"
] | [
"Use a set or map to keep track of the number of distinct elements.",
"Use 2-pointers to maintain the size, the number of unique elements, and the sum of all the elements in all subarrays of size k from left to right dynamically.****"
] | {
"canonical_parameter_names": [
"nums",
"m",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:46",
"tests_total": 108,... | cpp | {
"raw_signature": "long long maxSum(vector<int>& nums, int m, int k) {",
"container": "Solution",
"callable": "maxSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "m",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"... |
2,843 | count-symmetric-integers | Easy | You are given two positive integers low and high.
An integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x. Numbers with an odd number of digits are never symmetric.
Return the number of symmetric integers in the range [low, high].
Examp... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(low = 10,high = 20) == 1\n assert candidate(low = 1,high = 9999) == 624\n assert candidate(low = 500,high = 1500) == 20\n assert candidate(low = 1000,high = 1000) == 0\n assert candidate(low = 500,high = 550) == 0\n assert... | [
"1\n100",
"1200\n1230"
] | [
"Iterate over all numbers from low to high",
"Convert each number to a string and compare the sum of the first half with that of the second."
] | {
"canonical_parameter_names": [
"low",
"high"
],
"leetcode_dataset_entry_point": "Solution().countSymmetricIntegers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:51",
"tests_tot... | cpp | {
"raw_signature": "int countSymmetricIntegers(int low, int high) {",
"container": "Solution",
"callable": "countSymmetricIntegers",
"parameters": [
{
"name": "low",
"type": "int"
},
{
"name": "high",
"type": "int"
}
],
"return_type": "int",
"signature_source": "lee... |
2,844 | minimum-operations-to-make-a-special-number | Medium | You are given a 0-indexed string num representing a non-negative integer.
In one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.
Return the minimum number of operations required to make num special.
An integer x is considered special if it is divi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = \"10\") == 1\n assert candidate(num = \"00000\") == 0\n assert candidate(num = \"75\") == 0\n assert candidate(num = \"52\") == 2\n assert candidate(num = \"500000\") == 0\n assert candidate(num = \"5252525252\") == ... | [
"\"2245047\"",
"\"2908305\"",
"\"10\""
] | [
"If num contains a single zero digit then the answer is at most n - 1.",
"A number is divisible by 25 if its last two digits are 75, 50, 25, or 00.",
"Iterate over all possible pairs of indices i < j such that num[i] * 10 + num[j] is in [00,25,50,75]. Then, set the answer to min(answer, n - i - 2) ."
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().minimumOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:53",
"tests_total": 188,
"test... | cpp | {
"raw_signature": "int minimumOperations(string num) {",
"container": "Solution",
"callable": "minimumOperations",
"parameters": [
{
"name": "num",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,845 | count-of-interesting-subarrays | Medium | You are given a 0-indexed integer array nums, an integer modulo, and an integer k.
Your task is to find the count of subarrays that are interesting.
A subarray nums[l..r] is interesting if the following condition holds:
- Let cnt be the number of indices i in the range [l, r] such that nums[i] % modulo == k. Then, c... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [3, 2, 4],modulo = 2,k = 1) == 3\n assert candidate(nums = [8, 12, 16, 20, 24],modulo = 4,k = 0) == 2\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7],modulo = 7,k = 0) == 1\n assert candidate(nums = [3, 1, 9, 6],modulo = ... | [
"[3,2,4]\n2\n1",
"[3,1,9,6]\n3\n0"
] | [
"The problem can be solved using prefix sums.",
"Let count[i] be the number of indices where nums[i] % modulo == k among the first i indices.",
"count[0] = 0 and count[i] = count[i - 1] + (nums[i - 1] % modulo == k ? 1 : 0) for i = 1, 2, ..., n.",
"Now we want to calculate for each i = 1, 2, ..., n, how many ... | {
"canonical_parameter_names": [
"nums",
"modulo",
"k"
],
"leetcode_dataset_entry_point": "Solution().countInterestingSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:55... | cpp | {
"raw_signature": "long long countInterestingSubarrays(vector<int>& nums, int modulo, int k) {",
"container": "Solution",
"callable": "countInterestingSubarrays",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "modulo",
"type": "int"
},
{
... |
2,846 | minimum-edge-weight-equilibrium-queries-in-a-tree | Hard | There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [u_i, v_i, w_i] indicates that there is an edge between nodes u_i and v_i with weight w_i in the tree.
You are also given a 2D integer array queries of length m, ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 7,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 2], [4, 5, 2], [5, 6, 2]],queries = [[0, 3], [3, 6], [2, 6], [0, 6]]) == [0, 0, 1, 3]\n assert candidate(n = 8,edges = [[1, 2, 6], [1, 3, 4], [2, 4, 6], [2, 5, 3], [3, 6, 6], [3, ... | [
"7\n[[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]]\n[[0,3],[3,6],[2,6],[0,6]]",
"8\n[[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]]\n[[4,6],[0,4],[6,5],[7,4]]"
] | [
"Root the tree at any node.",
"Define a 2D array freq[node][weight] which saves the frequency of each edge weight on the path from the root to each node.",
"The frequency of edge weight w on the path from a to b is equal to freq[a][w] + freq[b][w] - freq[lca(a,b)][w] * 2, where lca(a,b) is the lowest common anc... | {
"canonical_parameter_names": [
"n",
"edges",
"queries"
],
"leetcode_dataset_entry_point": "Solution().minOperationsQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:04:58",
... | cpp | {
"raw_signature": "vector<int> minOperationsQueries(int n, vector<vector<int>>& edges, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "minOperationsQueries",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int... |
2,848 | points-that-intersect-with-cars | Easy | You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [start_i, end_i] where start_i is the starting point of the i^th car and end_i is the ending point of the i^th car.
Return the number of integer points on the line that are cove... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [[1, 100]]) == 100\n assert candidate(nums = [[1, 3], [5, 8]]) == 7\n assert candidate(nums = [[1, 1], [2, 2], [3, 3]]) == 3\n assert candidate(nums = [[10, 15], [20, 25]]) == 12\n assert candidate(nums = [[1, 100], [5... | [
"[[3,6],[1,5],[4,7]]",
"[[1,3],[5,8]]"
] | [
"Sort the array according to first element and then starting from the 0^th index remove the overlapping parts and return the count of non-overlapping points."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().numberOfPoints",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:02",
"tests_total": 85,
"tests_d... | cpp | {
"raw_signature": "int numberOfPoints(vector<vector<int>>& nums) {",
"container": "Solution",
"callable": "numberOfPoints",
"parameters": [
{
"name": "nums",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
2,849 | determine-if-a-cell-is-reachable-at-a-given-time | Medium | You are given four integers sx, sy, fx, fy, and a non-negative integer t.
In an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.
Return true if you can reach cell (fx, fy) after exactly t seconds, or false otherwise.
A cell's adjacent cells are the 8 cells ar... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(sx = 1,sy = 1,fx = 2,fy = 2,t = 1) == True\n assert candidate(sx = 2,sy = 4,fx = 7,fy = 7,t = 6) == True\n assert candidate(sx = 1,sy = 1,fx = 10,fy = 10,t = 14) == True\n assert candidate(sx = 1000000000,sy = 1000000000,fx = 10... | [
"2\n4\n7\n7\n6",
"3\n1\n7\n3\n3"
] | [
"Minimum time to reach the cell should be less than or equal to given time.",
"The answer is true if t is greater or equal than the Chebyshev distance from (sx, sy) to (fx, fy). However, there is one more edge case to be considered.",
"The answer is false If sx == fx and sy == fy"
] | {
"canonical_parameter_names": [
"sx",
"sy",
"fx",
"fy",
"t"
],
"leetcode_dataset_entry_point": "Solution().isReachableAtTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21... | cpp | {
"raw_signature": "bool isReachableAtTime(int sx, int sy, int fx, int fy, int t) {",
"container": "Solution",
"callable": "isReachableAtTime",
"parameters": [
{
"name": "sx",
"type": "int"
},
{
"name": "sy",
"type": "int"
},
{
"name": "fx",
"type": "int"
... |
2,850 | minimum-moves-to-spread-stones-over-grid | Medium | You are given a 0-indexed 2D integer matrix grid of size 3 * 3, representing the number of stones in each cell. The grid contains exactly 9 stones, and there can be multiple stones in a single cell.
In one move, you can move a single stone from its current cell to any other cell if the two cells share a side.
Return ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[2, 2, 1], [1, 1, 1], [1, 1, 1]]) == 0\n assert candidate(grid = [[0, 0, 9], [0, 0, 0], [0, 0, 0]]) == 18\n assert candidate(grid = [[2, 2, 1], [1, 1, 1], [1, 1, 2]]) == 0\n assert candidate(grid = [[1, 3, 0], [1, 0, 0],... | [
"[[1,1,0],[1,1,1],[1,2,1]]",
"[[1,3,0],[1,0,0],[1,0,3]]"
] | [
"There are at most 4 cells with more than one stone.",
"Let a be the number of cells containing more than one stone, and b be the number of cells containing no stones. . b^a ≤ 6561. Use this fact to come up with a bruteforce.",
"For all empty cells, bruteforce over all possible cells from which a stone can come... | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().minimumMoves",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:06",
"tests_total": 39,
"tests_dro... | cpp | {
"raw_signature": "int minimumMoves(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "minimumMoves",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
2,851 | string-transformation | Hard | You are given two strings s and t of equal length n. You can perform the following operation on the string s:
- Remove a suffix of s of length l where 0 < l < n and append it at the start of s.
For example, let s = 'abcd' then in one operation you can remove the suffix 'cd' and append it in front of s making s = 'cdab... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcd\",t = \"cdab\",k = 2) == 2\n assert candidate(s = \"abcdef\",t = \"defabc\",k = 3) == 21\n assert candidate(s = \"xyzabc\",t = \"abcxyz\",k = 5) == 521\n assert candidate(s = \"abcde\",t = \"eabcd\",k = 10) == 209715\... | [
"\"abcd\"\n\"cdab\"\n2",
"\"ababab\"\n\"ababab\"\n1"
] | [
"String t can be only constructed if it is a rotated version of string s.",
"Use KMP algorithm or Z algorithm to find the number of indices from where s is equal to t.",
"Use Dynamic Programming to count the number of ways."
] | {
"canonical_parameter_names": [
"s",
"t",
"k"
],
"leetcode_dataset_entry_point": "Solution().numberOfWays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:09",
"tests_total": 8... | cpp | {
"raw_signature": "int numberOfWays(string s, string t, long long k) {",
"container": "Solution",
"callable": "numberOfWays",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "t",
"type": "string"
},
{
"name": "k",
"type": "long long"
}
... |
2,855 | minimum-right-shifts-to-sort-the-array | Easy | You are given a 0-indexed array nums of length n containing distinct positive integers. Return the minimum number of right shifts required to sort nums and -1 if this is not possible.
A right shift is defined as shifting the element at index i to index (i + 1) % n, for all indices.
Example 1:
Input: nums = [3,4,5,1,... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [4, 5, 6, 1, 2, 3]) == 3\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [50, 10, 20, 30, 40]) == 4\n assert candidate(nums = [1, 3, 5... | [
"[3,4,5,1,2]",
"[1,3,5]",
"[2,1,4]"
] | [
"Find the pivot point around which the array is rotated.",
"Will the answer exist if there is more than one point where nums[i] < nums[i-1]?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minimumRightShifts",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:14",
"tests_total": 129,
"te... | cpp | {
"raw_signature": "int minimumRightShifts(vector<int>& nums) {",
"container": "Solution",
"callable": "minimumRightShifts",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeS... |
2,856 | minimum-array-length-after-pair-removals | Medium | Given an integer array num sorted in non-decreasing order.
You can perform the following operation any number of times:
- Choose two indices, i and j, where nums[i] < nums[j].
- Then, remove the elements at indices i and j from nums. The remaining elements retain their original order, and the array is re-indexed.
Re... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) ==... | [
"[1,2,3,4]",
"[1,1,2,2,3,3]",
"[1000000000,1000000000]",
"[2,3,4,4,4]"
] | [
"To minimize the length of the array, we should maximize the number of operations performed.",
"To perform k operations, it is optimal to use the smallest k values and the largest k values in nums.",
"What is the best way to make pairs from the smallest k values and the largest k values so it is possible to rem... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minLengthAfterRemovals",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:16",
"tests_total": 121,
... | cpp | {
"raw_signature": "int minLengthAfterRemovals(vector<int>& nums) {",
"container": "Solution",
"callable": "minLengthAfterRemovals",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
2,857 | count-pairs-of-points-with-distance-k | Medium | You are given a 2D integer array coordinates and an integer k, where coordinates[i] = [x_i, y_i] are the coordinates of the i^th point in a 2D plane.
We define the distance between two points (x_1, y_1) and (x_2, y_2) as (x1 XOR x2) + (y1 XOR y2) where XOR is the bitwise XOR operation.
Return the number of pairs (i, ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3]],k = 2) == 2\n assert candidate(coordinates = [[1, 3], [1, 3], [1, 3], [1, 3], [1, 3]],k = 0) == 10\n assert candidate(coordinates = [[1, 2], [4, 2], [1, 3], [5, 2]],k = 5) == 2\n as... | [
"[[1,2],[4,2],[1,3],[5,2]]\n5",
"[[1,3],[1,3],[1,3],[1,3],[1,3]]\n0"
] | [
"Suppose that x = x_1 XOR x_2 and y = y_1 XOR y_2 then we can get x_2 = x XOR x_1 and y_2 = y XOR y_1.",
"We are supposed to have k = x + y so we can get x_2 = x XOR x_1 and y_2 = (k - x) XOR y_1.",
"We can iterate over all possible values of x and count the number of points (x_1, x_2) and (x_2, y_2)."
] | {
"canonical_parameter_names": [
"coordinates",
"k"
],
"leetcode_dataset_entry_point": "Solution().countPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:19",
"tests_total": 91... | cpp | {
"raw_signature": "int countPairs(vector<vector<int>>& coordinates, int k) {",
"container": "Solution",
"callable": "countPairs",
"parameters": [
{
"name": "coordinates",
"type": "vector<vector<int>>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"sig... |
2,858 | minimum-edge-reversals-so-every-node-is-reachable | Hard | There is a simple directed graph with n nodes labeled from 0 to n - 1. The graph would form a tree if its edges were bi-directional.
You are given an integer n and a 2D integer array edges, where edges[i] = [u_i, v_i] represents a directed edge going from node u_i to node v_i.
An edge reversal changes the direction o... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 7,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == [0, 1, 2, 3, 4, 5, 6]\n assert candidate(n = 4,edges = [[2, 0], [2, 1], [1, 3]]) == [1, 1, 0, 2]\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) ... | [
"4\n[[2,0],[2,1],[1,3]]",
"3\n[[1,2],[2,0]]"
] | [
"The problem can be solved using tree DP.",
"Using node 0 as the root, let dp[x] be the minimum number of edge reversals so node x can reach every node in its subtree.",
"Using a DFS traversing the edges bidirectionally, we can compute dp.\ndp[x] = dp[y] + (1 if the edge between x and y is going from y to x; 0 ... | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().minEdgeReversals",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:21",
"tests_total": 42... | cpp | {
"raw_signature": "vector<int> minEdgeReversals(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "minEdgeReversals",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type": "vect... |
2,859 | sum-of-values-at-indices-with-k-set-bits | Easy | You are given a 0-indexed integer array nums and an integer k.
Return an integer that denotes the sum of elements in nums whose corresponding indices have exactly k set bits in their binary representation.
The set bits in an integer are the 1's present when it is written in binary.
- For example, the binary represen... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],k = 0) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 3) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 4) == 0\n assert candidate(nums = [32, 16, 8, 4, 2, 1],k ... | [
"[5,10,1,5,2]\n1",
"[4,3,2,1]\n2"
] | [
"Iterate through the indices i in the range [0, n - 1], for each index i count the number of bits in its binary representation. If it is k, add nums[i] to the result."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().sumIndicesWithKSetBits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:24",
"tests_total... | cpp | {
"raw_signature": "int sumIndicesWithKSetBits(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "sumIndicesWithKSetBits",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature... |
2,860 | happy-students | Medium | You are given a 0-indexed integer array nums of length n where n is the total number of students in the class. The class teacher tries to select a group of students so that all the students remain happy.
The i^th student will become happy if one of these two conditions is met:
- The student is selected and the total ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4]) == 2\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [10, 0, 9, 1, 8, 2, 7, 3, 6, 4, 5]) == 1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 2\n asse... | [
"[1,1]",
"[6,0,3,3,6,7,2,7]"
] | [
"If a student with nums[i] = x is selected, all the students with nums[j] <= x must be selected.",
"If a student with nums[i] = x is not selected, all the students with nums[j] >= x must not be selected.",
"Sort values in nums and try all possible values for x from 0 to n separately."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countWays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:26",
"tests_total": 120,
"tests_dropp... | cpp | {
"raw_signature": "int countWays(vector<int>& nums) {",
"container": "Solution",
"callable": "countWays",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,861 | maximum-number-of-alloys | Medium | You are the owner of a company that creates alloys using various types of metals. There are n different types of metals available, and you have access to k machines that can be used to create alloys. Each machine requires a specific amount of each metal type to create an alloy.
For the i^th machine to create an alloy,... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3,k = 2,budget = 15,composition = [[1, 1, 1], [1, 1, 10]],stock = [0, 0, 0],cost = [1, 2, 3]) == 2\n assert candidate(n = 1,k = 1,budget = 100,composition = [[5]],stock = [0],cost = [20]) == 1\n assert candidate(n = 2,k = 2,bud... | [
"3\n2\n15\n[[1,1,1],[1,1,10]]\n[0,0,0]\n[1,2,3]",
"3\n2\n15\n[[1,1,1],[1,1,10]]\n[0,0,100]\n[1,2,3]",
"2\n3\n10\n[[2,1],[1,2],[1,1]]\n[1,1]\n[5,5]"
] | [
"Use binary search to find the answer."
] | {
"canonical_parameter_names": [
"n",
"k",
"budget",
"composition",
"stock",
"cost"
],
"leetcode_dataset_entry_point": "Solution().maxNumberOfAlloys",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"... | cpp | {
"raw_signature": "int maxNumberOfAlloys(int n, int k, int budget, vector<vector<int>>& composition, vector<int>& stock, vector<int>& cost) {",
"container": "Solution",
"callable": "maxNumberOfAlloys",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "i... |
2,862 | maximum-element-sum-of-a-complete-subset-of-indices | Hard | You are given a 1-indexed array nums. Your task is to select a complete subset from nums where every pair of selected indices multiplied is a perfect square,. i. e. if you select a_i and a_j, i * j must be a perfect square.
Return the sum of the complete subset with the maximum sum.
Example 1:
Input: nums = [8,7,3,5... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [8, 10, 3, 8, 1, 13, 7, 9, 4]) == 20\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 30\n assert candidate(nums = [8, 7, 3, 5, 7, 2, 4,... | [
"[8,7,3,5,7,2,4,9]",
"[8,10,3,8,1,13,7,9,4]"
] | [
"Define P(x) as the product of primes p with odd exponents in x's factorization. Examples: For x = 18, factorization 2^1 × 3^2, P(18) = 2; for x = 45, factorization 3^2 × 5^1, P(45) = 5; for x = 50, factorization 2^1 × 5^2, P(50) = 2; for x = 210, factorization 2^1 × 3^1 × 5^1 × 7^1, P(210) = 210.",
"If P(i) = P(... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maximumSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:31",
"tests_total": 62,
"tests_dropp... | cpp | {
"raw_signature": "long long maximumSum(vector<int>& nums) {",
"container": "Solution",
"callable": "maximumSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
2,864 | maximum-odd-binary-number | Easy | You are given a binary string s that contains at least one '1'.
You have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.
Return a string representing the maximum odd binary number that can be created from the given combin... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1111\") == \"1111\"\n assert candidate(s = \"101010101\") == \"111100001\"\n assert candidate(s = \"110011\") == \"111001\"\n assert candidate(s = \"111\") == \"111\"\n assert candidate(s = \"1110\") == \"1101\"\n as... | [
"\"010\"",
"\"0101\""
] | [
"The binary representation of an odd number contains '1' in the least significant place."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().maximumOddBinaryNumber",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:35",
"tests_total": 78,
"te... | cpp | {
"raw_signature": "string maximumOddBinaryNumber(string s) {",
"container": "Solution",
"callable": "maximumOddBinaryNumber",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
2,865 | beautiful-towers-i | Medium | You are given an array heights of n integers representing the number of bricks in n consecutive towers. Your task is to remove some bricks to form a mountain-shaped tower arrangement. In this arrangement, the tower heights are non-decreasing, reaching a maximum peak value with one or multiple consecutive towers and the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(heights = [1, 3, 5, 7, 9, 7, 5, 3, 1]) == 41\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(heights = [7, 4, 7, 4, 7]) == 23\n assert candidate(heights = [3, 2, 5, 5, 2, 3]) == 18\n ass... | [
"[5,3,4,1,1]",
"[6,5,3,9,2,7]",
"[3,2,5,5,2,3]"
] | [
"Try all the possible indices i as the peak.",
"If i is the peak, i-1^th element, and heights[j] = min(heights[j], heights[j + 1]) for 0 <= j < i",
"If i is the peak, start from i+1^th element, heights[j] = min(heights[j], heights[j - 1]) for i < j < heights.size()"
] | {
"canonical_parameter_names": [
"heights"
],
"leetcode_dataset_entry_point": "Solution().maximumSumOfHeights",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:38",
"tests_total": 184,
... | cpp | {
"raw_signature": "long long maximumSumOfHeights(vector<int>& heights) {",
"container": "Solution",
"callable": "maximumSumOfHeights",
"parameters": [
{
"name": "heights",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_sour... |
2,866 | beautiful-towers-ii | Medium | You are given a 0-indexed array maxHeights of n integers.
You are tasked with building n towers in the coordinate line. The i^th tower is built at coordinate i and has a height of heights[i].
A configuration of towers is beautiful if the following conditions hold:
1. 1 <= heights[i] <= maxHeights[i]
2. heights is a ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(maxHeights = [1, 2, 3, 4, 5]) == 15\n assert candidate(maxHeights = [5, 4, 3, 2, 1]) == 15\n assert candidate(maxHeights = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 5000000000\n assert candidate(maxHeights... | [
"[5,3,4,1,1]",
"[6,5,3,9,2,7]",
"[3,2,5,5,2,3]"
] | [
"Try all the possible indices i as the peak.",
"Let left[i] be the maximum sum of heights for the prefix 0, …, i when index i is the peak.",
"Let right[i] be the maximum sum of heights for suffix i, …, (n - 1) when i is the peak",
"Compute values of left[i] from left to right using DP. For each i from 0 to n ... | {
"canonical_parameter_names": [
"maxHeights"
],
"leetcode_dataset_entry_point": "Solution().maximumSumOfHeights",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:40",
"tests_total": 111... | cpp | {
"raw_signature": "long long maximumSumOfHeights(vector<int>& maxHeights) {",
"container": "Solution",
"callable": "maximumSumOfHeights",
"parameters": [
{
"name": "maxHeights",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"typ... |
2,867 | count-valid-paths-in-a-tree | Hard | There is an undirected tree with n nodes labeled from 1 to n. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [u_i, v_i] indicates that there is an edge between nodes u_i and v_i in the tree.
Return the number of valid paths in the tree.
A path (a, b) is valid if there exist... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [6, 8]]) == 8\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [3, 6]]) == 6\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6],... | [
"5\n[[1,2],[1,3],[2,4],[2,5]]",
"6\n[[1,2],[1,3],[2,4],[3,5],[3,6]]"
] | [
"Use the sieve of Eratosthenes to find all prime numbers in the range [1, n].****",
"Root the tree at any node.",
"Let dp[i][0] = the number of vertical paths starting from i containing no prime nodes , and dp[i][1] = the number of vertical paths starting from i containing one prime node .",
"If i is not prim... | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().countPaths",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:43",
"tests_total": 34,
"t... | cpp | {
"raw_signature": "long long countPaths(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "countPaths",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type": "long long",
"sig... |
2,869 | minimum-operations-to-collect-elements | Easy | You are given an array nums of positive integers and an integer k.
In one operation, you can remove the last element of the array and add it to your collection.
Return the minimum number of operations needed to collect elements 1, 2, ..., k.
Example 1:
Input: nums = [3,1,5,4,2], k = 2
Output: 4
Explanation: After 4... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 1, 2, 1, 2],k = 2) == 2\n assert candidate(nums = [2, 3, 1, 4, 5],k = 4) == 5\n assert candidate(nums = [3, 1, 5, 4, 2],k = 5) == 5\n assert candidate(nums = [4, 3, 2, 1, 5],k = 5) == 5\n assert candidate(nums = [1... | [
"[3,1,5,4,2]\n2",
"[3,1,5,4,2]\n5",
"[3,2,5,3,1]\n3"
] | [
"Use an occurrence array.",
"Iterate over the elements in reverse order.",
"If the current element nums[i] is not marked in the occurrence array and nums[i] <= k, mark nums[i].",
"Keep track of how many integers you have marked.",
"Return the current index as soon as the number of marked integers becomes eq... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:47",
"tests_total": 100,
... | cpp | {
"raw_signature": "int minOperations(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "minOperations",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcod... |
2,870 | minimum-number-of-operations-to-make-array-empty | Medium | You are given a 0-indexed array nums consisting of positive integers.
There are two types of operations that you can apply on the array any number of times:
- Choose two elements with equal values and delete them from the array.
- Choose three elements with equal values and delete them from the array.
Return the min... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 5\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 6\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 4\n assert candidate(nums = [1... | [
"[2,3,3,2,2,4,2,3,4]",
"[2,1,2,2,3,3]"
] | [] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:50",
"tests_total": 107,
"tests_d... | cpp | {
"raw_signature": "int minOperations(vector<int>& nums) {",
"container": "Solution",
"callable": "minOperations",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,871 | split-array-into-maximum-number-of-subarrays | Medium | You are given an array nums consisting of non-negative integers.
We define the score of subarray nums[l..r] such that l <= r as nums[l] AND nums[l + 1] AND ... AND nums[r] where AND is the bitwise AND operation.
Consider splitting the array into one or more subarrays such that the following conditions are satisfied:
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [8, 12, 10, 14, 6, 7]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 1\n assert candidate(nums = [8, 8, 8, 8, 8]) == 1\n assert candid... | [
"[1,0,2,0,1,2]",
"[5,7,1,3]"
] | [
"The minimum score will always be the bitwise AND of all elements of the array.",
"If the minimum score is not equal to 0, the only possible split will be to keep all elements in one subarray.",
"Otherwise, all of the subarrays should have a score of 0, we can greedily split the array while trying to make each ... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:53",
"tests_total": 103,
"tests_dr... | cpp | {
"raw_signature": "int maxSubarrays(vector<int>& nums) {",
"container": "Solution",
"callable": "maxSubarrays",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,872 | maximum-number-of-k-divisible-components | Hard | There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree.
You are also given a 0-indexed integer array values of length n, where values[i]... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [2, 3], [2, 4], [2, 5]],values = [2, 10, 5, 1, 1, 1],k = 5) == 2\n assert candidate(n = 5,edges = [[0, 2], [1, 2], [1, 3], [2, 4]],values = [1, 8, 1, 4, 4],k = 6) == 2\n assert candidate(n = 3,edges =... | [
"5\n[[0,2],[1,2],[1,3],[2,4]]\n[1,8,1,4,4]\n6",
"7\n[[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]\n[3,0,6,1,5,2,1]\n3"
] | [
"Root the tree at node 0.",
"If a leaf node is not divisible by k, it must be in the same component as its parent node so we merge it with its parent node.",
"If a leaf node is divisible by k, it will be in its own components so we separate it from its parent node.",
"In each step, we either cut a leaf node d... | {
"canonical_parameter_names": [
"n",
"edges",
"values",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxKDivisibleComponents",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T... | cpp | {
"raw_signature": "int maxKDivisibleComponents(int n, vector<vector<int>>& edges, vector<int>& values, int k) {",
"container": "Solution",
"callable": "maxKDivisibleComponents",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"... |
2,873 | maximum-value-of-an-ordered-triplet-i | Easy | You are given a 0-indexed integer array nums.
Return the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.
The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].
Example 1:
Input: nums = [12,6,1,2,7]
Output... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [3, 2, 1, 5, 4, 6]) == 12\n assert candidate(nums = [10, 20, 3, 40, 5, 60, 7, 80, 9, 10]) == 4240\n assert candidate(nums = [12, 6, 1, 2, 7]) == 77\n assert candidate(nums = [8, 6, 4, 2, 10, 9, 7, 5, 3, 1]) == 60\n ass... | [
"[12,6,1,2,7]",
"[1,10,3,4,19]",
"[1,2,3]"
] | [
"Use three nested loops to find all the triplets."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maximumTripletValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:05:57",
"tests_total": 126,
"t... | cpp | {
"raw_signature": "long long maximumTripletValue(vector<int>& nums) {",
"container": "Solution",
"callable": "maximumTripletValue",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
2,874 | maximum-value-of-an-ordered-triplet-ii | Medium | You are given a 0-indexed integer array nums.
Return the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.
The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].
Example 1:
Input: nums = [12,6,1,2,7]
Output... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [12, 6, 1, 2, 7]) == 77\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 2000\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1... | [
"[12,6,1,2,7]",
"[1,10,3,4,19]",
"[1,2,3]"
] | [
"Preprocess the prefix maximum array, prefix_max[i] = max(nums[0], nums[1], …, nums[i]) and the suffix maximum array, suffix_max[i] = max(nums[i], nums[i + 1], …, nums[n - 1]).",
"For each index j, find two indices i and k such that i < j < k and (nums[i] - nums[j]) * nums[k] is the maximum, using the prefix and ... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maximumTripletValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:00",
"tests_total": 119,
"t... | cpp | {
"raw_signature": "long long maximumTripletValue(vector<int>& nums) {",
"container": "Solution",
"callable": "maximumTripletValue",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
2,875 | minimum-size-subarray-in-infinite-array | Medium | You are given a 0-indexed array nums and an integer target.
A 0-indexed array infinite_nums is generated by infinitely appending the elements of nums to itself.
Return the length of the shortest subarray of the array infinite_nums with a sum equal to target. If there is no such subarray return -1.
Example 1:
Input:... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],target = 150) == 5\n assert candidate(nums = [7, 7, 7, 7, 7],target = 28) == 4\n assert candidate(nums = [5, 5, 5, 5, 5],target = 15) == 3\n assert candidate(nums = [1, 2, 3, 4, 5],target = 9) == 2\n ... | [
"[1,2,3]\n5",
"[1,1,1,2,3]\n4",
"[2,4,6,8]\n3"
] | [
"Notice that, target is either: A subarray of nums, or prefix_sum[i] + k * sum(nums) + suffix_sum[j] for some i, j, k.",
"You can solve the problem for those two separate cases using hash map and prefix sums."
] | {
"canonical_parameter_names": [
"nums",
"target"
],
"leetcode_dataset_entry_point": "Solution().minSizeSubarray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:02",
"tests_total":... | cpp | {
"raw_signature": "int minSizeSubarray(vector<int>& nums, int target) {",
"container": "Solution",
"callable": "minSizeSubarray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "int",
"signature_sou... |
2,876 | count-visited-nodes-in-a-directed-graph | Hard | There is a directed graph consisting of n nodes numbered from 0 to n - 1 and n directed edges.
You are given a 0-indexed array edges where edges[i] indicates that there is an edge from node i to node edges[i].
Consider the following process on the graph:
- You start from a node x and keep visiting other nodes throug... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(edges = [1, 0]) == [2, 2]\n assert candidate(edges = [3, 3, 4, 2, 3]) == [4, 4, 3, 3, 3]\n assert candidate(edges = [1, 2, 0, 0]) == [3, 3, 3, 4]\n assert candidate(edges = [2, 0, 1, 4, 5, 3, 1]) == [3, 3, 3, 3, 3, 3, 4]\n as... | [
"[1,2,0,0]",
"[1,2,3,4,0]"
] | [
"Consider if the graph was only one cycle, what will be the answer for each node?",
"The actual graph will always consist of at least one cycle and some other nodes.",
"Calculate the answer for nodes in cycles the same way as in hint 1. How do you calculate the answer for the remaining nodes?"
] | {
"canonical_parameter_names": [
"edges"
],
"leetcode_dataset_entry_point": "Solution().countVisitedNodes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:05",
"tests_total": 91,
"tes... | cpp | {
"raw_signature": "vector<int> countVisitedNodes(vector<int>& edges) {",
"container": "Solution",
"callable": "countVisitedNodes",
"parameters": [
{
"name": "edges",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source":... |
2,894 | divisible-and-non-divisible-sums-difference | Easy | You are given positive integers n and m.
Define two integers as follows:
- num1: The sum of all integers in the range [1, n] (both inclusive) that are not divisible by m.
- num2: The sum of all integers in the range [1, n] (both inclusive) that are divisible by m.
Return the integer num1 - num2.
Example 1:
Input: ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 1000,m = 1000) == 498500\n assert candidate(n = 5,m = 6) == 15\n assert candidate(n = 5,m = 1) == -15\n assert candidate(n = 20,m = 4) == 90\n assert candidate(n = 100,m = 10) == 3950\n assert candidate(n = 1,m = 1) ==... | [
"10\n3",
"5\n6",
"5\n1"
] | [
"With arithmetic progression we know that the sum of integers in the range [1, n] is n * (n + 1) / 2 ."
] | {
"canonical_parameter_names": [
"n",
"m"
],
"leetcode_dataset_entry_point": "Solution().differenceOfSums",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:10",
"tests_total": 93,
... | cpp | {
"raw_signature": "int differenceOfSums(int n, int m) {",
"container": "Solution",
"callable": "differenceOfSums",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "m",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
... |
2,895 | minimum-processing-time | Medium | You have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors. Each task must be assigned to a unique core, and each core can only be used once.
You are given an array processorTime representing the time each processor becomes available and an a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(processorTime = [0, 0, 0, 0],tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(processorTime = [1000000000],tasks = [1, 1, 1, 1]) == 1000000001\n assert candidate(processorTime = [10, 20],tasks = [2,... | [
"[8,10]\n[2,2,3,1,8,7,4,5]",
"[10,20]\n[2,3,1,2,5,8,4,3]"
] | [
"It’s optimal to make the processor with earlier process time run 4 longer tasks.****",
"The largest processTime[i] + tasks[j] (when matched) is the answer."
] | {
"canonical_parameter_names": [
"processorTime",
"tasks"
],
"leetcode_dataset_entry_point": "Solution().minProcessingTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:12",
"tes... | cpp | {
"raw_signature": "int minProcessingTime(vector<int>& processorTime, vector<int>& tasks) {",
"container": "Solution",
"callable": "minProcessingTime",
"parameters": [
{
"name": "processorTime",
"type": "vector<int>&"
},
{
"name": "tasks",
"type": "vector<int>&"
}
],
... |
2,896 | apply-operations-to-make-two-strings-equal | Medium | You are given two 0-indexed binary strings s1 and s2, both of length n, and a positive integer x.
You can perform any of the following operations on the string s1 any number of times:
- Choose two indices i and j, and flip both s1[i] and s1[j]. The cost of this operation is x.
- Choose an index i such that i < n - 1 ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s1 = \"101010\",s2 = \"010101\",x = 1) == 3\n assert candidate(s1 = \"1111\",s2 = \"1111\",x = 3) == 0\n assert candidate(s1 = \"101010\",s2 = \"010101\",x = 5) == 3\n assert candidate(s1 = \"1111\",s2 = \"1111\",x = 5) == 0\n ... | [
"\"1100011000\"\n\"0101001010\"\n2",
"\"10110\"\n\"00011\"\n4"
] | [
"Save all the indices that have different characters on s1 and s2 into a list, and work only with this list.",
"Try to use dynamic programming on this list to solve the problem. What will be the states and transitions of this dp?"
] | {
"canonical_parameter_names": [
"s1",
"s2",
"x"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:14",
"tests_total"... | cpp | {
"raw_signature": "int minOperations(string s1, string s2, int x) {",
"container": "Solution",
"callable": "minOperations",
"parameters": [
{
"name": "s1",
"type": "string"
},
{
"name": "s2",
"type": "string"
},
{
"name": "x",
"type": "int"
}
],
"... |
2,897 | apply-operations-on-array-to-maximize-sum-of-squares | Hard | You are given a 0-indexed integer array nums and a positive integer k.
You can do the following operation on the array any number of times:
- Choose any two distinct indices i and j and simultaneously update the values of nums[i] to (nums[i] AND nums[j]) and nums[j] to (nums[i] OR nums[j]). Here, OR denotes the bitwi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == 99\n assert candidate(nums = [10, 10, 10, 10],k = 4) == 400\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 2) == 98\n assert candidate(nums = [10, 10, 10, 10],k = 2) == 200\n ... | [
"[2,6,5,8]\n2",
"[4,5,4,7]\n3"
] | [
"The operation described only transfers some bits from one element to another in their binary representation.",
"To have a maximum sum of squares, it is optimal to greedily make each number as big as possible."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:17",
"tests_total": 98,
"tests_... | cpp | {
"raw_signature": "int maxSum(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "maxSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets... |
2,899 | last-visited-integers | Easy | Given an integer array nums where nums[i] is either a positive integer or -1. We need to find for each -1 the respective positive integer, which we call the last visited integer.
To achieve this goal, let's define two empty arrays: seen and ans.
Start iterating from the beginning of the array nums.
- If a positive i... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [-1, -1, 1, 2, -1]) == [-1, -1, 2]\n assert candidate(nums = [1, 2, 3, 4, -1, -1, -1, -1]) == [4, 3, 2, 1]\n assert candidate(nums = [1, -1, -1, -1, 2, -1, -1, 3, -1]) == [1, -1, -1, 2, 1, 3]\n assert candidate(nums = [-1... | [
"[1,2,-1,-1,-1]",
"[1,-1,2,-1,-1]"
] | [
"It is sufficient to implement what the description is stating."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().lastVisitedIntegers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:22",
"tests_total": 261,
"t... | cpp | {
"raw_signature": "vector<int> lastVisitedIntegers(vector<int>& nums) {",
"container": "Solution",
"callable": "lastVisitedIntegers",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source... |
2,900 | longest-unequal-adjacent-groups-subsequence-i | Easy | You are given a string array words and a binary array groups both of length n.
A subsequence of words is alternating if for any two consecutive strings in the sequence, their corresponding elements at the same indices in groups are different (that is, there cannot be consecutive 0 or 1).
Your task is to select the lo... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['dog', 'cat', 'bird', 'fish'],groups = [0, 1, 1, 0]) == ['dog', 'cat', 'fish']\n assert candidate(words = ['x', 'y', 'z'],groups = [0, 1, 0]) == ['x', 'y', 'z']\n assert candidate(words = ['a', 'b', 'c', 'd'],groups = [1, ... | [
"[\"c\"]\n[0]",
"[\"d\"]\n[1]"
] | [
"This problem can be solved greedily.",
"Begin by constructing the answer starting with the first number in groups.",
"For each index i in the range [1, n - 1], add i to the answer if groups[i] != groups[i - 1]."
] | {
"canonical_parameter_names": [
"words",
"groups"
],
"leetcode_dataset_entry_point": "Solution().getLongestSubsequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:24",
"tests_... | cpp | {
"raw_signature": "vector<string> getLongestSubsequence(vector<string>& words, vector<int>& groups) {",
"container": "Solution",
"callable": "getLongestSubsequence",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
},
{
"name": "groups",
"type": "vector<int>&"
... |
2,901 | longest-unequal-adjacent-groups-subsequence-ii | Medium | You are given a string array words, and an array groups, both arrays having length n.
The hamming distance between two strings of equal length is the number of positions at which the corresponding characters are different.
You need to select the longest subsequence from an array of indices [0, 1, ..., n - 1], such th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['abc', 'bac', 'bca', 'cab', 'cba', 'acb'],groups = [1, 2, 1, 2, 1, 2]) == ['abc']\n assert candidate(words = ['same', 'sane', 'same'],groups = [1, 2, 1]) == ['same', 'sane', 'same']\n assert candidate(words = ['test', 'tas... | [
"[\"bab\",\"dab\",\"cab\"]\n[1,2,2]",
"[\"a\",\"b\",\"c\",\"d\"]\n[1,2,3,4]"
] | [
"Let dp[i] represent the length of the longest subsequence ending with words[i] that satisfies the conditions.",
"dp[i] = (maximum value of dp[j]) + 1 for indices j < i, where groups[i] != groups[j], words[i] and words[j] are equal in length, and the hamming distance between words[i] and words[j] is exactly 1.",
... | {
"canonical_parameter_names": [
"words",
"groups"
],
"leetcode_dataset_entry_point": "Solution().getWordsInLongestSubsequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:26",
... | cpp | {
"raw_signature": "vector<string> getWordsInLongestSubsequence(vector<string>& words, vector<int>& groups) {",
"container": "Solution",
"callable": "getWordsInLongestSubsequence",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
},
{
"name": "groups",
"type": "ve... |
2,902 | count-of-sub-multisets-with-bounded-sum | Hard | You are given a 0-indexed array nums of non-negative integers, and two integers l and r.
Return the count of sub-multisets within nums where the sum of elements in each subset falls within the inclusive range of [l, r].
Since the answer may be large, return it modulo 10^9+ 7.
A sub-multiset is an unordered collectio... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 2, 3],l = 6,r = 6) == 1\n assert candidate(nums = [10, 20, 30, 40, 50],l = 15,r = 100) == 23\n assert candidate(nums = [10, 20, 30, 40, 50],l = 15,r = 75) == 14\n assert candidate(nums = [10, 20, 30, 40, 50],l = 15... | [
"[1,2,2,3]\n6\n6",
"[2,1,4,2,7]\n1\n5",
"[1,2,1,3,5,2]\n3\n5"
] | [
"Since the sum of numsis at most 20000, the number of distinct elements of nums is 200.",
"Let dp[x] be the number of submultisets of nums with sum x.",
"The answer to the problem is dp[l] + dp[l+1] + … + dp[r].",
"Use coin change dp to transition between states."
] | {
"canonical_parameter_names": [
"nums",
"l",
"r"
],
"leetcode_dataset_entry_point": "Solution().countSubMultisets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:28",
"tests_t... | cpp | {
"raw_signature": "int countSubMultisets(vector<int>& nums, int l, int r) {",
"container": "Solution",
"callable": "countSubMultisets",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "l",
"type": "int"
},
{
"name": "r",
"type": "int... |
2,903 | find-indices-with-index-and-value-difference-i | Easy | You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.
Your task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:
- abs(i - j) >= indexDifference, and
- abs(nums[i] - nums[j]) >= valueDifference
Ret... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 7, 9],indexDifference = 2,valueDifference = 6) == [0, 3]\n assert candidate(nums = [0, 0, 0, 0, 0],indexDifference = 0,valueDifference = 0) == [0, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],indexDifference =... | [
"[5,1,4,1]\n2\n4",
"[2,1]\n0\n0",
"[1,2,3]\n2\n4"
] | [
"Use bruteforce.",
"You can use a nested loop to compare each pair of indices (i, j) and check if the conditions are satisfied."
] | {
"canonical_parameter_names": [
"nums",
"indexDifference",
"valueDifference"
],
"leetcode_dataset_entry_point": "Solution().findIndices",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30... | cpp | {
"raw_signature": "vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {",
"container": "Solution",
"callable": "findIndices",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "indexDifference",
"type": "int"
},
{... |
2,904 | shortest-and-lexicographically-smallest-beautiful-string | Medium | You are given a binary string s and a positive integer k.
A substring of s is beautiful if the number of 1's in it is exactly k.
Let len be the length of the shortest beautiful substring.
Return the lexicographically smallest beautiful substring of string s with length equal to len. If s doesn't contain a beautiful ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1100110011001100110011001100\",k = 6) == \"1100110011\"\n assert candidate(s = \"100011001\",k = 3) == \"11001\"\n assert candidate(s = \"1010101010\",k = 5) == \"101010101\"\n assert candidate(s = \"1111111111\",k = 5) ==... | [
"\"100011001\"\n3",
"\"1011\"\n2",
"\"000\"\n1"
] | [
"Notice that if we consider that index i is the leftmost index of a beautiful substring, it has only one candidate j, such that s[i:j] is beautiful and shortest too.",
"We can iterate over all possibilities of leftmost index i take s[i:j] and compare with the shortest and the lexicographically smallest beautiful ... | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().shortestBeautifulSubstring",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:33",
"tests_tota... | cpp | {
"raw_signature": "string shortestBeautifulSubstring(string s, int k) {",
"container": "Solution",
"callable": "shortestBeautifulSubstring",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "string",
"signature_sou... |
2,905 | find-indices-with-index-and-value-difference-ii | Medium | You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.
Your task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:
- abs(i - j) >= indexDifference, and
- abs(nums[i] - nums[j]) >= valueDifference
Ret... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100, 90, 80, 70, 60],indexDifference = 2,valueDifference = 25) == [0, 3]\n assert candidate(nums = [1, 10, 1, 10, 1, 10],indexDifference = 2,valueDifference = 8) == [0, 3]\n assert candidate(nums = [100, 90, 80, 70, 60, 50]... | [
"[5,1,4,1]\n2\n4",
"[2,1]\n0\n0",
"[1,2,3]\n2\n4"
] | [
"For each index i >= indexDifference, keep the indices j_1 and j_2 in the range [0, i - indexDifference] such that nums[j_1] and nums[j_2] are the minimum and maximum values in the index range.",
"Check if abs(nums[i] - nums[j_1]) >= valueDifference or abs(nums[i] - nums[j_2]) >= valueDifference.",
"j_1 and j_2... | {
"canonical_parameter_names": [
"nums",
"indexDifference",
"valueDifference"
],
"leetcode_dataset_entry_point": "Solution().findIndices",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30... | cpp | {
"raw_signature": "vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {",
"container": "Solution",
"callable": "findIndices",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "indexDifference",
"type": "int"
},
{... |
2,906 | construct-product-matrix | Medium | Given a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following condition is met:
- Each element p[i][j] is calculated as the product of all elements in grid except for the element grid[i][j]. This product is then taken modulo 12345... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == [[1, 1, 1], [1, 1, 1], [1, 1, 1]]\n assert candidate(grid = [[7], [11], [13]]) == [[143], [91], [77]]\n assert candidate(grid = [[1, 2, 3], [4, 5, 6]]) == [[720, 360, 240], [180, 144, 12... | [
"[[1,2],[3,4]]",
"[[12345],[2],[1]]"
] | [
"Try to solve this without using the '/' (division operation).",
"Create two 2D arrays for suffix and prefix product, and use them to find the product for each position."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().constructProductMatrix",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:38",
"tests_total": 82,
... | cpp | {
"raw_signature": "vector<vector<int>> constructProductMatrix(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "constructProductMatrix",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "vector<vector<int>>",
"signature_source": "... |
2,908 | minimum-sum-of-mountain-triplets-i | Easy | You are given a 0-indexed array nums of integers.
A triplet of indices (i, j, k) is a mountain if:
- i < j < k
- nums[i] < nums[j] and nums[k] < nums[j]
Return the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.
Example 1:
Input: nums = [8,6,1,5,3]
Output: 9
Explanation: T... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 4, 8, 7, 10, 2]) == 13\n assert candidate(nums = [1, 5, 3, 6, 4, 7, 2]) == 6\n assert candidate(nums = [10, 20, 15, 30, 25, 40]) == 45\n assert candidate(nums = [3, 3, 3, 3, 3, 3]) == -1\n assert candidate(nums = [... | [
"[8,6,1,5,3]",
"[5,4,8,7,10,2]",
"[6,5,4,3,4,5]"
] | [
"Bruteforce over all possible triplets."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minimumSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:42",
"tests_total": 118,
"tests_drop... | cpp | {
"raw_signature": "int minimumSum(vector<int>& nums) {",
"container": "Solution",
"callable": "minimumSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,909 | minimum-sum-of-mountain-triplets-ii | Medium | You are given a 0-indexed array nums of integers.
A triplet of indices (i, j, k) is a mountain if:
- i < j < k
- nums[i] < nums[j] and nums[k] < nums[j]
Return the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.
Example 1:
Input: nums = [8,6,1,5,3]
Output: 9
Explanation: T... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 1, 3, 1, 4, 1, 3, 1]) == 5\n assert candidate(nums = [100000000, 1, 100000000, 2, 100000000]) == 100000003\n assert candidate(nums = [5, 4, 8, 7, 10, 2]) == 13\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2,... | [
"[8,6,1,5,3]",
"[5,4,8,7,10,2]",
"[6,5,4,3,4,5]"
] | [
"If you fix index j, i will be the smallest integer to the left of j, and k the largest integer to the right of j.",
"To find i and k, preprocess the prefix minimum array prefix_min[i] = min(nums[0], nums[1], ..., nums[i]), and the suffix minimum array suffix_min[i] = min(nums[i], nums[i + 1], ..., nums[i - 1])."... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minimumSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:45",
"tests_total": 110,
"tests_drop... | cpp | {
"raw_signature": "int minimumSum(vector<int>& nums) {",
"container": "Solution",
"callable": "minimumSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,911 | minimum-changes-to-make-k-semi-palindromes | Hard | Given a string s and an integer k, partition s into k substrings such that the letter changes needed to make each substring a semi-palindrome are minimized.
Return the minimum number of letter changes required.
A semi-palindrome is a special type of string that can be divided into palindromes based on a repeating pat... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aabbcc\",k = 3) == 0\n assert candidate(s = \"abccba\",k = 2) == 2\n assert candidate(s = \"aabbccdd\",k = 4) == 0\n assert candidate(s = \"abcabcabc\",k = 4) == 4\n assert candidate(s = \"aaaaaa\",k = 2) == 0\n asse... | [
"\"abcac\"\n2"
] | [
"Define dp[i][j] as the minimum count of letter changes needed to split the suffix of string s starting from s[i] into j valid parts.",
"We have dp[i][j] = min(dp[x + 1][j - 1] + v[i][x]). Here v[i][x] is the minimum number of letter changes to change substring s[i..x] into semi-palindrome.",
"v[i][j] can be ca... | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().minimumChanges",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:47",
"tests_total": 119,
"... | cpp | {
"raw_signature": "int minimumChanges(string s, int k) {",
"container": "Solution",
"callable": "minimumChanges",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",... |
2,913 | subarrays-distinct-element-sum-of-squares-i | Easy | You are given a 0-indexed integer array nums.
The distinct count of a subarray of nums is defined as:
- Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].
Retu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 3, 2, 2, 1]) == 85\n assert candidate(nums = [10, 20, 10, 20, 10]) == 45\n assert candidate(nums = [1, 2, 2, 1]) == 25\n assert candidate(nums = [1, 3, 2, 3, 1]) == 70\n assert candidate(nums = [1]) == 1\n as... | [
"[1,2,1]",
"[1,1]"
] | [
"Use a set/heap to keep track of distinct element counts."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().sumCounts",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:52",
"tests_total": 105,
"tests_dropp... | cpp | {
"raw_signature": "int sumCounts(vector<int>& nums) {",
"container": "Solution",
"callable": "sumCounts",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,914 | minimum-number-of-changes-to-make-binary-string-beautiful | Medium | You are given a 0-indexed binary string s having an even length.
A string is beautiful if it's possible to partition it into one or more substrings such that:
- Each substring has an even length.
- Each substring contains only 1's or only 0's.
You can change any character in s to 0 or 1.
Return the minimum number o... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1111\") == 0\n assert candidate(s = \"101010\") == 3\n assert candidate(s = \"11001100\") == 0\n assert candidate(s = \"001100\") == 0\n assert candidate(s = \"10\") == 1\n assert candidate(s = \"110011\") == 0\n ... | [
"\"1001\"",
"\"10\"",
"\"0000\""
] | [
"For any valid partition, since each part consists of an even number of the same characters, we can further partition each part into lengths of exactly 2.",
"After noticing the first hint, we can decompose the whole string into disjoint blocks of size 2 and find the minimum number of changes required to make thos... | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().minChanges",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:54",
"tests_total": 116,
"tests_dropped... | cpp | {
"raw_signature": "int minChanges(string s) {",
"container": "Solution",
"callable": "minChanges",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,915 | length-of-the-longest-subsequence-that-sums-to-target | Medium | You are given a 0-indexed array of integers nums, and an integer target.
Return the length of the longest subsequence of nums that sums up to target. If no such subsequence exists, return -1.
A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 3, 7, 8, 10],target = 15) == 3\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 8, 9, 10],target = 15) == 4\n assert candidate(nums = [10, 20, 30, 40, 50],target = 50) == 2\n assert candidate(nums = [999, 1],target = 1000... | [
"[1,2,3,4,5]\n9",
"[4,1,3,2,1,5]\n7",
"[1,1,5,4,5]\n3"
] | [
"Use dynamic programming.",
"Let dp[i][j] be the maximum length of any subsequence of nums[0..i - 1] that sums to j.",
"dp[0][0] = 1, and dp[0][j] = 1 for all target ≥ j > 0.",
"dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - nums[i -1]) for all n ≥ i > 0 and target ≥ j > nums[i - 1]."
] | {
"canonical_parameter_names": [
"nums",
"target"
],
"leetcode_dataset_entry_point": "Solution().lengthOfLongestSubsequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:56",
"te... | cpp | {
"raw_signature": "int lengthOfLongestSubsequence(vector<int>& nums, int target) {",
"container": "Solution",
"callable": "lengthOfLongestSubsequence",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "... |
2,916 | subarrays-distinct-element-sum-of-squares-ii | Hard | You are given a 0-indexed integer array nums.
The distinct count of a subarray of nums is defined as:
- Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].
Retu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 105\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996]) == 105\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 77\n assert candidate(nums = [1, 1, 1,... | [
"[1,2,1]",
"[2,2]"
] | [
"Consider the sum of the count of distinct values of subarrays ending with index i, let’s call it sum. Now if you need the sum of all subarrays ending with index i + 1 think how it can be related to sum and what extra will be needed to add to this.",
"You can find that extra sum using the segment tree."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().sumCounts",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:06:59",
"tests_total": 113,
"tests_dropp... | cpp | {
"raw_signature": "int sumCounts(vector<int>& nums) {",
"container": "Solution",
"callable": "sumCounts",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,917 | find-the-k-or-of-an-array | Easy | You are given an integer array nums, and an integer k. Let's introduce K-or operation by extending the standard bitwise OR. In K-or, a bit position in the result is set to 1 if at least k numbers in nums have a 1 in that position.
Return the K-or of nums.
Example 1:
Input: nums = [7,12,9,8,9,15], k = 4
Output: 9
Exp... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 8, 5, 9, 11, 6, 8],k = 1) == 15\n assert candidate(nums = [7, 12, 9, 8, 9, 15],k = 4) == 9\n assert candidate(nums = [2, 12, 1, 11, 4, 5],k = 6) == 0\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1],k = 3) =... | [
"[7,12,9,8,9,15]\n4"
] | [
"Fix a bit from the range [0, 31], then count the number of elements of nums that have bit set in them.",
"bit is set in integer x if and only if 2^bit AND x == 2^bit, where AND is the bitwise AND operation."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().findKOr",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:01",
"tests_total": 92,
"tests... | cpp | {
"raw_signature": "int findKOr(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "findKOr",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippe... |
2,918 | minimum-equal-sum-of-two-arrays-after-replacing-zeros | Medium | You are given two arrays nums1 and nums2 consisting of positive integers.
You have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.
Return the minimum equal sum you can obtain, or -1 if it is impossible.
Example 1:
Input: nums1 = [3,2,... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [1, 0, 0, 0],nums2 = [0, 0, 0, 1]) == 4\n assert candidate(nums1 = [2, 0, 2, 0],nums2 = [1, 4]) == -1\n assert candidate(nums1 = [3, 2, 0, 1, 0],nums2 = [6, 5, 0]) == 12\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 2... | [
"[3,2,0,1,0]\n[6,5,0]",
"[2,0,2,0]\n[1,4]"
] | [
"Consider we replace all the 0’s with 1’s on both arrays, the answer will be -1 if there was no 0 in the array with the smaller sum of elements.",
"Otherwise, how can you update the value of exactly one of these 1’s to make the sum of the two arrays equal?"
] | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().minSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:04",
"tests_total": 104,
"... | cpp | {
"raw_signature": "long long minSum(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "minSum",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type": "long long",
"s... |
2,919 | minimum-increment-operations-to-make-array-beautiful | Medium | You are given a 0-indexed integer array nums having length n, and an integer k.
You can perform the following increment operation any number of times (including zero):
- Choose an index i in the range [0, n - 1], and increase nums[i] by 1.
An array is considered beautiful if, for any subarray with a size of 3 or mor... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [10, 9, 8, 7, 6],k = 10) == 2\n assert candidate(nums = [1000000000, 0, 1000000000, 0, 1000000000],k = 1000000000) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1,... | [
"[2,3,0,0,2]\n4",
"[0,1,3,3]\n5",
"[1,1,2]\n1"
] | [
"There needs to be at least one value among 3 consecutive values in the array that is greater than or equal to k.",
"The problem can be solved using dynamic programming.",
"Let dp[i] be the minimum number of increment operations required to make the subarray consisting of the first i values beautiful, while als... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().minIncrementOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:06",
"tests_total... | cpp | {
"raw_signature": "long long minIncrementOperations(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "minIncrementOperations",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "long long",
... |
2,920 | maximum-points-after-collecting-coins-from-all-nodes | Hard | There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree. You are also given a 0-indexed array coins of size n where coins[i] indicates ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(edges = [[0, 1], [1, 2], [2, 3]],coins = [10, 10, 3, 3],k = 5) == 11\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5]],coins = [10, 20, 30, 40, 50, 60],k = 15) == 120\n assert candidate(edges = [[0, 1], [1, 2], [2... | [
"[[0,1],[1,2],[2,3]]\n[10,10,3,3]\n5",
"[[0,1],[0,2]]\n[8,4,4]\n0"
] | [
"Let dp[x][t] be the maximum points we can get from the subtree rooted at node x and the second operation has been used t times in its ancestors.",
"Note that the value of each node <= 10^4, so when t >= 14 dp[x][t] is always 0.",
"General equation will be: dp[x][t] = max((coins[x] >> t) - k + sigma(dp[y][t]), ... | {
"canonical_parameter_names": [
"edges",
"coins",
"k"
],
"leetcode_dataset_entry_point": "Solution().maximumPoints",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:08",
"tests_... | cpp | {
"raw_signature": "int maximumPoints(vector<vector<int>>& edges, vector<int>& coins, int k) {",
"container": "Solution",
"callable": "maximumPoints",
"parameters": [
{
"name": "edges",
"type": "vector<vector<int>>&"
},
{
"name": "coins",
"type": "vector<int>&"
},
{
... |
2,923 | find-champion-i | Easy | There are n teams numbered from 0 to n - 1 in a tournament.
Given a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 <= i, j <= n - 1 and i != j team i is stronger than team j if grid[i][j] == 1, otherwise, team j is stronger than team i.
Team a will be the champion of the tournament if there is no... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 1, 1, 1], [0, 0, 0, 0], [0, 1, 0, 1], [0, 1, 0, 0]]) == 0\n assert candidate(grid = [[0, 0, 0, 1], [1, 0, 0, 1], [1, 1, 0, 1], [0, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 1, 0], [0, 0, 1], [1, 0, 0]]) == None\n ... | [
"[[0,1],[0,0]]",
"[[0,0,1],[1,0,1],[0,0,0]]"
] | [
"The champion should be stronger than all the other teams."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().findChampion",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:13",
"tests_total": 56,
"tests_dro... | cpp | {
"raw_signature": "int findChampion(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "findChampion",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
2,924 | find-champion-ii | Medium | There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG.
You are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [u_i, v_i] indicates that there is a directed edge from team u_i to team v_i in the graph.
A directed edg... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(n = 2,edges = [[0, 1]]) == 0\n assert candidate(n = 3,edges = [[0, 1]]) == -1\n assert candidate(n = 2,edges = []) == -1\n assert candidate(n = 6... | [
"3\n[[0,1],[1,2]]",
"4\n[[0,2],[1,3],[1,2]]"
] | [
"The champion(s) should have in-degree 0 in the DAG."
] | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().findChampion",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:16",
"tests_total": 78,
... | cpp | {
"raw_signature": "int findChampion(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "findChampion",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_s... |
2,925 | maximum-score-after-applying-operations-on-a-tree | Medium | There is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree.
You are also given a 0-indexed integer array values of length n, where value... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],values = [20, 10, 9, 7, 4, 3, 5]) == 40\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [2, 4], [4, 5]],values = [5, 2, 5, 2, 1, 1]) == 11\n assert candidate(edges = [[0,... | [
"[[0,1],[0,2],[0,3],[2,4],[4,5]]\n[5,2,5,2,1,1]",
"[[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]\n[20,10,9,7,4,3,5]"
] | [
"Let dp[i] be the maximum score we can get on the subtree rooted at i and sum[i] be the sum of all the values of the subtree rooted at i.",
"If we don’t take value[i] into the final score, we can take all the nodes of the subtrees rooted at i’s children.",
"If we take value[i] into the score, then each subtree ... | {
"canonical_parameter_names": [
"edges",
"values"
],
"leetcode_dataset_entry_point": "Solution().maximumScoreAfterOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:18",
"... | cpp | {
"raw_signature": "long long maximumScoreAfterOperations(vector<vector<int>>& edges, vector<int>& values) {",
"container": "Solution",
"callable": "maximumScoreAfterOperations",
"parameters": [
{
"name": "edges",
"type": "vector<vector<int>>&"
},
{
"name": "values",
"type": ... |
2,926 | maximum-balanced-subsequence-sum | Hard | You are given a 0-indexed integer array nums.
A subsequence of nums having length k and consisting of indices i_0 < i_1 < ... < i_{k-1} is balanced if the following holds:
- nums[i_j] - nums[i_{j-1}] >= i_j - i_{j-1}, for every j in the range [1, k - 1].
A subsequence of nums having length 1 is considered balanced.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [-2, -1]) == -1\n assert candidate(nums = [3, 3, 5, 6]) == 14\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18])... | [
"[3,3,5,6]",
"[5,-1,-3,8]",
"[-2,-1]"
] | [
"Let dp[x] represent the maximum sum of a balanced subsequence ending at x.",
"Rewriting the formula nums[i_j] - nums[i_{j-1}] >= i_j - i_{j-1} gives nums[i_j] - i_j >= nums[i_{j-1}] - i_{j-1}.",
"So, for some index x, we need to find an index y, y < x, such that dp[x] = nums[x] + dp[y] is maximized, and nums[x... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxBalancedSubsequenceSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:20",
"tests_total": 159... | cpp | {
"raw_signature": "long long maxBalancedSubsequenceSum(vector<int>& nums) {",
"container": "Solution",
"callable": "maxBalancedSubsequenceSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"typ... |
2,928 | distribute-candies-among-children-i | Easy | You are given two positive integers n and limit.
Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.
Example 1:
Input: n = 5, limit = 2
Output: 3
Explanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 10,limit = 5) == 21\n assert candidate(n = 3,limit = 3) == 10\n assert candidate(n = 5,limit = 2) == 3\n assert candidate(n = 4,limit = 2) == 6\n assert candidate(n = 7,limit = 3) == 6\n assert candidate(n = 4,limit = ... | [
"5\n2",
"3\n3"
] | [
"Use three nested for loops to check all the triplets."
] | {
"canonical_parameter_names": [
"n",
"limit"
],
"leetcode_dataset_entry_point": "Solution().distributeCandies",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:25",
"tests_total": 7... | cpp | {
"raw_signature": "int distributeCandies(int n, int limit) {",
"container": "Solution",
"callable": "distributeCandies",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "limit",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSn... |
2,929 | distribute-candies-among-children-ii | Medium | You are given two positive integers n and limit.
Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.
Example 1:
Input: n = 5, limit = 2
Output: 3
Explanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 7,limit = 7) == 36\n assert candidate(n = 1000000,limit = 1000000) == 500001500001\n assert candidate(n = 10,limit = 5) == 21\n assert candidate(n = 3,limit = 3) == 10\n assert candidate(n = 5,limit = 2) == 3\n assert ... | [
"5\n2",
"3\n3"
] | [
"We can enumerate the number of candies of one particular child, let it be i which means 0 <= i <= min(limit, n).",
"Suppose the 2nd child gets j candies. Then 0 <= j <= limit and i + j <= n.",
"The 3rd child will hence get n - i - j candies and we should have 0 <= n - i - j <= limit.",
"After some transforma... | {
"canonical_parameter_names": [
"n",
"limit"
],
"leetcode_dataset_entry_point": "Solution().distributeCandies",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:27",
"tests_total": 9... | cpp | {
"raw_signature": "long long distributeCandies(int n, int limit) {",
"container": "Solution",
"callable": "distributeCandies",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "limit",
"type": "int"
}
],
"return_type": "long long",
"signature_source": "lee... |
2,930 | number-of-strings-which-can-be-rearranged-to-contain-substring | Medium | You are given an integer n.
A string s is called good if it contains only lowercase English characters and it is possible to rearrange the characters of s such that the new string contains "leet" as a substring.
For example:
- The string "lteer" is good because we can rearrange it to form "leetr" .
- "letl" is not g... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4) == 12\n assert candidate(n = 1) == 0\n assert candidate(n = 10) == 83943898\n assert candidate(n = 5) == 1460\n assert candidate(n = 3) == 0\n assert candidate(n = 125) == 558399309\n assert candidate(n = 100) ==... | [
"4",
"10"
] | [
"A good string must contain at least one l, one t, and two e.",
"Divide the problem into subproblems and use Dynamic Programming."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().stringCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:30",
"tests_total": 21,
"tests_dropped... | cpp | {
"raw_signature": "int stringCount(int n) {",
"container": "Solution",
"callable": "stringCount",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,931 | maximum-spending-after-buying-items | Hard | You are given a 0-indexed m * n integer matrix values, representing the values of m * n different items in m different shops. Each shop has n items where the j^th item in the i^th shop has a value of values[i][j]. Additionally, the items in the i^th shop are sorted in non-increasing order of value. That is, values[i][j... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(values = [[10, 8, 6, 4, 2], [9, 7, 5, 3, 2]]) == 386\n assert candidate(values = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 78\n assert candidate(values = [[1], [1], [1], [1], [1], [1], [1], [1], [1], [1]]) == 55\n assert ca... | [
"[[8,5,2],[6,4,1],[9,7,3]]",
"[[10,8,6,4,2],[9,7,5,3,2]]"
] | [
"Iterate on days 1 to m * n.",
"On each day, buy the product that minimizes values[i][values[i].length - 1], and pop it from values[i]."
] | {
"canonical_parameter_names": [
"values"
],
"leetcode_dataset_entry_point": "Solution().maxSpending",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:32",
"tests_total": 97,
"tests_dr... | cpp | {
"raw_signature": "long long maxSpending(vector<vector<int>>& values) {",
"container": "Solution",
"callable": "maxSpending",
"parameters": [
{
"name": "values",
"type": "vector<vector<int>>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source... |
2,932 | maximum-strong-pair-xor-i | Easy | You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:
- |x - y| <= min(x, y)
You need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.
Return the maxim... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [15, 25, 35, 45, 55]) == 58\n assert candidate(nums = [2, 4, 6, 8, 10, 12]) == 14\n assert candidate(nums = [1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 2, 4, 8, 16]) == 24\n assert candidate(nums = [2, 2, 4, 4, 6,... | [
"[1,2,3,4,5]",
"[10,100]",
"[5,6,25,30]"
] | [
"The constraints are small enough to make brute-force solutions pass."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maximumStrongPairXor",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:35",
"tests_total": 125,
"... | cpp | {
"raw_signature": "int maximumStrongPairXor(vector<int>& nums) {",
"container": "Solution",
"callable": "maximumStrongPairXor",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
2,933 | high-access-employees | Medium | You are given a 2D 0-indexed array of strings, access_times, with size n. For each i where 0 <= i <= n - 1, access_times[i][0] represents the name of an employee, and access_times[i][1] represents the access time of that employee. All entries in access_times are within the same day.
The access time is represented as f... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(access_times = [['z', '1200'], ['z', '1201'], ['z', '1202'], ['z', '1203']]) == ['z']\n assert candidate(access_times = [['r', '0100'], ['r', '0159'], ['r', '0130'], ['r', '0145']]) == ['r']\n assert candidate(access_times = [['x',... | [
"[[\"a\",\"0549\"],[\"b\",\"0457\"],[\"a\",\"0532\"],[\"a\",\"0621\"],[\"b\",\"0540\"]]",
"[[\"d\",\"0002\"],[\"c\",\"0808\"],[\"c\",\"0829\"],[\"e\",\"0215\"],[\"d\",\"1508\"],[\"d\",\"1444\"],[\"d\",\"1410\"],[\"c\",\"0809\"]]",
"[[\"cd\",\"1025\"],[\"ab\",\"1025\"],[\"cd\",\"1046\"],[\"cd\",\"1055\"],[\"ab\"... | [
"Sort the access times in each person’s list.",
"A person’s name should be in the answer list if there are 2 access times in his/her access time list (after sorting), where the index difference is at least 2 and the time difference is strictly less than 60 minutes."
] | {
"canonical_parameter_names": [
"access_times"
],
"leetcode_dataset_entry_point": "Solution().findHighAccessEmployees",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:37",
"tests_total... | cpp | {
"raw_signature": "vector<string> findHighAccessEmployees(vector<vector<string>>& access_times) {",
"container": "Solution",
"callable": "findHighAccessEmployees",
"parameters": [
{
"name": "access_times",
"type": "vector<vector<string>>&"
}
],
"return_type": "vector<string>",
"signat... |
2,934 | minimum-operations-to-maximize-last-elements-in-arrays | Medium | You are given two 0-indexed integer arrays, nums1 and nums2, both having length n.
You are allowed to perform a series of operations (possibly none).
In an operation, you select an index i in the range [0, n - 1] and swap the values of nums1[i] and nums2[i].
Your task is to find the minimum number of operations requ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [5, 5, 5],nums2 = [5, 5, 5]) == 0\n assert candidate(nums1 = [1, 2],nums2 = [2, 1]) == 1\n assert candidate(nums1 = [10, 9, 8],nums2 = [7, 6, 5]) == -1\n assert candidate(nums1 = [3, 3, 3],nums2 = [3, 3, 3]) == 0\n as... | [
"[1,2,7]\n[4,5,3]",
"[2,3,4,5,9]\n[8,8,4,4,4]",
"[1,5,4]\n[2,5,3]"
] | [
"Consider how to calculate the minimum number of operations when nums1[n - 1] and nums2[n - 1] are fixed (they are not swapped).",
"For each index i, there are only 3 possibilities:\n- nums1[i] <= nums1[n - 1] && nums2[i] <= nums2[n - 1]. We don't need to swap them.\n- nums1[i] <= nums2[n - 1] && nums2[i] <= nums... | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:39",
"tests_total": 1... | cpp | {
"raw_signature": "int minOperations(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "minOperations",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type": "int",
... |
2,935 | maximum-strong-pair-xor-ii | Hard | You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:
- |x - y| <= min(x, y)
You need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.
Return the maxim... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128]) == 192\n assert candidate(nums = [1023, 2047, 3071, 4095, 5119]) == 7168\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 0\n assert candidate(nums = [100000, 100001, 100002, 100... | [
"[1,2,3,4,5]",
"[10,100]",
"[500,520,2500,3000]"
] | [
"Sort the array, now let x <= y which means |x - y| <= min(x, y) can now be written as y - x <= x or in other words, y <= 2 * x.",
"If x and y have the same number of bits, try makingy’s bits different from x if possible for each bit starting from the second most significant bit.",
"If y has 1 more bit than x a... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maximumStrongPairXor",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:41",
"tests_total": 127,
"... | cpp | {
"raw_signature": "int maximumStrongPairXor(vector<int>& nums) {",
"container": "Solution",
"callable": "maximumStrongPairXor",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
2,937 | make-three-strings-equal | Easy | You are given three strings: s1, s2, and s3. In one operation you can choose one of these strings and delete its rightmost character. Note that you cannot completely empty a string.
Return the minimum number of operations required to make the strings equal. If it is impossible to make them equal, return -1.
Example 1... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s1 = \"abc\",s2 = \"abb\",s3 = \"ab\") == 2\n assert candidate(s1 = \"abcde\",s2 = \"abcdf\",s3 = \"abcde\") == 3\n assert candidate(s1 = \"abcd\",s2 = \"abcf\",s3 = \"abcd\") == 3\n assert candidate(s1 = \"abcd\",s2 = \"abce\",... | [
"\"abc\"\n\"abb\"\n\"ab\"",
"\"dac\"\n\"bac\"\n\"cac\""
] | [
"Calculate the length of the longest common prefix of the 3 strings."
] | {
"canonical_parameter_names": [
"s1",
"s2",
"s3"
],
"leetcode_dataset_entry_point": "Solution().findMinimumOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:44",
"tes... | cpp | {
"raw_signature": "int findMinimumOperations(string s1, string s2, string s3) {",
"container": "Solution",
"callable": "findMinimumOperations",
"parameters": [
{
"name": "s1",
"type": "string"
},
{
"name": "s2",
"type": "string"
},
{
"name": "s3",
"type":... |
2,938 | separate-black-and-white-balls | Medium | There are n balls on a table, each ball has a color black or white.
You are given a 0-indexed binary string s of length n, where 1 and 0 represent black and white balls, respectively.
In each step, you can choose two adjacent balls and swap them.
Return the minimum number of steps to group all the black balls to the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"110100\") == 8\n assert candidate(s = \"1111\") == 0\n assert candidate(s = \"100100101\") == 9\n assert candidate(s = \"110011\") == 4\n assert candidate(s = \"00110011\") == 4\n assert candidate(s = \"11110000\") =... | [
"\"101\"",
"\"100\"",
"\"0111\""
] | [
"Every 1 in the string s should be swapped with every 0 on its right side.",
"Iterate right to left and count the number of 0 that have already occurred, whenever you iterate on 1 add that counter to the answer."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().minimumSteps",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:46",
"tests_total": 152,
"tests_dropp... | cpp | {
"raw_signature": "long long minimumSteps(string s) {",
"container": "Solution",
"callable": "minimumSteps",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,939 | maximum-xor-product | Medium | Given three integers a, b, and n, return the maximum value of (a XOR x) * (b XOR x) where 0 <= x < 2^n.
Since the answer may be too large, return it modulo 10^9+ 7.
Note that XOR is the bitwise XOR operation.
Example 1:
Input: a = 12, b = 5, n = 4
Output: 98
Explanation: For x = 2, (a XOR x) = 14 and (b XOR x) = 7.... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(a = 7,b = 14,n = 4) == 98\n assert candidate(a = 15,b = 9,n = 4) == 143\n assert candidate(a = 1,b = 2,n = 1) == 2\n assert candidate(a = 6,b = 7,n = 5) == 930\n assert candidate(a = 1024,b = 512,n = 11) == 1570305\n asser... | [
"12\n5\n4",
"6\n7\n5",
"1\n6\n3"
] | [
"Iterate over bits from most significant to least significant.",
"For the i^th bit, if both a and b have the same value, we can always make x’s i^th bit different from a and b, so a ^ x and b ^ x both have the i^th bit set.",
"Otherwise, we can only set the i^th bit of one of a ^ x or b ^ x. Depending on the pr... | {
"canonical_parameter_names": [
"a",
"b",
"n"
],
"leetcode_dataset_entry_point": "Solution().maximumXorProduct",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:49",
"tests_tota... | cpp | {
"raw_signature": "int maximumXorProduct(long long a, long long b, int n) {",
"container": "Solution",
"callable": "maximumXorProduct",
"parameters": [
{
"name": "a",
"type": "long long"
},
{
"name": "b",
"type": "long long"
},
{
"name": "n",
"type": "int... |
2,940 | find-building-where-alice-and-bob-can-meet | Hard | You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the i^th building.
If a person is in building i, they can move to any other building j if and only if i < j and heights[i] < heights[j].
You are also given another array queries where queries[i] = [a_i, b_i]. On th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(heights = [10, 20, 30, 40, 50],queries = [[0, 4], [1, 3], [2, 2], [3, 1]]) == [4, 3, 2, 3]\n assert candidate(heights = [1, 2, 3, 4, 5],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 4]]) == [1, 2, 3, 4, 4]\n assert candidate(heigh... | [
"[6,4,8,5,2,7]\n[[0,1],[0,3],[2,4],[3,4],[2,2]]",
"[5,3,8,2,6,1,4,6]\n[[0,7],[3,5],[5,2],[3,0],[1,6]]"
] | [
"For each query [x, y], if x > y, swap x and y. Now, we can assume that x <= y.",
"For each query [x, y], if x == y or heights[x] < heights[y], then the answer is y since x ≤ y.",
"Otherwise, we need to find the smallest index t such that y < t and heights[x] < heights[t]. Note that heights[y] <= heights[x], so... | {
"canonical_parameter_names": [
"heights",
"queries"
],
"leetcode_dataset_entry_point": "Solution().leftmostBuildingQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:51",
"t... | cpp | {
"raw_signature": "vector<int> leftmostBuildingQueries(vector<int>& heights, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "leftmostBuildingQueries",
"parameters": [
{
"name": "heights",
"type": "vector<int>&"
},
{
"name": "queries",
"type": "vector<... |
2,942 | find-words-containing-character | Easy | You are given a 0-indexed array of strings words and a character x.
Return an array of indices representing the words that contain the character x.
Note that the returned array may be in any order.
Example 1:
Input: words = ["leet","code"], x = "e"
Output: [0,1]
Explanation: "e" occurs in both words: "leet", and "c... | {
"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 ... | [
"[\"leet\",\"code\"]\n\"e\"",
"[\"abc\",\"bcd\",\"aaaa\",\"cbc\"]\n\"a\"",
"[\"abc\",\"bcd\",\"aaaa\",\"cbc\"]\n\"z\""
] | [
"Use two nested loops."
] | {
"canonical_parameter_names": [
"words",
"x"
],
"leetcode_dataset_entry_point": "Solution().findWordsContaining",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:07:56",
"tests_total":... | cpp | {
"raw_signature": "vector<int> findWordsContaining(vector<string>& words, char x) {",
"container": "Solution",
"callable": "findWordsContaining",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
},
{
"name": "x",
"type": "char"
}
],
"return_type": "vector... |
2,943 | maximize-area-of-square-hole-in-grid | Medium | You are given the two integers, n and m and two integer arrays, hBars and vBars. The grid has n + 2 horizontal and m + 2 vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from 1.
You can remove some of the bars in hBars from horizontal bars and some of the bars in vBars from vertical bars. Note t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 1,m = 1,hBars = [2],vBars = [2]) == 4\n assert candidate(n = 2,m = 3,hBars = [2, 3],vBars = [2, 4]) == 4\n assert candidate(n = 2,m = 1,hBars = [2, 3],vBars = [2]) == 4\n assert candidate(n = 5,m = 5,hBars = [2, 3, 4],vBars ... | [
"2\n1\n[2,3]\n[2]",
"1\n1\n[2]\n[2]",
"2\n3\n[2,3]\n[2,4]"
] | [
"Sort hBars and vBars and consider them separately.",
"Compute the longest sequence of consecutive integer values in each array, denoted as [hx, hy] and [vx, vy], respectively.",
"The maximum square length we can get is min(hy - hx + 2, vy - vx + 2).",
"Square the maximum square length to get the area."
] | {
"canonical_parameter_names": [
"n",
"m",
"hBars",
"vBars"
],
"leetcode_dataset_entry_point": "Solution().maximizeSquareHoleArea",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21... | cpp | {
"raw_signature": "int maximizeSquareHoleArea(int n, int m, vector<int>& hBars, vector<int>& vBars) {",
"container": "Solution",
"callable": "maximizeSquareHoleArea",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "m",
"type": "int"
},
{
"name": "hBa... |
2,944 | minimum-number-of-coins-for-fruits | Medium | You are given an 0-indexed integer array prices where prices[i] denotes the number of coins needed to purchase the (i + 1)^th fruit.
The fruit market has the following reward for each fruit:
- If you purchase the (i + 1)^th fruit at prices[i] coins, you can get any number of the next i fruits for free.
Note that eve... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(prices = [1, 10, 1, 1]) == 2\n assert candidate(prices = [5, 5, 5, 5]) == 10\n assert candidate(prices = [1]) == 1\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 22\n assert candidate(prices = [5, 5, 5, 5, 5,... | [
"[3,1,2]",
"[1,10,1,1]",
"[26,18,6,12,49,7,45,45]"
] | [
"The intended solution uses Dynamic Programming.",
"Let dp[i] denote the minimum number of coins, such that we bought i^th fruit and acquired all the fruits in the range [i...n].",
"dp[i] = min(dp[i], dp[j] + prices[i]) , where j is in the range [i + 1, i + 1 + i]."
] | {
"canonical_parameter_names": [
"prices"
],
"leetcode_dataset_entry_point": "Solution().minimumCoins",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:08:01",
"tests_total": 122,
"tests_... | cpp | {
"raw_signature": "int minimumCoins(vector<int>& prices) {",
"container": "Solution",
"callable": "minimumCoins",
"parameters": [
{
"name": "prices",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"... |
2,945 | find-maximum-non-decreasing-array-length | Hard | You are given a 0-indexed integer array nums.
You can perform any number of operations, where each operation involves selecting a subarray of the array and replacing it with the sum of its elements. For example, if the given array is [1,3,5,6] and you select subarray [3,5] the array will convert to [1,8,6].
Return th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8]) == 10\n assert candidate(nums = [1, 100, 1000]) == 3\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert... | [
"[5,2,2]",
"[1,2,3,4]",
"[4,3,2,6]"
] | [
"Let dp[i] be the maximum number of elements in the increasing sequence after processing the first i elements of the original array.",
"We have dp[0] = 0. dp[i + 1] >= dp[i] (since if we have the solution for the first i elements, we can always merge the last one of the first i + 1 elements which is nums[i] into ... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findMaximumLength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:08:04",
"tests_total": 111,
"tes... | cpp | {
"raw_signature": "int findMaximumLength(vector<int>& nums) {",
"container": "Solution",
"callable": "findMaximumLength",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
2,946 | matrix-similarity-after-cyclic-shifts | Easy | You are given an m x n integer matrix mat and an integer k. The matrix rows are 0-indexed.
The following process happens k times:
- Even-indexed rows (0, 2, 4, ...) are cyclically shifted to the left.
- Odd-indexed rows (1, 3, 5, ...) are cyclically shifted to the right.
Return true if the final modified matrix aft... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mat = [[2, 2], [2, 2]],k = 3) == True\n assert candidate(mat = [[1, 2, 1, 2], [5, 5, 5, 5], [6, 3, 6, 3]],k = 2) == True\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],k = 1) == False\n assert candidate(m... | [
"[[1,2,3],[4,5,6],[7,8,9]]\n4",
"[[1,2,1,2],[5,5,5,5],[6,3,6,3]]\n2",
"[[2,2],[2,2]]\n3"
] | [
"You can reduce k shifts to (k % n) shifts as after n shifts the matrix will become similar to the initial matrix."
] | {
"canonical_parameter_names": [
"mat",
"k"
],
"leetcode_dataset_entry_point": "Solution().areSimilar",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:08:06",
"tests_total": 99,
"tes... | cpp | {
"raw_signature": "bool areSimilar(vector<vector<int>>& mat, int k) {",
"container": "Solution",
"callable": "areSimilar",
"parameters": [
{
"name": "mat",
"type": "vector<vector<int>>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "bool",
"signature_source"... |
2,947 | count-beautiful-substrings-i | Medium | You are given a string s and a positive integer k.
Let vowels and consonants be the number of vowels and consonants in a string.
A string is beautiful if:
- vowels == consonants.
- (vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.
Return the number of non-... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aeaeaeae\",k = 8) == 0\n assert candidate(s = \"bcdfghjklmnpqrstvwxyz\",k = 2) == 0\n assert candidate(s = \"aebcdfe\",k = 3) == 0\n assert candidate(s = \"baeyh\",k = 2) == 2\n assert candidate(s = \"aebcdeedaa\",k = 4... | [
"\"baeyh\"\n2",
"\"abba\"\n1",
"\"bcdf\"\n1"
] | [
"Iterate over all substrings and maintain the frequencies of vowels and consonants."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().beautifulSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:08:08",
"tests_total": 90,... | cpp | {
"raw_signature": "int beautifulSubstrings(string s, int k) {",
"container": "Solution",
"callable": "beautifulSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/code... |
2,948 | make-lexicographically-smallest-array-by-swapping-elements | Medium | You are given a 0-indexed array of positive integers nums and a positive integer limit.
In one operation, you can choose any two indices i and j and swap nums[i] and nums[j] if |nums[i] - nums[j]| <= limit.
Return the lexicographically smallest array that can be obtained by performing the operation any number of time... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1],limit = 1) == [1, 1, 1, 1, 1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],limit = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],limit = 2) == ... | [
"[1,5,3,9,8]\n2",
"[1,7,6,18,2,1]\n3",
"[1,7,28,19,10]\n3"
] | [
"Construct a virtual graph where all elements in nums are nodes and the pairs satisfying the condition have an edge between them.",
"Instead of constructing all edges, we only care about the connected components.",
"Can we use DSU?",
"Sort nums. Now we just need to consider if the consecutive elements have an... | {
"canonical_parameter_names": [
"nums",
"limit"
],
"leetcode_dataset_entry_point": "Solution().lexicographicallySmallestArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:08:10",
... | cpp | {
"raw_signature": "vector<int> lexicographicallySmallestArray(vector<int>& nums, int limit) {",
"container": "Solution",
"callable": "lexicographicallySmallestArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "limit",
"type": "int"
}
],
"r... |
2,949 | count-beautiful-substrings-ii | Hard | You are given a string s and a positive integer k.
Let vowels and consonants be the number of vowels and consonants in a string.
A string is beautiful if:
- vowels == consonants.
- (vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.
Return the number of non-... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aeiaaioaaaaeiiiiouuuooououuoiiiuuuuaeiou\",k = 10) == 0\n assert candidate(s = \"aabbcc\",k = 4) == 1\n assert candidate(s = \"zzzzz\",k = 1) == 0\n assert candidate(s = \"baeyh\",k = 2) == 2\n assert candidate(s = \"bb... | [
"\"baeyh\"\n2",
"\"abba\"\n1",
"\"bcdf\"\n1"
] | [
"For the given k find all the x integers such that x^2 % k == 0. Notice, that there aren’t many such candidates.",
"We can iterate over all such x values and count the number of substrings such that vowels == consonants == x.",
"This can be done with prefix sums and hash map."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().beautifulSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:08:12",
"tests_total": 91,... | cpp | {
"raw_signature": "long long beautifulSubstrings(string s, int k) {",
"container": "Solution",
"callable": "beautifulSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "long long",
"signature_source": "l... |
2,951 | find-the-peaks | Easy | You are given a 0-indexed array mountain. Your task is to find all the peaks in the mountain array.
Return an array that consists of indices of peaks in the given array in any order.
Notes:
- A peak is defined as an element that is strictly greater than its neighboring elements.
- The first and last elements of the ... | {
"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,4,4]",
"[1,4,3,8,5]"
] | [
"If nums[i] > num[i - 1] and nums[i] > nums[i + 1] nums[i] is a peak."
] | {
"canonical_parameter_names": [
"mountain"
],
"leetcode_dataset_entry_point": "Solution().findPeaks",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:08:17",
"tests_total": 115,
"tests_d... | cpp | {
"raw_signature": "vector<int> findPeaks(vector<int>& mountain) {",
"container": "Solution",
"callable": "findPeaks",
"parameters": [
{
"name": "mountain",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
2,952 | minimum-number-of-coins-to-be-added | Medium | You are given a 0-indexed integer array coins, representing the values of the coins available, and an integer target.
An integer x is obtainable if there exists a subsequence of coins that sums to x.
Return the minimum number of coins of any value that need to be added to the array so that every integer in the range ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(coins = [3, 6, 9],target = 15) == 2\n assert candidate(coins = [2, 5, 10],target = 20) == 2\n assert candidate(coins = [1, 4, 10],target = 19) == 2\n assert candidate(coins = [1, 1, 1],target = 20) == 3\n assert candidate(coi... | [
"[1,4,10]\n19",
"[1,4,10,5,7,19]\n19",
"[1,1,1]\n20"
] | [
"Sort the coins array and maintain the smallest sum that is unobtainable by induction.",
"If we don’t use any coins, the smallest integer that we cannot obtain by sum is 1. Suppose currently, for a fixed set of the first several coins the smallest integer that we cannot obtain is x + 1, namely we can form all int... | {
"canonical_parameter_names": [
"coins",
"target"
],
"leetcode_dataset_entry_point": "Solution().minimumAddedCoins",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:08:19",
"tests_tota... | cpp | {
"raw_signature": "int minimumAddedCoins(vector<int>& coins, int target) {",
"container": "Solution",
"callable": "minimumAddedCoins",
"parameters": [
{
"name": "coins",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "int",
"signatu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.