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,765
longest-alternating-subarray
Easy
You are given a 0-indexed integer array nums. A subarray s of length m is called alternating if: - m is greater than 1. - s_1 = s_0 + 1. - The 0-indexed subarray s looks like [s_0, s_1, s_0, s_1,...,s_{(m-1) % 2}]. In other words, s_1 - s_0 = 1, s_2 - s_1 = -1, s_3 - s_2 = 1, s_4 - s_3 = -1, and so on up to s[m - 1] -...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [10, 9, 8, 9, 8, 9, 10]) == 4\n assert candidate(nums = [3, 2, 1, 2, 1, 2, 3, 2, 1]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == -1\n assert candid...
[ "[2,3,4,3,4]", "[4,5,6]" ]
[ "As the constraints are low, you can check each subarray for the given condition." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().alternatingSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:29", "tests_total": 157, "t...
typescript
{ "raw_signature": "function alternatingSubarray(nums: number[]): number {", "container": null, "callable": "alternatingSubarray", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
2,766
relocate-marbles
Medium
You are given a 0-indexed integer array nums representing the initial positions of some marbles. You are also given two 0-indexed integer arrays moveFrom and moveTo of equal length. Throughout moveFrom.length steps, you will change the positions of the marbles. On the i^th step, you will move all marbles at position m...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],moveFrom = [1, 2, 3],moveTo = [5, 5, 5]) == [4, 5]\n assert candidate(nums = [1, 6, 7, 8],moveFrom = [1, 7, 2],moveTo = [2, 9, 5]) == [5, 6, 8, 9]\n assert candidate(nums = [5, 5, 5, 5],moveFrom = [5],moveTo ...
[ "[1,6,7,8]\n[1,7,2]\n[2,9,5]", "[1,1,3,3]\n[1,3]\n[2,2]" ]
[ "Can we solve this problem using a set or map?", "Sequentially process pairs from moveFrom[i] and moveTo[i]. In each step, remove the occurrence of moveFrom[i] and add moveTo[i] into the set." ]
{ "canonical_parameter_names": [ "nums", "moveFrom", "moveTo" ], "leetcode_dataset_entry_point": "Solution().relocateMarbles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:31", ...
typescript
{ "raw_signature": "function relocateMarbles(nums: number[], moveFrom: number[], moveTo: number[]): number[] {", "container": null, "callable": "relocateMarbles", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "moveFrom", "type": "number[]" }, { ...
2,767
partition-string-into-minimum-beautiful-substrings
Medium
Given a binary string s, partition the string into one or more substrings such that each substring is beautiful. A string is beautiful if: - It doesn't contain leading zeros. - It's the binary representation of a number that is a power of 5. Return the minimum number of substrings in such partition. If it is impossi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"1100101\") == -1\n assert candidate(s = \"100000000000000\") == -1\n assert candidate(s = \"101010101010101\") == -1\n assert candidate(s = \"101010101\") == -1\n assert candidate(s = \"111\") == 3\n assert candidate...
[ "\"1011\"", "\"111\"", "\"0\"" ]
[ "To check if number x is a power of 5 or not, we will divide x by 5 while x > 1 and x mod 5 == 0. After iteration if x == 1, then it was a power of 5.", "Since the constraint of s.length is small, we can use recursion to find all the partitions." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minimumBeautifulSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:33", "tests_total": 148, ...
typescript
{ "raw_signature": "function minimumBeautifulSubstrings(s: string): number {", "container": null, "callable": "minimumBeautifulSubstrings", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetc...
2,768
number-of-black-blocks
Medium
You are given two integers m and n representing the dimensions of a 0-indexed m x n grid. You are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordinates [x, y] is colored black. All cells in the grid that do not appear in coordinates are white. A b...
{ "language": "python", "source": "def check(candidate):\n assert candidate(m = 5,n = 5,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2]]) == [9, 3, 3, 0, 1]\n assert candidate(m = 5,n = 5,coordinates = [[2, 2], [3, 3], [1, 1]]) == [6, 8, 2, 0, 0]\n assert candidate(m = 3,n = 3,coordinates = [[0, 0], ...
[ "3\n3\n[[0,0]]", "3\n3\n[[0,0],[1,1],[0,2]]" ]
[ "The number of blocks is too much but the number of black cells is less than that.", "It means the number of blocks with at least one black cell is O(|coordinates|). let’s just hold them.", "Iterate through the coordinates and update the block counts accordingly. For each coordinate, determine which block(s) it...
{ "canonical_parameter_names": [ "m", "n", "coordinates" ], "leetcode_dataset_entry_point": "Solution().countBlackBlocks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:36", "t...
typescript
{ "raw_signature": "function countBlackBlocks(m: number, n: number, coordinates: number[][]): number[] {", "container": null, "callable": "countBlackBlocks", "parameters": [ { "name": "m", "type": "number" }, { "name": "n", "type": "number" }, { "name": "coordin...
2,769
find-the-maximum-achievable-number
Easy
Given two integers, num and t. A number x is achievable if it can become equal to num after applying the following operation at most t times: - Increase or decrease x by 1, and simultaneously increase or decrease num by 1. Return the maximum possible value of x. Example 1: Input: num = 4, t = 1 Output: 6 Explanatio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = 1,t = 50) == 101\n assert candidate(num = 10,t = 5) == 20\n assert candidate(num = 50,t = 50) == 150\n assert candidate(num = 1,t = 1) == 3\n assert candidate(num = 25,t = 25) == 75\n assert candidate(num = 3,t = 2) ...
[ "4\n1", "3\n2" ]
[ "Let x be the answer, it’s always optimal to decrease x in each operation and increase nums." ]
{ "canonical_parameter_names": [ "num", "t" ], "leetcode_dataset_entry_point": "Solution().theMaximumAchievableX", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:38", "tests_total":...
typescript
{ "raw_signature": "function theMaximumAchievableX(num: number, t: number): number {", "container": null, "callable": "theMaximumAchievableX", "parameters": [ { "name": "num", "type": "number" }, { "name": "t", "type": "number" } ], "return_type": "number", "signatu...
2,770
maximum-number-of-jumps-to-reach-the-last-index
Medium
You are given a 0-indexed array nums of n integers and an integer target. You are initially positioned at index 0. In one step, you can jump from index i to any index j such that: - 0 <= i < j < n - -target <= nums[j] - nums[i] <= target Return the maximum number of jumps you can make to reach index n - 1. If there...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 6, 4, 1, 2],target = 3) == 5\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],target = 9) == 9\n assert candidate(nums = [1, 5, 10, 15, 20],target = 4) == -1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, ...
[ "[1,3,6,4,1,2]\n2", "[1,3,6,4,1,2]\n3", "[1,3,6,4,1,2]\n0" ]
[ "Use a dynamic programming approach.", "Define a dynamic programming array dp of size n, where dp[i] represents the maximum number of jumps from index 0 to index i.", "For each j iterate over all i < j. Set dp[j] = max(dp[j], dp[i] + 1) if -target <= nums[j] - nums[i] <= target." ]
{ "canonical_parameter_names": [ "nums", "target" ], "leetcode_dataset_entry_point": "Solution().maximumJumps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:40", "tests_total": 14...
typescript
{ "raw_signature": "function maximumJumps(nums: number[], target: number): number {", "container": null, "callable": "maximumJumps", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "target", "type": "number" } ], "return_type": "number", "signature...
2,771
longest-non-decreasing-subarray-from-two-arrays
Medium
You are given two 0-indexed integer arrays nums1 and nums2 of length n. Let's define another 0-indexed integer array, nums3, of length n. For each index i in the range [0, n - 1], you can assign either nums1[i] or nums2[i] to nums3[i]. Your task is to maximize the length of the longest non-decreasing subarray in nums...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [2, 3, 1],nums2 = [1, 2, 1]) == 2\n assert candidate(nums1 = [8, 6, 4, 2],nums2 = [7, 5, 3, 1]) == 1\n assert candidate(nums1 = [1, 2, 2, 2, 3],nums2 = [2, 2, 3, 3, 4]) == 5\n assert candidate(nums1 = [1000000000, 1, 100...
[ "[2,3,1]\n[1,2,1]", "[1,3,2,1]\n[2,2,3,4]", "[1,1]\n[2,2]" ]
[ "Consider using dynamic programming.", "Let dp[i][0] (dp[i][1]) be the length of the longest non-decreasing ending with nums1[i] (nums2[i]).", "Initialize dp[i][0] to 1. If nums1[i] >= nums1[i - 1] then dp[i][0] may be dp[i - 1][0] + 1. If nums1[i] >= nums2[i - 1] then dp[i][0] may be dp[i - 1][1] + 1. Perform ...
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().maxNonDecreasingLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:43", "tests_...
typescript
{ "raw_signature": "function maxNonDecreasingLength(nums1: number[], nums2: number[]): number {", "container": null, "callable": "maxNonDecreasingLength", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" } ], "return_type"...
2,772
apply-operations-to-make-all-array-elements-equal-to-zero
Medium
You are given a 0-indexed integer array nums and a positive integer k. You can apply the following operation on the array any number of times: - Choose any subarray of size k from the array and decrease all its elements by 1. Return true if you can make all the array elements equal to 0, or false otherwise. A subar...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 3, 1, 1, 0],k = 3) == True\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == True\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == False\n assert candidate(nums = [1000000, 1000000, 1000000],k = 3) == True\n ...
[ "[2,2,3,1,1,0]\n3", "[1,3,1,1]\n2" ]
[ "In case it is possible, then how can you do the operations? which subarrays do you choose and in what order?", "The order of the chosen subarrays should be from the left to the right of the array" ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().checkArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:46", "tests_total": 101, "t...
typescript
{ "raw_signature": "function checkArray(nums: number[], k: number): boolean {", "container": null, "callable": "checkArray", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "boolean", "signature_source": "l...
2,778
sum-of-squares-of-special-elements
Easy
You are given a 1-indexed integer array nums of length n. An element nums[i] of nums is called special if i divides n, i.e. n % i == 0. Return the sum of the squares of all special elements of nums. Example 1: Input: nums = [1,2,3,4] Output: 21 Explanation: There are exactly 3 special elements in nums: nums[1] sinc...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25]) == 650\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4]) == 21\n assert candidate(nums = [49, 49, 49, 49, 49...
[ "[1,2,3,4]", "[2,7,1,19,18,3]" ]
[ "Iterate over all the elements of the array. For each index i, check if it is special using the modulo operator.", "if n%i == 0, index i is special and you should add nums[i] to the answer." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().sumOfSquares", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:50", "tests_total": 105, "tests_dr...
typescript
{ "raw_signature": "function sumOfSquares(nums: number[]): number {", "container": null, "callable": "sumOfSquares", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
2,779
maximum-beauty-of-an-array-after-applying-operation
Medium
You are given a 0-indexed array nums and a non-negative integer k. In one operation, you can do the following: - Choose an index i that hasn't been chosen before from the range [0, nums.length - 1]. - Replace nums[i] with any integer from the range [nums[i] - k, nums[i] + k]. The beauty of the array is the length of...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 3) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 3\n assert candidate(nums = [10, 20, 30, 40, 50],k = 15) == 4\n assert candidate(nums = [5, 15, 25, 35],k = 5...
[ "[4,6,1,2]\n2", "[1,1,1,1]\n10" ]
[ "Sort the array.", "The problem becomes the following: find maximum subarray A[i … j] such that A[j] - A[i] ≤ 2 * k." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumBeauty", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:53", "tests_total": 119, ...
typescript
{ "raw_signature": "function maximumBeauty(nums: number[], k: number): number {", "container": null, "callable": "maximumBeauty", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source"...
2,780
minimum-index-of-a-valid-split
Medium
An element x of an integer array arr of length m is dominant if more than half the elements of arr have a value of x. You are given a 0-indexed integer array nums of length n with one dominant element. You can split nums at an index i into two arrays nums[0, ..., i] and nums[i + 1, ..., n - 1], but the split is only ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 1]) == 0\n assert candidate(nums = [3, 3, 3, 3, 7, 2, 2]) == -1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 1]) == 0\n assert candidate...
[ "[1,2,2,2]", "[2,1,3,1,1,1,7,1,2,1]", "[3,3,3,3,7,2,2]" ]
[ "Find the dominant element of nums by using a hashmap to maintain element frequency, we denote the dominant element as x and its frequency as f.", "For each index in [0, n - 2], calculate f1, x’s frequency in the subarray [0, i] when looping the index. And f2, x’s frequency in the subarray [i + 1, n - 1] which is...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumIndex", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:55", "tests_total": 12, "tests_dro...
typescript
{ "raw_signature": "function minimumIndex(nums: number[]): number {", "container": null, "callable": "minimumIndex", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
2,781
length-of-the-longest-valid-substring
Hard
You are given a string word and an array of strings forbidden. A string is called valid if none of its substrings are present in forbidden. Return the length of the longest valid substring of the string word. A substring is a contiguous sequence of characters in a string, possibly empty. Example 1: Input: word = "...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"zzzzzzzzzz\",forbidden = ['zz']) == 1\n assert candidate(word = \"abacab\",forbidden = ['ba', 'ca']) == 2\n assert candidate(word = \"leetcode\",forbidden = ['de', 'le', 'e']) == 4\n assert candidate(word = \"abcde\",fo...
[ "\"cbaaaabc\"\n[\"aaa\",\"cb\"]", "\"leetcode\"\n[\"de\",\"le\",\"e\"]" ]
[]
{ "canonical_parameter_names": [ "word", "forbidden" ], "leetcode_dataset_entry_point": "Solution().longestValidSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:59", "test...
typescript
{ "raw_signature": "function longestValidSubstring(word: string, forbidden: string[]): number {", "container": null, "callable": "longestValidSubstring", "parameters": [ { "name": "word", "type": "string" }, { "name": "forbidden", "type": "string[]" } ], "return_type"...
2,784
check-if-array-is-good
Easy
You are given an integer array nums. We consider an array good if it is a permutation of an array base[n]. base[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 exactly once, plus two occurrences of n). For example, base[1] = [1, 1] and base[3] = [1, 2, 3, 3]. Re...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 3, 2]) == True\n assert candidate(nums = [2, 1, 1]) == False\n assert candidate(nums = [2, 1, 2]) == True\n assert candidate(nums = [1, 2, 3, 3, 5, 4]) == False\n assert candidate(nums = [2, 2]) == False\n as...
[ "[2, 1, 3]", "[1, 3, 3, 2]", "[1, 1]", "[3, 4, 4, 1, 2, 1]" ]
[ "Find the maximum element of the array." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().isGood", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:03", "tests_total": 120, "tests_dropped"...
typescript
{ "raw_signature": "function isGood(nums: number[]): boolean {", "container": null, "callable": "isGood", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,785
sort-vowels-in-a-string
Medium
Given a 0-indexed string s, permute s to get a new string t such that: - All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then t[i] = s[i]. - The vowels must be sorted in the nondecreasing order of their ASCII values. More forma...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"b\") == \"b\"\n assert candidate(s = \"bCdEfGhIjK\") == \"bCdEfGhIjK\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"AEIOUaeiou\") == \"AEIOUaeiou\"\n ...
[ "\"lEetcOde\"", "\"lYmpH\"" ]
[ "Add all the vowels in an array and sort the array.", "Replace characters in string s if it's a vowel from the new array." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().sortVowels", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:06", "tests_total": 150, "tests_dropped...
typescript
{ "raw_signature": "function sortVowels(s: string): string {", "container": null, "callable": "sortVowels", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,786
visit-array-positions-to-maximize-score
Medium
You are given a 0-indexed integer array nums and a positive integer x. You are initially at position 0 in the array and you can visit other positions according to the following rules: - If you are currently in position i, then you can move to any position j such that i < j. - For each position i that you visit, you g...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],x = 1) == 11\n assert candidate(nums = [10, 13, 15, 17, 19],x = 10) == 64\n assert candidate(nums = [1, 2, 3, 4, 5, 6],x = 2) == 13\n assert candidate(nums = [10, 13, 14, 15, 19],x = 10) == 48\n assert ...
[ "[2,3,6,1,9,2]\n5", "[2,4,6,8]\n3" ]
[ "How can we use dynamic programming to solve the problem?", "Let dp[i] be the answer to the subarray nums[0…i]. What are the transitions of this dp?" ]
{ "canonical_parameter_names": [ "nums", "x" ], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:08", "tests_total": 109, "tes...
typescript
{ "raw_signature": "function maxScore(nums: number[], x: number): number {", "container": null, "callable": "maxScore", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "x", "type": "number" } ], "return_type": "number", "signature_source": "leetcod...
2,787
ways-to-express-an-integer-as-sum-of-powers
Medium
Given two positive integers n and x. Return the number of ways n can be expressed as the sum of the x^th power of unique positive integers, in other words, the number of sets of unique integers [n_1, n_2, ..., n_k] where n = n_1^x + n_2^x + ... + n_k^x. Since the result can be very large, return it modulo 10^9 + 7. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 100,x = 4) == 0\n assert candidate(n = 50,x = 2) == 3\n assert candidate(n = 200,x = 2) == 9\n assert candidate(n = 300,x = 5) == 0\n assert candidate(n = 160,x = 3) == 1\n assert candidate(n = 4,x = 1) == 2\n asser...
[ "10\n2", "4\n1" ]
[ "You can use dynamic programming, where dp[k][j] represents the number of ways to express k as the sum of the x-th power of unique positive integers such that the biggest possible number we use is j.", "To calculate dp[k][j], you can iterate over the numbers smaller than j and try to use each one as a power of x ...
{ "canonical_parameter_names": [ "n", "x" ], "leetcode_dataset_entry_point": "Solution().numberOfWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:10", "tests_total": 96, "tes...
typescript
{ "raw_signature": "function numberOfWays(n: number, x: number): number {", "container": null, "callable": "numberOfWays", "parameters": [ { "name": "n", "type": "number" }, { "name": "x", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/...
2,788
split-strings-by-separator
Easy
Given an array of strings words and a character separator, split each string in words by separator. Return an array of strings containing the new strings formed after the splits, excluding empty strings. Notes - separator is used to determine where the split should occur, but it is not included as part of the result...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['no-separator'],separator = \",\") == ['no-separator']\n assert candidate(words = ['hello.world', 'foo.bar.baz'],separator = \".\") == ['hello', 'world', 'foo', 'bar', 'baz']\n assert candidate(words = ['test|test|test'],s...
[ "[\"one.two.three\",\"four.five\",\"six\"]\n\".\"", "[\"$easy$\",\"$problem$\"]\n\"$\"", "[\"|||\"]\n\"|\"" ]
[ "Iterate over each string in the given array using a loop and perform string splitting based on the provided separator character.", "Be sure not to return empty strings." ]
{ "canonical_parameter_names": [ "words", "separator" ], "leetcode_dataset_entry_point": "Solution().splitWordsBySeparator", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:13", "tes...
typescript
{ "raw_signature": "function splitWordsBySeparator(words: string[], separator: string): string[] {", "container": null, "callable": "splitWordsBySeparator", "parameters": [ { "name": "words", "type": "string[]" }, { "name": "separator", "type": "string" } ], "return_t...
2,789
largest-element-in-an-array-after-merge-operations
Medium
You are given a 0-indexed array nums consisting of positive integers. You can do the following operation on the array any number of times: - Choose an index i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i + 1]. Replace the element nums[i + 1] with nums[i] + nums[i + 1] and delete the element nums[i] from t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 30\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000]) =...
[ "[2,3,7,9,3]", "[5,3,3]" ]
[ "Start from the end of the array and keep merging elements together until it is no longer possible.", "The answer will be the resulting element from the last merge operation." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxArrayValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:15", "tests_total": 124, "tests_d...
typescript
{ "raw_signature": "function maxArrayValue(nums: number[]): number {", "container": null, "callable": "maxArrayValue", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
2,790
maximum-number-of-groups-with-increasing-length
Hard
You are given a 0-indexed array usageLimits of length n. Your task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no more than usageLimits[i] times in total across all groups. You must also satisfy the following conditions: - Each group must consist of distinct numbers, meani...
{ "language": "python", "source": "def check(candidate):\n assert candidate(usageLimits = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(usageLimits = [1000000000, 1000000000, 1000000000]) == 3\n assert candidate(usageLimits = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 9\n assert candidate(usageLimit...
[ "[1,2,5]", "[2,1,2]", "[1,1]" ]
[ "Can we solve this problem using sorting and binary search?", "Sort the array in increasing order and run a binary search on the number of groups, x.", "To determine if a value x is feasible, greedily distribute the numbers such that each group receives 1, 2, 3, ..., x numbers." ]
{ "canonical_parameter_names": [ "usageLimits" ], "leetcode_dataset_entry_point": "Solution().maxIncreasingGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:18", "tests_total": 70...
typescript
{ "raw_signature": "function maxIncreasingGroups(usageLimits: number[]): number {", "container": null, "callable": "maxIncreasingGroups", "parameters": [ { "name": "usageLimits", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_sourc...
2,798
number-of-employees-who-met-the-target
Easy
There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company. The company requires each employee to work for at least target hours. You are given a 0-indexed array of non-negative integers hours of length n and a non-negative integer target. Return the in...
{ "language": "python", "source": "def check(candidate):\n assert candidate(hours = [5, 5, 5, 5, 5],target = 5) == 5\n assert candidate(hours = [3, 4, 5, 6, 7],target = 4) == 4\n assert candidate(hours = [1, 5, 7, 9],target = 8) == 1\n assert candidate(hours = [10, 10, 10],target = 10) == 3\n assert ...
[ "[0,1,2,3,4]\n2", "[5,1,4,2,2]\n6" ]
[ "Iterate over the elements of array hours and check if the value is greater than or equal to target." ]
{ "canonical_parameter_names": [ "hours", "target" ], "leetcode_dataset_entry_point": "Solution().numberOfEmployeesWhoMetTarget", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:26", ...
typescript
{ "raw_signature": "function numberOfEmployeesWhoMetTarget(hours: number[], target: number): number {", "container": null, "callable": "numberOfEmployeesWhoMetTarget", "parameters": [ { "name": "hours", "type": "number[]" }, { "name": "target", "type": "number" } ], "...
2,799
count-complete-subarrays-in-an-array
Medium
You are given an array nums consisting of positive integers. We call a subarray of an array complete if the following condition is satisfied: - The number of distinct elements in the subarray is equal to the number of distinct elements in the whole array. Return the number of complete subarrays. A subarray is a con...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == 28\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 4\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996]) == 1\n assert candidate(nums = [1, 2, 3, 1, 2, 3]) == 10\n assert candidate(nums...
[ "[1,3,1,2,2]", "[5,5,5,5]" ]
[ "Let’s say k is the number of distinct elements in the array. Our goal is to find the number of subarrays with k distinct elements.", "Since the constraints are small, you can check every subarray." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countCompleteSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:28", "tests_total": 99, ...
typescript
{ "raw_signature": "function countCompleteSubarrays(nums: number[]): number {", "container": null, "callable": "countCompleteSubarrays", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
2,800
shortest-string-that-contains-three-strings
Medium
Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings. If there are multiple such strings, return the lexicographically smallest one. Return a string denoting the answer to the problem. Notes - A string a is lexicographically smaller ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(a = \"aaaa\",b = \"bbbb\",c = \"cccc\") == \"aaaabbbbcccc\"\n assert candidate(a = \"aaa\",b = \"aa\",c = \"a\") == \"aaa\"\n assert candidate(a = \"ab\",b = \"ba\",c = \"aba\") == \"aba\"\n assert candidate(a = \"hello\",b = \"...
[ "\"abc\"\n\"bca\"\n\"aaa\"", "\"ab\"\n\"ba\"\n\"aba\"" ]
[ "Think about how you can generate all possible strings that contain all three input strings as substrings. Can you come up with an efficient algorithm to do this?", "Check all permutations of the words a, b, and c. For each permutation, begin by appending some letters to the end of the first word to form the seco...
{ "canonical_parameter_names": [ "a", "b", "c" ], "leetcode_dataset_entry_point": "Solution().minimumString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:30", "tests_total": ...
typescript
{ "raw_signature": "function minimumString(a: string, b: string, c: string): string {", "container": null, "callable": "minimumString", "parameters": [ { "name": "a", "type": "string" }, { "name": "b", "type": "string" }, { "name": "c", "type": "string" ...
2,801
count-stepping-numbers-in-range
Hard
Given two positive integers low and high represented as strings, find the count of stepping numbers in the inclusive range [low, high]. A stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1. Return an integer denoting the count of stepping numbers in the inclusi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(low = \"123\",high = \"456\") == 13\n assert candidate(low = \"5555555555\",high = \"6666666666\") == 436\n assert candidate(low = \"1111111111\",high = \"2222222222\") == 307\n assert candidate(low = \"1000000000\",high = \"100...
[ "\"1\"\n\"11\"", "\"90\"\n\"101\"" ]
[ "Calculate the number of stepping numbers in the range [1, high] and subtract the number of stepping numbers in the range [1, low - 1].", "The main problem is calculating the number of stepping numbers in the range [1, x].", "First, calculate the number of stepping numbers shorter than x in length, which can be...
{ "canonical_parameter_names": [ "low", "high" ], "leetcode_dataset_entry_point": "Solution().countSteppingNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:32", "tests_total...
typescript
{ "raw_signature": "function countSteppingNumbers(low: string, high: string): number {", "container": null, "callable": "countSteppingNumbers", "parameters": [ { "name": "low", "type": "string" }, { "name": "high", "type": "string" } ], "return_type": "number", "sig...
2,806
account-balance-after-rounded-purchase
Easy
Initially, you have a bank account balance of 100 dollars. You are given an integer purchaseAmount representing the amount you will spend on a purchase in dollars, in other words, its price. When making the purchase, first the purchaseAmount is rounded to the nearest multiple of 10. Let us call this value roundedAmou...
{ "language": "python", "source": "def check(candidate):\n assert candidate(purchaseAmount = 100) == 0\n assert candidate(purchaseAmount = 85) == 10\n assert candidate(purchaseAmount = 15) == 80\n assert candidate(purchaseAmount = 10) == 90\n assert candidate(purchaseAmount = 45) == 50\n assert ca...
[ "9", "15", "10" ]
[ "To determine the nearest multiple of 10, we can brute force the rounded amount since there are at most 100 options. In case of multiple nearest multiples, choose the largest.", "Another solution is observing that the rounded amount is floor((purchaseAmount + 5) / 10) * 10. Using this formula, we can calculate th...
{ "canonical_parameter_names": [ "purchaseAmount" ], "leetcode_dataset_entry_point": "Solution().accountBalanceAfterPurchase", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:37", "tests...
typescript
{ "raw_signature": "function accountBalanceAfterPurchase(purchaseAmount: number): number {", "container": null, "callable": "accountBalanceAfterPurchase", "parameters": [ { "name": "purchaseAmount", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippe...
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_...
typescript
{ "raw_signature": "function minimumSeconds(nums: number[]): number {", "container": null, "callable": "minimumSeconds", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
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...
typescript
{ "raw_signature": "function minimumTime(nums1: number[], nums2: number[], x: number): number {", "container": null, "callable": "minimumTime", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" }, { "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...
typescript
{ "raw_signature": "function finalString(s: string): string {", "container": null, "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, ...
typescript
{ "raw_signature": "function canSplitArray(nums: number[], m: number): boolean {", "container": null, "callable": "canSplitArray", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "m", "type": "number" } ], "return_type": "boolean", "signature_sourc...
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, "...
typescript
{ "raw_signature": "function maximumSafenessFactor(grid: number[][]): number {", "container": null, "callable": "maximumSafenessFactor", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "l...
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":...
typescript
{ "raw_signature": "function findMaximumElegance(items: number[][], k: number): number {", "container": null, "callable": "findMaximumElegance", "parameters": [ { "name": "items", "type": "number[][]" }, { "name": "k", "type": "number" } ], "return_type": "number", ...
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"...
typescript
{ "raw_signature": "function maxSum(nums: number[]): number {", "container": null, "callable": "maxSum", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "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"...
typescript
{ "raw_signature": "function minAbsoluteDifference(nums: number[], x: number): number {", "container": null, "callable": "minAbsoluteDifference", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "x", "type": "number" } ], "return_type": "number", "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,...
typescript
{ "raw_signature": "function countPairs(nums: number[], target: number): number {", "container": null, "callable": "countPairs", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "target", "type": "number" } ], "return_type": "number", "signature_sou...
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"...
typescript
{ "raw_signature": "function canMakeSubsequence(str1: string, str2: string): boolean {", "container": null, "callable": "canMakeSubsequence", "parameters": [ { "name": "str1", "type": "string" }, { "name": "str2", "type": "string" } ], "return_type": "boolean", "sig...
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...
typescript
{ "raw_signature": "function minimumOperations(nums: number[]): number {", "container": null, "callable": "minimumOperations", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
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", ...
typescript
{ "raw_signature": "function numberOfBeautifulIntegers(low: number, high: number, k: number): number {", "container": null, "callable": "numberOfBeautifulIntegers", "parameters": [ { "name": "low", "type": "number" }, { "name": "high", "type": "number" }, { "nam...
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...
typescript
{ "raw_signature": "function isAcronym(words: string[], s: string): boolean {", "container": null, "callable": "isAcronym", "parameters": [ { "name": "words", "type": "string[]" }, { "name": "s", "type": "string" } ], "return_type": "boolean", "signature_source": "l...
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...
typescript
{ "raw_signature": "function minimumSum(n: number, k: number): number {", "container": null, "callable": "minimumSum", "parameters": [ { "name": "n", "type": "number" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/code...
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": ...
typescript
{ "raw_signature": "function maximizeTheProfit(n: number, offers: number[][]): number {", "container": null, "callable": "maximizeTheProfit", "parameters": [ { "name": "n", "type": "number" }, { "name": "offers", "type": "number[][]" } ], "return_type": "number", "s...
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":...
typescript
{ "raw_signature": "function longestEqualSubarray(nums: number[], k: number): number {", "container": null, "callable": "longestEqualSubarray", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "sig...
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...
typescript
{ "raw_signature": "function furthestDistanceFromOrigin(moves: string): number {", "container": null, "callable": "furthestDistanceFromOrigin", "parameters": [ { "name": "moves", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source"...
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":...
typescript
{ "raw_signature": "function minimumPossibleSum(n: number, target: number): number {", "container": null, "callable": "minimumPossibleSum", "parameters": [ { "name": "n", "type": "number" }, { "name": "target", "type": "number" } ], "return_type": "number", "signatu...
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...
typescript
{ "raw_signature": "function minOperations(nums: number[], target: number): number {", "container": null, "callable": "minOperations", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "target", "type": "number" } ], "return_type": "number", "signatu...
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...
typescript
{ "raw_signature": "function getMaxFunctionValue(receiver: number[], k: number): number {", "container": null, "callable": "getMaxFunctionValue", "parameters": [ { "name": "receiver", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", ...
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...
typescript
{ "raw_signature": "function canBeEqual(s1: string, s2: string): boolean {", "container": null, "callable": "canBeEqual", "parameters": [ { "name": "s1", "type": "string" }, { "name": "s2", "type": "string" } ], "return_type": "boolean", "signature_source": "leetcod...
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, "...
typescript
{ "raw_signature": "function checkStrings(s1: string, s2: string): boolean {", "container": null, "callable": "checkStrings", "parameters": [ { "name": "s1", "type": "string" }, { "name": "s2", "type": "string" } ], "return_type": "boolean", "signature_source": "lee...
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,...
typescript
{ "raw_signature": "function maxSum(nums: number[], m: number, k: number): number {", "container": null, "callable": "maxSum", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "m", "type": "number" }, { "name": "k", "type": "number" } ...
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...
typescript
{ "raw_signature": "function countSymmetricIntegers(low: number, high: number): number {", "container": null, "callable": "countSymmetricIntegers", "parameters": [ { "name": "low", "type": "number" }, { "name": "high", "type": "number" } ], "return_type": "number", ...
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...
typescript
{ "raw_signature": "function minimumOperations(num: string): number {", "container": null, "callable": "minimumOperations", "parameters": [ { "name": "num", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
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...
typescript
{ "raw_signature": "function countInterestingSubarrays(nums: number[], modulo: number, k: number): number {", "container": null, "callable": "countInterestingSubarrays", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "modulo", "type": "number" }, { ...
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", ...
typescript
{ "raw_signature": "function minOperationsQueries(n: number, edges: number[][], queries: number[][]): number[] {", "container": null, "callable": "minOperationsQueries", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" }, { ...
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...
typescript
{ "raw_signature": "function numberOfPoints(nums: number[][]): number {", "container": null, "callable": "numberOfPoints", "parameters": [ { "name": "nums", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
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...
typescript
{ "raw_signature": "function isReachableAtTime(sx: number, sy: number, fx: number, fy: number, t: number): boolean {", "container": null, "callable": "isReachableAtTime", "parameters": [ { "name": "sx", "type": "number" }, { "name": "sy", "type": "number" }, { "...
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...
typescript
{ "raw_signature": "function minimumMoves(grid: number[][]): number {", "container": null, "callable": "minimumMoves", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
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...
typescript
{ "raw_signature": "function numberOfWays(s: string, t: string, k: number): number {", "container": null, "callable": "numberOfWays", "parameters": [ { "name": "s", "type": "string" }, { "name": "t", "type": "string" }, { "name": "k", "type": "number" ...
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...
typescript
{ "raw_signature": "function minimumRightShifts(nums: number[]): number {", "container": null, "callable": "minimumRightShifts", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
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, ...
typescript
{ "raw_signature": "function minLengthAfterRemovals(nums: number[]): number {", "container": null, "callable": "minLengthAfterRemovals", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
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...
typescript
{ "raw_signature": "function countPairs(coordinates: number[][], k: number): number {", "container": null, "callable": "countPairs", "parameters": [ { "name": "coordinates", "type": "number[][]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signa...
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...
typescript
{ "raw_signature": "function minEdgeReversals(n: number, edges: number[][]): number[] {", "container": null, "callable": "minEdgeReversals", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" } ], "return_type": "number[]", "s...
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...
typescript
{ "raw_signature": "function sumIndicesWithKSetBits(nums: number[], k: number): number {", "container": null, "callable": "sumIndicesWithKSetBits", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", ...
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...
typescript
{ "raw_signature": "function countWays(nums: number[]): number {", "container": null, "callable": "countWays", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "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", "...
typescript
{ "raw_signature": "function maxNumberOfAlloys(n: number, k: number, budget: number, composition: number[][], stock: number[], cost: number[]): number {", "container": null, "callable": "maxNumberOfAlloys", "parameters": [ { "name": "n", "type": "number" }, { "name": "k", "ty...
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...
typescript
{ "raw_signature": "function maximumSum(nums: number[]): number {", "container": null, "callable": "maximumSum", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
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...
typescript
{ "raw_signature": "function maximumOddBinaryNumber(s: string): string {", "container": null, "callable": "maximumOddBinaryNumber", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
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, ...
typescript
{ "raw_signature": "function maximumSumOfHeights(heights: number[]): number {", "container": null, "callable": "maximumSumOfHeights", "parameters": [ { "name": "heights", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
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...
typescript
{ "raw_signature": "function maximumSumOfHeights(maxHeights: number[]): number {", "container": null, "callable": "maximumSumOfHeights", "parameters": [ { "name": "maxHeights", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source"...
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...
typescript
{ "raw_signature": "function countPaths(n: number, edges: number[][]): number {", "container": null, "callable": "countPaths", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" } ], "return_type": "number", "signature_source"...
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, ...
typescript
{ "raw_signature": "function minOperations(nums: number[], k: number): number {", "container": null, "callable": "minOperations", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source"...
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...
typescript
{ "raw_signature": "function minOperations(nums: number[]): number {", "container": null, "callable": "minOperations", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "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...
typescript
{ "raw_signature": "function maxSubarrays(nums: number[]): number {", "container": null, "callable": "maxSubarrays", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "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...
typescript
{ "raw_signature": "function maxKDivisibleComponents(n: number, edges: number[][], values: number[], k: number): number {", "container": null, "callable": "maxKDivisibleComponents", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" ...
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...
typescript
{ "raw_signature": "function maximumTripletValue(nums: number[]): number {", "container": null, "callable": "maximumTripletValue", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
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...
typescript
{ "raw_signature": "function maximumTripletValue(nums: number[]): number {", "container": null, "callable": "maximumTripletValue", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
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":...
typescript
{ "raw_signature": "function minSizeSubarray(nums: number[], target: number): number {", "container": null, "callable": "minSizeSubarray", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "target", "type": "number" } ], "return_type": "number", "sig...
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...
typescript
{ "raw_signature": "function countVisitedNodes(edges: number[]): number[] {", "container": null, "callable": "countVisitedNodes", "parameters": [ { "name": "edges", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcod...
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, ...
typescript
{ "raw_signature": "function differenceOfSums(n: number, m: number): number {", "container": null, "callable": "differenceOfSums", "parameters": [ { "name": "n", "type": "number" }, { "name": "m", "type": "number" } ], "return_type": "number", "signature_source": "l...
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...
typescript
{ "raw_signature": "function minProcessingTime(processorTime: number[], tasks: number[]): number {", "container": null, "callable": "minProcessingTime", "parameters": [ { "name": "processorTime", "type": "number[]" }, { "name": "tasks", "type": "number[]" } ], "return...
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"...
typescript
{ "raw_signature": "function minOperations(s1: string, s2: string, x: number): number {", "container": null, "callable": "minOperations", "parameters": [ { "name": "s1", "type": "string" }, { "name": "s2", "type": "string" }, { "name": "x", "type": "number...
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_...
typescript
{ "raw_signature": "function maxSum(nums: number[], k: number): number {", "container": null, "callable": "maxSum", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/co...
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...
typescript
{ "raw_signature": "function lastVisitedIntegers(nums: number[]): number[] {", "container": null, "callable": "lastVisitedIntegers", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetc...
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_...
typescript
{ "raw_signature": "function getLongestSubsequence(words: string[], groups: number[]): string[] {", "container": null, "callable": "getLongestSubsequence", "parameters": [ { "name": "words", "type": "string[]" }, { "name": "groups", "type": "number[]" } ], "return_typ...
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", ...
typescript
{ "raw_signature": "function getWordsInLongestSubsequence(words: string[], groups: number[]): string[] {", "container": null, "callable": "getWordsInLongestSubsequence", "parameters": [ { "name": "words", "type": "string[]" }, { "name": "groups", "type": "number[]" } ],...
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...
typescript
{ "raw_signature": "function countSubMultisets(nums: number[], l: number, r: number): number {", "container": null, "callable": "countSubMultisets", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "l", "type": "number" }, { "name": "r", "...
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...
typescript
{ "raw_signature": "function findIndices(nums: number[], indexDifference: number, valueDifference: number): number[] {", "container": null, "callable": "findIndices", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "indexDifference", "type": "number" }, ...
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...
typescript
{ "raw_signature": "function shortestBeautifulSubstring(s: string, k: number): string {", "container": null, "callable": "shortestBeautifulSubstring", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "string", "s...
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...
typescript
{ "raw_signature": "function findIndices(nums: number[], indexDifference: number, valueDifference: number): number[] {", "container": null, "callable": "findIndices", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "indexDifference", "type": "number" }, ...
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, ...
typescript
{ "raw_signature": "function constructProductMatrix(grid: number[][]): number[][] {", "container": null, "callable": "constructProductMatrix", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number[][]", "signature_source": "leetcode/codeSnippets", "type_s...
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...
typescript
{ "raw_signature": "function minimumSum(nums: number[]): number {", "container": null, "callable": "minimumSum", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "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...
typescript
{ "raw_signature": "function minimumSum(nums: number[]): number {", "container": null, "callable": "minimumSum", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "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, "...
typescript
{ "raw_signature": "function minimumChanges(s: string, k: number): number {", "container": null, "callable": "minimumChanges", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetc...
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...
typescript
{ "raw_signature": "function sumCounts(nums: number[]): number {", "container": null, "callable": "sumCounts", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "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...
typescript
{ "raw_signature": "function minChanges(s: string): number {", "container": null, "callable": "minChanges", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "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...
typescript
{ "raw_signature": "function lengthOfLongestSubsequence(nums: number[], target: number): number {", "container": null, "callable": "lengthOfLongestSubsequence", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "target", "type": "number" } ], "return_t...
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...
typescript
{ "raw_signature": "function sumCounts(nums: number[]): number {", "container": null, "callable": "sumCounts", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "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...
typescript
{ "raw_signature": "function findKOr(nums: number[], k: number): number {", "container": null, "callable": "findKOr", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/...
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, "...
typescript
{ "raw_signature": "function minSum(nums1: number[], nums2: number[]): number {", "container": null, "callable": "minSum", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" } ], "return_type": "number", "signature_source"...
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...
typescript
{ "raw_signature": "function minIncrementOperations(nums: number[], k: number): number {", "container": null, "callable": "minIncrementOperations", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", ...
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_...
typescript
{ "raw_signature": "function maximumPoints(edges: number[][], coins: number[], k: number): number {", "container": null, "callable": "maximumPoints", "parameters": [ { "name": "edges", "type": "number[][]" }, { "name": "coins", "type": "number[]" }, { "name": "k...
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...
typescript
{ "raw_signature": "function findChampion(grid: number[][]): number {", "container": null, "callable": "findChampion", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
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, ...
typescript
{ "raw_signature": "function findChampion(n: number, edges: number[][]): number {", "container": null, "callable": "findChampion", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" } ], "return_type": "number", "signature_sou...