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
3,071
minimum-operations-to-write-the-letter-y-on-a-grid
Medium
You are given a 0-indexed n x n grid where n is odd, and grid[r][c] is 0, 1, or 2. We say that a cell belongs to the Letter Y if it belongs to one of the following: - The diagonal starting at the top-left cell and ending at the center cell of the grid. - The diagonal starting at the top-right cell and ending at the c...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 4\n assert candidate(grid = [[1, 0, 2], [0, 1, 0], [2, 0, 1]]) == 4\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 3\n assert candidate(grid = [[1, 0, 1], [0, 0, 0], ...
[ "[[1,2,2],[1,1,0],[0,1,0]]", "[[0,1,0,1,0],[2,1,0,1,2],[2,2,2,0,1],[2,2,2,2,2],[2,1,2,2,2]]" ]
[]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minimumOperationsToWriteY", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:58", "tests_total": 76,...
typescript
{ "raw_signature": "function minimumOperationsToWriteY(grid: number[][]): number {", "container": null, "callable": "minimumOperationsToWriteY", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_sou...
3,072
distribute-elements-into-two-arrays-ii
Hard
You are given a 1-indexed array of integers nums of length n. We define a function greaterCount such that greaterCount(arr, val) returns the number of elements in arr that are strictly greater than val. You need to distribute all the elements of nums between two arrays arr1 and arr2 using n operations. In the first o...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 2, 1, 5, 4, 9, 8, 7, 6, 10]) == [3, 1, 9, 8, 7, 6, 2, 5, 4, 10]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == [100, 80, 70, 60, 50, 40, 30, 20, 10, 90]\n assert candidate(nums = [1, 1, 1, 1, 1, ...
[ "[2,1,3,3]", "[5,14,3,1,2]", "[3,3,3,3]" ]
[ "We need a data structure that counts the number of integers greater than a given value x and supports insertion.", "Use Segment Tree or Binary Indexed Tree by compressing the numbers to the range [1,n]." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().resultArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:01", "tests_total": 106, "tests_dro...
typescript
{ "raw_signature": "function resultArray(nums: number[]): number[] {", "container": null, "callable": "resultArray", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
3,074
apple-redistribution-into-boxes
Easy
You are given an array apple of size n and an array capacity of size m. There are n packs where the i^th pack contains apple[i] apples. There are m boxes as well, and the i^th box has a capacity of capacity[i] apples. Return the minimum number of boxes you need to select to redistribute these n packs of apples into b...
{ "language": "python", "source": "def check(candidate):\n assert candidate(apple = [10, 20, 30],capacity = [15, 10, 25]) == None\n assert candidate(apple = [10, 20, 30, 40],capacity = [10, 10, 10, 10, 10, 10, 10]) == None\n assert candidate(apple = [45, 5],capacity = [50]) == 1\n assert candidate(apple...
[ "[1,3,2]\n[4,3,1,5,2]", "[5,5,5]\n[2,4,2,7]" ]
[ "Sort array capacity in non-decreasing order.", "Greedily select boxes with the largest capacities to redistribute apples optimally." ]
{ "canonical_parameter_names": [ "apple", "capacity" ], "leetcode_dataset_entry_point": "Solution().minimumBoxes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:06", "tests_total":...
typescript
{ "raw_signature": "function minimumBoxes(apple: number[], capacity: number[]): number {", "container": null, "callable": "minimumBoxes", "parameters": [ { "name": "apple", "type": "number[]" }, { "name": "capacity", "type": "number[]" } ], "return_type": "number", ...
3,075
maximize-happiness-of-selected-children
Medium
You are given an array happiness of length n, and a positive integer k. There are n children standing in a queue, where the i^th child has happiness value happiness[i]. You want to select k children from these n children in k turns. In each turn, when you select a child, the happiness value of all the children that h...
{ "language": "python", "source": "def check(candidate):\n assert candidate(happiness = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 30\n assert candidate(happiness = [10, 20, 30, 40, 50],k = 5) == 140\n assert candidate(happiness = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 15\n assert candidate(happiness ...
[ "[1,2,3]\n2", "[1,1,1,1]\n2", "[2,3,4,5]\n1" ]
[ "Since all the unselected numbers are decreasing at the same rate, we should greedily select k largest values.", "The ith largest number (i = 1, 2, 3,…k) should decrease by (i - 1) when it is picked.", "Add 0 if the decreased value is negative." ]
{ "canonical_parameter_names": [ "happiness", "k" ], "leetcode_dataset_entry_point": "Solution().maximumHappinessSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:09", "tests_tot...
typescript
{ "raw_signature": "function maximumHappinessSum(happiness: number[], k: number): number {", "container": null, "callable": "maximumHappinessSum", "parameters": [ { "name": "happiness", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number"...
3,076
shortest-uncommon-substring-in-an-array
Medium
You are given an array arr of size n consisting of non-empty strings. Find a string array answer of size n such that: - answer[i] is the shortest substring of arr[i] that does not occur as a substring in any other string in arr. If multiple such substrings exist, answer[i] should be the lexicographically smallest. An...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = ['abcabc', 'bcabc', 'cabc', 'abcd']) == ['abca', '', '', 'd']\n assert candidate(arr = ['aaa', 'aab', 'aba', 'abb']) == ['aaa', 'aab', 'ba', 'bb']\n assert candidate(arr = ['abc', 'bcd', 'abcd']) == ['', '', 'abcd']\n asse...
[ "[\"cab\",\"ad\",\"bad\",\"c\"]", "[\"abc\",\"bcd\",\"abcd\"]" ]
[ "Try a brute force solution where you check every substring.", "Use a Hash map to keep track of the substrings." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().shortestSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:11", "tests_total": 109, "tes...
typescript
{ "raw_signature": "function shortestSubstrings(arr: string[]): string[] {", "container": null, "callable": "shortestSubstrings", "parameters": [ { "name": "arr", "type": "string[]" } ], "return_type": "string[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
3,077
maximum-strength-of-k-disjoint-subarrays
Hard
You are given an array of integers nums with length n, and a positive odd integer k. Select exactly k disjoint subarrays sub_1, sub_2, ..., sub_k from nums such that the last element of sub_i appears before the first element of sub_{i+1} for all 1 <= i <= k-1. The goal is to maximize their combined strength. The stre...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [-10, -20, -30, -40, -50],k = 3) == 100\n assert candidate(nums = [12, -2, -2, -2, -2],k = 5) == 64\n assert candidate(nums = [5, 1, 2, 3, 4, 5, 6],k = 3) == 41\n assert candidate(nums = [1, -1, 1, -1, 1, -1],k = 3) == 6\...
[ "[1,2,3,-1,2]\n3", "[12,-2,-2,-2,-2]\n5", "[-1,-2,-3]\n1" ]
[ "Let dp[i][j][x == 0/1] be the maximum strength to select j disjoint subarrays from the original array’s suffix (nums[i..(n - 1)]), x denotes whether we select the element or not.", "Initially dp[n][0][0] == 0.", "We have dp[i][j][1] = nums[i] * get(j) + max(dp[i + 1][j - 1][0], dp[i + 1][j][1]) where get(j) = ...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumStrength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:14", "tests_total": 108,...
typescript
{ "raw_signature": "function maximumStrength(nums: number[], k: number): number {", "container": null, "callable": "maximumStrength", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_sou...
3,079
find-the-sum-of-encrypted-integers
Easy
You are given an integer array nums containing positive integers. We define a function encrypt such that encrypt(x) replaces every digit in x with the largest digit in x. For example, encrypt(523) = 555 and encrypt(213) = 333. Return the sum of encrypted elements. Example 1: Input: nums = [1,2,3] Output: 6 Explanati...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [523, 213, 111]) == 999\n assert candidate(nums = [523, 213, 111]) == 999\n assert candidate(nums = [1, 10, 100, 1000]) == 1234\n assert candidate(nums = [999, 100, 101]) == 1221\n assert candidate(nums = [9, 8, 7, 6, ...
[ "[1,2,3]", "[10,21,31]" ]
[ "Encrypted numbers are of the form 11…1 * maxDigit." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().sumOfEncryptedInt", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:18", "tests_total": 102, "tes...
typescript
{ "raw_signature": "function sumOfEncryptedInt(nums: number[]): number {", "container": null, "callable": "sumOfEncryptedInt", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
3,080
mark-elements-on-array-by-performing-queries
Medium
You are given a 0-indexed array nums of size n consisting of positive integers. You are also given a 2D array queries of size m where queries[i] = [index_i, k_i]. Initially all elements of the array are unmarked. You need to apply m queries on the array in order, where on the i^th query you do the following: - Mark...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [[4, 1], [0, 2], [2, 2]]) == [90, 40, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [[0, 2], [1, 1]]) == [90, 50]\n assert candidate(nums = [5, 3, 8, 1, 4],queries = [[2, 1], [4, ...
[ "[1,2,2,1,2,3,1]\n[[1,2],[3,3],[4,2]]", "[1,4,2,3]\n[[0,1]]" ]
[ "Use another array to keep track of marked indices.", "Sort the array nums to be able to find the smallest unmarked elements quickly in each query." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().unmarkedSumArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:21", "tests_total...
typescript
{ "raw_signature": "function unmarkedSumArray(nums: number[], queries: number[][]): number[] {", "container": null, "callable": "unmarkedSumArray", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "queries", "type": "number[][]" } ], "return_type": "n...
3,081
replace-question-marks-in-string-to-minimize-its-value
Medium
You are given a string s. s[i] is either a lowercase English letter or '?'. For a string t having length m containing only lowercase English letters, we define the function cost(i) for an index i as the number of characters equal to t[i] that appeared before it, i.e. in the range [0, i - 1]. The value of t is the sum...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbcc??\") == \"aabbccde\"\n assert candidate(s = \"abcabcabc???\") == \"abcabcabcdef\"\n assert candidate(s = \"a????b\") == \"acdefb\"\n assert candidate(s = \"a\") == \"a\"\n assert candidate(s = \"????????\") == \"...
[ "\"???\"", "\"a?a?\"" ]
[ "The cost does not depend on the order of characters. If a character c appears x times, the cost is exactly 0 + 1 + 2 + … + (x - 1) = x * (x - 1) / 2.", "We know the total number of question marks; for each one, we should select the letter with the minimum frequency to replace it.", "The letter selection can be...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minimizeStringValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:24", "tests_total": 38, "tests...
typescript
{ "raw_signature": "function minimizeStringValue(s: string): string {", "container": null, "callable": "minimizeStringValue", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
3,082
find-the-sum-of-the-power-of-all-subsequences
Hard
You are given an integer array nums of length n and a positive integer k. The power of an array of integers is defined as the number of subsequences with their sum equal to k. Return the sum of power of all subsequences of nums. Since the answer may be very large, return it modulo 10^9 + 7. Example 1: Input: num...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 40\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 15) == 8064\n assert candidate(nums = [1, 2, 4, 8, 16],k = 31) == 1\n assert candidate(nums = [10, 20, 30],k = 60) == 1\n assert...
[ "[1,2,3]\n3", "[2,3,3]\n5", "[1,2,3]\n7" ]
[ "If there is a subsequence of length j with the sum of elements k, it contributes 2^{n - j} to the answer.", "Let dp[i][j] represent the number of subsequences in the subarray nums[0..i] which have a sum of j.", "We can find the dp[i][k] for all 0 <= i <= n-1 and multiply them with 2^{n - j} to get final answer...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().sumOfPower", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:26", "tests_total": 103, "t...
typescript
{ "raw_signature": "function sumOfPower(nums: number[], k: number): number {", "container": null, "callable": "sumOfPower", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "lee...
3,083
existence-of-a-substring-in-a-string-and-its-reverse
Easy
Given a string s, find any substring of length 2 which is also present in the reverse of s. Return true if such a substring exists, and false otherwise. Example 1: Input: s = "leetcode" Output: true Explanation: Substring "ee" is of length 2 which is also present in reverse(s) == "edocteel". Example 2: Input: s = ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcba\") == True\n assert candidate(s = \"deified\") == True\n assert candidate(s = \"abab\") == True\n assert candidate(s = \"ab\") == False\n assert candidate(s = \"mnopqr\") == False\n assert candidate(s = \"aa\")...
[ "\"leetcode\"", "\"abcba\"", "\"abcd\"" ]
[ "Make a new string by reversing the string s.", "For every substring of length 2 in s, check if there is a corresponding substring in the reverse of s." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().isSubstringPresent", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:28", "tests_total": 122, "tests...
typescript
{ "raw_signature": "function isSubstringPresent(s: string): boolean {", "container": null, "callable": "isSubstringPresent", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
3,084
count-substrings-starting-and-ending-with-given-character
Medium
You are given a string s and a character c. Return the total number of substrings of s that start and end with c. Example 1: Input: s = "abada", c = "a" Output: 6 Explanation: Substrings starting and ending with "a" are: "abada", "abada", "abada", "abada", "abada", "abada". Example 2: Input: s = "zzz", c = "z" Outp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzz\",c = \"z\") == 6\n assert candidate(s = \"abcabcabc\",c = \"b\") == 6\n assert candidate(s = \"abcdefg\",c = \"f\") == 1\n assert candidate(s = \"abcabcabc\",c = \"a\") == 6\n assert candidate(s = \"hello\",c = \"l...
[ "\"abada\"\n\"a\"", "\"zzz\"\n\"z\"" ]
[ "Count the number of characters 'c' in string s, let’s call it m.", "We can select 2 numbers i and j such that i <= j are the start and end indices of substring. Note that i and j can be the same.", "The answer is m * (m + 1) / 2." ]
{ "canonical_parameter_names": [ "s", "c" ], "leetcode_dataset_entry_point": "Solution().countSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:30", "tests_total": 105, ...
typescript
{ "raw_signature": "function countSubstrings(s: string, c: string): number {", "container": null, "callable": "countSubstrings", "parameters": [ { "name": "s", "type": "string" }, { "name": "c", "type": "string" } ], "return_type": "number", "signature_source": "lee...
3,085
minimum-deletions-to-make-string-k-special
Medium
You are given a string word and an integer k. We consider word to be k-special if |freq(word[i]) - freq(word[j])| <= k for all indices i and j in the string. Here, freq(x) denotes the frequency of the character x in word, and |y| denotes the absolute value of y. Return the minimum number of characters you need to de...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"abacabadaba\",k = 2) == 3\n assert candidate(word = \"abacabadabacaba\",k = 3) == 4\n assert candidate(word = \"xyz\",k = 0) == 0\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 10...
[ "\"aabcaba\"\n0", "\"dabdcbdcdcd\"\n2", "\"aaabaaa\"\n2" ]
[ "Count the frequency of each letter.", "Suppose we select several characters as the final answer, and let x be the character with the smallest frequency in the answer. It can be shown that out of the selected characters, the optimal solution will never delete an occurrence of character x to obtain the answer.", ...
{ "canonical_parameter_names": [ "word", "k" ], "leetcode_dataset_entry_point": "Solution().minimumDeletions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:33", "tests_total": 53,...
typescript
{ "raw_signature": "function minimumDeletions(word: string, k: number): number {", "container": null, "callable": "minimumDeletions", "parameters": [ { "name": "word", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_sourc...
3,086
minimum-moves-to-pick-k-ones
Hard
You are given a binary array nums of length n, a positive integer k and a non-negative integer maxChanges. Alice plays a game, where the goal is for Alice to pick up k ones from nums using the minimum number of moves. When the game starts, Alice picks up any index aliceIndex in the range [0, n - 1] and stands there. I...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5,maxChanges = 5) == 8\n assert candidate(nums = [1, 1, 0, 0, 0, 0, 0, 0, 0, 1],k = 3,maxChanges = 2) == 3\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 2,maxChanges = 1) == ...
[ "[1,1,0,0,0,1,1,0,0,1]\n3\n1", "[0,0,0,0]\n2\n3" ]
[ "Ones created using a change require 2 moves. Hence except for the immediate neighbors of the index where we move all the ones, we should try to use change operations.", "For some subset of ones, it is always better to move the ones to the median position.", "We only need to be concerned with the indices where ...
{ "canonical_parameter_names": [ "nums", "k", "maxChanges" ], "leetcode_dataset_entry_point": "Solution().minimumMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:35", "tes...
typescript
{ "raw_signature": "function minimumMoves(nums: number[], k: number, maxChanges: number): number {", "container": null, "callable": "minimumMoves", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" }, { "name": "maxChanges",...
3,090
maximum-length-substring-with-two-occurrences
Easy
Given a string s, return the maximum length of a substring such that it contains at most two occurrences of each character. Example 1: Input: s = "bcbbbcba" Output: 4 Explanation: The following substring has a length of 4 and contains at most two occurrences of each character: "bcbbbcba". Example 2: Input: s = "aaa...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 2\n assert candidate(s = \"aaabbbccc\") == 4\n assert candidate(s = \"aabbaa\") == 4\n assert candidate(s = \"abababab\") == 4\n assert candidate(s = \"aabacbebebe\") == 6\n assert candidate(s = \"aba...
[ "\"bcbbbcba\"", "\"aaaa\"" ]
[ "We can try all substrings by brute-force since the constraints are very small." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().maximumLengthSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:40", "tests_total": 78, "te...
typescript
{ "raw_signature": "function maximumLengthSubstring(s: string): number {", "container": null, "callable": "maximumLengthSubstring", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
3,091
apply-operations-to-make-sum-of-array-greater-than-or-equal-to-k
Medium
You are given a positive integer k. Initially, you have an array nums = [1]. You can perform any of the following operations on the array any number of times (possibly zero): - Choose any element in the array and increase its value by 1. - Duplicate any element in the array and add it to the end of the array. Return...
{ "language": "python", "source": "def check(candidate):\n assert candidate(k = 100) == 18\n assert candidate(k = 20) == 7\n assert candidate(k = 1) == 0\n assert candidate(k = 15) == 6\n assert candidate(k = 11) == 5\n assert candidate(k = 3) == 2\n assert candidate(k = 100000) == 631\n ass...
[ "11", "1" ]
[ "It is optimal to make all the increase operations first and all the duplicate operations last.", "Iterate over all possible number of increase operations that can be done and find the corresponding number of duplicate operations." ]
{ "canonical_parameter_names": [ "k" ], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:42", "tests_total": 58, "tests_dropp...
typescript
{ "raw_signature": "function minOperations(k: number): number {", "container": null, "callable": "minOperations", "parameters": [ { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,092
most-frequent-ids
Medium
The problem involves tracking the frequency of IDs in a collection that changes over time. You have two integer arrays, nums and freq, of equal length n. Each element in nums represents an ID, and the corresponding element in freq indicates how many times that ID should be added to or removed from the collection at eac...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 2, 3, 3, 3],freq = [1, 1, 1, -1, -1, -1]) == [1, 1, 2, 2, 2, 2]\n assert candidate(nums = [1, 1, 1, 1, 1],freq = [-1, -1, -1, -1, -1]) == [-1, -2, -3, -4, -5]\n assert candidate(nums = [2, 3, 2, 1],freq = [3, 2, -3, 1...
[ "[2,3,2,1]\n[3,2,-3,1]", "[5,5,3]\n[2,-2,1]" ]
[ "Use an ordered set for maintaining the occurrences of each ID.", "After step i find the occurrences of nums[i].", "Change the occurrences of nums[i] in the ordered set." ]
{ "canonical_parameter_names": [ "nums", "freq" ], "leetcode_dataset_entry_point": "Solution().mostFrequentIDs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:44", "tests_total": 1...
typescript
{ "raw_signature": "function mostFrequentIDs(nums: number[], freq: number[]): number[] {", "container": null, "callable": "mostFrequentIDs", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "freq", "type": "number[]" } ], "return_type": "number[]", ...
3,093
longest-common-suffix-queries
Hard
You are given two arrays of strings wordsContainer and wordsQuery. For each wordsQuery[i], you need to find a string from wordsContainer that has the longest common suffix with wordsQuery[i]. If there are two or more strings in wordsContainer that share the longest common suffix, find the string that is the smallest i...
{ "language": "python", "source": "def check(candidate):\n assert candidate(wordsContainer = ['banana', 'mango', 'papaya'],wordsQuery = ['ana', 'ango', 'aya']) == [0, 1, 2]\n assert candidate(wordsContainer = ['abcde', 'bcde', 'cde', 'de', 'e'],wordsQuery = ['cde', 'de', 'e', 'a', 'b']) == [2, 3, 4, 4, 4]\n ...
[ "[\"abcd\",\"bcd\",\"xbcd\"]\n[\"cd\",\"bcd\",\"xyz\"]", "[\"abcdefgh\",\"poiuygh\",\"ghghgh\"]\n[\"gh\",\"acbfgh\",\"acbfegh\"]" ]
[ "If we reverse the strings, the problem changes to finding the longest common prefix.", "Build a Trie, each node is a letter and only saves the best word’s index in each node, based on the criteria." ]
{ "canonical_parameter_names": [ "wordsContainer", "wordsQuery" ], "leetcode_dataset_entry_point": "Solution().stringIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:47", "t...
typescript
{ "raw_signature": "function stringIndices(wordsContainer: string[], wordsQuery: string[]): number[] {", "container": null, "callable": "stringIndices", "parameters": [ { "name": "wordsContainer", "type": "string[]" }, { "name": "wordsQuery", "type": "string[]" } ], "...
3,095
shortest-subarray-with-or-at-least-k-i
Easy
You are given an array nums of non-negative integers and an integer k. An array is called special if the bitwise OR of all of its elements is at least k. Return the length of the shortest special non-empty subarray of nums, or return -1 if no special subarray exists. Example 1: Input: nums = [1,2,3], k = 2 Output: ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 0],k = 1) == -1\n assert candidate(nums = [5, 5, 5, 5],k = 5) == 1\n assert candidate(nums = [1, 2],k = 0) == 1\n assert candidate(nums = [4, 5, 6, 7],k = 12) == -1\n assert candidate(nums = [1, 2, 3],k = 2) == ...
[ "[1,2,3]\n2", "[2,1,8]\n10", "[1,2]\n0" ]
[ "The constraints are small. Brute force checking all the subarrays." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().minimumSubarrayLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:49", "tests_total"...
typescript
{ "raw_signature": "function minimumSubarrayLength(nums: number[], k: number): number {", "container": null, "callable": "minimumSubarrayLength", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "s...
3,096
minimum-levels-to-gain-more-points
Medium
You are given a binary array possible of length n. Alice and Bob are playing a game that consists of n levels. Some of the levels in the game are impossible to clear while others can always be cleared. In particular, if possible[i] == 0, then the i^th level is impossible to clear for both the players. A player gains 1...
{ "language": "python", "source": "def check(candidate):\n assert candidate(possible = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [0, 0, 0, 0, 1, 1, 1, 1]) == -1\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(possible = [0, 0, 0, 0, 0, 0, 0, 0]) =...
[ "[1,0,1,0]", "[1,1,1,1,1]", "[0,0]" ]
[ "Change all 0 in possible array into -1.", "We need to find the shortest non-empty prefix of the new possible array such that the sum of elements in it is strictly larger than the remaining part." ]
{ "canonical_parameter_names": [ "possible" ], "leetcode_dataset_entry_point": "Solution().minimumLevels", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:52", "tests_total": 114, "tes...
typescript
{ "raw_signature": "function minimumLevels(possible: number[]): number {", "container": null, "callable": "minimumLevels", "parameters": [ { "name": "possible", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
3,097
shortest-subarray-with-or-at-least-k-ii
Medium
You are given an array nums of non-negative integers and an integer k. An array is called special if the bitwise OR of all of its elements is at least k. Return the length of the shortest special non-empty subarray of nums, or return -1 if no special subarray exists. Example 1: Input: nums = [1,2,3], k = 2 Output: ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 1\n assert candidate(nums = [0, 0, 0],k = 1) == -1\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 10) == 2\n assert candidate(nums = [5, 5, 5, 5],k = 5) == 1\n assert candidat...
[ "[1,2,3]\n2", "[2,1,8]\n10", "[1,2]\n0" ]
[ "For each nums[i], we can maintain each subarray’s bitwise OR result ending with it.", "The property of bitwise OR is that it never unsets any bits and only sets new bits", "So the number of different results for each nums[i] is at most the number of bits 32." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().minimumSubarrayLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:54", "tests_total"...
typescript
{ "raw_signature": "function minimumSubarrayLength(nums: number[], k: number): number {", "container": null, "callable": "minimumSubarrayLength", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "s...
3,098
find-the-sum-of-subsequence-powers
Hard
You are given an integer array nums of length n, and a positive integer k. The power of a subsequence is defined as the minimum absolute difference between any two elements in the subsequence. Return the sum of powers of all subsequences of nums which have length equal to k. Since the answer may be large, return it ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [-10, -20, -30, -40, -50],k = 3) == 110\n assert candidate(nums = [100, 200, 300, 400, 500, 600],k = 6) == 100\n assert candidate(nums = [1, 2, 3, 4],k = 3) == 4\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 0\n ...
[ "[1,2,3,4]\n3", "[2,2]\n2", "[4,3,-1]\n2" ]
[ "Sort nums.", "There are at most n^2 distinct differences.", "For a particular difference d, let dp[len][i][j] be the number of subsequences of length len in the subarray nums[0..i] where the last element picked was at index j.", "For each index, we can check if it can be picked if nums[i] - nums[j] <= d." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().sumOfPowers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:56", "tests_total": 120, "...
typescript
{ "raw_signature": "function sumOfPowers(nums: number[], k: number): number {", "container": null, "callable": "sumOfPowers", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "l...
3,099
harshad-number
Easy
An integer divisible by the sum of its digits is said to be a Harshad number. You are given an integer x. Return the sum of the digits of x if x is a Harshad number, otherwise, return -1. Example 1: Input: x = 18 Output: 9 Explanation: The sum of digits of x is 9. 18 is divisible by 9. So 18 is a Harshad number and t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(x = 50) == 5\n assert candidate(x = 23) == -1\n assert candidate(x = 10) == 1\n assert candidate(x = 18) == 9\n assert candidate(x = 1) == 1\n assert candidate(x = 90) == 9\n assert candidate(x = 57) == -1\n assert c...
[ "18", "23" ]
[ "Use a while loop and divide x by 10 to find the sum of the digits of x." ]
{ "canonical_parameter_names": [ "x" ], "leetcode_dataset_entry_point": "Solution().sumOfTheDigitsOfHarshadNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:58", "tests_total": 53...
typescript
{ "raw_signature": "function sumOfTheDigitsOfHarshadNumber(x: number): number {", "container": null, "callable": "sumOfTheDigitsOfHarshadNumber", "parameters": [ { "name": "x", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": ...
3,100
water-bottles-ii
Medium
You are given two integers numBottles and numExchange. numBottles represents the number of full water bottles that you initially have. In one operation, you can perform one of the following operations: - Drink any number of full water bottles turning them into empty bottles. - Exchange numExchange empty bottles with ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(numBottles = 10,numExchange = 3) == 13\n assert candidate(numBottles = 2,numExchange = 3) == 2\n assert candidate(numBottles = 13,numExchange = 6) == 15\n assert candidate(numBottles = 100,numExchange = 1) == 114\n assert can...
[ "13\n6", "10\n3" ]
[ "Simulate the process step by step. At each step, drink numExchange bottles of water then exchange them for a full bottle. Keep repeating this step until you cannot exchange bottles anymore." ]
{ "canonical_parameter_names": [ "numBottles", "numExchange" ], "leetcode_dataset_entry_point": "Solution().maxBottlesDrunk", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:01", "te...
typescript
{ "raw_signature": "function maxBottlesDrunk(numBottles: number, numExchange: number): number {", "container": null, "callable": "maxBottlesDrunk", "parameters": [ { "name": "numBottles", "type": "number" }, { "name": "numExchange", "type": "number" } ], "return_type"...
3,101
count-alternating-subarrays
Medium
You are given a binary array nums. We call a subarray alternating if no two adjacent elements in the subarray have the same value. Return the number of alternating subarrays in nums. Example 1: Input: nums = [0,1,1,1] Output: 5 Explanation: The following subarrays are alternating: [0], [1], [1], [1], and [0,1]. Ex...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 1, 1, 0, 0]) == 8\n assert candidate(nums = [0, 1, 0, 1, 0, 1]) == 21\n assert candidate(nums = [1, 0, 1, 0, 1]) == 15\n assert candidate(nums = [1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 0, 0, 1, 0, 1, 1,...
[ "[0,1,1,1]", "[1,0,1,0]" ]
[ "Try using dynamic programming.", "Let dp[i] be the number of alternating subarrays ending at index i.", "The final answer is the sum of dp[i] over all indices i from 0 to n - 1." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countAlternatingSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:03", "tests_total": 110...
typescript
{ "raw_signature": "function countAlternatingSubarrays(nums: number[]): number {", "container": null, "callable": "countAlternatingSubarrays", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source"...
3,102
minimize-manhattan-distances
Hard
You are given an array points representing integer coordinates of some points on a 2D plane, where points[i] = [x_i, y_i]. The distance between two points is defined as their Manhattan distance. Return the minimum possible value for maximum distance between any two points by removing exactly one point. Example 1: I...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 4\n assert candidate(points = [[1, 9], [9, 1], [2, 8], [8, 2], [3, 7], [7, 3], [4, 6], [6, 4], [5, 5]]) == 14\n assert candidate(points = [[1, 2], [4, 6], [8, 10], [15, 18]]) == 15\n ...
[ "[[3,10],[5,15],[10,2],[4,4]]", "[[1,1],[1,1],[1,1]]" ]
[ "Notice that the Manhattan distance between two points [x_i, y_i] and [x_j, y_j] is max({x_i - x_j + y_i - y_j, x_i - x_j - y_i + y_j, - x_i + x_j + y_i - y_j, - x_i + x_j - y_i + y_j}).", "If you replace points as [x_i - y_i, x_i + y_i] then the Manhattan distance is max(max(x_i) - min(x_i), max(y_i) - min(y_i)...
{ "canonical_parameter_names": [ "points" ], "leetcode_dataset_entry_point": "Solution().minimumDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:06", "tests_total": 155, "tes...
typescript
{ "raw_signature": "function minimumDistance(points: number[][]): number {", "container": null, "callable": "minimumDistance", "parameters": [ { "name": "points", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
3,105
longest-strictly-increasing-or-strictly-decreasing-subarray
Easy
You are given an array of integers nums. Return the length of the longest subarray of nums which is either strictly increasing or strictly decreasing. Example 1: Input: nums = [1,4,3,3,2] Output: 2 Explanation: The strictly increasing subarrays of nums are [1], [2], [3], [3], [4], and [1,4]. The strictly decreasing s...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 4, 7, 8, 6, 9]) == 3\n assert candidate(nums = [1, 2, 2, 3, 4, 5]) == 4\n assert candidate(nums = [10, 9, 4, 3, 3, 2, 1]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candida...
[ "[1,4,3,3,2]", "[3,3,3,3]", "[3,2,1]" ]
[]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().longestMonotonicSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:10", "tests_total": 139,...
typescript
{ "raw_signature": "function longestMonotonicSubarray(nums: number[]): number {", "container": null, "callable": "longestMonotonicSubarray", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": ...
3,106
lexicographically-smallest-string-after-operations-with-constraint
Medium
You are given a string s and an integer k. Define a function distance(s_1, s_2) between two strings s_1 and s_2 of the same length n as: - The sum of the minimum distance between s_1[i] and s_2[i] when the characters from 'a' to 'z' are placed in a cyclic order, for all i in the range [0, n - 1]. For example, distan...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zbbz\",k = 3) == \"aaaz\"\n assert candidate(s = \"abc\",k = 1) == \"aac\"\n assert candidate(s = \"abc\",k = 0) == \"abc\"\n assert candidate(s = \"zzz\",k = 9) == \"aaa\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgf...
[ "\"zbbz\"\n3", "\"xaxcd\"\n4", "\"lol\"\n0" ]
[ "The problem can be approached greedily.", "For each index in order from 0 to n - 1, we try all letters from 'a' to 'z', selecting the first one as long as the current total distance accumulated is not larger than k." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().getSmallestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:12", "tests_total": 110, ...
typescript
{ "raw_signature": "function getSmallestString(s: string, k: number): string {", "container": null, "callable": "getSmallestString", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "string", "signature_source": ...
3,107
minimum-operations-to-make-median-of-array-equal-to-k
Medium
You are given an integer array nums and a non-negative integer k. In one operation, you can increase or decrease any element by 1. Return the minimum number of operations needed to make the median of nums equal to k. The median of an array is defined as the middle element of the array when it is sorted in non-decreas...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 3, 3, 7, 7, 9],k = 3) == 0\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3],k = 500000000) == 499999997\n assert candidate(nums = [2, 5, 6, 8, 5],k = ...
[ "[2,5,6,8,5]\n4", "[2,5,6,8,5]\n7", "[1,2,3,4,5,6]\n4" ]
[ "Sort nums in non-descending order.", "For all the smaller values on the left side of the median, change them to k if they are larger than k.", "For all the larger values on the right side of the median, change them to k if they are smaller than k." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().minOperationsToMakeMedianK", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:15", "tests_t...
typescript
{ "raw_signature": "function minOperationsToMakeMedianK(nums: number[], k: number): number {", "container": null, "callable": "minOperationsToMakeMedianK", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "num...
3,108
minimum-cost-walk-in-weighted-graph
Hard
There is an undirected weighted graph with n vertices labeled from 0 to n - 1. You are given the integer n and an array edges, where edges[i] = [u_i, v_i, w_i] indicates that there is an edge between vertices u_i and v_i with a weight of w_i. A walk on a graph is a sequence of vertices and edges. The walk starts and ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 10,edges = [[0, 1, 1], [2, 3, 2], [4, 5, 3], [6, 7, 4], [8, 9, 5]],query = [[0, 9], [1, 8]]) == [-1, -1]\n assert candidate(n = 6,edges = [[0, 1, 5], [1, 2, 4], [2, 3, 3], [3, 4, 2], [4, 5, 1]],query = [[0, 5], [2, 4]]) == [0, 0]\...
[ "5\n[[0,1,7],[1,3,7],[1,2,1]]\n[[0,3],[3,4]]", "3\n[[0,2,7],[0,1,15],[1,2,6],[1,2,1]]\n[[1,2]]" ]
[ "The intended solution uses Disjoint Set Union.", "Notice that, if u and v are not connected then the answer is -1, otherwise we can use all the edges from the connected component where both belong to." ]
{ "canonical_parameter_names": [ "n", "edges", "query" ], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:18", "tests_to...
typescript
{ "raw_signature": "function minimumCost(n: number, edges: number[][], query: number[][]): number[] {", "container": null, "callable": "minimumCost", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" }, { "name": "query",...
3,110
score-of-a-string
Easy
You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters. Return the score of s. Example 1: Input: s = "hello" Output: 13 Explanation: The ASCII values of the characters in s are: 'h' = 104, 'e' = 101, 'l' = 108, 'o' = 111. So, t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 25\n assert candidate(s = \"abracadabra\") == 78\n assert candidate(s = \"zzzz\") == 0\n assert candidate(s = \"zyx\") == 2\n assert candidate(s = \"mnopqr\") == 5\n assert candidate(...
[ "\"hello\"", "\"zaz\"" ]
[ "Sum the difference between all the adjacent characters by just taking the absolute difference of their ASCII values." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().scoreOfString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:23", "tests_total": 87, "tests_dropp...
typescript
{ "raw_signature": "function scoreOfString(s: string): number {", "container": null, "callable": "scoreOfString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,111
minimum-rectangles-to-cover-points
Medium
You are given a 2D integer array points, where points[i] = [x_i, y_i]. You are also given an integer w. Your task is to cover all the given points with rectangles. Each rectangle has its lower end at some point (x_1, 0) and its upper end at some point (x_2, y_2), where x_1 <= x_2, y_2 >= 0, and the condition x_2 - x_1...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],w = 1) == 3\n assert candidate(points = [[5, 5], [10, 10], [15, 15]],w = 5) == 2\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9...
[ "[[2,1],[1,0],[1,4],[1,8],[3,5],[4,6]]\n1", "[[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]]\n2", "[[2,3],[1,2]]\n0" ]
[ "The y values don't matter; only the x values matter.", "Sort all the points by x_i.", "Each time, select the smallest x value, x_0, from the unselected points, and then select all the points with x values not larger than x_0 + w." ]
{ "canonical_parameter_names": [ "points", "w" ], "leetcode_dataset_entry_point": "Solution().minRectanglesToCoverPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:25", "tests...
typescript
{ "raw_signature": "function minRectanglesToCoverPoints(points: number[][], w: number): number {", "container": null, "callable": "minRectanglesToCoverPoints", "parameters": [ { "name": "points", "type": "number[][]" }, { "name": "w", "type": "number" } ], "return_typ...
3,112
minimum-time-to-visit-disappearing-nodes
Medium
There is an undirected graph of n nodes. You are given a 2D array edges, where edges[i] = [u_i, v_i, length_i] describes an edge between node u_i and node v_i with a traversal time of length_i units. Additionally, you are given an array disappear, where disappear[i] denotes the time when the node i disappears from the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 2,edges = [[0, 1, 1]],disappear = [1, 1]) == [0, -1]\n assert candidate(n = 6,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5]],disappear = [1, 2, 3, 4, 5, 6]) == [0, 1, -1, -1, -1, -1]\n assert candidate(n = 4,ed...
[ "3\n[[0,1,2],[1,2,1],[0,2,4]]\n[1,1,5]", "3\n[[0,1,2],[1,2,1],[0,2,4]]\n[1,3,5]", "2\n[[0,1,1]]\n[1,1]" ]
[ "Use Dijkstra’s algorithm, but only visit nodes if you can reach them before disappearance." ]
{ "canonical_parameter_names": [ "n", "edges", "disappear" ], "leetcode_dataset_entry_point": "Solution().minimumTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:28", "test...
typescript
{ "raw_signature": "function minimumTime(n: number, edges: number[][], disappear: number[]): number[] {", "container": null, "callable": "minimumTime", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" }, { "name": "disap...
3,113
find-the-number-of-subarrays-where-boundary-elements-are-maximum
Hard
You are given an array of positive integers nums. Return the number of subarrays of nums, where the first and the last elements of the subarray are equal to the largest element in the subarray. Example 1: Input: nums = [1,4,3,3,2] Output: 6 Explanation: There are 6 subarrays which have the first and the last element...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 5, 4, 5]) == 8\n assert candidate(nums = [2, 1, 2, 1, 2]) == 8\n assert candidate(nums = [1, 3, 2, 3, 1, 3]) == 9\n assert candidate(nums = [1, 2, 2, 1]) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, ...
[ "[1,4,3,3,2]", "[3,3,3]", "[1]" ]
[ "For each element nums[i], we can count the number of valid subarrays ending with it.", "For each index i, find the nearest index j on its left (j < i) such that nums[j] < nums[i]. This can be done via a monotonic stack.", "For each index i, find the number of indices k in the window [j + 1, i] such that nums[k...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().numberOfSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:31", "tests_total": 110, "tes...
typescript
{ "raw_signature": "function numberOfSubarrays(nums: number[]): number {", "container": null, "callable": "numberOfSubarrays", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
3,114
latest-time-you-can-obtain-after-replacing-characters
Easy
You are given a string s representing a 12-hour format time where some of the digits (possibly none) are replaced with a "?". 12-hour times are formatted as "HH:MM", where HH is between 00 and 11, and MM is between 00 and 59. The earliest 12-hour time is 00:00, and the latest is 11:59. You have to replace all the "?"...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"10:?5\") == \"10:55\"\n assert candidate(s = \"??:5?\") == \"11:59\"\n assert candidate(s = \"1?:4?\") == \"11:49\"\n assert candidate(s = \"1?:?4\") == \"11:54\"\n assert candidate(s = \"11:?9\") == \"11:59\"\n asse...
[ "\"1?:?4\"", "\"0?:5?\"" ]
[ "Try using a brute force approach.", "Iterate over all possible times that can be generated from the string and find the latest one." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().findLatestTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:33", "tests_total": 121, "tests_dro...
typescript
{ "raw_signature": "function findLatestTime(s: string): string {", "container": null, "callable": "findLatestTime", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,115
maximum-prime-difference
Medium
You are given an integer array nums. Return an integer that is the maximum distance between the indices of two (not necessarily different) prime numbers in nums. Example 1: Input: nums = [4,2,9,5,3] Output: 3 Explanation: nums[1], nums[3], and nums[4] are prime. So the answer is |4 - 1| = 3. Example 2: Input: nums...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [97, 1, 97, 1, 97]) == 4\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 9\n assert candidate(nums = [100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 52, 49, 46, 43, 40, 37, 34, 31, 28, 25, 22, ...
[ "[4,2,9,5,3]", "[4,8,2,8]" ]
[ "Find all prime numbers in the nums.", "Find the first and the last prime number in the nums." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maximumPrimeDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:36", "tests_total": 53, ...
typescript
{ "raw_signature": "function maximumPrimeDifference(nums: number[]): number {", "container": null, "callable": "maximumPrimeDifference", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
3,116
kth-smallest-amount-with-single-denomination-combination
Hard
You are given an integer array coins representing coins of different denominations and an integer k. You have an infinite number of coins of each denomination. However, you are not allowed to combine coins of different denominations. Return the k^th smallest amount that can be made using these coins. Example 1: Inp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(coins = [15, 20, 25],k = 15) == 125\n assert candidate(coins = [4, 8, 12],k = 10) == 40\n assert candidate(coins = [2, 3, 5, 7],k = 12) == 15\n assert candidate(coins = [7, 11, 13],k = 15) == 52\n assert candidate(coins = [3,...
[ "[3,6,9]\n3", "[5,2]\n7" ]
[ "Binary search the answer x.", "Use the inclusion-exclusion principle to count the number of distinct amounts that can be made up to x." ]
{ "canonical_parameter_names": [ "coins", "k" ], "leetcode_dataset_entry_point": "Solution().findKthSmallest", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:38", "tests_total": 110...
typescript
{ "raw_signature": "function findKthSmallest(coins: number[], k: number): number {", "container": null, "callable": "findKthSmallest", "parameters": [ { "name": "coins", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_s...
3,117
minimum-sum-of-values-by-dividing-array
Hard
You are given two arrays nums and andValues of length n and m respectively. The value of an array is equal to the last element of that array. You have to divide nums into m disjoint contiguous subarrays such that for the i^th subarray [l_i, r_i], the bitwise AND of the subarray elements is equal to andValues[i], in o...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5],andValues = [5, 5]) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16],andValues = [0, 0, 0]) == 28\n assert candidate(nums = [8, 12, 10, 14],andValues = [8, 14]) == 24\n assert candidate(nums = [10...
[ "[1,4,3,3,2]\n[0,3,3,2]", "[2,3,5,7,7,7,5]\n[0,7,5]", "[1,2,3,4]\n[2]" ]
[ "Let dp[i][j] be the optimal answer to split nums[0..(i - 1)] into the first j andValues.", "dp[i][j] = min(dp[(i - z)][j - 1]) + nums[i - 1] over all x <= z <= y and dp[0][0] = 0, where x and y are the longest and shortest subarrays ending with nums[i - 1] and the bitwise-and of all the values in it is andValues...
{ "canonical_parameter_names": [ "nums", "andValues" ], "leetcode_dataset_entry_point": "Solution().minimumValueSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:40", "tests_tota...
typescript
{ "raw_signature": "function minimumValueSum(nums: number[], andValues: number[]): number {", "container": null, "callable": "minimumValueSum", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "andValues", "type": "number[]" } ], "return_type": "numbe...
3,120
count-the-number-of-special-characters-i
Easy
You are given a string word. A letter is called special if it appears both in lowercase and uppercase in word. Return the number of special letters in word. Example 1: Input: word = "aaAbcBC" Output: 3 Explanation: The special characters in word are 'a', 'b', and 'c'. Example 2: Input: word = "abc" Output: 0 Expla...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"abc\") == 0\n assert candidate(word = \"xyzXYZ\") == 3\n assert candidate(word = \"aabbcc\") == 0\n assert candidate(word = \"AABBCC\") == 0\n assert candidate(word = \"cCcCc\") == 1\n assert candidate(word = \"Aa...
[ "\"aaAbcBC\"", "\"abc\"", "\"abBCab\"" ]
[ "The constraints are small. For all 52 characters, check if they are present in word." ]
{ "canonical_parameter_names": [ "word" ], "leetcode_dataset_entry_point": "Solution().numberOfSpecialChars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:45", "tests_total": 159, "...
typescript
{ "raw_signature": "function numberOfSpecialChars(word: string): number {", "container": null, "callable": "numberOfSpecialChars", "parameters": [ { "name": "word", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
3,121
count-the-number-of-special-characters-ii
Medium
You are given a string word. A letter c is called special if it appears both in lowercase and uppercase in word, and every lowercase occurrence of c appears before the first uppercase occurrence of c. Return the number of special letters in word. Example 1: Input: word = "aaAbcBC" Output: 3 Explanation: The special ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"aAbBcCdDeEfFgG\") == 7\n assert candidate(word = \"AaBbCc\") == 0\n assert candidate(word = \"aabbCC\") == 0\n assert candidate(word = \"Aabbcc\") == 0\n assert candidate(word = \"abABcdCD\") == 4\n assert candida...
[ "\"aaAbcBC\"", "\"abc\"", "\"AbBCab\"" ]
[ "For each character c, store the first occurrence of its uppercase and the last occurrence of its lowercase." ]
{ "canonical_parameter_names": [ "word" ], "leetcode_dataset_entry_point": "Solution().numberOfSpecialChars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:48", "tests_total": 100, "...
typescript
{ "raw_signature": "function numberOfSpecialChars(word: string): number {", "container": null, "callable": "numberOfSpecialChars", "parameters": [ { "name": "word", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
3,122
minimum-number-of-operations-to-satisfy-conditions
Medium
You are given a 2D matrix grid of size m x n. In one operation, you can change the value of any cell to any non-negative number. You need to perform some operations such that each cell grid[i][j] is: - Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists). - Different from the cell to its right,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1], [2], [3]]) == 2\n assert candidate(grid = [[1, 1, 1], [0, 0, 0]]) == 3\n assert candidate(grid = [[0, 1, 2], [2, 1, 0], [0, 1, 2]]) == 2\n assert candidate(grid = [[9, 9], [9, 9], [9, 9]]) == 3\n assert candidate...
[ "[[1,0,2],[1,0,2]]", "[[1,1,1],[0,0,0]]", "[[1],[2],[3]]" ]
[]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:50", "tests_total": 108, "tes...
typescript
{ "raw_signature": "function minimumOperations(grid: number[][]): number {", "container": null, "callable": "minimumOperations", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
3,123
find-edges-in-shortest-paths
Hard
You are given an undirected weighted graph of n nodes numbered from 0 to n - 1. The graph consists of m edges represented by a 2D array edges, where edges[i] = [a_i, b_i, w_i] indicates that there is an edge between nodes a_i and b_i with weight w_i. Consider all the shortest paths from node 0 to node n - 1 in the gra...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,edges = [[0, 1, 2], [0, 2, 2], [1, 2, 3], [1, 3, 2], [2, 3, 1], [2, 4, 4], [3, 4, 2]]) == [False, True, False, False, True, False, True]\n assert candidate(n = 7,edges = [[0, 1, 2], [0, 2, 5], [1, 2, 1], [1, 3, 4], [2, 3, 2], [3...
[ "6\n[[0,1,4],[0,2,1],[1,3,2],[1,4,3],[1,5,1],[2,3,1],[3,5,3],[4,5,2]]", "4\n[[2,0,1],[0,1,1],[0,3,4],[3,2,2]]" ]
[ "Find all the shortest paths starting from nodes 0 and n - 1 to all other nodes.", "How to use the above calculated shortest paths to check if an edge is part of at least one shortest path from 0 to n - 1?" ]
{ "canonical_parameter_names": [ "n", "edges" ], "leetcode_dataset_entry_point": "Solution().findAnswer", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:53", "tests_total": 67, "t...
typescript
{ "raw_signature": "function findAnswer(n: number, edges: number[][]): boolean[] {", "container": null, "callable": "findAnswer", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" } ], "return_type": "boolean[]", "signature_s...
3,127
make-a-square-with-the-same-color
Easy
You are given a 2D matrix grid of size 3 x 3 consisting only of characters 'B' and 'W'. Character 'W' represents the white color, and character 'B' represents the black color. Your task is to change the color of at most one cell so that the matrix has a 2 x 2 square where all cells are of the same color. Return true ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [['B', 'W', 'B'], ['W', 'B', 'W'], ['B', 'W', 'B']]) == False\n assert candidate(grid = [['B', 'B', 'W'], ['B', 'B', 'W'], ['B', 'B', 'W']]) == True\n assert candidate(grid = [['B', 'W', 'B'], ['B', 'W', 'W'], ['B', 'W', 'B'...
[ "[[\"B\",\"W\",\"B\"],[\"B\",\"W\",\"W\"],[\"B\",\"W\",\"B\"]]", "[[\"B\",\"W\",\"B\"],[\"W\",\"B\",\"W\"],[\"B\",\"W\",\"B\"]]", "[[\"B\",\"W\",\"B\"],[\"B\",\"W\",\"W\"],[\"B\",\"W\",\"W\"]]" ]
[ "It is impossible to create 2 x 2 square with the same color by changing the color of at most one cell when the number of ‘W' or 'B’ in all squares is 2." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().canMakeSquare", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:57", "tests_total": 10, "tests_dr...
typescript
{ "raw_signature": "function canMakeSquare(grid: string[][]): boolean {", "container": null, "callable": "canMakeSquare", "parameters": [ { "name": "grid", "type": "string[][]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
3,128
right-triangles
Medium
You are given a 2D boolean matrix grid. A collection of 3 elements of grid is a right triangle if one of its elements is in the same row with another element and in the same column with the third element. The 3 elements may not be next to each other. Return an integer that is the number of right triangles that can be...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 36\n assert candidate(grid = [[0, 1, 0], [0, 1, 1], [0, 1, 0]]) == 2\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == 8\n assert candidate(grid =...
[ "[[0,1,0],[0,1,1],[0,1,0]]", "[[1,0,0,0],[0,1,0,1],[1,0,0,0]]", "[[1,0,1],[1,0,0],[1,0,0]]" ]
[ "If grid[x][y] is 1, it can form a right triangle with an element of grid with value 1 in the same row and an element of grid with value 1 in the same column.", "So we just need to count the number of 1s in each row and column.", "For each x, y with grid[x][y] = 1 if there are row[x] 1s in the row x and col[y] ...
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().numberOfRightTriangles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:00", "tests_total": 67, ...
typescript
{ "raw_signature": "function numberOfRightTriangles(grid: number[][]): number {", "container": null, "callable": "numberOfRightTriangles", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": ...
3,129
find-all-possible-stable-binary-arrays-i
Medium
You are given 3 positive integers num_zeros, num_ones, and limit. A binary array arr is called stable if: - The number of occurrences of 0 in arr is exactly num_zeros. - The number of occurrences of 1 in arr is exactly num_ones. - Each subarray of arr with a size greater than limit must contain at least one occurrenc...
{ "language": "python", "source": "def check(candidate):\n assert candidate(zero = 3,one = 5,limit = 3) == 40\n assert candidate(zero = 5,one = 5,limit = 4) == 242\n assert candidate(zero = 5,one = 5,limit = 2) == 84\n assert candidate(zero = 1,one = 1,limit = 1) == 2\n assert candidate(zero = 2,one ...
[ "1\n1\n2", "1\n2\n1", "3\n3\n2" ]
[ "Let dp[a][b][c = 0/1][d] be the number of stable arrays with exactly a 0s, b 1s and consecutive d value of c’s at the end.", "Try each case by appending a 0/1 at last to get the inductions." ]
{ "canonical_parameter_names": [ "zero", "one", "limit" ], "leetcode_dataset_entry_point": "Solution().numberOfStableArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:02", ...
typescript
{ "raw_signature": "function numberOfStableArrays(zero: number, one: number, limit: number): number {", "container": null, "callable": "numberOfStableArrays", "parameters": [ { "name": "zero", "type": "number" }, { "name": "one", "type": "number" }, { "name": "l...
3,130
find-all-possible-stable-binary-arrays-ii
Hard
You are given 3 positive integers num_zeros, num_ones, and limit. A binary array arr is called stable if: - The number of occurrences of 0 in arr is exactly num_zeros. - The number of occurrences of 1 in arr is exactly num_ones. - Each subarray of arr with a size greater than limit must contain at least one occurrenc...
{ "language": "python", "source": "def check(candidate):\n assert candidate(zero = 5,one = 5,limit = 4) == 242\n assert candidate(zero = 100,one = 100,limit = 50) == 375840050\n assert candidate(zero = 5,one = 5,limit = 2) == 84\n assert candidate(zero = 4,one = 4,limit = 3) == 62\n assert candidate(...
[ "1\n1\n2", "1\n2\n1", "3\n3\n2" ]
[ "Let dp[x][y][z = 0/1] be the number of stable arrays with exactly x zeros, y ones, and the last element is z. (0 or 1). dp[x][y][0] + dp[x][y][1] is the answer for given (x, y).", "If we have already placed x 1 and y 0, if we place a group of k 0, the number of ways is dp[x-k][y][1]. We can place a group with si...
{ "canonical_parameter_names": [ "zero", "one", "limit" ], "leetcode_dataset_entry_point": "Solution().numberOfStableArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:05", ...
typescript
{ "raw_signature": "function numberOfStableArrays(zero: number, one: number, limit: number): number {", "container": null, "callable": "numberOfStableArrays", "parameters": [ { "name": "zero", "type": "number" }, { "name": "one", "type": "number" }, { "name": "l...
3,131
find-the-integer-added-to-array-i
Easy
You are given two arrays of equal length, nums1 and nums2. Each element in nums1 has been increased (or decreased in the case of negative) by an integer, represented by the variable x. As a result, nums1 becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequenc...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [10],nums2 = [5]) == -5\n assert candidate(nums1 = [100, 200, 300],nums2 = [150, 250, 350]) == 50\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9, 10]) == 5\n assert candidate(nums1 = [7, 7, 7],nums2 = [10...
[ "[2,6,4]\n[9,7,5]", "[10]\n[5]", "[1,1,1,1]\n[1,1,1,1]" ]
[ "Notice that, after sorting both arrays, there should be a one-to-one correspondence between every element.", "Thus x = min(nums2) - min(nums1)." ]
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().addedInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:07", "tests_total": 10...
typescript
{ "raw_signature": "function addedInteger(nums1: number[], nums2: number[]): number {", "container": null, "callable": "addedInteger", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" } ], "return_type": "number", "signa...
3,132
find-the-integer-added-to-array-ii
Medium
You are given two integer arrays nums1 and nums2. We say that nums2 is reachable from nums1 with an integer x if there exist two elements in nums1 that, when removed, and x is added to all the remaining elements of nums1 (or subtracted in the case of a negative x), the resulting array becomes equal to nums2. Two array...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [20, 30, 40]) == -10\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [12, 22, 32]) == -18\n assert candidate(nums1 = [4, 20, 16, 12, 8],nums2 = [14, 18, 10]) == -2\n assert candidate(...
[ "[4,20,16,12,8]\n[14,18,10]", "[3,5,5,3]\n[7,7]" ]
[ "Try all possibilities to remove 2 elements from nums1.", "x should be equal to min(nums2) - min(nums1), check it naively." ]
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().minimumAddedInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:09", "tests_tot...
typescript
{ "raw_signature": "function minimumAddedInteger(nums1: number[], nums2: number[]): number {", "container": null, "callable": "minimumAddedInteger", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" } ], "return_type": "num...
3,133
minimum-array-end
Medium
You are given two integers n and x. You have to construct an array of positive integers nums of size n where for every 0 <= i < n - 1, nums[i + 1] is greater than nums[i], and the result of the bitwise AND operation between all elements of nums is x. Return the minimum possible value of nums[n - 1]. Example 1: Input...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,x = 8) == 11\n assert candidate(n = 5,x = 1) == 9\n assert candidate(n = 10,x = 1) == 19\n assert candidate(n = 5,x = 3) == 19\n assert candidate(n = 2,x = 7) == 15\n assert candidate(n = 1,x = 10) == 10\n assert ...
[ "3\n4", "2\n7" ]
[ "Each element of the array should be obtained by “merging” x and v where v = 0, 1, 2, …(n - 1).", "To merge x with another number v, keep the set bits of x untouched, for all the other bits, fill the set bits of v from right to left in order one by one.", "So the final answer is the “merge” of x and n - 1." ]
{ "canonical_parameter_names": [ "n", "x" ], "leetcode_dataset_entry_point": "Solution().minEnd", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:11", "tests_total": 106, "tests_dr...
typescript
{ "raw_signature": "function minEnd(n: number, x: number): number {", "container": null, "callable": "minEnd", "parameters": [ { "name": "n", "type": "number" }, { "name": "x", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets...
3,134
find-the-median-of-the-uniqueness-array
Hard
You are given an integer array nums. The uniqueness array of nums is the sorted array that contains the number of distinct elements of all the subarrays of nums. In other words, it is a sorted array consisting of distinct(nums[i..j]), for all 0 <= i <= j < nums.length. Here, distinct(nums[i..j]) denotes the number of ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 2\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1...
[ "[1,2,3]", "[3,4,3,4,5]", "[4,3,5,4]" ]
[ "Binary search over the answer.", "For a given x, you need to check if x is the median, to the left of the median, or to the right of the median. You can do that by counting the number of sub-arrays nums[i…j] such that distinct(num[i…j]) <= x.", "Use the sliding window to solve the counting problem in the hint ...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().medianOfUniquenessArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:14", "tests_total": 101, ...
typescript
{ "raw_signature": "function medianOfUniquenessArray(nums: number[]): number {", "container": null, "callable": "medianOfUniquenessArray", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "l...
3,137
minimum-number-of-operations-to-make-word-k-periodic
Medium
You are given a string word of size n, and an integer k such that k divides n. In one operation, you can pick any two indices i and j, that are divisible by k, then replace the substring of length k starting at i with the substring of length k starting at j. That is, replace the substring word[i..i + k - 1] with the s...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"xyzxyzxyzxyzxyzxyz\",k = 3) == 0\n assert candidate(word = \"xyzxyzxyzxyz\",k = 3) == 0\n assert candidate(word = \"abcdefghijabcdefghij\",k = 5) == 2\n assert candidate(word = \"abcabcabc\",k = 3) == 0\n assert cand...
[ "\"leetcodeleet\"\n4", "\"leetcoleet\"\n2" ]
[ "Calculate the frequency of each substring of length k that starts at an index that is divisible by k.", "The period of the final string will be the substring with the highest frequency." ]
{ "canonical_parameter_names": [ "word", "k" ], "leetcode_dataset_entry_point": "Solution().minimumOperationsToMakeKPeriodic", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:22", "t...
typescript
{ "raw_signature": "function minimumOperationsToMakeKPeriodic(word: string, k: number): number {", "container": null, "callable": "minimumOperationsToMakeKPeriodic", "parameters": [ { "name": "word", "type": "string" }, { "name": "k", "type": "number" } ], "return_typ...
3,138
minimum-length-of-anagram-concatenation
Medium
You are given a string s, which is known to be a concatenation of anagrams of some string t. Return the minimum possible length of the string t. An anagram is formed by rearranging the letters of a string. For example, "aab", "aba", and, "baa" are anagrams of "aab". Example 1: Input: s = "abba" Output: 2 Explanatio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"abababab\") == 2\n assert cand...
[ "\"abba\"", "\"cdef\"", "\"abcbcacabbaccba\"" ]
[ "The answer should be a divisor of s.length.", "Check each candidate naively." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minAnagramLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:26", "tests_total": 73, "tests_dr...
typescript
{ "raw_signature": "function minAnagramLength(s: string): number {", "container": null, "callable": "minAnagramLength", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,139
minimum-cost-to-equalize-array
Hard
You are given an integer array nums and two integers cost1 and cost2. You are allowed to perform either of the following operations any number of times: - Choose an index i from nums and increase nums[i] by 1 for a cost of cost1. - Choose two different indices i, j, from nums and increase nums[i] and nums[j] by 1 for ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 1],cost1 = 5,cost2 = 2) == 15\n assert candidate(nums = [1, 3, 5, 7, 9],cost1 = 2,cost2 = 4) == 40\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost1 = 1,cost2 = 2) == 0\n assert candidate(nums = [10, 10, ...
[ "[4,1]\n5\n2", "[2,3,3,3,5]\n2\n1", "[3,5,3]\n1\n3" ]
[ "How can you determine the minimum cost if you know the maximum value in the array once all values are made equal?", "If cost2 > cost1 * 2, we should just use cost1 to change all the values to the maximum one.", "Otherwise, it's optimal to choose the smallest two values and use cost2 to increase both of them.",...
{ "canonical_parameter_names": [ "nums", "cost1", "cost2" ], "leetcode_dataset_entry_point": "Solution().minCostToEqualizeArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:29...
typescript
{ "raw_signature": "function minCostToEqualizeArray(nums: number[], cost1: number, cost2: number): number {", "container": null, "callable": "minCostToEqualizeArray", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "cost1", "type": "number" }, { ...
3,142
check-if-grid-satisfies-conditions
Easy
You are given a 2D matrix grid of size m x n. You need to check if each cell grid[i][j] is: - Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists). - Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists). Return true if all the cells satisfy these conditions, o...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1], [2], [3]]) == False\n assert candidate(grid = [[5, 4, 3], [5, 4, 3], [5, 4, 3]]) == True\n assert candidate(grid = [[5, 4, 3, 2, 1], [5, 4, 3, 2, 1]]) == True\n assert candidate(grid = [[5, 4], [5, 3]]) == False\n ...
[ "[[1,0,2],[1,0,2]]", "[[1,1,1],[0,0,0]]", "[[1],[2],[3]]" ]
[ "Check if each column has same value in each cell.", "If the previous condition is satisfied, we can simply check the first cells in adjacent columns." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().satisfiesConditions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:35", "tests_total": 116, "t...
typescript
{ "raw_signature": "function satisfiesConditions(grid: number[][]): boolean {", "container": null, "callable": "satisfiesConditions", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
3,143
maximum-points-inside-the-square
Medium
You are given a 2D array points and a string s where, points[i] represents the coordinates of point i, and s[i] represents the tag of point i. A valid square is a square centered at the origin (0, 0), has edges parallel to the axes, and does not contain two points with the same tag. Return the maximum number of point...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 1], [-1, -1], [2, -2]],s = \"ccd\") == 0\n assert candidate(points = [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]],s = \"abcde\") == 5\n assert candidate(points = [[0, 1], [1, 0], [1, 1]],s = \"abc\") == 3\n assert ca...
[ "[[2,2],[-1,-2],[-4,4],[-3,1],[3,-3]]\n\"abdca\"", "[[1,1],[-2,-2],[-2,2]]\n\"abb\"", "[[1,1],[-1,-1],[2,-2]]\n\"ccd\"" ]
[ "The smallest edge length of a square to include point (x, y) is max(abs(x), abs(y)) * 2.", "Sort the points by max(abs(x), abs(y)) and try each edge length, check the included point tags." ]
{ "canonical_parameter_names": [ "points", "s" ], "leetcode_dataset_entry_point": "Solution().maxPointsInsideSquare", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:39", "tests_tota...
typescript
{ "raw_signature": "function maxPointsInsideSquare(points: number[][], s: string): number {", "container": null, "callable": "maxPointsInsideSquare", "parameters": [ { "name": "points", "type": "number[][]" }, { "name": "s", "type": "string" } ], "return_type": "numbe...
3,144
minimum-substring-partition-of-equal-character-frequency
Medium
Given a string s, you need to partition it into one or more balanced substrings. For example, if s == "ababcc" then ("abab", "c", "c"), ("ab", "abc", "c"), and ("ababcc") are all valid partitions, but ("a", "bab", "cc"), ("aba", "bc", "c"), and ("ab", "abcc") are not. The unbalanced substrings are bolded. Return the m...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 1\n assert candidate(s = \"aaabbbccc\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 1\n assert candidate(s = \"aabbaabbccddccdd\") == 1\n assert candidate(s = \"abcdef\") == 1\n ass...
[ "\"fabccddg\"", "\"abababaccddb\"" ]
[ "Let dp[i] be the minimum number of partitions for the prefix ending at index i + 1.", "dp[i] can be calculated as the min(dp[j]) over all j such that j < i and word[j+1…i] is valid." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minimumSubstringsInPartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:41", "tests_total": 72,...
typescript
{ "raw_signature": "function minimumSubstringsInPartition(s: string): number {", "container": null, "callable": "minimumSubstringsInPartition", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "l...
3,146
permutation-difference-between-two-strings
Easy
You are given two strings s and t such that every character occurs at most once in s and t is a permutation of s. The permutation difference between s and t is defined as the sum of the absolute difference between the index of the occurrence of each character in s and the index of the occurrence of the same character ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 338\n assert candidate(s = \"mnopqr\",t = \"qrpmno\") == 18\n assert candidate(s = \"abcde\",t = \"edbac\") == 12\n assert candidate(s = \"abcxyz\",t = \"...
[ "\"abc\"\n\"bac\"", "\"abcde\"\n\"edbac\"" ]
[ "For each character, find the indices of its occurrences in string s then in string t." ]
{ "canonical_parameter_names": [ "s", "t" ], "leetcode_dataset_entry_point": "Solution().findPermutationDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:43", "tests_total...
typescript
{ "raw_signature": "function findPermutationDifference(s: string, t: string): number {", "container": null, "callable": "findPermutationDifference", "parameters": [ { "name": "s", "type": "string" }, { "name": "t", "type": "string" } ], "return_type": "number", "sig...
3,147
taking-maximum-energy-from-the-mystic-dungeon
Medium
In a mystic dungeon, n magicians are standing in a line. Each magician has an attribute that gives you energy. Some magicians can give you negative energy, which means taking energy from you. You have been cursed in such a way that after absorbing energy from magician i, you will be instantly transported to magician (...
{ "language": "python", "source": "def check(candidate):\n assert candidate(energy = [100, -100, 100, -100, 100, 100],k = 2) == 300\n assert candidate(energy = [-1, -2, -3, -4, -5],k = 3) == -3\n assert candidate(energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 30\n assert candidate(energy = [1, 2, 3,...
[ "[5,2,-10,-5,1]\n3", "[-2,-3,-1]\n2" ]
[ "Let dp[i] denote the energy we gain starting from index i.", "We can notice, that dp[i] = dp[i + k] + energy[i]." ]
{ "canonical_parameter_names": [ "energy", "k" ], "leetcode_dataset_entry_point": "Solution().maximumEnergy", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:46", "tests_total": 120,...
typescript
{ "raw_signature": "function maximumEnergy(energy: number[], k: number): number {", "container": null, "callable": "maximumEnergy", "parameters": [ { "name": "energy", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_sou...
3,148
maximum-difference-score-in-a-grid
Medium
You are given an m x n matrix grid consisting of positive integers. You can move from a cell in the matrix to any other cell that is either to the bottom or to the right (not necessarily adjacent). The score of a move from a cell with the value c1 to a cell with the value c2 is c2 - c1. You can start at any cell, and ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]) == 6\n assert candidate(grid = [[4, 3, 2], [3, 2, 1]]) == -1\n assert candidate(grid = [[100, 90, 80], [70, 60, 50], [40, 30, 20]]) == -10\n assert candidate(grid ...
[ "[[9,5,7,3],[8,9,6,1],[6,7,14,3],[2,5,3,1]]", "[[4,3,2],[3,2,1]]" ]
[ "Any path from a cell (x1, y1) to another cell (x2, y2) will always have a score of grid[x2][y2] - grid[x1][y1].", "Let’s say we fix the starting cell (x1, y1), how to the find a cell (x2, y2) such that the value grid[x2][y2] - grid[x1][y1] is the maximum possible?" ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:49", "tests_total": 83, "tests_dropped...
typescript
{ "raw_signature": "function maxScore(grid: number[][]): number {", "container": null, "callable": "maxScore", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,149
find-the-minimum-cost-array-permutation
Hard
You are given an array nums which is a permutation of [0, 1, 2, ..., n - 1]. The score of any permutation of [0, 1, 2, ..., n - 1] named perm is defined as: score(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[perm[0]]| Return the permutation perm which has the minimum possi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [0, 7, 6, 8, 5, 9, 4, 10, 3, 11, 2, 12, 1, 13]\n assert candidate(nums = [2, 0, 1, 3]) == [0, 1, 2, 3]\n assert candidate(nums = [0, 2, 1]) == [0, 2, 1]\n assert candidat...
[ "[1,0,2]", "[0,2,1]" ]
[ "The score function is cyclic, so we can always set perm[0] = 0 for the smallest lexical order.", "It’s similar to the Traveling Salesman Problem. Use Dynamic Programming.", "Use a bitmask to track which elements have been assigned to perm." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findPermutation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:51", "tests_total": 113, "tests...
typescript
{ "raw_signature": "function findPermutation(nums: number[]): number[] {", "container": null, "callable": "findPermutation", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
3,151
special-array-i
Easy
An array is considered special if the parity of every pair of adjacent elements is different. In other words, one element in each pair must be even, and the other must be odd. You are given an array of integers nums. Return true if nums is a special array, otherwise, return false. Example 1: Input: nums = [1] Output...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 99, 100]) == True\n assert candidate(nums = [5, 2, 7, 8]) == True\n assert candidate(nums = [20, 30, 40, 50, 60]) == False\n assert candidate(nums = [3, 8, 3, 8, 3, 8]) == True\n assert candidate(nums = [2, 3, 4,...
[ "[1]", "[2,1,4]", "[4,3,1,6]" ]
[ "Try to check the parity of each element and its previous element." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().isArraySpecial", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:53", "tests_total": 127, "tests_...
typescript
{ "raw_signature": "function isArraySpecial(nums: number[]): boolean {", "container": null, "callable": "isArraySpecial", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
3,152
special-array-ii
Medium
An array is considered special if every pair of its adjacent elements contains two numbers with different parity. You are given an array of integer nums and a 2D integer matrix queries, where for queries[i] = [from_i, to_i] your task is to check that subarray nums[from_i..to_i] is special or not. Return an array of b...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2],queries = [[0, 4]]) == [False]\n assert candidate(nums = [2, 4, 6, 8, 10],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 4]]) == [True, True, True, True, True, False]\n assert candidate(nums = [1, 3, ...
[ "[3,4,1,2,6]\n[[0,4]]", "[4,3,1,6]\n[[0,2],[2,3]]" ]
[ "Try to split the array into some non-intersected continuous special subarrays.", "For each query check that the first and the last elements of that query are in the same subarray or not." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().isArraySpecial", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:56", "tests_total":...
typescript
{ "raw_signature": "function isArraySpecial(nums: number[], queries: number[][]): boolean[] {", "container": null, "callable": "isArraySpecial", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "queries", "type": "number[][]" } ], "return_type": "bool...
3,153
sum-of-digit-differences-of-all-pairs
Medium
You are given an array nums consisting of positive integers where all integers have the same number of digits. The digit difference between two integers is the count of different digits that are in the same position in the two integers. Return the sum of the digit differences between all pairs of integers in nums. E...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [12345, 54321, 13245]) == 11\n assert candidate(nums = [10, 10, 10, 10]) == 0\n assert candidate(nums = [123, 234, 345]) == 9\n assert candidate(nums = [123, 456, 789]) == 9\n assert candidate(nums = [987, 876, 765, 65...
[ "[13,23,12]", "[10,10,10,10]" ]
[ "You can solve the problem for digits that are on the same position separately, and then sum up all the answers.", "For each position, count the number of occurences of each digit from 0 to 9 that appear on that position.", "Let c be the number of occurences of a digit on a position, that will contribute with c...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().sumDigitDifferences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:59", "tests_total": 105, "t...
typescript
{ "raw_signature": "function sumDigitDifferences(nums: number[]): number {", "container": null, "callable": "sumDigitDifferences", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
3,154
find-number-of-ways-to-reach-the-k-th-stair
Hard
You are given a non-negative integer k. There exists a staircase with an infinite number of stairs, with the lowest stair numbered 0. Alice has an integer jump, with an initial value of 0. She starts on stair 1 and wants to reach stair k using any number of operations. If she is on stair i, in one operation she can: ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(k = 1000) == 0\n assert candidate(k = 100) == 0\n assert candidate(k = 20) == 0\n assert candidate(k = 1000000000) == 0\n assert candidate(k = 1) == 4\n assert candidate(k = 10) == 0\n assert candidate(k = 10000) == 0\n...
[ "0", "1" ]
[ "On using x operations of the second type and y operations of the first type, the stair 2^x - y is reached.", "Since first operations cannot be consecutive, there are exactly x + 1 positions (before and after each power of 2) to perform the second operation.", "Using combinatorics, we have ^{x + 1}C_y number of...
{ "canonical_parameter_names": [ "k" ], "leetcode_dataset_entry_point": "Solution().waysToReachStair", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:01", "tests_total": 79, "tests_dr...
typescript
{ "raw_signature": "function waysToReachStair(k: number): number {", "container": null, "callable": "waysToReachStair", "parameters": [ { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,158
find-the-xor-of-numbers-which-appear-twice
Easy
You are given an array nums, where each number in the array appears either once or twice. Return the bitwise XOR of all the numbers that appear twice in the array, or 0 if no number appears twice. Example 1: Input: nums = [1,2,1,3] Output: 1 Explanation: The only number that appears twice in nums is 1. Example 2: ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 20, 30, 30, 40, 50]) == 20\n assert candidate(nums = [8, 8, 9, 9, 10, 10, 11]) == 11\n assert candidate(nums = [10, 10, 20, 20, 30]) == 30\n assert candidate(nums = [5, 5, 6, 7, 7, 8, 8, 9]) == 10\n assert can...
[ "[1,2,1,3]", "[1,2,3]", "[1,2,2,1]" ]
[ "The constraints are small. Brute force checking each value in the array." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().duplicateNumbersXOR", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:09", "tests_total": 120, "t...
typescript
{ "raw_signature": "function duplicateNumbersXOR(nums: number[]): number {", "container": null, "callable": "duplicateNumbersXOR", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
3,159
find-occurrences-of-an-element-in-an-array
Medium
You are given an integer array nums, an integer array queries, and an integer x. For each queries[i], you need to find the index of the queries[i]^th occurrence of x in the nums array. If there are fewer than queries[i] occurrences of x, the answer should be -1 for that query. Return an integer array answer containin...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],x = 1) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1]\n assert candidate(nums = [3, 2, 1],queries = [1, 1, 1],x = 3) == [0, 0, 0]\n assert candidate(nums = ...
[ "[1,3,1,7]\n[1,3,2,4]\n1", "[1,2,3]\n[10]\n5" ]
[ "Compress the array nums and save all the occurrences of each element in the separate arrays." ]
{ "canonical_parameter_names": [ "nums", "queries", "x" ], "leetcode_dataset_entry_point": "Solution().occurrencesOfElement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:11", ...
typescript
{ "raw_signature": "function occurrencesOfElement(nums: number[], queries: number[], x: number): number[] {", "container": null, "callable": "occurrencesOfElement", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "queries", "type": "number[]" }, { ...
3,160
find-the-number-of-distinct-colors-among-the-balls
Medium
You are given an integer limit and a 2D array queries of size n x 2. There are limit + 1 balls with distinct labels in the range [0, limit]. Initially, all balls are uncolored. For every query in queries that is of the form [x, y], you mark ball x with the color y. After each query, you need to find the number of colo...
{ "language": "python", "source": "def check(candidate):\n assert candidate(limit = 3,queries = [[0, 1], [1, 2], [2, 3], [0, 1]]) == [1, 2, 3, 3]\n assert candidate(limit = 1,queries = [[0, 1], [1, 2]]) == [1, 2]\n assert candidate(limit = 4,queries = [[0, 1], [1, 2], [2, 2], [3, 4], [4, 5]]) == [1, 2, 2, ...
[ "4\n[[1,4],[2,5],[1,3],[3,4]]", "4\n[[0,1],[1,2],[2,2],[3,4],[4,5]]" ]
[ "Use two HashMaps to maintain the color of each ball and the set of balls with each color." ]
{ "canonical_parameter_names": [ "limit", "queries" ], "leetcode_dataset_entry_point": "Solution().queryResults", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:13", "tests_total": ...
typescript
{ "raw_signature": "function queryResults(limit: number, queries: number[][]): number[] {", "container": null, "callable": "queryResults", "parameters": [ { "name": "limit", "type": "number" }, { "name": "queries", "type": "number[][]" } ], "return_type": "number[]", ...
3,161
block-placement-queries
Hard
There exists an infinite number line, with its origin at 0 and extending towards the positive x-axis. You are given a 2D array queries, which contains two types of queries: 1. For a query of type 1, queries[i] = [1, x]. Build an obstacle at distance x from the origin. It is guaranteed that there is no obstacle at dis...
{ "language": "python", "source": "def check(candidate):\n assert candidate(queries = [[2, 5, 2], [1, 3], [2, 5, 3], [1, 4], [2, 5, 1]]) == [True, True, True]\n assert candidate(queries = [[2, 10, 5], [1, 3], [2, 5, 2], [1, 10], [2, 10, 3]]) == [True, True, True]\n assert candidate(queries = [[1, 7], [2, 7...
[ "[[1,2],[2,3,3],[2,3,1],[2,2,2]]", "[[1,7],[2,7,6],[1,2],[2,7,5],[2,7,6]]" ]
[ "Let d[x] be the distance of the next obstacle after x.", "For each query of type 2, we just need to check if max(d[0], d[1], d[2], …d[x - sz]) > sz.", "Use segment tree to maintain d[x]." ]
{ "canonical_parameter_names": [ "queries" ], "leetcode_dataset_entry_point": "Solution().getResults", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:16", "tests_total": 131, "tests_d...
typescript
{ "raw_signature": "function getResults(queries: number[][]): boolean[] {", "container": null, "callable": "getResults", "parameters": [ { "name": "queries", "type": "number[][]" } ], "return_type": "boolean[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
3,162
find-the-number-of-good-pairs-i
Easy
You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k. A pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1). Return the total number of good pairs. Example 1: Input: nums1 = [1,3,4], nums2 = [1,3,4]...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [7, 14, 21],nums2 = [1, 7],k = 3) == 2\n assert candidate(nums1 = [1, 3, 4],nums2 = [1, 3, 4],k = 1) == 5\n assert candidate(nums1 = [7, 14, 21],nums2 = [1, 7, 14],k = 1) == 7\n assert candidate(nums1 = [7, 14, 21],nums2...
[ "[1,3,4]\n[1,3,4]\n1", "[1,2,4,12]\n[2,4]\n3" ]
[ "The constraints are small. Check all pairs." ]
{ "canonical_parameter_names": [ "nums1", "nums2", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:19", "tests_...
typescript
{ "raw_signature": "function numberOfPairs(nums1: number[], nums2: number[], k: number): number {", "container": null, "callable": "numberOfPairs", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" }, { "name": "k", ...
3,163
string-compression-iii
Medium
Given a string word, compress it using the following algorithm: - Begin with an empty string comp. While word is not empty, use the following operation: - Remove a maximum length prefix of word made of a single character c repeating at most 9 times. - Append the length of the prefix followed by c to comp. Return ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"pppppppppppppppppppppppppppppppppppppp\") == \"9p9p9p9p2p\"\n assert candidate(word = \"abcde\") == \"1a1b1c1d1e\"\n assert candidate(word = \"aabbcc\") == \"2a2b2c\"\n assert candidate(word = \"aaaaaaaaaaaaaabb\") == \...
[ "\"abcde\"", "\"aaaaaaaaaaaaaabb\"" ]
[ "Each time, just cut the same character in prefix up to at max 9 times. It’s always better to cut a bigger prefix." ]
{ "canonical_parameter_names": [ "word" ], "leetcode_dataset_entry_point": "Solution().compressedString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:21", "tests_total": 25, "tests...
typescript
{ "raw_signature": "function compressedString(word: string): string {", "container": null, "callable": "compressedString", "parameters": [ { "name": "word", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
3,164
find-the-number-of-good-pairs-ii
Medium
You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k. A pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1). Return the total number of good pairs. Example 1: Input: nums1 = [1,3,4], nums2 = [1,3,4]...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [7, 14, 21],nums2 = [1, 7, 14],k = 7) == 3\n assert candidate(nums1 = [1, 3, 4],nums2 = [1, 3, 4],k = 1) == 5\n assert candidate(nums1 = [100, 200, 300],nums2 = [10, 20, 30],k = 10) == 5\n assert candidate(nums1 = [5, 10...
[ "[1,3,4]\n[1,3,4]\n1", "[1,2,4,12]\n[2,4]\n3" ]
[ "Let f[v] be the number of occurrences of v/k in nums2.", "For each value v in nums1, enumerating all its factors d (in sqrt(v) time) and sum up all the f[d] to get the final answer.", "It is also possible to improve the complexity from len(nums1) * sqrt(v) to len(nums1) * log(v) - How?" ]
{ "canonical_parameter_names": [ "nums1", "nums2", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:24", "tests_...
typescript
{ "raw_signature": "function numberOfPairs(nums1: number[], nums2: number[], k: number): number {", "container": null, "callable": "numberOfPairs", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" }, { "name": "k", ...
3,165
maximum-sum-of-subsequence-with-non-adjacent-elements
Hard
You are given an array nums consisting of integers. You are also given a 2D array queries, where queries[i] = [pos_i, x_i]. For query i, we first set nums[pos_i] equal to x_i, then we calculate the answer to query i which is the maximum sum of a subsequence of nums where no two adjacent elements are selected. Return ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 200, 300, 400, 500],queries = [[0, -100], [2, -200], [4, -300]]) == 2100\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [[0, 10], [4, -10], [2, 0]]) == 46\n assert candidate(nums = [-1, -2, -3, -4, -5],queries = [...
[ "[3,5,9]\n[[1,-2],[0,-3]]", "[0,-1]\n[[0,-5]]" ]
[ "Can you solve each query in O(nums.length) with dynamic programming?", "In order to optimize, we will use segment tree where each node contains the maximum value of (front element has been chosen or not, back element has been chosen or not)." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().maximumSumSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:26", "tests_...
typescript
{ "raw_signature": "function maximumSumSubsequence(nums: number[], queries: number[][]): number {", "container": null, "callable": "maximumSumSubsequence", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "queries", "type": "number[][]" } ], "return_t...
3,168
minimum-number-of-chairs-in-a-waiting-room
Easy
You are given a string s. Simulate events at each second i: - If s[i] == 'E', a person enters the waiting room and takes one of the chairs in it. - If s[i] == 'L', a person leaves the waiting room, freeing up a chair. Return the minimum number of chairs needed so that a chair is available for every person who enters ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"ELEELEELLL\") == 3\n assert candidate(s = \"EEEEEEE\") == 7\n assert candidate(s = \"EELLEELLL\") == 2\n assert candidate(s = \"E\") == 1\n assert candidate(s = \"EELLEL\") == 2\n assert candidate(s = \"ELE\") == 1\n...
[ "\"EEEEEEE\"", "\"ELELEEL\"", "\"ELEELEELLL\"" ]
[ "Iterate from left to right over the string and keep track of the number of people in the waiting room using a variable that you will increment on every occurrence of ‘E’ and decrement on every occurrence of ‘L’.", "The answer is the maximum number of people in the waiting room at any instance." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minimumChairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:31", "tests_total": 144, "tests_drop...
typescript
{ "raw_signature": "function minimumChairs(s: string): number {", "container": null, "callable": "minimumChairs", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,169
count-days-without-meetings
Medium
You are given a positive integer days representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array meetings of size n where, meetings[i] = [start_i, end_i] represents the starting and ending days of meeting i (inclusive). Return the count of days when the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(days = 15,meetings = [[5, 6], [6, 7], [7, 8]]) == 11\n assert candidate(days = 10,meetings = [[5, 7], [1, 3], [9, 10]]) == 2\n assert candidate(days = 15,meetings = [[1, 2], [3, 5], [6, 8], [10, 12], [14, 15]]) == 2\n assert can...
[ "10\n[[5,7],[1,3],[9,10]]", "5\n[[2,4],[1,3]]", "6\n[[1,6]]" ]
[ "Merge the overlapping meetings and sort the new meetings timings.", "Return the sum of difference between the end time of a meeting and the start time of the next meeting for all adjacent pairs." ]
{ "canonical_parameter_names": [ "days", "meetings" ], "leetcode_dataset_entry_point": "Solution().countDays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:34", "tests_total": 90,...
typescript
{ "raw_signature": "function countDays(days: number, meetings: number[][]): number {", "container": null, "callable": "countDays", "parameters": [ { "name": "days", "type": "number" }, { "name": "meetings", "type": "number[][]" } ], "return_type": "number", "signatu...
3,170
lexicographically-minimum-string-after-removing-stars
Medium
You are given a string s. It may contain any number of '*' characters. Your task is to remove all '*' characters. While there is a '*', do the following operation: - Delete the leftmost '*' and the smallest non-'*' character to its left. If there are several smallest characters, you can delete any of them. Return th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"*a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z\") == \"z\"\n assert candidate(s = \"*a*b*c\") == \"c\"\n assert candidate(s = \"aaba*\") == \"aab\"\n assert candidate(s = \"z*z*z*z\") == \"z\"\n assert candidate(s...
[ "\"aaba*\"", "\"abc\"" ]
[]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().clearStars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:36", "tests_total": 70, "tests_dropped"...
typescript
{ "raw_signature": "function clearStars(s: string): string {", "container": null, "callable": "clearStars", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,171
find-subarray-with-bitwise-or-closest-to-k
Hard
You are given an array nums and an integer k. You need to find a subarray of nums such that the absolute difference between k and the bitwise OR of the subarray elements is as small as possible. In other words, select a subarray nums[l..r] such that |k - (nums[l] OR nums[l + 1] ... OR nums[r])| is minimum. Return the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000000],k = 500000000) == 500000000\n assert candidate(nums = [10, 20, 30, 40],k = 25) == 5\n assert candidate(nums = [1],k = 10) == 9\n assert candidate(nums = [5, 6, 7, 8, 9],k = 7) == 0\n assert candidate(nums ...
[ "[1,2,4,5]\n3", "[1,3,1,3]\n2", "[1]\n10" ]
[ "Let dp[i] be the set of all the bitwise OR of all the subarrays ending at index i.", "We start from nums[i], taking the bitwise OR result by including elements one by one from i towards left. Notice that only unset bits can become set on adding an element, and set bits never become unset again.", "Hence dp[i] ...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().minimumDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:39", "tests_total": 12...
typescript
{ "raw_signature": "function minimumDifference(nums: number[], k: number): number {", "container": null, "callable": "minimumDifference", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature...
3,174
clear-digits
Easy
You are given a string s. Your task is to remove all digits by doing this operation repeatedly: - Delete the first digit and the closest non-digit character to its left. Return the resulting string after removing all digits. Note that the operation cannot be performed on a digit that does not have any non-digit cha...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdef\") == \"abcdef\"\n assert candidate(s = \"a1b2c3d4e5\") == \"\"\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0\") == \"\"\n assert candidate(s = \"a1b2c3d4e5f6\") == \"\"\n assert candidate(s = \"a1b2c3\") == \"\"...
[ "\"abc\"", "\"cb34\"" ]
[ "Process string s from left to right, if s[i] is a digit, mark the nearest unmarked non-digit index to its left.", "Delete all digits and all marked characters." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().clearDigits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:43", "tests_total": 72, "tests_dropped...
typescript
{ "raw_signature": "function clearDigits(s: string): string {", "container": null, "callable": "clearDigits", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,175
find-the-first-player-to-win-k-games-in-a-row
Medium
A competition consists of n players numbered from 0 to n - 1. You are given an integer array skills of size n and a positive integer k, where skills[i] is the skill level of player i. All integers in skills are unique. All players are standing in a queue in order from player 0 to player n - 1. The competition proces...
{ "language": "python", "source": "def check(candidate):\n assert candidate(skills = [5, 1, 9, 2, 8, 3, 7, 4, 6],k = 3) == 2\n assert candidate(skills = [1000000, 999999, 999998, 999997],k = 4) == 0\n assert candidate(skills = [2, 5, 4],k = 3) == 1\n assert candidate(skills = [1, 3, 2, 5, 4],k = 1) == 1...
[ "[4,2,6,3,9]\n2", "[2,5,4]\n3" ]
[ "Suppose that k ≥ n, there is exactly one player who can win k games in a row. Who is it?", "In case k < n, you can simulate the competition process described." ]
{ "canonical_parameter_names": [ "skills", "k" ], "leetcode_dataset_entry_point": "Solution().findWinningPlayer", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:46", "tests_total": ...
typescript
{ "raw_signature": "function findWinningPlayer(skills: number[], k: number): number {", "container": null, "callable": "findWinningPlayer", "parameters": [ { "name": "skills", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signa...
3,176
find-the-maximum-length-of-a-good-subsequence-i
Medium
You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1]. Return the maximum possible length of a good subsequence of nums. Example 1: Input: nums = [1,2,1,1,3], k = 2 O...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 4) == 10\n assert candidate(nums = [1, 2, 3, 2, 1],k = 1) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 0) == 1\n ...
[ "[1,2,1,1,3]\n2", "[1,2,3,4,5,1]\n0" ]
[ "The absolute values in nums don’t really matter. So we can remap the set of values to the range [0, n - 1].", "Let dp[i][j] be the length of the longest subsequence till index j with at most i positions such that seq[i] != seq[i + 1].", "For each value x from left to right, update dp[i][x] = max(dp[i][x] + 1, ...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:48", "tests_total": 109, ...
typescript
{ "raw_signature": "function maximumLength(nums: number[], k: number): number {", "container": null, "callable": "maximumLength", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source"...
3,177
find-the-maximum-length-of-a-good-subsequence-ii
Hard
You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1]. Return the maximum possible length of a good subsequence of nums. Example 1: Input: nums = [1,2,1,1,3], k = 2 O...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 4) == 10\n assert candidate(nums = [1, 2, 3, 2, 1],k = 1) == 3\n assert can...
[ "[1,2,1,1,3]\n2", "[1,2,3,4,5,1]\n0" ]
[ "The absolute values in nums don’t really matter. So we can remap the set of values to the range [0, n - 1].", "Let dp[i][j] be the length of the longest subsequence till index j with at most i positions such that seq[i] != seq[i + 1].", "For each value x from left to right, update dp[i][x] = max(dp[i][x] + 1, ...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:51", "tests_total": 107, ...
typescript
{ "raw_signature": "function maximumLength(nums: number[], k: number): number {", "container": null, "callable": "maximumLength", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source"...
3,178
find-the-child-who-has-the-ball-after-k-seconds
Easy
You are given two positive integers n and k. There are n children numbered from 0 to n - 1 standing in a queue in order from left to right. Initially, child 0 holds a ball and the direction of passing the ball is towards the right direction. After each second, the child holding the ball passes it to the child next to ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 50,k = 50) == 48\n assert candidate(n = 3,k = 5) == 1\n assert candidate(n = 2,k = 1) == 1\n assert candidate(n = 40,k = 20) == 20\n assert candidate(n = 5,k = 6) == 2\n assert candidate(n = 10,k = 15) == 3\n assert...
[ "3\n5", "5\n6", "4\n2" ]
[ "The ball will go back to child 0 after 2 * (n - 1) seconds and everything is the same as time 0.", "So the answer for k is the same as the answer for k % (2 * (n - 1))." ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfChild", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:53", "tests_total": 82, "te...
typescript
{ "raw_signature": "function numberOfChild(n: number, k: number): number {", "container": null, "callable": "numberOfChild", "parameters": [ { "name": "n", "type": "number" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcod...
3,179
find-the-n-th-value-after-k-seconds
Medium
You are given two integers n and k. Initially, you start with an array a of n integers where a[i] = 1 for all 0 <= i <= n - 1. After each second, you simultaneously update each element to be the sum of all its preceding elements plus the element itself. For example, after one second, a[0] remains the same, a[1] become...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 7,k = 4) == 210\n assert candidate(n = 2,k = 4) == 5\n assert candidate(n = 2,k = 5) == 6\n assert candidate(n = 8,k = 4) == 330\n assert candidate(n = 2,k = 1) == 2\n assert candidate(n = 1,k = 1) == 1\n assert can...
[ "4\n5", "5\n3" ]
[ "Calculate the prefix sum array of nums, k times." ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().valueAfterKSeconds", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:55", "tests_total": 63, ...
typescript
{ "raw_signature": "function valueAfterKSeconds(n: number, k: number): number {", "container": null, "callable": "valueAfterKSeconds", "parameters": [ { "name": "n", "type": "number" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source"...
3,180
maximum-total-reward-using-operations-i
Medium
You are given an integer array rewardValues of length n, representing the values of rewards. Initially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times: - Choose an unmarked index i from the range [0, n - 1]. - If rewardValues[i] is greate...
{ "language": "python", "source": "def check(candidate):\n assert candidate(rewardValues = [1, 1, 3, 3]) == 4\n assert candidate(rewardValues = [2000, 1]) == 2001\n assert candidate(rewardValues = [1, 6, 4, 3, 2]) == 11\n assert candidate(rewardValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 37\n as...
[ "[1,1,3,3]", "[1,6,4,3,2]" ]
[ "Sort the rewards array first.", "If we decide to apply some rewards, it's always optimal to apply them in order.", "Let dp[i][j] (true/false) be the state after the first i rewards, indicating whether we can get exactly j points.", "The transition is given by: dp[i][j] = dp[i - 1][j - rewardValues[i]] if j -...
{ "canonical_parameter_names": [ "rewardValues" ], "leetcode_dataset_entry_point": "Solution().maxTotalReward", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:57", "tests_total": 104, ...
typescript
{ "raw_signature": "function maxTotalReward(rewardValues: number[]): number {", "container": null, "callable": "maxTotalReward", "parameters": [ { "name": "rewardValues", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
3,181
maximum-total-reward-using-operations-ii
Hard
You are given an integer array rewardValues of length n, representing the values of rewards. Initially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times: - Choose an unmarked index i from the range [0, n - 1]. - If rewardValues[i] is greate...
{ "language": "python", "source": "def check(candidate):\n assert candidate(rewardValues = [1, 2, 3, 4, 5]) == 9\n assert candidate(rewardValues = [1, 1, 3, 3]) == 4\n assert candidate(rewardValues = [50000, 40000, 30000, 20000, 10000]) == 90000\n assert candidate(rewardValues = [1, 2, 2, 1, 1, 2, 2, 1,...
[ "[1,1,3,3]", "[1,6,4,3,2]" ]
[ "Sort the rewards array first.", "If we decide to apply some rewards, it's always optimal to apply them in order.", "The transition is given by: dp[i][j] = dp[i - 1][j - rewardValues[i]] if j - rewardValues[i] < rewardValues[i].", "Note that the dp array is a boolean array. We just need 1 bit per element, so ...
{ "canonical_parameter_names": [ "rewardValues" ], "leetcode_dataset_entry_point": "Solution().maxTotalReward", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:00", "tests_total": 87, ...
typescript
{ "raw_signature": "function maxTotalReward(rewardValues: number[]): number {", "container": null, "callable": "maxTotalReward", "parameters": [ { "name": "rewardValues", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
3,184
count-pairs-that-form-a-complete-day-i
Easy
Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day. A complete day is defined as a time duration that is an exact multiple of 24 hours. For example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 h...
{ "language": "python", "source": "def check(candidate):\n assert candidate(hours = [23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11\n assert candidate(hours = [24, 48, 72, 96, 120]) == 10\n assert candidate(hours = [1000000000, 1000000000, 1000000000, 1000000000])...
[ "[12,12,30,24,24]", "[72,48,24,3]" ]
[ "Brute force all pairs (i, j) and check if they form a valid complete day. It is considered a complete day if (hours[i] + hours[j]) % 24 == 0." ]
{ "canonical_parameter_names": [ "hours" ], "leetcode_dataset_entry_point": "Solution().countCompleteDayPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:04", "tests_total": 83, ...
typescript
{ "raw_signature": "function countCompleteDayPairs(hours: number[]): number {", "container": null, "callable": "countCompleteDayPairs", "parameters": [ { "name": "hours", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
3,185
count-pairs-that-form-a-complete-day-ii
Medium
Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day. A complete day is defined as a time duration that is an exact multiple of 24 hours. For example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 h...
{ "language": "python", "source": "def check(candidate):\n assert candidate(hours = [5, 19, 15, 1, 23, 7, 17, 11, 3, 21, 9, 13, 20, 18, 4, 16, 8, 12, 6, 22, 14, 2, 10, 10, 10]) == 13\n assert candidate(hours = [24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384, 408, 432, 456, 480, 504...
[ "[12,12,30,24,24]", "[72,48,24,3]" ]
[ "A pair (i, j) forms a valid complete day if (hours[i] + hours[j]) % 24 == 0.", "Using an array or a map, for each index j moving from left to right, increase the answer by the count of (24 - hours[j]) % 24, and then increase the count of hours[j]." ]
{ "canonical_parameter_names": [ "hours" ], "leetcode_dataset_entry_point": "Solution().countCompleteDayPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:07", "tests_total": 73, ...
typescript
{ "raw_signature": "function countCompleteDayPairs(hours: number[]): number {", "container": null, "callable": "countCompleteDayPairs", "parameters": [ { "name": "hours", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
3,186
maximum-total-damage-with-spell-casting
Medium
A magician has various spells. You are given an array power, where each element represents the damage of a spell. Multiple spells can have the same damage value. It is a known fact that if a magician decides to cast a spell with a damage of power[i], they cannot cast any spell with a damage of power[i] - 2, power[i] ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(power = [5, 5, 5, 5, 5]) == 25\n assert candidate(power = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91]) == 506\n assert candidate(power = [5, 3, 8, 9, 2]) == 16\n assert candidate(power = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59]) ...
[ "[1,1,3,4]", "[7,1,6,6]" ]
[ "If we ever decide to use some spell with power x, then we will use all spells with power x.", "Think of dynamic programming.", "dp[i][j] represents the maximum damage considering up to the i-th unique spell and j represents the number of spells skipped (up to 3 as per constraints)." ]
{ "canonical_parameter_names": [ "power" ], "leetcode_dataset_entry_point": "Solution().maximumTotalDamage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:10", "tests_total": 99, "te...
typescript
{ "raw_signature": "function maximumTotalDamage(power: number[]): number {", "container": null, "callable": "maximumTotalDamage", "parameters": [ { "name": "power", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
3,187
peaks-in-array
Hard
A peak in an array arr is an element that is greater than its previous and next element in arr. You are given an integer array nums and a 2D integer array queries. You have to process queries of two types: - queries[i] = [1, l_i, r_i], determine the count of peak elements in the subarray nums[l_i..r_i]. - queries[i]...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 1, 4, 2, 5],queries = [[2, 3, 4], [1, 0, 4]]) == [0]\n assert candidate(nums = [4, 1, 4, 2, 1, 5],queries = [[2, 2, 4], [1, 0, 2], [1, 0, 4]]) == [0, 1]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5],queries = [[1...
[ "[3,1,4,2,5]\n[[2,3,4],[1,0,4]]", "[4,1,4,2,1,5]\n[[2,2,4],[1,0,2],[1,0,4]]" ]
[ "Let p[i] be whether nums[i] is a peak in the original array. Namely p[i] = nums[i] > nums[i - 1] && nums[i] > nums[i + 1].", "Updating nums[i], only affects p[i], p[i - 1] and p[i + 1]. We can recalculate the 3 values in constant time.", "The answer for [l_i, r_i] is p[l_i + 1] + p[l_i + 2] + … + p[r_i - 1] (n...
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().countOfPeaks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:13", "tests_total": 8...
typescript
{ "raw_signature": "function countOfPeaks(nums: number[], queries: number[][]): number[] {", "container": null, "callable": "countOfPeaks", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "queries", "type": "number[][]" } ], "return_type": "number[]"...
3,190
find-minimum-operations-to-make-all-elements-divisible-by-three
Easy
You are given an integer array nums. In one operation, you can add or subtract 1 from any element of nums. Return the minimum number of operations to make all elements of nums divisible by 3. Example 1: Input: nums = [1,2,3,4] Output: 3 Explanation: All array elements can be made divisible by 3 using 3 operations: -...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 4, 5]) == 4\n assert candidate(nums = [1, 1, 1, 1]) == 4\n assert candidate(nums = [3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 2, 4, 5, 7]) == 5\n assert candidate(nums = [1, 2, 4, 5, 7, 8]) == 6\n asser...
[ "[1,2,3,4]", "[3,6,9]" ]
[ "If x % 3 != 0 we can always increment or decrement x such that we only need 1 operation.", "Add min(nums[i] % 3, 3 - (nums[i] % 3)) to the count of operations." ]
{ "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:16:18", "tests_total": 117, "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...
3,191
minimum-operations-to-make-binary-array-elements-equal-to-one-i
Medium
You are given a binary array nums. You can do the following operation on the array any number of times (possibly zero): - Choose any 3 consecutive elements from the array and flip all of them. Flipping an element means changing its value from 0 to 1, and from 1 to 0. Return the minimum number of operations required...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 0, 1, 0, 1]) == 3\n assert candidate(nums = [0, 0, 1, 1, 1, 0, 0]) == -1\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 0, 1, 1, 0]) == 4\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candi...
[ "[0,1,1,1,0,0]", "[0,1,1,1]" ]
[ "If nums[0] is 0, then the only way to change it to 1 is by doing an operation on the first 3 elements of the array.", "After Changing nums[0] to 1, use the same logic on the remaining array." ]
{ "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:16:20", "tests_total": 109, "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...
3,192
minimum-operations-to-make-binary-array-elements-equal-to-one-ii
Medium
You are given a binary array nums. You can do the following operation on the array any number of times (possibly zero): - Choose any index i from the array and flip all the elements from index i to the end of the array. Flipping an element means changing its value from 0 to 1, and from 1 to 0. Return the minimum nu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 0, 1, 0, 1]) == 6\n assert candidate(nums = [1, 0, 1, 0, 1]) == 4\n assert candidate(nums = [0, 1, 0, 1, 0]) == 5\n assert candidate(nums = [0, 0, 1, 1, 1, 0]) == 3\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1...
[ "[0,1,1,0,1]", "[1,0,0,0]" ]
[ "The only way to change nums[0] to 1 is by performing an operation with index i = 0.", "Iterate from left to right and perform an operation at each index i where nums[i] is 0, and keep track of how many operations are currently performed on the suffix." ]
{ "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:16:23", "tests_total": 68, "tests_dr...
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...
3,193
count-the-number-of-inversions
Hard
You are given an integer n and a 2D array requirements, where requirements[i] = [end_i, cnt_i] represents the end index and the inversion count of each requirement. A pair of indices (i, j) from an integer array nums is called an inversion if: - i < j and nums[i] > nums[j] Return the number of permutations perm of [...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,requirements = [[3, 3], [1, 1], [2, 2], [0, 0]]) == 1\n assert candidate(n = 5,requirements = [[4, 6], [2, 2], [3, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 2,requirements = [[0, 0], [1, 0]]) == 1\n assert candidate...
[ "3\n[[2,2],[0,0]]", "3\n[[2,2],[1,1],[0,0]]", "2\n[[0,0],[1,0]]" ]
[ "Let dp[i][j] denote the number of arrays of length i with j inversions.", "dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] + … + dp[i - 1][0].", "dp[i][j] = 0 if for some x, requirements[x][0] == i and requirements[x][1] != j." ]
{ "canonical_parameter_names": [ "n", "requirements" ], "leetcode_dataset_entry_point": "Solution().numberOfPermutations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:25", "tests...
typescript
{ "raw_signature": "function numberOfPermutations(n: number, requirements: number[][]): number {", "container": null, "callable": "numberOfPermutations", "parameters": [ { "name": "n", "type": "number" }, { "name": "requirements", "type": "number[][]" } ], "return_typ...
3,194
minimum-average-of-smallest-and-largest-elements
Easy
You have an array of floating point numbers averages which is initially empty. You are given an array nums of n integers where n is even. You repeat the following procedure n / 2 times: - Remove the smallest element, minElement, and the largest element maxElement, from nums. - Add (minElement + maxElement) / 2 to ave...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat...
[ "[7,8,3,4,15,13,4,1]", "[1,9,8,3,10,5]", "[1,2,3,7,8,9]" ]
[ "If nums is sorted, then the elements of averages are (nums[i] + nums[n - i - 1]) / 2 for all i < n / 2." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumAverage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:27", "tests_total": 132, "tests_...
typescript
{ "raw_signature": "function minimumAverage(nums: number[]): number {", "container": null, "callable": "minimumAverage", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
3,195
find-the-minimum-area-to-cover-all-ones-i
Medium
You are given a 2D binary array grid. Find a rectangle with horizontal and vertical sides with the smallest area, such that all the 1's in grid lie inside this rectangle. Return the minimum possible area of the rectangle. Example 1: Input: grid = [[0,1,0],[1,0,1]] Output: 6 Explanation: The smallest rectangle has a ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [1, 0, 0]]) == 1\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]) == 20\n assert cand...
[ "[[0,1,0],[1,0,1]]", "[[0,0],[1,0]]" ]
[ "Find the minimum and maximum coordinates of a cell with a value of 1 in both directions." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minimumArea", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:30", "tests_total": 76, "tests_drop...
typescript
{ "raw_signature": "function minimumArea(grid: number[][]): number {", "container": null, "callable": "minimumArea", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
3,196
maximize-total-cost-of-alternating-subarrays
Medium
You are given an integer array nums with length n. The cost of a subarray nums[l..r], where 0 <= l <= r < n, is defined as: cost(l, r) = nums[l] - nums[l + 1] + ... + nums[r] * (-1)^{r - l} Your task is to split nums into subarrays such that the total cost of the subarrays is maximized, ensuring each element belongs...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, -3, 8, 7, -2, 6]) == 31\n assert candidate(nums = [5, -3, 2, 7, -6, 1]) == 24\n assert candidate(nums = [5, -3, 2, -4, 6]) == 20\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, -1, 1, -1]) == 4\n ...
[ "[1,-2,3,4]", "[1,-1,1,-1]", "[0]", "[1,-1]" ]
[ "The problem can be solved using dynamic programming.", "Since we can always start a new subarray, the problem is the same as selecting some elements in the array and flipping their signs to negative to maximize the sum. However, we cannot flip the signs of 2 consecutive elements, and the first element in the arr...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maximumTotalCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:32", "tests_total": 105, "test...
typescript
{ "raw_signature": "function maximumTotalCost(nums: number[]): number {", "container": null, "callable": "maximumTotalCost", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
3,197
find-the-minimum-area-to-cover-all-ones-ii
Hard
You are given a 2D binary array grid. You need to find 3 non-overlapping rectangles having non-zero areas with horizontal and vertical sides such that all the 1's in grid lie inside these rectangles. Return the minimum possible sum of the area of these rectangles. Note that the rectangles are allowed to touch. Examp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1]]) == 5\n assert candidate(grid = [[1, 1, 0, 0, 1], [1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [0, 0, 1, 1, 0]]) == 10\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 1, 1, 0, 0], [0, 1, 1, 0, 0], [1, 0, 0,...
[ "[[1,0,1],[1,1,1]]", "[[1,0,1,0],[0,1,0,1]]" ]
[ "Consider covering using 2 rectangles. As the rectangles don’t overlap, one of the rectangles must either be vertically above or horizontally left to the other.", "To find the minimum area, check all possible vertical and horizontal splits.", "For 3 rectangles, extend the idea to first covering using one rectan...
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minimumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:34", "tests_total": 62, "tests_dropp...
typescript
{ "raw_signature": "function minimumSum(grid: number[][]): number {", "container": null, "callable": "minimumSum", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
3,200
maximum-height-of-a-triangle
Easy
You are given two integers red and blue representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1^st row will have 1 ball, the 2^nd row will have 2 balls, the 3^rd row will have 3 balls, and so on. All the balls in a particular row should be the same color...
{ "language": "python", "source": "def check(candidate):\n assert candidate(red = 100,blue = 1) == 2\n assert candidate(red = 3,blue = 7) == 3\n assert candidate(red = 50,blue = 50) == 13\n assert candidate(red = 5,blue = 5) == 3\n assert candidate(red = 1,blue = 1) == 1\n assert candidate(red = 1...
[ "2\n4", "2\n1", "1\n1", "10\n1" ]
[ "Count the max height using both possibilities. That is, red ball as top and blue ball as top.", "For counting the max height, use a simple for loop and remove the number of balls required at this level." ]
{ "canonical_parameter_names": [ "red", "blue" ], "leetcode_dataset_entry_point": "Solution().maxHeightOfTriangle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:39", "tests_total"...
typescript
{ "raw_signature": "function maxHeightOfTriangle(red: number, blue: number): number {", "container": null, "callable": "maxHeightOfTriangle", "parameters": [ { "name": "red", "type": "number" }, { "name": "blue", "type": "number" } ], "return_type": "number", "signa...
3,201
find-the-maximum-length-of-valid-subsequence-i
Medium
You are given an integer array nums. A subsequence sub of nums with length x is called valid if it satisfies: - (sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2. Return the length of the longest valid subsequence of nums. Example 1: Input: nums = [1,2,3,4] Output: 4 Explanatio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(nums = [1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 2, 1, 1, 2, 1, 2]) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candida...
[ "[1,2,3,4]", "[1,2,1,1,2,1,2]", "[1,3]" ]
[ "The possible sequence either contains all even elements, all odd elements, alternate even odd, or alternate odd even elements.", "Considering only the parity of elements, there are only 4 possibilities and we can try all of them.", "When selecting an element with any parity, try to select the earliest one." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:41", "tests_total": 115, "tests_d...
typescript
{ "raw_signature": "function maximumLength(nums: number[]): number {", "container": null, "callable": "maximumLength", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
3,202
find-the-maximum-length-of-valid-subsequence-ii
Medium
You are given an integer array nums and a positive integer k. A subsequence sub of nums with length x is called valid if it satisfies: - (sub[0] + sub[1]) % k == (sub[1] + sub[2]) % k == ... == (sub[x - 2] + sub[x - 1]) % k. Return the length of the longest valid subsequence of nums. Example 1: Input: nums = [1,2,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 6, 8, 10],k = 4) == 3\n assert candidate(nums = [1, 4, 2, 3, 1, 4],k = 3) == 4\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 5\n assert candidate(nums = [3, 1, 3, 1, 3, 1, 3, 1],k = 2) == 8\n assert candidate...
[ "[1,2,3,4,5]\n2", "[1,4,2,3,1,4]\n3" ]
[ "Fix the value of (subs[0] + subs[1]) % k from the k possible values. Let it be val.", "Let dp[i] store the maximum length of a subsequence with its last element x such that x % k == i.", "Answer for a subsequence ending at index y is dp[(k + val - (y % k)) % k] + 1." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:44", "tests_total": 125, ...
typescript
{ "raw_signature": "function maximumLength(nums: number[], k: number): number {", "container": null, "callable": "maximumLength", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source"...
3,203
find-minimum-diameter-after-merging-two-trees
Hard
There exist two undirected trees with n and m nodes, numbered from 0 to n - 1 and from 0 to m - 1, respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges1[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the first tree and ed...
{ "language": "python", "source": "def check(candidate):\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 6\n assert candidate(edges1 = [[0, 1], [0, 2], [0, 3]],edges2 = [[0, 1]]) == 3\n assert candidate(edges1 = [[0, 1], [0, 2], [0, 3], [2,...
[ "[[0,1],[0,2],[0,3]]\n[[0,1]]", "[[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]\n[[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]" ]
[ "Suppose that we connected node a in tree1 with node b in tree2. The diameter length of the resulting tree will be the largest of the following 3 values:\n1. The diameter of tree 1.\n2. The diameter of tree 2.\n3. The length of the longest path that starts at node a and that is completely within Tree 1 + The length...
{ "canonical_parameter_names": [ "edges1", "edges2" ], "leetcode_dataset_entry_point": "Solution().minimumDiameterAfterMerge", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:47", "t...
typescript
{ "raw_signature": "function minimumDiameterAfterMerge(edges1: number[][], edges2: number[][]): number {", "container": null, "callable": "minimumDiameterAfterMerge", "parameters": [ { "name": "edges1", "type": "number[][]" }, { "name": "edges2", "type": "number[][]" } ...