question_id int64 3.24k 3.51k | task_id stringclasses 191
values | difficulty stringclasses 3
values | problem_description stringclasses 191
values | canonical_tests dict | public_tests listlengths 2 4 | hints listlengths 0 7 | metadata dict | language stringclasses 9
values | interface dict |
|---|---|---|---|---|---|---|---|---|---|
3,395 | subsequences-with-a-unique-middle-mode-i | Hard | Given an integer array nums, find the number of subsequences of size 5 of nums with a unique middle mode.
Since the answer may be very large, return it modulo 10^9 + 7.
A mode of a sequence of numbers is defined as the element that appears the maximum number of times in the sequence.
A sequence of numbers contains a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1]) == 5613\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4... | [
"[1,1,1,1,1,1]",
"[1,2,2,3,3,4]",
"[0,1,2,3,4,5,6,7,8]"
] | [
"For each index, find the number of subsequences for which it is the unique middle mode. What combinations of values can the two numbers on the left and the right take?",
"For example, we can have exactly 1 element on the left equal to the middle and all other elements differ. What other combinations are acceptab... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().subsequencesWithMiddleMode",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:23:44",
"tests_total": 13... | go | {
"raw_signature": "func subsequencesWithMiddleMode(nums []int) int {",
"container": null,
"callable": "subsequencesWithMiddleMode",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/code... |
3,396 | minimum-number-of-operations-to-make-elements-in-array-distinct | Easy | You are given an integer array nums. You need to ensure that the elements in the array are distinct. To achieve this, you can perform the following operation any number of times:
- Remove 3 elements from the beginning of the array. If the array has fewer than 3 elements, remove all remaining elements.
Note that an em... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 5, 6, 4, 4]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [10, 20, 30, 10, 20, 30, 10, 20, 30]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n a... | [
"[1,2,3,4,2,3,3,5,7]",
"[4,5,6,4,4]",
"[6,7,8,9]"
] | [
"The constraints are small. Try brute force."
] | {
"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:23:46",
"tests_total": 116,
"tes... | go | {
"raw_signature": "func minimumOperations(nums []int) int {",
"container": null,
"callable": "minimumOperations",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,397 | maximum-number-of-distinct-elements-after-operations | Medium | You are given an integer array nums and an integer k.
You are allowed to perform the following operation on each element of the array at most once:
- Add an integer in the range [-k, k] to the element.
Return the maximum possible number of distinct elements in nums after performing the operations.
Example 1:
Input... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1000000000, 1, 1000000000],k = 1000000000) == 4\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 5\n assert candidate(nums = [10, 10, 10, 10, 10],k = 5) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],k = 0) == 1\n ... | [
"[1,2,2,3,3,4]\n2",
"[4,4,4,4]\n1"
] | [
"Can we use sorting here?",
"Find the minimum element which is not used for each element."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxDistinctElements",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:23:48",
"tests_total": ... | go | {
"raw_signature": "func maxDistinctElements(nums []int, k int) int {",
"container": null,
"callable": "maxDistinctElements",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/c... |
3,398 | smallest-substring-with-identical-characters-i | Hard | You are given a binary string s of length n and an integer numOps.
You are allowed to perform the following operation on s at most numOps times:
- Select any index i (where 0 <= i < n) and flip s[i]. If s[i] == '1', change s[i] to '0' and vice versa.
You need to minimize the length of the longest substring of s such... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"111000\",numOps = 1) == 3\n assert candidate(s = \"11111\",numOps = 2) == 1\n assert candidate(s = \"101010\",numOps = 3) == 1\n assert candidate(s = \"1100110011\",numOps = 3) == 2\n assert candidate(s = \"001100\",num... | [
"\"000001\"\n1",
"\"0000\"\n2",
"\"0101\"\n0"
] | [
"Can we use binary search here?",
"Use DP for predicate function"
] | {
"canonical_parameter_names": [
"s",
"numOps"
],
"leetcode_dataset_entry_point": "Solution().minLength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:23:50",
"tests_total": 120,
"... | go | {
"raw_signature": "func minLength(s string, numOps int) int {",
"container": null,
"callable": "minLength",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "numOps",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
... |
3,399 | smallest-substring-with-identical-characters-ii | Hard | You are given a binary string s of length n and an integer numOps.
You are allowed to perform the following operation on s at most numOps times:
- Select any index i (where 0 <= i < n) and flip s[i]. If s[i] == '1', change s[i] to '0' and vice versa.
You need to minimize the length of the longest substring of s such... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"000001\",numOps = 1) == 2\n assert candidate(s = \"111000\",numOps = 2) == 1\n assert candidate(s = \"11111111\",numOps = 3) == 2\n assert candidate(s = \"111110\",numOps = 2) == 1\n assert candidate(s = \"101010\",numO... | [
"\"000001\"\n1",
"\"0000\"\n2",
"\"0101\"\n0"
] | [
"Binary search for the answer.",
"Group the same digits by size of (mid + 1) and ignore any remainder. Flip one in each group (the last one).",
"For the last group, we can flip the 2nd last one.",
"What if the answer was 1?"
] | {
"canonical_parameter_names": [
"s",
"numOps"
],
"leetcode_dataset_entry_point": "Solution().minLength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:23:52",
"tests_total": 128,
"... | go | {
"raw_signature": "func minLength(s string, numOps int) int {",
"container": null,
"callable": "minLength",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "numOps",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
... |
3,402 | minimum-operations-to-make-columns-strictly-increasing | Easy | You are given a m x n matrix grid consisting of non-negative integers.
In one operation, you can increment the value of any grid[i][j] by 1.
Return the minimum number of operations needed to make all columns of grid strictly increasing.
Example 1:
Input: grid = [[3,2],[1,3],[3,4],[0,1]]
Output: 15
Explanation:
- To... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 9\n assert candidate(grid = [[0, 0, 0], [1, 1, 1], [2, 2, 2]]) == 0\n assert candidate(grid = [[3, 2, 1], [2, 1, 0], [1, 2, 3]]) == 12\n assert candidate(grid = [[10, 20], [15, 25], [... | [
"[[3,2],[1,3],[3,4],[0,1]]",
"[[3,2,1],[2,1,0],[1,2,3]]"
] | [
"grid[i + 1][j] must be at least equal to grid[i][j] + 1.",
"Iterate on i in increasing order, and set grid[i + 1][j] = max(grid[i][j]+1, grid[i + 1][j])."
] | {
"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:23:57",
"tests_total": 93,
"test... | go | {
"raw_signature": "func minimumOperations(grid [][]int) int {",
"container": null,
"callable": "minimumOperations",
"parameters": [
{
"name": "grid",
"type": "[][]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,403 | find-the-lexicographically-largest-string-from-the-box-i | Medium | You are given a string word, and an integer numFriends.
Alice is organizing a game for her numFriends friends. There are multiple rounds in the game, where in each round:
- word is split into numFriends non-empty strings, such that no previous round has had the exact same split.
- All the split words are put into a b... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word = \"aabbcc\",numFriends = 2) == \"cc\"\n assert candidate(word = \"zxy\",numFriends = 1) == \"zxy\"\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcba\",numFriends = 5) == \"zyxwvutsrqponmlkjihgfe\"\n assert candidate(w... | [
"\"dbca\"\n2",
"\"gggg\"\n4"
] | [
"Find lexicographically largest substring of size n - numFriends + 1 or less starting at every index."
] | {
"canonical_parameter_names": [
"word",
"numFriends"
],
"leetcode_dataset_entry_point": "Solution().answerString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:23:59",
"tests_total"... | go | {
"raw_signature": "func answerString(word string, numFriends int) string {",
"container": null,
"callable": "answerString",
"parameters": [
{
"name": "word",
"type": "string"
},
{
"name": "numFriends",
"type": "int"
}
],
"return_type": "string",
"signature_source":... |
3,404 | count-special-subsequences | Medium | You are given an array nums consisting of positive integers.
A special subsequence is defined as a subsequence of length 4, represented by indices (p, q, r, s), where p < q < r < s. This subsequence must satisfy the following conditions:
- nums[p] * nums[r] == nums[q] * nums[s]
- There must be at least one element be... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 17550\n assert candidate(nums = [10, 20, 30, 40, 10, 20, 30, 40, 10, 20, 30, 40, 10]) == 23\n assert candidate(nums = [1, 1, 2, 2... | [
"[1,2,3,4,3,6,1]",
"[3,4,3,4,3,4,3,4]"
] | [
"Count pairs where nums[p] / nums[q] equals nums[s] / nums[r], using GCD to handle ratios efficiently.",
"Try iterating over (p, q) pairs and efficiently count valid (r, s) pairs with the same ratio."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().numberOfSubsequences",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:01",
"tests_total": 127,
"... | go | {
"raw_signature": "func numberOfSubsequences(nums []int) int64 {",
"container": null,
"callable": "numberOfSubsequences",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "int64",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets... |
3,407 | substring-matching-pattern | Easy | You are given a string s and a pattern string p, where p contains exactly one '*' character.
The '*' in p can be replaced with any sequence of zero or more characters.
Return true if p can be made a substring of s, and false otherwise.
Example 1:
Input: s = "leetcode", p = "ee*e"
Output: true
Explanation:
By replac... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"luck\",p = \"u*\") == True\n assert candidate(s = \"xy\",p = \"*\") == True\n assert candidate(s = \"leetcode\",p = \"ee*e\") == True\n assert candidate(s = \"testcase\",p = \"te*se\") == True\n assert candidate(s = \"c... | [
"\"leetcode\"\n\"ee*e\"",
"\"car\"\n\"c*v\"",
"\"luck\"\n\"u*\""
] | [
"Divide the pattern in two strings and search in the string."
] | {
"canonical_parameter_names": [
"s",
"p"
],
"leetcode_dataset_entry_point": "Solution().hasMatch",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:09",
"tests_total": 209,
"tests_... | go | {
"raw_signature": "func hasMatch(s string, p string) bool {",
"container": null,
"callable": "hasMatch",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "p",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"t... |
3,409 | longest-subsequence-with-decreasing-adjacent-difference | Medium | You are given an array of integers nums.
Your task is to find the length of the longest subsequence seq of nums, such that the absolute differences between consecutive elements form a non-increasing sequence of integers. In other words, for a subsequence seq_0, seq_1, seq_2, ..., seq_m of nums, |seq_1 - seq_0| >= |seq... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 6\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10]) == 8\n assert candidate(nums = [300, 1, 300, 2, 300, 3, 300]) == 7\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == ... | [
"[16,6,3]",
"[6,5,3,4,2,1]",
"[10,20,10,19,10,20]"
] | [
"Use dynamic programming.",
"Store the maximum answer for each index and every possible difference."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().longestSubsequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:11",
"tests_total": 121,
"te... | go | {
"raw_signature": "func longestSubsequence(nums []int) int {",
"container": null,
"callable": "longestSubsequence",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,410 | maximize-subarray-sum-after-removing-all-occurrences-of-one-element | Hard | You are given an integer array nums.
You can do the following operation on the array at most once:
- Choose any integer x such that nums remains non-empty on removing all occurrences of x.
- Remove all occurrences of x from the array.
Return the maximum subarray sum across all possible resulting arrays.
Example 1:
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, -1, 3, -2, 4, -3, 5]) == 12\n assert candidate(nums = [1, -1, 1, -1, 1]) == 3\n assert candidate(nums = [1, 2, 2, 1]) == 6\n assert candidate(nums = [5, -3, 5, -2, 5, -1, 5]) == 17\n assert candidate(nums = [-3,... | [
"[-3,2,-2,-1,3,-2,3]",
"[1,2,3,4]"
] | [
"Use a segment tree data structure to solve the problem.",
"Each node of the segment tree should store the subarray sum, the maximum subarray sum, the maximum prefix sum, and the maximum suffix sum within the subarray defined by that node."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxSubarraySum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:14",
"tests_total": 140,
"tests_... | go | {
"raw_signature": "func maxSubarraySum(nums []int) int64 {",
"container": null,
"callable": "maxSubarraySum",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "int64",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,411 | maximum-subarray-with-equal-products | Easy | You are given an array of positive integers nums.
An array arr is called product equivalent if prod(arr) == lcm(arr) * gcd(arr), where:
- prod(arr) is the product of all elements of arr.
- gcd(arr) is the GCD of all elements of arr.
- lcm(arr) is the LCM of all elements of arr.
Return the length of the longest produ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [6, 3, 2, 1, 5, 4]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert... | [
"[1,2,1,2,1,1,1]",
"[2,3,4,5,6]",
"[1,2,3,1,4,5,1]"
] | [
"What is the maximum possible lcm?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxLength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:16",
"tests_total": 126,
"tests_dropp... | go | {
"raw_signature": "func maxLength(nums []int) int {",
"container": null,
"callable": "maxLength",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,412 | find-mirror-score-of-a-string | Medium | You are given a string s.
We define the mirror of a letter in the English alphabet as its corresponding letter when the alphabet is reversed. For example, the mirror of 'a' is 'z', and the mirror of 'y' is 'b'.
Initially, all characters in the string s are unmarked.
You start with a score of 0, and you perform the f... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"b\") == 0\n assert candidate(s = \"mirror\") == 1\n assert candidate(s = \"az\") == 1\n assert candidate(s = \"abbabba\") == 0\n assert candidate(s = \"abcba\") == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxy... | [
"\"aczzx\"",
"\"abcdef\""
] | [
"Create a stack for every character.",
"For each index, check if the stack for mirror of the letter at that index is empty."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().calculateScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:18",
"tests_total": 74,
"tests_drop... | go | {
"raw_signature": "func calculateScore(s string) int64 {",
"container": null,
"callable": "calculateScore",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int64",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,413 | maximum-coins-from-k-consecutive-bags | Medium | There are an infinite amount of bags on a number line, one bag for each coordinate. Some of these bags contain coins.
You are given a 2D array coins, where coins[i] = [l_i, r_i, c_i] denotes that every bag from l_i to r_i contains c_i coins.
The segments that coins contain are non-overlapping.
You are also given an ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(coins = [[8, 10, 1], [1, 3, 2], [5, 6, 4]],k = 4) == 10\n assert candidate(coins = [[1, 10, 3]],k = 2) == 6\n assert candidate(coins = [[10, 20, 5], [30, 40, 10], [50, 60, 15]],k = 5) == 75\n assert candidate(coins = [[1, 2, 5],... | [
"[[8,10,1],[1,3,2],[5,6,4]]\n4",
"[[1,10,3]]\n2"
] | [
"An optimal starting position for k consecutive bags will be either l_i or r_i - k + 1."
] | {
"canonical_parameter_names": [
"coins",
"k"
],
"leetcode_dataset_entry_point": "Solution().maximumCoins",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:21",
"tests_total": 115,
... | go | {
"raw_signature": "func maximumCoins(coins [][]int, k int) int64 {",
"container": null,
"callable": "maximumCoins",
"parameters": [
{
"name": "coins",
"type": "[][]int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int64",
"signature_source": "leetcode/codeS... |
3,417 | zigzag-grid-traversal-with-skip | Easy | You are given an m x n 2D array grid of positive integers.
Your task is to traverse grid in a zigzag pattern while skipping every alternate cell.
Zigzag pattern traversal is defined as following the below actions:
- Start at the top-left cell (0, 0).
- Move right within a row until the end of the row is reached.
- D... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 3, 5], [2, 4, 6], [7, 9, 11], [8, 10, 12]]) == [1, 5, 4, 7, 11, 10]\n assert candidate(grid = [[2, 4, 6], [8, 10, 12], [14, 16, 18], [20, 22, 24], [26, 28, 30]]) == [2, 6, 10, 14, 18, 22, 26, 30]\n assert candidate(grid... | [
"[[1,2],[3,4]]",
"[[2,1],[2,1],[2,1]]",
"[[1,2,3],[4,5,6],[7,8,9]]"
] | [] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().zigzagTraversal",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:26",
"tests_total": 71,
"tests_... | go | {
"raw_signature": "func zigzagTraversal(grid [][]int) []int {",
"container": null,
"callable": "zigzagTraversal",
"parameters": [
{
"name": "grid",
"type": "[][]int"
}
],
"return_type": "[]int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,418 | maximum-amount-of-money-robot-can-earn | Medium | You are given an m x n grid. A robot starts at the top-left corner of the grid (0, 0) and wants to reach the bottom-right corner (m - 1, n - 1). The robot can move either right or down at any point in time.
The grid contains a value coins[i][j] in each cell:
- If coins[i][j] >= 0, the robot gains that many coins.
- I... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(coins = [[0, 1, -1], [1, -2, 3], [2, -3, 4]]) == 8\n assert candidate(coins = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9]]) == 34\n assert candidate(coins = [[1000, -1000, 1000, -1000], [-1000, 1000, -1000, 1000], [1000, -10... | [
"[[0,1,-1],[1,-2,3],[2,-3,4]]",
"[[10,10,10],[10,10,10]]"
] | [
"Use Dynamic Programming.",
"Let dp[i][j][k] denote the maximum amount of money a robot can earn by starting at cell (i,j) and having neutralized k robbers."
] | {
"canonical_parameter_names": [
"coins"
],
"leetcode_dataset_entry_point": "Solution().maximumAmount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:29",
"tests_total": 85,
"tests_d... | go | {
"raw_signature": "func maximumAmount(coins [][]int) int {",
"container": null,
"callable": "maximumAmount",
"parameters": [
{
"name": "coins",
"type": "[][]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,419 | minimize-the-maximum-edge-weight-of-graph | Medium | You are given two integers, n and threshold, as well as a directed weighted graph of n nodes numbered from 0 to n - 1. The graph is represented by a 2D integer array edges, where edges[i] = [A_i, B_i, W_i] indicates that there is an edge going from node A_i to node B_i with weight W_i.
You have to remove some edges fr... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,edges = [[1, 2, 1], [1, 3, 3], [1, 4, 5], [2, 3, 2], [3, 4, 2], [4, 0, 1]],threshold = 1) == 2\n assert candidate(n = 5,edges = [[1, 0, 1], [2, 0, 2], [3, 0, 1], [4, 3, 1], [2, 1, 1]],threshold = 2) == 1\n assert candidate(n ... | [
"5\n[[1,0,1],[2,0,2],[3,0,1],[4,3,1],[2,1,1]]\n2",
"5\n[[0,1,1],[0,2,2],[0,3,1],[0,4,1],[1,2,1],[1,4,1]]\n1",
"5\n[[1,2,1],[1,3,3],[1,4,5],[2,3,2],[3,4,2],[4,0,1]]\n1",
"5\n[[1,2,1],[1,3,3],[1,4,5],[2,3,2],[4,0,1]]\n1"
] | [
"Can we use binary search?",
"Invert the edges in the graph."
] | {
"canonical_parameter_names": [
"n",
"edges",
"threshold"
],
"leetcode_dataset_entry_point": "Solution().minMaxWeight",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:32",
"tes... | go | {
"raw_signature": "func minMaxWeight(n int, edges [][]int, threshold int) int {",
"container": null,
"callable": "minMaxWeight",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "[][]int"
},
{
"name": "threshold",
"type": "int"
... |
3,420 | count-non-decreasing-subarrays-after-k-operations | Hard | You are given an array nums of n integers and an integer k.
For each subarray of nums, you can apply up to k operations on it. In each operation, you increment any element of the subarray by 1.
Note that each subarray is considered independently, meaning changes made to one subarray do not persist to another.
Return... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1],k = 10) == 15\n assert candidate(nums = [10, 20, 10, 20, 10],k = 15) == 13\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 55\n assert candidate(nums = [1, 100, 2, 99, 3, 98],k = 100) =... | [
"[6,3,1,2,4,4]\n7",
"[6,3,1,3,6]\n4"
] | [
"Use a sparse table.",
"Compute sp[e][i] = [lastElement, operations] where operations is the number of operations required to make the subarray nums[i...i + 2^e - 1] non-decreasing, and lastElement be the value of the last element after the operations were applied on it.",
"How can we combine sp[a][i] with sp[b... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().countNonDecreasingSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:35",
"tests_... | go | {
"raw_signature": "func countNonDecreasingSubarrays(nums []int, k int) int64 {",
"container": null,
"callable": "countNonDecreasingSubarrays",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int64",
"signature_... |
3,423 | maximum-difference-between-adjacent-elements-in-a-circular-array | Easy | Given a circular array nums, find the maximum absolute difference between adjacent elements.
Note: In a circular array, the first and last elements are adjacent.
Example 1:
Input: nums = [1,2,4]
Output: 3
Explanation:
Because nums is circular, nums[0] and nums[2] are adjacent. They have the maximum absolute differen... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100, 1, 100, 1, 100]) == 99\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 50\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == 6\n assert candidate(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == 45\n as... | [
"[1,2,4]",
"[-5,-10,-5]"
] | [
"Traverse from the second element to the last element and check the difference of every adjacent pair.",
"The edge case is to check the difference between the first and last elements."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxAdjacentDistance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:40",
"tests_total": 120,
"t... | go | {
"raw_signature": "func maxAdjacentDistance(nums []int) int {",
"container": null,
"callable": "maxAdjacentDistance",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,424 | minimum-cost-to-make-arrays-identical | Medium | You are given two integer arrays arr and brr of length n, and an integer k. You can perform the following operations on arr any number of times:
- Split arr into any number of contiguous subarrays and rearrange these subarrays in any order. This operation has a fixed cost of k.
-
Choose any element in arr and add or s... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [0, 0, 0],brr = [0, 0, 0],k = 10) == 0\n assert candidate(arr = [2, 1],brr = [2, 1],k = 0) == 0\n assert candidate(arr = [0, 0, 0],brr = [0, 0, 0],k = 100) == 0\n assert candidate(arr = [1, 2, 3],brr = [3, 2, 1],k = 10) ==... | [
"[-7,9,5]\n[7,-2,-5]\n2",
"[2,1]\n[2,1]\n0"
] | [
"What does Operation 1 (rearranging subarrays) actually accomplish?",
"Calculate sum(abs(arr[i] - brr[i])) if you do not use Operation 1.",
"Calculate sum(abs(arr[i] - brr[i])) after sorting both arrays if you use Operation 1."
] | {
"canonical_parameter_names": [
"arr",
"brr",
"k"
],
"leetcode_dataset_entry_point": "Solution().minCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:44",
"tests_total": 12... | go | {
"raw_signature": "func minCost(arr []int, brr []int, k int64) int64 {",
"container": null,
"callable": "minCost",
"parameters": [
{
"name": "arr",
"type": "[]int"
},
{
"name": "brr",
"type": "[]int"
},
{
"name": "k",
"type": "int64"
}
],
"return_... |
3,426 | manhattan-distances-of-all-arrangements-of-pieces | Hard | You are given three integers m, n, and k.
There is a rectangular grid of size m × n containing k identical pieces. Return the sum of Manhattan distances between every pair of pieces over all valid arrangements of pieces.
A valid arrangement is a placement of all k pieces on the grid with at most one piece per cell.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(m = 5,n = 5,k = 5) == 1771000\n assert candidate(m = 100,n = 100,k = 10) == 384963906\n assert candidate(m = 10,n = 10,k = 20) == 80781589\n assert candidate(m = 1,n = 4,k = 3) == 20\n assert candidate(m = 10,n = 10,k = 10) =... | [
"2\n2\n2",
"1\n4\n3"
] | [
"Fix two pieces in two specific locations and find the number of boards where this can happen.",
"A particular pair of positions will be counted exactly C(m * n - 2, k - 2) times. Calculate the total distance for all pairs of positions and multiply it with C(m * n - 2, k - 2)."
] | {
"canonical_parameter_names": [
"m",
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().distanceSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:49",
"tests_total": 89... | go | {
"raw_signature": "func distanceSum(m int, n int, k int) int {",
"container": null,
"callable": "distanceSum",
"parameters": [
{
"name": "m",
"type": "int"
},
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
... |
3,427 | sum-of-variable-length-subarrays | Easy | You are given an integer array nums of size n. For each index i where 0 <= i < n, define a subarray nums[start ... i] where start = max(0, i - nums[i]).
Return the total sum of all elements from the subarray defined for each index in the array.
Example 1:
Input: nums = [2,3,1]
Output: 11
Explanation:
i | Subarray |... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 38\n assert candidate(nums = [50, 25, 50, 25, 50]) == 600\n assert candidate(nums = [10, 5, 2, 3]) == 62\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 19\n assert candidate(nums = [10... | [
"[2,3,1]",
"[3,1,1,2]"
] | [
"The constraints are small, so brute force for each index."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().subarraySum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:51",
"tests_total": 94,
"tests_drop... | go | {
"raw_signature": "func subarraySum(nums []int) int {",
"container": null,
"callable": "subarraySum",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,428 | maximum-and-minimum-sums-of-at-most-size-k-subsequences | Medium | You are given an integer array nums and a positive integer k. Return the sum of the maximum and minimum elements of all subsequences of nums with at most k elements.
Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: nums = [1,2,3], k = 2
Output: 24
Explanation:
The subsequences of nums... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [7, 8, 9, 10, 11],k = 4) == 540\n assert candidate(nums = [5, 0, 6],k = 1) == 22\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 7007\n assert candidate(nums = [4, 3, 2, 1],k = 3) == 70\n assert can... | [
"[1,2,3]\n2",
"[5,0,6]\n1",
"[1,1,1]\n2"
] | [
"Sort the array."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().minMaxSums",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:53",
"tests_total": 107,
"t... | go | {
"raw_signature": "func minMaxSums(nums []int, k int) int {",
"container": null,
"callable": "minMaxSums",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"t... |
3,429 | paint-house-iv | Medium | You are given an even integer n representing the number of houses arranged in a straight line, and a 2D array cost of size n x 3, where cost[i][j] represents the cost of painting house i with color j + 1.
The houses will look beautiful if they satisfy the following conditions:
- No two adjacent houses are painted the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,cost = [[3, 5, 7], [6, 2, 9], [4, 8, 1], [7, 3, 5]]) == 9\n assert candidate(n = 10,cost = [[5, 5, 5], [4, 4, 4], [3, 3, 3], [2, 2, 2], [1, 1, 1], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]]) == 30\n assert candida... | [
"4\n[[3,5,7],[6,2,9],[4,8,1],[7,3,5]]",
"6\n[[2,4,6],[5,3,8],[7,1,9],[4,6,2],[3,5,7],[8,2,4]]"
] | [
"Use dynamic programming to calculate the minimum cost while ensuring that the adjacency and equidistant constraints are satisfied.",
"Try all 9 combinations of colors for equidistant pairs to get the minimum cost."
] | {
"canonical_parameter_names": [
"n",
"cost"
],
"leetcode_dataset_entry_point": "Solution().minCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:24:56",
"tests_total": 91,
"tests... | go | {
"raw_signature": "func minCost(n int, cost [][]int) int64 {",
"container": null,
"callable": "minCost",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "cost",
"type": "[][]int"
}
],
"return_type": "int64",
"signature_source": "leetcode/codeSnippets",
... |
3,432 | count-partitions-with-even-sum-difference | Easy | You are given an integer array nums of length n.
A partition is defined as an index i where 0 <= i < n - 1, splitting the array into two non-empty subarrays such that:
- Left subarray contains indices [0, i].
- Right subarray contains indices [i + 1, n - 1].
Return the number of partitions where the difference betwe... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100, 100, 100, 100]) == 3\n assert candidate(nums = [100, 100]) == 1\n assert candidate(nums = [100, 100, 100, 100, 100]) == 4\n assert candidate(nums = [1, 2, 2]) == 0\n assert candidate(nums = [1, 1, 1, 1]) == 3\n ... | [
"[10,10,3,7,6]",
"[1,2,2]",
"[2,4,6,8]"
] | [
"If the parity of the sum is even, the partition is valid; otherwise, there is no partition."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countPartitions",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:01",
"tests_total": 92,
"tests_... | go | {
"raw_signature": "func countPartitions(nums []int) int {",
"container": null,
"callable": "countPartitions",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,433 | count-mentions-per-user | Medium | You are given an integer numberOfUsers representing the total number of users and an array events of size n x 3.
Each events[i] can be either of the following two types:
1. Message Event: ["MESSAGE", "timestamp_i", "mentions_string_i"]
- This event indicates that a set of users was mentioned in a message at timesta... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(numberOfUsers = 1,events = [['MESSAGE', '1', 'id0'], ['MESSAGE', '1', 'HERE'], ['MESSAGE', '1', 'ALL']]) == [3]\n assert candidate(numberOfUsers = 2,events = [['OFFLINE', '10', '0'], ['MESSAGE', '12', 'HERE']]) == [0, 1]\n assert c... | [
"2\n[[\"MESSAGE\",\"10\",\"id1 id0\"],[\"OFFLINE\",\"11\",\"0\"],[\"MESSAGE\",\"71\",\"HERE\"]]",
"2\n[[\"MESSAGE\",\"10\",\"id1 id0\"],[\"OFFLINE\",\"11\",\"0\"],[\"MESSAGE\",\"12\",\"ALL\"]]",
"2\n[[\"OFFLINE\",\"10\",\"0\"],[\"MESSAGE\",\"12\",\"HERE\"]]"
] | [
"Sort events by timestamp and then process each event.",
"Maintain two sets for offline and online user IDs."
] | {
"canonical_parameter_names": [
"numberOfUsers",
"events"
],
"leetcode_dataset_entry_point": "Solution().countMentions",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:04",
"tests_... | go | {
"raw_signature": "func countMentions(numberOfUsers int, events [][]string) []int {",
"container": null,
"callable": "countMentions",
"parameters": [
{
"name": "numberOfUsers",
"type": "int"
},
{
"name": "events",
"type": "[][]string"
}
],
"return_type": "[]int",
"... |
3,434 | maximum-frequency-after-subarray-operation | Medium | You are given an array nums of length n. You are also given an integer k.
You perform the following operation on nums once:
- Select a subarray nums[i..j] where 0 <= i <= j <= n - 1.
- Select an integer x and add x to all the elements in nums[i..j].
Find the maximum frequency of the value k after the operation.
Exa... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 5\n assert candidate(nums = [10, 20, 30, 40, 50],k = 50) == 2\n assert candidate(nums = [1, 50, 1, 50, 1],k = 50) == 3\n assert candidate(nums = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25],k = 25) =... | [
"[1,2,3,4,5,6]\n1",
"[10,2,3,4,5,5,4,3,2,2]\n10"
] | [
"Fix the element you want to convert to k.",
"Use prefix sums to optimize counting occurrences of an element."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxFrequency",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:06",
"tests_total": 132,
... | go | {
"raw_signature": "func maxFrequency(nums []int, k int) int {",
"container": null,
"callable": "maxFrequency",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
... |
3,435 | frequencies-of-shortest-supersequences | Hard | You are given an array of strings words. Find all shortest common supersequences (SCS) of words that are not permutations of each other.
A shortest common supersequence is a string of minimum length that contains each string in words as a subsequence.
Return a 2D array of integers freqs that represent all the SCSs. E... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ... | [
"[\"ab\",\"ba\"]",
"[\"aa\",\"ac\"]",
"[\"aa\",\"bb\",\"cc\"]"
] | [
"Each SCS contains at most 2 occurrences of each character. Why?",
"Construct every subset of possible characters (1 or 2).",
"Check if a supersequence could be constructed using Topological Sort."
] | {
"canonical_parameter_names": [
"words"
],
"leetcode_dataset_entry_point": "Solution().supersequences",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:08",
"tests_total": 146,
"tests... | go | {
"raw_signature": "func supersequences(words []string) [][]int {",
"container": null,
"callable": "supersequences",
"parameters": [
{
"name": "words",
"type": "[]string"
}
],
"return_type": "[][]int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets... |
3,438 | find-valid-pair-of-adjacent-digits-in-string | Easy | You are given a string s consisting only of digits. A valid pair is defined as two adjacent digits in s such that:
- The first digit is not equal to the second.
- Each digit in the pair appears in s exactly as many times as its numeric value.
Return the first valid pair found in the string s when traversing from left... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"213123\") == \"\"\n assert candidate(s = \"9999999998888888777777666665555444332211\") == \"\"\n assert candidate(s = \"221\") == \"21\"\n assert candidate(s = \"22221111\") == \"\"\n assert candidate(s = \"122223333344... | [
"\"2523533\"",
"\"221\"",
"\"22\""
] | [
"Use a HashMap to count the frequency of each digit."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().findValidPair",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:13",
"tests_total": 166,
"tests_drop... | go | {
"raw_signature": "func findValidPair(s string) string {",
"container": null,
"callable": "findValidPair",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,439 | reschedule-meetings-for-maximum-free-time-i | Medium | You are given an integer eventTime denoting the duration of an event, where the event occurs from time t = 0 to time t = eventTime.
You are also given two integer arrays startTime and endTime, each of length n. These represent the start and end time of n non-overlapping meetings, where the i^th meeting occurs during t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(eventTime = 15,k = 3,startTime = [1, 5, 9],endTime = [3, 7, 12]) == 8\n assert candidate(eventTime = 10,k = 1,startTime = [0, 2, 9],endTime = [1, 4, 10]) == 6\n assert candidate(eventTime = 5,k = 1,startTime = [1, 3],endTime = [2, ... | [
"5\n1\n[1,3]\n[2,5]",
"10\n1\n[0,2,9]\n[1,4,10]",
"5\n2\n[0,1,2,3,4]\n[1,2,3,4,5]"
] | [
"In a sequence of K meetings and K + 1 gaps, you could move all meetings to the start of the sequence to get the max free time.",
"Use a sliding window of K + 1 size to store sum of gaps and take the maximum."
] | {
"canonical_parameter_names": [
"eventTime",
"k",
"startTime",
"endTime"
],
"leetcode_dataset_entry_point": "Solution().maxFreeTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30... | go | {
"raw_signature": "func maxFreeTime(eventTime int, k int, startTime []int, endTime []int) int {",
"container": null,
"callable": "maxFreeTime",
"parameters": [
{
"name": "eventTime",
"type": "int"
},
{
"name": "k",
"type": "int"
},
{
"name": "startTime",
... |
3,440 | reschedule-meetings-for-maximum-free-time-ii | Medium | You are given an integer eventTime denoting the duration of an event. You are also given two integer arrays startTime and endTime, each of length n.
These represent the start and end times of n non-overlapping meetings that occur during the event between time t = 0 and time t = eventTime, where the i^th meeting occurs... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(eventTime = 50,startTime = [0, 5, 10, 15, 20],endTime = [3, 8, 13, 18, 23]) == 29\n assert candidate(eventTime = 50,startTime = [5, 15, 25, 35],endTime = [10, 20, 30, 40]) == 20\n assert candidate(eventTime = 20,startTime = [0, 5, ... | [
"5\n[1,3]\n[2,5]",
"10\n[0,7,9]\n[1,8,10]",
"10\n[0,3,7,9]\n[1,4,8,10]",
"5\n[0,1,2,3,4]\n[1,2,3,4,5]"
] | [
"If we reschedule a meeting earlier or later, we need to find a gap of length at least endTime[i] - startTime[i]. Try maintaining the gaps in some sorted data structure."
] | {
"canonical_parameter_names": [
"eventTime",
"startTime",
"endTime"
],
"leetcode_dataset_entry_point": "Solution().maxFreeTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:18... | go | {
"raw_signature": "func maxFreeTime(eventTime int, startTime []int, endTime []int) int {",
"container": null,
"callable": "maxFreeTime",
"parameters": [
{
"name": "eventTime",
"type": "int"
},
{
"name": "startTime",
"type": "[]int"
},
{
"name": "endTime",
... |
3,441 | minimum-cost-good-caption | Hard | You are given a string caption of length n. A good caption is a string where every character appears in groups of at least 3 consecutive occurrences.
For example:
- "aaabbb" and "aaaaccc" are good captions.
- "aabbb" and "ccccd" are not good captions.
You can perform the following operation any number of times:
Cho... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(caption = \"cdcd\") == \"cccc\"\n assert candidate(caption = \"xyz\") == \"yyy\"\n assert candidate(caption = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"aaaaccceeefffhhhiiikkklllnnnoooqqqrrrtttuuuwwwxxxzzz\"\n ... | [
"\"cdcd\"",
"\"aca\"",
"\"bc\""
] | [
"Construct a DP table and try all possible characters at every index.",
"Choose characters greedily to get the lexicographically smallest caption."
] | {
"canonical_parameter_names": [
"caption"
],
"leetcode_dataset_entry_point": "Solution().minCostGoodCaption",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:21",
"tests_total": 80,
"... | go | {
"raw_signature": "func minCostGoodCaption(caption string) string {",
"container": null,
"callable": "minCostGoodCaption",
"parameters": [
{
"name": "caption",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSn... |
3,442 | maximum-difference-between-even-and-odd-frequency-i | Easy | You are given a string s consisting of lowercase English letters.
Your task is to find the maximum difference diff = freq(a_1) - freq(a_2) between the frequency of characters a_1 and a_2 in the string such that:
- a_1 has an odd frequency in the string.
- a_2 has an even frequency in the string.
Return this maximum ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abacabadabacaba\") == -1\n assert candidate(s = \"aabbc\") == -1\n assert candidate(s = \"aaabbbcccdddeeefffgghhhiiiijjjjkkkkllllmmmmmnnnnooooo\") == 3\n assert candidate(s = \"aabbccdde\") == -1\n assert candidate(s = ... | [
"\"aaaaabbc\"",
"\"abcabcab\""
] | [
"Use a frequency map to identify the maximum odd and minimum even frequencies. Then, calculate their difference."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().maxDifference",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:23",
"tests_total": 49,
"tests_dropp... | go | {
"raw_signature": "func maxDifference(s string) int {",
"container": null,
"callable": "maxDifference",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,443 | maximum-manhattan-distance-after-k-changes | Medium | You are given a string s consisting of the characters 'N', 'S', 'E', and 'W', where s[i] indicates movements in an infinite grid:
- 'N' : Move north by 1 unit.
- 'S' : Move south by 1 unit.
- 'E' : Move east by 1 unit.
- 'W' : Move west by 1 unit.
Initially, you are at the origin (0, 0). You can change at most k char... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"NSWWEW\",k = 3) == 6\n assert candidate(s = \"EEEEEE\",k = 0) == 6\n assert candidate(s = \"NNN\",k = 0) == 3\n assert candidate(s = \"NWSE\",k = 1) == 3\n assert candidate(s = \"EEEE\",k = 4) == 4\n assert candidate... | [
"\"NWSE\"\n1",
"\"NSWWEW\"\n3"
] | [
"We can brute force all the possible directions (NE, NW, SE, SW).",
"Change up to k characters to maximize the distance in the chosen direction."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxDistance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:26",
"tests_total": 108,
"tes... | go | {
"raw_signature": "func maxDistance(s string, k int) int {",
"container": null,
"callable": "maxDistance",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"typ... |
3,444 | minimum-increments-for-target-multiples-in-an-array | Hard | You are given two arrays, nums and target.
In a single operation, you may increment any element of nums by 1.
Return the minimum number of operations required so that each element in target has at least one multiple in nums.
Example 1:
Input: nums = [1,2,3], target = [4]
Output: 1
Explanation:
The minimum number of... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 10, 15],target = [5, 10, 15]) == 0\n assert candidate(nums = [5, 10, 15, 20],target = [5, 15]) == 0\n assert candidate(nums = [10, 20, 30],target = [5, 15]) == 0\n assert candidate(nums = [1, 1, 1],target = [3]) == 2\... | [
"[1,2,3]\n[4]",
"[8,4]\n[10,5]",
"[7,9,10]\n[7]"
] | [
"Use bitmask dynamic programming."
] | {
"canonical_parameter_names": [
"nums",
"target"
],
"leetcode_dataset_entry_point": "Solution().minimumIncrements",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:28",
"tests_total... | go | {
"raw_signature": "func minimumIncrements(nums []int, target []int) int {",
"container": null,
"callable": "minimumIncrements",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "target",
"type": "[]int"
}
],
"return_type": "int",
"signature_source": "... |
3,445 | maximum-difference-between-even-and-odd-frequency-ii | Hard | You are given a string s and an integer k. Your task is to find the maximum difference between the frequency of two characters, freq[a] - freq[b], in a substring subs of s, such that:
- subs has a size of at least k.
- Character a has an odd frequency in subs.
- Character b has a non-zero even frequency in subs.
Retu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1010101010\",k = 4) == 1\n assert candidate(s = \"000111\",k = 2) == 1\n assert candidate(s = \"101010101\",k = 4) == 1\n assert candidate(s = \"444333222111\",k = 6) == 1\n assert candidate(s = \"111222333\",k = 6) == ... | [
"\"12233\"\n4",
"\"1122211\"\n3",
"\"110\"\n3"
] | [
"Fix the two characters.",
"Use prefix sum (maintain 2 characters' parities as status)."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxDifference",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:30",
"tests_total": 137,
"t... | go | {
"raw_signature": "func maxDifference(s string, k int) int {",
"container": null,
"callable": "maxDifference",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
... |
3,446 | sort-matrix-by-diagonals | Medium | You are given an n x n square matrix of integers grid. Return the matrix such that:
- The diagonals in the bottom-left triangle (including the middle diagonal) are sorted in non-increasing order.
- The diagonals in the top-right triangle are sorted in non-decreasing order.
Example 1:
Input: grid = [[1,7,3],[9,8,2],[... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[5, 2, 9], [8, 3, 6], [1, 4, 7]]) == [[7, 2, 9], [8, 5, 6], [1, 4, 3]]\n assert candidate(grid = [[0, 1], [1, 2]]) == [[2, 1], [1, 0]]\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == [[9, 4, 7], [6, 5, 8], [... | [
"[[1,7,3],[9,8,2],[4,5,6]]",
"[[0,1],[1,2]]",
"[[1]]"
] | [
"Use a data structure to store all values in each diagonal.",
"Sort and replace them in the matrix."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().sortMatrix",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:32",
"tests_total": 79,
"tests_dropp... | go | {
"raw_signature": "func sortMatrix(grid [][]int) [][]int {",
"container": null,
"callable": "sortMatrix",
"parameters": [
{
"name": "grid",
"type": "[][]int"
}
],
"return_type": "[][]int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,447 | assign-elements-to-groups-with-constraints | Medium | You are given an integer array groups, where groups[i] represents the size of the i^th group. You are also given an integer array elements.
Your task is to assign one element to each group based on the following rules:
- An element at index j can be assigned to a group i if groups[i] is divisible by elements[j].
- If... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(groups = [1, 1, 1, 1, 1],elements = [1]) == [0, 0, 0, 0, 0]\n assert candidate(groups = [10, 10, 10, 10],elements = [5, 10]) == [0, 0, 0, 0]\n assert candidate(groups = [11, 22, 33, 44, 55],elements = [11, 22]) == [0, 0, 0, 0, 0]\n... | [
"[8,4,3,2,4]\n[4,2]",
"[2,3,5,7]\n[5,3,3]",
"[10,21,30,41]\n[2,1]"
] | [
"Can a sieve-like approach be applied here?",
"Starting from the smallest index, iterate through the multiples of the element and assign it to groups divisible by that value.",
"Process each element once.",
"Find all divisors of each group, then match them with elements."
] | {
"canonical_parameter_names": [
"groups",
"elements"
],
"leetcode_dataset_entry_point": "Solution().assignElements",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:36",
"tests_tota... | go | {
"raw_signature": "func assignElements(groups []int, elements []int) []int {",
"container": null,
"callable": "assignElements",
"parameters": [
{
"name": "groups",
"type": "[]int"
},
{
"name": "elements",
"type": "[]int"
}
],
"return_type": "[]int",
"signature_sour... |
3,448 | count-substrings-divisible-by-last-digit | Hard | You are given a string s consisting of digits.
Return the number of substrings of s divisible by their non-zero last digit.
Note: A substring may contain leading zeros.
Example 1:
Input: s = "12936"
Output: 11
Explanation:
Substrings "29", "129", "293" and "2936" are not divisible by their last digit. There are 15 ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"24680\") == 6\n assert candidate(s = \"11111\") == 15\n assert candidate(s = \"5701283\") == 18\n assert candidate(s = \"9876543210\") == 35\n assert candidate(s = \"1001001001\") == 22\n assert candidate(s = \"99999... | [
"\"12936\"",
"\"5701283\"",
"\"1010101010\""
] | [
"Let dp[index][i][j] be the number of subarrays s[start...index] such that s[start...index] % i == j.",
"For every pair (i, j), add dp[index - 1][i][j] to dp[index][i][(j * 10 + x)%i)].",
"You should optimize this solution so that it can fit into the memory limit.",
"In order to find dp[index][i][j] we use va... | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().countSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:38",
"tests_total": 113,
"tests_dr... | go | {
"raw_signature": "func countSubstrings(s string) int64 {",
"container": null,
"callable": "countSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int64",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,449 | maximize-the-minimum-game-score | Hard | You are given an array points of size n and an integer m. There is another array gameScore of size n, where gameScore[i] represents the score achieved at the i^th game. Initially, gameScore[i] == 0 for all i.
You start at index -1, which is outside the array (before the first position at index 0). You can make at most... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(points = [5, 3, 8, 2, 6],m = 10) == 6\n assert candidate(points = [5, 9, 3, 7],m = 7) == 6\n assert candidate(points = [1, 1, 1, 1, 1],m = 5) == 1\n assert candidate(points = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],m = 20) == 2\n asse... | [
"[2,4]\n3",
"[1,2,3]\n5"
] | [
"Can we use binary search?",
"What happens if you fix the game score as x?",
"We should go from i to (i + 1) back and forth, making the value for each index i (from left to right) no less than x."
] | {
"canonical_parameter_names": [
"points",
"m"
],
"leetcode_dataset_entry_point": "Solution().maxScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:41",
"tests_total": 95,
"te... | go | {
"raw_signature": "func maxScore(points []int, m int) int64 {",
"container": null,
"callable": "maxScore",
"parameters": [
{
"name": "points",
"type": "[]int"
},
{
"name": "m",
"type": "int"
}
],
"return_type": "int64",
"signature_source": "leetcode/codeSnippets",
... |
3,452 | sum-of-good-numbers | Easy | Given an array of integers nums and an integer k, an element nums[i] is considered good if it is strictly greater than the elements at indices i - k and i + k (if those indices exist). If neither of these indices exists, nums[i] is still considered good.
Return the sum of all the good elements in the array.
Example 1... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 1],k = 1) == 2\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 2) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 27\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],... | [
"[1,3,2,1,5,4]\n2",
"[2,1]\n1"
] | [
"For each index, check if nums[i] is strictly greater than nums[i - k] and nums[i + k]."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().sumOfGoodNumbers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:45",
"tests_total": 109... | go | {
"raw_signature": "func sumOfGoodNumbers(nums []int, k int) int {",
"container": null,
"callable": "sumOfGoodNumbers",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSni... |
3,453 | separate-squares-i | Medium | You are given a 2D integer array squares. Each squares[i] = [x_i, y_i, l_i] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.
Find the minimum y-coordinate value of a horizontal line such that the total area of the squares above the line equals the total area o... | {
"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... | [
"[[0,0,1],[2,2,1]]",
"[[0,0,2],[1,1,1]]"
] | [
"Binary search on the answer."
] | {
"canonical_parameter_names": [
"squares"
],
"leetcode_dataset_entry_point": "Solution().separateSquares",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:48",
"tests_total": 107,
"te... | go | {
"raw_signature": "func separateSquares(squares [][]int) float64 {",
"container": null,
"callable": "separateSquares",
"parameters": [
{
"name": "squares",
"type": "[][]int"
}
],
"return_type": "float64",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnip... |
3,454 | separate-squares-ii | Hard | You are given a 2D integer array squares. Each squares[i] = [x_i, y_i, l_i] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.
Find the minimum y-coordinate value of a horizontal line such that the total area covered by squares above the line equals the total ar... | {
"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... | [
"[[0,0,1],[2,2,1]]",
"[[0,0,2],[1,1,1]]"
] | [
"Use a line sweep and a segment tree.",
"The line must lie in one of the squares."
] | {
"canonical_parameter_names": [
"squares"
],
"leetcode_dataset_entry_point": "Solution().separateSquares",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:51",
"tests_total": 103,
"te... | go | {
"raw_signature": "func separateSquares(squares [][]int) float64 {",
"container": null,
"callable": "separateSquares",
"parameters": [
{
"name": "squares",
"type": "[][]int"
}
],
"return_type": "float64",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnip... |
3,455 | shortest-matching-substring | Hard | You are given a string s and a pattern string p, where p contains exactly two '*' characters.
The '*' in p matches any sequence of zero or more characters.
Return the length of the shortest substring in s that matches p. If there is no such substring, return -1.
Note: The empty substring is considered valid.
Exampl... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcdefg\",p = \"*bcd*fg\") == 6\n assert candidate(s = \"abcabcabc\",p = \"*bc*bc\") == 5\n assert candidate(s = \"mississippi\",p = \"mis*si*\") == 5\n assert candidate(s = \"baccbaadbc\",p = \"cc*baa*adb\") == -1\n as... | [
"\"abaacbaecebce\"\n\"ba*c*ce\"",
"\"baccbaadbc\"\n\"cc*baa*adb\"",
"\"a\"\n\"**\"",
"\"madlogic\"\n\"*adlogi*\""
] | [
"The pattern string p can be divided into three segments.",
"Use the KMP algorithm to locate all occurrences of each segment in s."
] | {
"canonical_parameter_names": [
"s",
"p"
],
"leetcode_dataset_entry_point": "Solution().shortestMatchingSubstring",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:53",
"tests_total... | go | {
"raw_signature": "func shortestMatchingSubstring(s string, p string) int {",
"container": null,
"callable": "shortestMatchingSubstring",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "p",
"type": "string"
}
],
"return_type": "int",
"signature_source... |
3,456 | find-special-substring-of-length-k | Easy | You are given a string s and an integer k.
Determine if there exists a substring of length exactly k in s that satisfies the following conditions:
1. The substring consists of only one distinct character (e.g., "aaa" or "bbb").
2. If there is a character immediately before the substring, it must be different from the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abc\",k = 2) == False\n assert candidate(s = \"aabbccddeeff\",k = 2) == True\n assert candidate(s = \"abcde\",k = 1) == True\n assert candidate(s = \"zzzz\",k = 4) == True\n assert candidate(s = \"xyzxyz\",k = 1) == Tru... | [
"\"aaabaaa\"\n3",
"\"abc\"\n2"
] | [
"Return true if there is a sequence of consecutive characters of length k"
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().hasSpecialSubstring",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:56",
"tests_total": 111... | go | {
"raw_signature": "func hasSpecialSubstring(s string, k int) bool {",
"container": null,
"callable": "hasSpecialSubstring",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcode/cod... |
3,457 | eat-pizzas | Medium | You are given an integer array pizzas of size n, where pizzas[i] represents the weight of the i^th pizza. Every day, you eat exactly 4 pizzas. Due to your incredible metabolism, when you eat pizzas of weights W, X, Y, and Z, where W <= X <= Y <= Z, you gain the weight of only 1 pizza!
- On odd-numbered days (1-indexed... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(pizzas = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 320\n assert candidate(pizzas = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 20\n assert candidate(pizzas = [1, 3, 2, 4, 7, 6, 9, 8, 13, 12, 11, 10, 15, 14, 1... | [
"[1,2,3,4,5,6,7,8]",
"[2,1,1,1,1,1,1,1]"
] | [
"On odd-numbered days, it is optimal to pair the smallest three and the largest one.",
"On even-numbered days, it is optimal to pair the smallest two and the largest two.",
"There will be ceil((n / 4) / 2) odd-numbered days. Select pizzas for all odd-numbered days first.",
"Select the remaining pizzas for the... | {
"canonical_parameter_names": [
"pizzas"
],
"leetcode_dataset_entry_point": "Solution().maxWeight",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:25:58",
"tests_total": 103,
"tests_dro... | go | {
"raw_signature": "func maxWeight(pizzas []int) int64 {",
"container": null,
"callable": "maxWeight",
"parameters": [
{
"name": "pizzas",
"type": "[]int"
}
],
"return_type": "int64",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,458 | select-k-disjoint-special-substrings | Medium | Given a string s of length n and an integer k, determine whether it is possible to select k disjoint special substrings.
A special substring is a substring where:
- Any character present inside the substring should not appear outside it in the string.
- The substring is not the entire string s.
Note that all k subst... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"single\",k = 0) == True\n assert candidate(s = \"abeabe\",k = 0) == True\n assert candidate(s = \"cdefdc\",k = 3) == False\n assert candidate(s = \"abacabadabacaba\",k = 3) == False\n assert candidate(s = \"aabbccddeeff... | [
"\"abcdbaefab\"\n2",
"\"cdefdc\"\n3",
"\"abeabe\"\n0"
] | [
"There are at most 26 start points (which are the first occurrence of each letter) and at most 26 end points (which are the last occurrence of each letter) of the substring.",
"Starting from each character, build the smallest special substring interval containing it.",
"Use dynamic programming on the obtained i... | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxSubstringLength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:00",
"tests_total": 95,
... | go | {
"raw_signature": "func maxSubstringLength(s string, k int) bool {",
"container": null,
"callable": "maxSubstringLength",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeS... |
3,459 | length-of-longest-v-shaped-diagonal-segment | Hard | You are given a 2D integer matrix grid of size n x m, where each element is either 0, 1, or 2.
A V-shaped diagonal segment is defined as:
- The segment starts with 1.
- The subsequent elements follow this infinite sequence: 2, 0, 2, 0, ....
- The segment:
- Starts along a diagonal direction (top-left to bottom-righ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 1\n assert candidate(grid = [[1, 2, 0, 2, 0, 1, 2], [0, 2, 1, 2, 1, 2, 2], [0, 0, 2, 1, 2, 1, 2], [2, 0, 2, 1, 2, 1, 0]]) == 3\n assert candidate(grid = [[2, 0, 0, 0], [1, 2, 2, 2], [0, ... | [
"[[2,2,1,2,2],[2,0,2,2,0],[2,0,1,1,0],[1,0,2,2,2],[2,0,0,2,2]]",
"[[2,2,2,2,2],[2,0,2,2,0],[2,0,1,1,0],[1,0,2,2,2],[2,0,0,2,2]]",
"[[1,2,2,2,2],[2,2,2,2,0],[2,0,0,0,0],[0,0,2,2,2],[2,0,0,2,0]]",
"[[1]]"
] | [
"Use dynamic programming to determine the best point to make a 90-degree rotation in the diagonal path while maintaining the required sequence.",
"Represent dynamic programming states as (row, col, currentDirection, hasMadeTurnYet). Track the current position, direction of traversal, and whether a turn has alread... | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().lenOfVDiagonal",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:03",
"tests_total": 76,
"tests_d... | go | {
"raw_signature": "func lenOfVDiagonal(grid [][]int) int {",
"container": null,
"callable": "lenOfVDiagonal",
"parameters": [
{
"name": "grid",
"type": "[][]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,461 | check-if-digits-are-equal-in-string-after-operations-i | Easy | You are given a string s consisting of digits. Perform the following operation repeatedly until the string has exactly two digits:
- For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10.
- Replace s with the sequence of newly calculated d... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"9876543210\") == False\n assert candidate(s = \"100100\") == False\n assert candidate(s = \"123321\") == True\n assert candidate(s = \"111\") == True\n assert candidate(s = \"1234567890\") == False\n assert candidate... | [
"\"3902\"",
"\"34789\""
] | [
"Simulate the operations as described."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().hasSameDigits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:07",
"tests_total": 127,
"tests_drop... | go | {
"raw_signature": "func hasSameDigits(s string) bool {",
"container": null,
"callable": "hasSameDigits",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,462 | maximum-sum-with-at-most-k-elements | Medium | You are given a 2D integer matrix grid of size n x m, an integer array limits of length n, and an integer k. The task is to find the maximum sum of at most k elements from the matrix grid such that:
-
The number of elements taken from the i^th row of grid does not exceed limits[i].
Return the maximum sum.
Example 1:... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[10, 20, 30], [5, 15, 25], [1, 9, 18]],limits = [2, 1, 2],k = 5) == 102\n assert candidate(grid = [[5, 3, 7], [8, 2, 6]],limits = [2, 2],k = 3) == 21\n assert candidate(grid = [[1, 2], [3, 4]],limits = [1, 2],k = 2) == 7\n ... | [
"[[1,2],[3,4]]\n[1,2]\n2",
"[[5,3,7],[8,2,6]]\n[2,2]\n3"
] | [
"Sort each row in descending order and extract the top limits[i] elements.",
"Use a max-heap to efficiently pick the largest k elements across all rows."
] | {
"canonical_parameter_names": [
"grid",
"limits",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:10",
"tests_total":... | go | {
"raw_signature": "func maxSum(grid [][]int, limits []int, k int) int64 {",
"container": null,
"callable": "maxSum",
"parameters": [
{
"name": "grid",
"type": "[][]int"
},
{
"name": "limits",
"type": "[]int"
},
{
"name": "k",
"type": "int"
}
],
"r... |
3,463 | check-if-digits-are-equal-in-string-after-operations-ii | Hard | You are given a string s consisting of digits. Perform the following operation repeatedly until the string has exactly two digits:
- For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10.
- Replace s with the sequence of newly calculated d... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"9876543210\") == False\n assert candidate(s = \"111\") == True\n assert candidate(s = \"1234567890\") == False\n assert candidate(s = \"898989898\") == True\n assert candidate(s = \"1111111111\") == True\n assert can... | [
"\"3902\"",
"\"34789\""
] | [
"Can we use nCr and use Pascal's triangle values here?",
"nCr mod 10 can be uniquely determined from nCr mod 2 and nCr mod 5.",
"Use Lucas's theorem."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().hasSameDigits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:12",
"tests_total": 108,
"tests_drop... | go | {
"raw_signature": "func hasSameDigits(s string) bool {",
"container": null,
"callable": "hasSameDigits",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,464 | maximize-the-distance-between-points-on-a-square | Hard | You are given an integer side, representing the edge length of a square with corners at (0, 0), (0, side), (side, 0), and (side, side) on a Cartesian plane.
You are also given a positive integer k and a 2D integer array points, where points[i] = [x_i, y_i] represents the coordinate of a point lying on the boundary of ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(side = 4,points = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 4], [2, 4], [3, 4], [4, 4], [4, 3], [4, 2], [4, 1], [4, 0], [3, 0], [2, 0], [1, 0]],k = 8) == 2\n assert candidate(side = 3,points = [[0, 0], [0, 1], [0, 2], [0, 3], [3, 0... | [
"2\n[[0,2],[2,0],[2,2],[0,0]]\n4",
"2\n[[0,0],[1,2],[2,0],[2,2],[2,1]]\n4",
"2\n[[0,0],[0,1],[0,2],[1,2],[2,0],[2,2],[2,1]]\n5"
] | [
"Can we use binary search for this problem?",
"Think of the coordinates on a straight line in clockwise order.",
"Binary search on the minimum Manhattan distance x.",
"During the binary search, for each coordinate, find the immediate next coordinate with distance >= x.",
"Greedily select up to k coordinates... | {
"canonical_parameter_names": [
"side",
"points",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxDistance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:14",
"tests_to... | go | {
"raw_signature": "func maxDistance(side int, points [][]int, k int) int {",
"container": null,
"callable": "maxDistance",
"parameters": [
{
"name": "side",
"type": "int"
},
{
"name": "points",
"type": "[][]int"
},
{
"name": "k",
"type": "int"
}
],
... |
3,467 | transform-array-by-parity | Easy | You are given an integer array nums. Transform nums by performing the following operations in the exact order specified:
1. Replace each even number with 0.
2. Replace each odd numbers with 1.
3. Sort the modified array in non-decreasing order.
Return the resulting array after performing these operations.
Example 1:... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == [0, 0, 0, 0, 1, 1, 1, 1, 1]\n assert candidate(nums = [4, 3, 2, 1]) == [0, 0, 1, 1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 0, 0, 0, 0, 1, 1, 1, 1, ... | [
"[4,3,2,1]",
"[1,5,1,4,2]"
] | [
"Let x be the number of even numbers, and y be the number of odd numbers. Output 0 x times, followed by 1 y times."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().transformArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:20",
"tests_total": 104,
"tests_... | go | {
"raw_signature": "func transformArray(nums []int) []int {",
"container": null,
"callable": "transformArray",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "[]int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,468 | find-the-number-of-copy-arrays | Medium | You are given an array original of length n and a 2D array bounds of length n x 2, where bounds[i] = [u_i, v_i].
You need to find the number of possible arrays copy of length n such that:
1. (copy[i] - copy[i - 1]) == (original[i] - original[i - 1]) for 1 <= i <= n - 1.
2. u_i <= copy[i] <= v_i for 0 <= i <= n - 1.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(original = [1, 2, 3, 4],bounds = [[1, 10], [2, 9], [3, 8], [4, 7]]) == 4\n assert candidate(original = [3, 5, 7, 9],bounds = [[2, 4], [4, 6], [6, 8], [8, 10]]) == 3\n assert candidate(original = [10, 11, 12, 13],bounds = [[8, 10], ... | [
"[1,2,3,4]\n[[1,2],[2,3],[3,4],[4,5]]",
"[1,2,3,4]\n[[1,10],[2,9],[3,8],[4,7]]",
"[1,2,1,2]\n[[1,1],[2,3],[3,3],[2,3]]"
] | [
"copy[0] uniquely determines all other values.",
"Possible values for copy[0] are in [u[0], v[0]].",
"From left to right, compute valid ranges for each index by intersecting bounds with the previous range.",
"The answer is the size of the valid range for the last index."
] | {
"canonical_parameter_names": [
"original",
"bounds"
],
"leetcode_dataset_entry_point": "Solution().countArrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:23",
"tests_total":... | go | {
"raw_signature": "func countArrays(original []int, bounds [][]int) int {",
"container": null,
"callable": "countArrays",
"parameters": [
{
"name": "original",
"type": "[]int"
},
{
"name": "bounds",
"type": "[][]int"
}
],
"return_type": "int",
"signature_source": "... |
3,469 | find-minimum-cost-to-remove-array-elements | Medium | You are given an integer array nums. Your task is to remove all elements from the array by performing one of the following operations at each step until nums is empty:
- Choose any two elements from the first three elements of nums and remove them. The cost of this operation is the maximum of the two elements removed.... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10]) == 20\n assert candidate(nums = [10, 20, 30]) == 40\n assert candidate(nums = [999999, 1]) == 999999\n assert candidate(nums = [5, 3, 7, 9, 1, 4]) == 18\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3,... | [
"[6,2,8,4]",
"[2,1,3,3]"
] | [
"Can we use dynamic programming here?",
"Use dynamic programming. The process guarantees that the remaining elements form a prefix of the array with at most one previous element.",
"Define the state as dp[i][j], where i represents the last remaining element and j represents the starting index of the current pre... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:25",
"tests_total": 116,
"tests_dropped... | go | {
"raw_signature": "func minCost(nums []int) int {",
"container": null,
"callable": "minCost",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,470 | permutations-iv | Hard | Given two integers, n and k, an alternating permutation is a permutation of the first n positive integers such that no two adjacent elements are both odd or both even.
Return the k-th alternating permutation sorted in lexicographical order. If there are fewer than k valid alternating permutations, return an empty list... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 100,k = 1000000000000000) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, ... | [
"4\n6",
"3\n2",
"2\n3"
] | [
"If n is odd, the first number must be odd.",
"If n is even, the first number can be either odd or even.",
"From smallest to largest, place each number and subtract the number of permutations from k.",
"The number of permutations can be calculated using factorials."
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().permute",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:27",
"tests_total": 97,
"tests_dr... | go | {
"raw_signature": "func permute(n int, k int64) []int {",
"container": null,
"callable": "permute",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int64"
}
],
"return_type": "[]int",
"signature_source": "leetcode/codeSnippets",
"type_sour... |
3,471 | find-the-largest-almost-missing-integer | Easy | You are given an integer array nums and an integer k.
An integer x is almost missing from nums if x appears in exactly one subarray of size k within nums.
Return the largest almost missing integer from nums. If no such integer exists, return -1.
A subarray is a contiguous sequence of elements within an array.
Examp... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5],k = 2) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 10\n assert candidate(nums = [1, 2, 3, 4, 5... | [
"[3,9,2,1,7]\n3",
"[3,9,7,2,1,7]\n4",
"[0,0]\n1"
] | [
"Solve the problem for three different cases: k = 1, k = n, and 1 < k < n",
"If k = 1, return the largest element that occurs exactly once in nums",
"If k = n, return the largest element in nums",
"If 1 < k < n, all elements different from nums[0] and nums[n - 1] will occur in more than one subarray of size k... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().largestInteger",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:29",
"tests_total": 120,
... | go | {
"raw_signature": "func largestInteger(nums []int, k int) int {",
"container": null,
"callable": "largestInteger",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippet... |
3,472 | longest-palindromic-subsequence-after-at-most-k-operations | Medium | You are given a string s and an integer k.
In one operation, you can replace the character at any position with the next or previous letter in the alphabet (wrapping around so that 'a' is after 'z'). For example, replacing 'a' with the next letter results in 'b', and replacing 'a' with the previous letter results in '... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"zxy\",k = 1) == 3\n assert candidate(s = \"a\",k = 5) == 1\n assert candidate(s = \"abced\",k = 2) == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 25) == 14\n assert candidate(s = \"zzzzz\",k = 1) == 5\n ... | [
"\"abced\"\n2",
"\"aaazzz\"\n4"
] | [
"Use dynamic programming.",
"dp[i][j][k] is the length of the longest palindromic subsequence in substring [i..j] with cost at most k.",
"dp[i][j][k] = max(dp[i + 1][j][k], dp[i][j - 1][k], dp[i + 1][j - 1][k - dist(s[i], s[j])] + 2), where dist(x, y) is the minimum cyclic distance between x and y."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().longestPalindromicSubsequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:32",
"tests_t... | go | {
"raw_signature": "func longestPalindromicSubsequence(s string, k int) int {",
"container": null,
"callable": "longestPalindromicSubsequence",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_sour... |
3,473 | sum-of-k-subarrays-with-length-at-least-m | Medium | You are given an integer array nums and two integers, k and m.
Return the maximum sum of k non-overlapping subarrays of nums, where each subarray has a length of at least m.
Example 1:
Input: nums = [1,2,-1,3,3,4], k = 2, m = 2
Output: 13
Explanation:
The optimal choice is:
- Subarray nums[3..5] with sum 3 + 3 + 4 =... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 0, -1, 0, 1, -1, 0, 1],k = 2,m = 2) == 2\n assert candidate(nums = [5, 4, 3, 2, 1],k = 2,m = 2) == 15\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 2,m = 3) == 0\n assert candidate(nums = [1, 2, 3, 4, 5... | [
"[1,2,-1,3,3,4]\n2\n2",
"[-10,3,-1,-2]\n4\n1"
] | [
"Dynamic Programming",
"Prefix Sum",
"Let dp[i][j] be the maximum sum with i subarrays for the first j elements"
] | {
"canonical_parameter_names": [
"nums",
"k",
"m"
],
"leetcode_dataset_entry_point": "Solution().maxSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:34",
"tests_total": 211,... | go | {
"raw_signature": "func maxSum(nums []int, k int, m int) int {",
"container": null,
"callable": "maxSum",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "k",
"type": "int"
},
{
"name": "m",
"type": "int"
}
],
"return_type": "int",
... |
3,474 | lexicographically-smallest-generated-string | Hard | You are given two strings, str1 and str2, of lengths n and m, respectively.
A string word of length n + m - 1 is defined to be generated by str1 and str2 if it satisfies the following conditions for each index 0 <= i <= n - 1:
- If str1[i] == 'T', the substring of word with size m starting at index i is equal to str2... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(str1 = \"FF\",str2 = \"z\") == \"aa\"\n assert candidate(str1 = \"FT\",str2 = \"c\") == \"ac\"\n assert candidate(str1 = \"FT\",str2 = \"yz\") == \"ayz\"\n assert candidate(str1 = \"TTT\",str2 = \"aaa\") == \"aaaaa\"\n assert... | [
"\"TFTF\"\n\"ab\"",
"\"TFTF\"\n\"abc\"",
"\"FT\"\n\"aa\""
] | [
"Use dynamic programming.",
"Fill the fixed part.",
"Use KMP's next table for DP.",
"The state is the prefix length and the longest suffix length that matches the pattern.",
"Each unknown character can be selected from ['a', 'b'].",
"Can you think of a greedy approach?"
] | {
"canonical_parameter_names": [
"str1",
"str2"
],
"leetcode_dataset_entry_point": "Solution().generateString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:36",
"tests_total": 26... | go | {
"raw_signature": "func generateString(str1 string, str2 string) string {",
"container": null,
"callable": "generateString",
"parameters": [
{
"name": "str1",
"type": "string"
},
{
"name": "str2",
"type": "string"
}
],
"return_type": "string",
"signature_source": "... |
3,477 | fruits-into-baskets-ii | Easy | You are given two arrays of integers, fruits and baskets, each of length n, where fruits[i] represents the quantity of the i^th type of fruit, and baskets[j] represents the capacity of the j^th basket.
From left to right, place the fruits according to these rules:
- Each fruit type must be placed in the leftmost avai... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(fruits = [5, 5, 5, 5],baskets = [4, 4, 4, 4]) == 4\n assert candidate(fruits = [100, 200, 300],baskets = [100, 200, 300]) == 0\n assert candidate(fruits = [1, 3, 5, 7],baskets = [2, 4, 6, 8]) == 0\n assert candidate(fruits = [10... | [
"[4,2,5]\n[3,5,4]",
"[3,6,1]\n[6,4,7]"
] | [
"Simulate the operations for each fruit as described"
] | {
"canonical_parameter_names": [
"fruits",
"baskets"
],
"leetcode_dataset_entry_point": "Solution().numOfUnplacedFruits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:41",
"tests_... | go | {
"raw_signature": "func numOfUnplacedFruits(fruits []int, baskets []int) int {",
"container": null,
"callable": "numOfUnplacedFruits",
"parameters": [
{
"name": "fruits",
"type": "[]int"
},
{
"name": "baskets",
"type": "[]int"
}
],
"return_type": "int",
"signature_... |
3,478 | choose-k-elements-with-maximum-sum | Medium | You are given two integer arrays, nums1 and nums2, both of length n, along with a positive integer k.
For each index i from 0 to n - 1, perform the following:
- Find all indices j where nums1[j] is less than nums1[i].
- Choose at most k values of nums2[j] at these indices to maximize the total sum.
Return an array a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],k = 2) == [0, 50, 90, 90, 90]\n assert candidate(nums1 = [100000, 90000, 80000, 70000, 60000],nums2 = [1, 2, 3, 4, 5],k = 4) == [14, 12, 9, 5, 0]\n assert candidate(nums1 = ... | [
"[4,2,1,5,3]\n[10,20,30,40,50]\n2",
"[2,2,2,2]\n[3,1,2,3]\n1"
] | [
"Sort nums1 and its corresponding nums2 values together based on nums1.",
"Use a max heap to track the top k values of nums2 as you process each element in the sorted order."
] | {
"canonical_parameter_names": [
"nums1",
"nums2",
"k"
],
"leetcode_dataset_entry_point": "Solution().findMaxSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:43",
"tests_tot... | go | {
"raw_signature": "func findMaxSum(nums1 []int, nums2 []int, k int) []int64 {",
"container": null,
"callable": "findMaxSum",
"parameters": [
{
"name": "nums1",
"type": "[]int"
},
{
"name": "nums2",
"type": "[]int"
},
{
"name": "k",
"type": "int"
}
]... |
3,479 | fruits-into-baskets-iii | Medium | You are given two arrays of integers, fruits and baskets, each of length n, where fruits[i] represents the quantity of the i^th type of fruit, and baskets[j] represents the capacity of the j^th basket.
From left to right, place the fruits according to these rules:
- Each fruit type must be placed in the leftmost avai... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(fruits = [5, 5, 5, 5, 5],baskets = [1, 2, 3, 4, 5]) == 4\n assert candidate(fruits = [4, 2, 5],baskets = [3, 5, 4]) == 1\n assert candidate(fruits = [1, 1, 1, 1],baskets = [1, 1, 1, 1]) == 0\n assert candidate(fruits = [10000000... | [
"[4,2,5]\n[3,5,4]",
"[3,6,1]\n[6,4,7]"
] | [
"Sort the baskets by the pair of (basket[i], i) in the array.",
"For each fruit from left to right, use binary search to find the first index in the sorted array such that basket[i] >= fruit.",
"Use a segment tree to maintain the smallest original indices where basket[i] >= fruit.",
"When a valid index is fou... | {
"canonical_parameter_names": [
"fruits",
"baskets"
],
"leetcode_dataset_entry_point": "Solution().numOfUnplacedFruits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:46",
"tests_... | go | {
"raw_signature": "func numOfUnplacedFruits(fruits []int, baskets []int) int {",
"container": null,
"callable": "numOfUnplacedFruits",
"parameters": [
{
"name": "fruits",
"type": "[]int"
},
{
"name": "baskets",
"type": "[]int"
}
],
"return_type": "int",
"signature_... |
3,480 | maximize-subarrays-after-removing-one-conflicting-pair | Hard | You are given an integer n which represents an array nums containing the numbers from 1 to n in order. Additionally, you are given a 2D array conflictingPairs, where conflictingPairs[i] = [a, b] indicates that a and b form a conflicting pair.
Remove exactly one element from conflictingPairs. Afterward, count the numbe... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 7,conflictingPairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 8\n assert candidate(n = 6,conflictingPairs = [[1, 3], [2, 4], [3, 5], [4, 6]]) == 12\n assert candidate(n = 6,conflictingPairs = [[1, 3], [3, 5], [2, 4]... | [
"4\n[[2,3],[1,4]]",
"5\n[[1,2],[2,5],[3,5]]"
] | [
"Let f[i] (where i = 1, 2, 3, ..., n) be the end index of the longest valid subarray (without any conflicting pair) starting at index i.",
"The answer is: sigma(f[i] - i + 1) for i in [1..n], which simplifies to: sigma(f[i]) - n * (n + 1) / 2 + n.",
"Focus on maintaining f[i].",
"If we have a conflicting pair... | {
"canonical_parameter_names": [
"n",
"conflictingPairs"
],
"leetcode_dataset_entry_point": "Solution().maxSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:49",
"tests_tot... | go | {
"raw_signature": "func maxSubarrays(n int, conflictingPairs [][]int) int64 {",
"container": null,
"callable": "maxSubarrays",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "conflictingPairs",
"type": "[][]int"
}
],
"return_type": "int64",
"signature_so... |
3,483 | unique-3-digit-even-numbers | Easy | You are given an array of digits called digits. Your task is to determine the number of distinct three-digit even numbers that can be formed using these digits.
Note: Each copy of a digit can only be used once per number, and there may not be leading zeros.
Example 1:
Input: digits = [1,2,3,4]
Output: 12
Explanation... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(digits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(digits = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 1\n assert candidate(digits = [6, 6, 6]) == 1\n assert candidate(digits = [1, 3, 5]) == 0\n assert candidate(digits ... | [
"[1,2,3,4]",
"[0,2,2]",
"[6,6,6]",
"[1,3,5]"
] | [
"Use brute force to try all possibilities"
] | {
"canonical_parameter_names": [
"digits"
],
"leetcode_dataset_entry_point": "Solution().totalNumbers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:53",
"tests_total": 128,
"tests_... | go | {
"raw_signature": "func totalNumbers(digits []int) int {",
"container": null,
"callable": "totalNumbers",
"parameters": [
{
"name": "digits",
"type": "[]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,485 | longest-common-prefix-of-k-strings-after-removal | Hard | You are given an array of strings words and an integer k.
For each index i in the range [0, words.length - 1], find the length of the longest common prefix among any k strings (selected at distinct indices) from the remaining array after removing the i^th element.
Return an array answer, where answer[i] is the answer... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['banana', 'band', 'bend', 'bendy'],k = 3) == [1, 1, 1, 1]\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abcg'],k = 2) == [3, 3, 3, 3]\n assert candidate(words = ['apple', 'application', 'aptitude', 'appetite'],k = 3... | [
"[\"jump\",\"run\",\"run\",\"jump\",\"run\"]\n2",
"[\"dog\",\"racer\",\"car\"]\n2"
] | [
"Use a trie to store all the strings initially.",
"For each node in the trie, maintain the count of paths ending there.",
"For each arr[i], remove it from the trie and update the counts.",
"During evaluation, find the innermost node with at least k paths ending there.",
"Use a multiset or similar structure ... | {
"canonical_parameter_names": [
"words",
"k"
],
"leetcode_dataset_entry_point": "Solution().longestCommonPrefix",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:26:56",
"tests_total":... | go | {
"raw_signature": "func longestCommonPrefix(words []string, k int) []int {",
"container": null,
"callable": "longestCommonPrefix",
"parameters": [
{
"name": "words",
"type": "[]string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "[]int",
"signature_source":... |
3,487 | maximum-unique-subarray-sum-after-deletion | Easy | You are given an integer array nums.
You are allowed to delete any number of elements from nums without making it empty. After performing the deletions, select a subarray of nums such that:
1. All elements in the subarray are unique.
2. The sum of the elements in the subarray is maximized.
Return the maximum sum of ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [-1, 2, -3, 4, -5]) == 6\n assert candidate(nums = [-10, 1, 20, -30, 40, -50, 60]) == 121\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == 1\n assert ... | [
"[1,2,3,4,5]",
"[1,1,0,1,1]",
"[1,2,-1,-2,1,0,-1]"
] | [
"If the maximum element in the array is less than zero, the answer is the maximum element.",
"Otherwise, the answer is the sum of all unique values that are greater than or equal to zero."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:00",
"tests_total": 121,
"tests_dropped"... | go | {
"raw_signature": "func maxSum(nums []int) int {",
"container": null,
"callable": "maxSum",
"parameters": [
{
"name": "nums",
"type": "[]int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,488 | closest-equal-element-queries | Medium | You are given a circular array nums and an array queries.
For each query i, you have to find the following:
- The minimum distance between the element at index queries[i] and any other index j in the circular array, where nums[j] == nums[queries[i]]. If no such index exists, the answer for that query should be -1.
R... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 1, 4, 1, 3, 2],queries = [0, 3, 5]) == [2, -1, 3]\n assert candidate(nums = [1, 2, 3, 4],queries = [0, 1, 2, 3]) == [-1, -1, -1, -1]\n assert candidate(nums = [1000000, 1000000, 1000000],queries = [0, 1, 2]) == [1, 1,... | [
"[1,3,1,4,1,3,2]\n[0,3,5]",
"[1,2,3,4]\n[0,1,2,3]"
] | [
"Use a dictionary that maps each unique value in the array to a sorted list of its indices.",
"For each query, use binary search on the sorted indices list to find the nearest occurrences of the target value."
] | {
"canonical_parameter_names": [
"nums",
"queries"
],
"leetcode_dataset_entry_point": "Solution().solveQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:03",
"tests_total": 9... | go | {
"raw_signature": "func solveQueries(nums []int, queries []int) []int {",
"container": null,
"callable": "solveQueries",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "queries",
"type": "[]int"
}
],
"return_type": "[]int",
"signature_source": "leet... |
3,489 | zero-array-transformation-iv | Medium | You are given an integer array nums of length n and a 2D array queries, where queries[i] = [l_i, r_i, val_i].
Each queries[i] represents the following action on nums:
- Select a subset of indices in the range [l_i, r_i] from nums.
- Decrement the value at each selected index by exactly val_i.
A Zero Array is an arra... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 2, 6],queries = [[0, 1, 1], [0, 2, 1], [1, 4, 2], [4, 4, 4], [3, 4, 1], [4, 4, 5]]) == 4\n assert candidate(nums = [2, 0, 2],queries = [[0, 2, 1], [0, 2, 1], [1, 1, 3]]) == 2\n assert candidate(nums = [1, 2, 3, 2, ... | [
"[2,0,2]\n[[0,2,1],[0,2,1],[1,1,3]]",
"[4,3,2,1]\n[[1,3,2],[0,2,1]]",
"[1,2,3,2,1]\n[[0,1,1],[1,2,1],[2,3,2],[3,4,1],[4,4,1]]",
"[1,2,3,2,6]\n[[0,1,1],[0,2,1],[1,4,2],[4,4,4],[3,4,1],[4,4,5]]"
] | [
"Use dynamic programming.",
"For each nums[i], use DP to check whether the queries[.][2] values (i.e., the val values) of the queries that affect it can form a combination with a sum equal to nums[i]."
] | {
"canonical_parameter_names": [
"nums",
"queries"
],
"leetcode_dataset_entry_point": "Solution().minZeroArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:06",
"tests_total": 1... | go | {
"raw_signature": "func minZeroArray(nums []int, queries [][]int) int {",
"container": null,
"callable": "minZeroArray",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "queries",
"type": "[][]int"
}
],
"return_type": "int",
"signature_source": "leet... |
3,490 | count-beautiful-numbers | Hard | You are given two positive integers, l and r. A positive integer is called beautiful if the product of its digits is divisible by the sum of its digits.
Return the count of beautiful numbers between l and r, inclusive.
Example 1:
Input: l = 10, r = 20
Output: 2
Explanation:
The beautiful numbers in the range are 10 ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(l = 999,r = 999) == 1\n assert candidate(l = 1,r = 9) == 9\n assert candidate(l = 900,r = 1000) == 35\n assert candidate(l = 789,r = 890) == 35\n assert candidate(l = 500,r = 5000) == 1800\n assert candidate(l = 5,r = 50) ... | [
"10\n20",
"1\n15"
] | [
"Use digit dynamic programming."
] | {
"canonical_parameter_names": [
"l",
"r"
],
"leetcode_dataset_entry_point": "Solution().beautifulNumbers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:08",
"tests_total": 92,
... | go | {
"raw_signature": "func beautifulNumbers(l int, r int) int {",
"container": null,
"callable": "beautifulNumbers",
"parameters": [
{
"name": "l",
"type": "int"
},
{
"name": "r",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
... |
3,492 | maximum-containers-on-a-ship | Easy | You are given a positive integer n representing an n x n cargo deck on a ship. Each cell on the deck can hold one container with a weight of exactly w.
However, the total weight of all containers, if loaded onto the deck, must not exceed the ship's maximum weight capacity, maxWeight.
Return the maximum number of cont... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 10,w = 5,maxWeight = 25) == 5\n assert candidate(n = 10,w = 1,maxWeight = 10) == 10\n assert candidate(n = 5,w = 2,maxWeight = 20) == 10\n assert candidate(n = 5,w = 10,maxWeight = 50) == 5\n assert candidate(n = 5,w = 10... | [
"2\n3\n15",
"3\n5\n20"
] | [
"What are the limits on the number of containers?",
"We can load at most min(n * n, maxWeight / w) containers."
] | {
"canonical_parameter_names": [
"n",
"w",
"maxWeight"
],
"leetcode_dataset_entry_point": "Solution().maxContainers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:12",
"tests_... | go | {
"raw_signature": "func maxContainers(n int, w int, maxWeight int) int {",
"container": null,
"callable": "maxContainers",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "w",
"type": "int"
},
{
"name": "maxWeight",
"type": "int"
}
],
"r... |
3,493 | properties-graph | Medium | You are given a 2D integer array properties having dimensions n x m and an integer k.
Define a function intersect(a, b) that returns the number of distinct integers common to both arrays a and b.
Construct an undirected graph where each index i corresponds to properties[i]. There is an edge between node i and node j ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(properties = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]],k = 3) == 1\n assert candidate(properties = [[10, 20, 30], [30, 40, 50], [40, 50, 60], [50, 60, 70]],k = 1) == 1\n assert candidate(properties = [[1, 1, 1, 1], [... | [
"[[1,2],[1,1],[3,4],[4,5],[5,6],[7,7]]\n1",
"[[1,2,3],[2,3,4],[4,3,5]]\n2",
"[[1,1],[1,1]]\n2"
] | [
"How can we optimally find the intersection of two arrays? One way is to use len(set(a) & set(b)).",
"For connected components, think about using DFS, BFS, or DSU."
] | {
"canonical_parameter_names": [
"properties",
"k"
],
"leetcode_dataset_entry_point": "Solution().numberOfComponents",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:15",
"tests_tot... | go | {
"raw_signature": "func numberOfComponents(properties [][]int, k int) int {",
"container": null,
"callable": "numberOfComponents",
"parameters": [
{
"name": "properties",
"type": "[][]int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source... |
3,494 | find-the-minimum-amount-of-time-to-brew-potions | Medium | You are given two integer arrays, skill and mana, of length n and m, respectively.
In a laboratory, n wizards must brew m potions in order. Each potion has a mana capacity mana[j] and must pass through all the wizards sequentially to be brewed properly. The time taken by the i^th wizard on the j^th potion is time_ij =... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(skill = [10, 20, 30],mana = [1, 2, 3, 4, 5]) == 490\n assert candidate(skill = [3, 2, 1],mana = [6, 5, 4]) == 57\n assert candidate(skill = [1, 1, 1],mana = [1, 1, 1]) == 5\n assert candidate(skill = [1, 2, 3],mana = [4, 5, 6, 7... | [
"[1,5,2,4]\n[5,1,4,2]",
"[1,1,1]\n[1,1,1]",
"[1,2,3,4]\n[1,2]"
] | [
"Maintain each wizard's earliest free time (for the last potion) as f[i].",
"Let x be the current mana value. Starting from now = f[0], update now = max(now + skill[i - 1] * x, f[i]) for i in [1..n]. Then, the final f[n - 1] = now + skill[n - 1] * x for this potion.",
"Update all other f values by f[i] = f[i + ... | {
"canonical_parameter_names": [
"skill",
"mana"
],
"leetcode_dataset_entry_point": "Solution().minTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:17",
"tests_total": 103,
"... | go | {
"raw_signature": "func minTime(skill []int, mana []int) int64 {",
"container": null,
"callable": "minTime",
"parameters": [
{
"name": "skill",
"type": "[]int"
},
{
"name": "mana",
"type": "[]int"
}
],
"return_type": "int64",
"signature_source": "leetcode/codeSnipp... |
3,495 | minimum-operations-to-make-array-elements-zero | Hard | You are given a 2D array queries, where queries[i] is of the form [l, r]. Each queries[i] defines an array of integers nums consisting of elements ranging from l to r, both inclusive.
In one operation, you can:
- Select two integers a and b from the array.
- Replace them with floor(a / 4) and floor(b / 4).
Your task... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(queries = [[1, 2], [2, 4]]) == 3\n assert candidate(queries = [[10, 20], [20, 30], [30, 40]]) == 48\n assert candidate(queries = [[1, 1000000000], [500000000, 1000000000]]) == 11071043045\n assert candidate(queries = [[1, 100], ... | [
"[[1,2],[2,4]]",
"[[2,6]]"
] | [
"For a number x, the number of \"/4\" operations to change it to 0 is floor(log4(x)) + 1.",
"Always pair the 2 numbers with the maximum \"/4\" operations needed."
] | {
"canonical_parameter_names": [
"queries"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:20",
"tests_total": 94,
"tests... | go | {
"raw_signature": "func minOperations(queries [][]int) int64 {",
"container": null,
"callable": "minOperations",
"parameters": [
{
"name": "queries",
"type": "[][]int"
}
],
"return_type": "int64",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,498 | reverse-degree-of-a-string | Easy | Given a string s, calculate its reverse degree.
The reverse degree is calculated as follows:
1. For each character, multiply its position in the reversed alphabet ('a' = 26, 'b' = 25, ..., 'z' = 1) with its position in the string (1-indexed).
2. Sum these products for all characters in the string.
Return the reverse... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"zzzz\") == 10\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 15678\n assert candidate(s = \"world\") == 230\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 3276\n assert ca... | [
"\"abc\"",
"\"zaza\""
] | [
"Simulate the operations as described."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().reverseDegree",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:25",
"tests_total": 55,
"tests_dropp... | go | {
"raw_signature": "func reverseDegree(s string) int {",
"container": null,
"callable": "reverseDegree",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,499 | maximize-active-section-with-trade-i | Medium | You are given a binary string s of length n, where:
- '1' represents an active section.
- '0' represents an inactive section.
You can perform at most one trade to maximize the number of active sections in s. In a trade, you:
- Convert a contiguous block of '1's that is surrounded by '0's to all '0's.
- Afterward, co... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"01010\") == 4\n assert candidate(s = \"1000100\") == 7\n assert candidate(s = \"010101010\") == 6\n assert candidate(s = \"1001001001\") == 8\n assert candidate(s = \"11111\") == 5\n assert candidate(s = \"0011001100... | [
"\"01\"",
"\"0100\"",
"\"1000100\"",
"\"01010\""
] | [
"Split the string into several zero-one segments.",
"For each one-segment, if it has two neighbors (i.e., it is surrounded by two zero-segments), the total sum of their lengths is one of the candidates for delta.",
"Find the maximum delta and add it to the total number of ones in the string."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().maxActiveSectionsAfterTrade",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:28",
"tests_total": 88,
... | go | {
"raw_signature": "func maxActiveSectionsAfterTrade(s string) int {",
"container": null,
"callable": "maxActiveSectionsAfterTrade",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSn... |
3,500 | minimum-cost-to-divide-array-into-subarrays | Hard | You are given two integer arrays, nums and cost, of the same size, and an integer k.
You can divide nums into subarrays. The cost of the i^th subarray consisting of elements nums[l..r] is:
- (nums[0] + nums[1] + ... + nums[r] + k * i) * (cost[l] + cost[l + 1] + ... + cost[r]).
Note that i represents the order of the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1],cost = [1],k = 1) == 2\n assert candidate(nums = [4, 8, 5, 1, 14, 2, 2, 12, 1],cost = [7, 2, 8, 4, 2, 2, 1, 1, 2],k = 7) == 985\n assert candidate(nums = [1, 2, 3, 4, 5],cost = [5, 4, 3, 2, 1],k = 2) == 130\n assert c... | [
"[3,1,4]\n[4,6,6]\n1",
"[4,8,5,1,14,2,2,12,1]\n[7,2,8,4,2,2,1,1,2]\n7"
] | [
"dp[i] is the minimum cost to split the array suffix starting at i.",
"Observe that no matter how many subarrays we have, if we have the first subarray on the left, the total cost of the previous subarrays increases by k * total_cost_of_the_subarray. This is because when we increase i to (i + 1), the cost increas... | {
"canonical_parameter_names": [
"nums",
"cost",
"k"
],
"leetcode_dataset_entry_point": "Solution().minimumCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:31",
"tests_tota... | go | {
"raw_signature": "func minimumCost(nums []int, cost []int, k int) int64 {",
"container": null,
"callable": "minimumCost",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "cost",
"type": "[]int"
},
{
"name": "k",
"type": "int"
}
],
... |
3,501 | maximize-active-section-with-trade-ii | Hard | You are given a binary string s of length n, where:
- '1' represents an active section.
- '0' represents an inactive section.
You can perform at most one trade to maximize the number of active sections in s. In a trade, you:
- Convert a contiguous block of '1's that is surrounded by '0's to all '0's.
- Afterward, co... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"0100\",queries = [[0, 3], [0, 2], [1, 3], [2, 3]]) == [4, 3, 1, 1]\n assert candidate(s = \"01\",queries = [[0, 1]]) == [1]\n assert candidate(s = \"01010\",queries = [[0, 3], [1, 4], [1, 3]]) == [4, 4, 2]\n assert candida... | [
"\"01\"\n[[0,1]]",
"\"0100\"\n[[0,3],[0,2],[1,3],[2,3]]",
"\"1000100\"\n[[1,5],[0,6],[0,4]]",
"\"01010\"\n[[0,3],[1,4],[1,3]]"
] | [
"Split consecutive zeros and ones into segments and give each segment an ID.",
"The answer should be the maximum of ans[i] = len[i - 1] + len[i + 1], where i is a one-segment.",
"For a zero-segment, define ans[i] = 0.",
"Note that all three segments (i - 1, i, and i + 1) should be fully covered by the substri... | {
"canonical_parameter_names": [
"s",
"queries"
],
"leetcode_dataset_entry_point": "Solution().maxActiveSectionsAfterTrade",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:34",
"tes... | go | {
"raw_signature": "func maxActiveSectionsAfterTrade(s string, queries [][]int) []int {",
"container": null,
"callable": "maxActiveSectionsAfterTrade",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "queries",
"type": "[][]int"
}
],
"return_type": "[]int... |
3,502 | minimum-cost-to-reach-every-position | Easy | You are given an integer array cost of size n. You are currently at position n (at the end of the line) in a line of n + 1 people (numbered from 0 to n).
You wish to move forward in the line, but each person in front of you charges a specific amount to swap places. The cost to swap with person i is given by cost[i].
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(cost = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(cost = [10, 20, 30, 40, 50]) == [10, 10, 10, 10, 10]\n assert candidate(cost = [50, 25, 75, 100, 20, 30, 40, 60, 80, 90]) == [50, 25, ... | [
"[5,3,4,1,3,2]",
"[1,2,4,6,7]"
] | [
"Note that once you swap to a position with a lower cost, you can reach any later position for free.",
"Use a min prefix array."
] | {
"canonical_parameter_names": [
"cost"
],
"leetcode_dataset_entry_point": "Solution().minCosts",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:36",
"tests_total": 109,
"tests_droppe... | go | {
"raw_signature": "func minCosts(cost []int) []int {",
"container": null,
"callable": "minCosts",
"parameters": [
{
"name": "cost",
"type": "[]int"
}
],
"return_type": "[]int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,503 | longest-palindrome-after-substring-concatenation-i | Medium | You are given two strings, s and t.
You can create a new string by selecting a substring from s (possibly empty) and a substring from t (possibly empty), then concatenating them in order.
Return the length of the longest palindrome that can be formed this way.
Example 1:
Input: s = "a", t = "a"
Output: 2
Explanatio... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"b\",t = \"aaaa\") == 4\n assert candidate(s = \"hello\",t = \"world\") == 3\n assert candidate(s = \"different\",t = \"entirely\") == 5\n assert candidate(s = \"level\",t = \"deified\") == 7\n assert candidate(s = \"xyz... | [
"\"a\"\n\"a\"",
"\"abc\"\n\"def\"",
"\"b\"\n\"aaaa\"",
"\"abcde\"\n\"ecdba\""
] | [
"Brute force"
] | {
"canonical_parameter_names": [
"s",
"t"
],
"leetcode_dataset_entry_point": "Solution().longestPalindrome",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:39",
"tests_total": 101,
... | go | {
"raw_signature": "func longestPalindrome(s string, t string) int {",
"container": null,
"callable": "longestPalindrome",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "t",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/cod... |
3,504 | longest-palindrome-after-substring-concatenation-ii | Hard | You are given two strings, s and t.
You can create a new string by selecting a substring from s (possibly empty) and a substring from t (possibly empty), then concatenating them in order.
Return the length of the longest palindrome that can be formed this way.
Example 1:
Input: s = "a", t = "a"
Output: 2
Explanatio... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"b\",t = \"aaaa\") == 4\n assert candidate(s = \"hello\",t = \"world\") == 3\n assert candidate(s = \"aaaa\",t = \"bbbb\") == 4\n assert candidate(s = \"abcde\",t = \"ecdba\") == 5\n assert candidate(s = \"noon\",t = \"m... | [
"\"a\"\n\"a\"",
"\"abc\"\n\"def\"",
"\"b\"\n\"aaaa\"",
"\"abcde\"\n\"ecdba\""
] | [
"Let dp[i][j] be the length of the longest answer if we try starting it with s[i] and ending it with t[j].",
"For s, preprocess the length of the longest palindrome starting at index i as p[i].",
"For t, preprocess the length of the longest palindrome ending at index j as q[j].",
"If s[i] != t[j], then dp[i][... | {
"canonical_parameter_names": [
"s",
"t"
],
"leetcode_dataset_entry_point": "Solution().longestPalindrome",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:41",
"tests_total": 122,
... | go | {
"raw_signature": "func longestPalindrome(s string, t string) int {",
"container": null,
"callable": "longestPalindrome",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "t",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/cod... |
3,505 | minimum-operations-to-make-elements-within-k-subarrays-equal | Hard | You are given an integer array nums and two integers, x and k. You can perform the following operation any number of times (including zero):
- Increase or decrease any element of nums by 1.
Return the minimum number of operations needed to have at least k non-overlapping subarrays of size exactly x in nums, where all... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1000000, -1000000, 1000000, -1000000, 1000000],x = 2,k = 2) == 4000000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 10,k = 1) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1... | [
"[5,-2,1,3,7,3,6,4,-1]\n3\n2",
"[9,-2,-2,-2,1,5]\n2\n2"
] | [
"Making every element of an x-sized window equal to its median is optimal.",
"Precalculate this for each window."
] | {
"canonical_parameter_names": [
"nums",
"x",
"k"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:27:44",
"tests_total... | go | {
"raw_signature": "func minOperations(nums []int, x int, k int) int64 {",
"container": null,
"callable": "minOperations",
"parameters": [
{
"name": "nums",
"type": "[]int"
},
{
"name": "x",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"retur... |
3,243 | shortest-distance-after-road-addition-queries-i | Medium | You are given an integer n and a 2D integer array queries.
There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0 <= i < n - 1.
queries[i] = [u_i, v_i] represents the addition of a new unidirectional road from city u_i to city v_i. After each query, ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 7,queries = [[0, 5], [1, 6], [2, 4]]) == [2, 2, 2]\n assert candidate(n = 8,queries = [[1, 5], [2, 6], [3, 7], [0, 4], [0, 6], [0, 7]]) == [4, 4, 4, 4, 2, 1]\n assert candidate(n = 6,queries = [[1, 3], [2, 5], [0, 3]]) == [4, 3... | [
"5\n[[2,4],[0,2],[0,4]]",
"4\n[[0,3],[0,2]]"
] | [
"Maintain the graph and use an efficient shortest path algorithm after each update.",
"We use BFS/Dijkstra for each query."
] | {
"canonical_parameter_names": [
"n",
"queries"
],
"leetcode_dataset_entry_point": "Solution().shortestDistanceAfterQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:12",
"te... | java | {
"raw_signature": "public int[] shortestDistanceAfterQueries(int n, int[][] queries) {",
"container": "Solution",
"callable": "shortestDistanceAfterQueries",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "queries",
"type": "int[][]"
}
],
"return_type": "i... |
3,244 | shortest-distance-after-road-addition-queries-ii | Hard | You are given an integer n and a 2D integer array queries.
There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0 <= i < n - 1.
queries[i] = [u_i, v_i] represents the addition of a new unidirectional road from city u_i to city v_i. After each query, ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,queries = [[2, 4], [0, 2], [0, 4]]) == [3, 2, 1]\n assert candidate(n = 4,queries = [[0, 3], [0, 2]]) == [1, 1]\n assert candidate(n = 75000,queries = [[37500, 74999], [18750, 74999], [56250, 74999], [9375, 74999], [28125, 74... | [
"5\n[[2,4],[0,2],[0,4]]",
"4\n[[0,3],[0,2]]"
] | [] | {
"canonical_parameter_names": [
"n",
"queries"
],
"leetcode_dataset_entry_point": "Solution().shortestDistanceAfterQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:15",
"te... | java | {
"raw_signature": "public int[] shortestDistanceAfterQueries(int n, int[][] queries) {",
"container": "Solution",
"callable": "shortestDistanceAfterQueries",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "queries",
"type": "int[][]"
}
],
"return_type": "i... |
3,248 | snake-in-matrix | Easy | There is a snake in an n x n matrix grid and can move in four possible directions. Each cell in the grid is identified by the position: grid[i][j] = (i * n) + j.
The snake starts at cell 0 and follows a sequence of commands.
You are given an integer n representing the size of the grid and an array of strings commands... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 2,commands = ['RIGHT', 'DOWN']) == 3\n assert candidate(n = 5,commands = ['RIGHT', 'DOWN', 'RIGHT', 'DOWN', 'RIGHT', 'DOWN']) == 18\n assert candidate(n = 2,commands = ['RIGHT', 'DOWN']) == 3\n assert candidate(n = 4,command... | [
"2\n[\"RIGHT\",\"DOWN\"]",
"3\n[\"DOWN\",\"RIGHT\",\"UP\"]"
] | [
"Try to update the row and column of the snake after each command."
] | {
"canonical_parameter_names": [
"n",
"commands"
],
"leetcode_dataset_entry_point": "Solution().finalPositionOfSnake",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:20",
"tests_tot... | java | {
"raw_signature": "public int finalPositionOfSnake(int n, List<String> commands) {",
"container": "Solution",
"callable": "finalPositionOfSnake",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "commands",
"type": "List<String>"
}
],
"return_type": "int",
... |
3,250 | find-the-count-of-monotonic-pairs-i | Hard | You are given an array of positive integers nums of length n.
We call a pair of non-negative integer arrays (arr1, arr2) monotonic if:
- The lengths of both arrays are n.
- arr1 is monotonically non-decreasing, in other words, arr1[0] <= arr1[1] <= ... <= arr1[n - 1].
- arr2 is monotonically non-increasing, in other ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [50, 1, 50, 1, 50]) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3]) == 84\n assert candidate(nums = [10, 20, 30, 40, 50]) == 3003\n assert candidate(nums = [5, 5, 5, 5]) == 126\n assert candidate(nums = [1, 2, 3, 4,... | [
"[2,3,2]",
"[5,5,5,5]"
] | [
"Let dp[i][s] is the number of monotonic pairs of length i with the arr1[i - 1] = s.",
"If arr1[i - 1] = s, arr2[i - 1] = nums[i - 1] - s.",
"Check if the state in recurrence is valid."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countOfPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:25",
"tests_total": 105,
"tests_dr... | java | {
"raw_signature": "public int countOfPairs(int[] nums) {",
"container": "Solution",
"callable": "countOfPairs",
"parameters": [
{
"name": "nums",
"type": "int[]"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,251 | find-the-count-of-monotonic-pairs-ii | Hard | You are given an array of positive integers nums of length n.
We call a pair of non-negative integer arrays (arr1, arr2) monotonic if:
- The lengths of both arrays are n.
- arr1 is monotonically non-decreasing, in other words, arr1[0] <= arr1[1] <= ... <= arr1[n - 1].
- arr2 is monotonically non-increasing, in other ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 3, 2]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 659632782\n assert candidate(nums = [1, 1, 1, 1, ... | [
"[2,3,2]",
"[5,5,5,5]"
] | [] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countOfPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:27",
"tests_total": 82,
"tests_dro... | java | {
"raw_signature": "public int countOfPairs(int[] nums) {",
"container": "Solution",
"callable": "countOfPairs",
"parameters": [
{
"name": "nums",
"type": "int[]"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,254 | find-the-power-of-k-size-subarrays-i | Medium | You are given an array of integers nums of length n and a positive integer k.
The power of an array is defined as:
- Its maximum element if all of its elements are consecutive and sorted in ascending order.
- -1 otherwise.
You need to find the power of all subarrays of nums of size k.
Return an integer array result... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == [5]\n assert candidate(nums = [2, 2, 2, 2, 2],k = 4) == [-1, -1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11],k = 5) == [-1, -1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5],k = 4) == [-1, -1, ... | [
"[1,2,3,4,3,2,5]\n3",
"[2,2,2,2,2]\n4",
"[3,2,3,2,3,2]\n2"
] | [
"Can we use a brute force solution with nested loops and HashSet?"
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().resultsArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:32",
"tests_total": 127,
... | java | {
"raw_signature": "public int[] resultsArray(int[] nums, int k) {",
"container": "Solution",
"callable": "resultsArray",
"parameters": [
{
"name": "nums",
"type": "int[]"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int[]",
"signature_source": "leetcode/cod... |
3,255 | find-the-power-of-k-size-subarrays-ii | Medium | You are given an array of integers nums of length n and a positive integer k.
The power of an array is defined as:
- Its maximum element if all of its elements are consecutive and sorted in ascending order.
- -1 otherwise.
You need to find the power of all subarrays of nums of size k.
Return an integer array result... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100, 101, 102, 103, 104, 105],k = 2) == [101, 102, 103, 104, 105]\n assert candidate(nums = [2, 2, 2, 2, 2],k = 4) == [-1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, ... | [
"[1,2,3,4,3,2,5]\n3",
"[2,2,2,2,2]\n4",
"[3,2,3,2,3,2]\n2"
] | [
"Let dp[i] denote the length of the longest subarray ending at index i that has consecutive and sorted elements.",
"Use a TreeMap with a sliding window to check if there are k elements in the subarray ending at index i.",
"If TreeMap has less than k elements and dp[i] < k, the subarray has power equal to -1.",
... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().resultsArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:35",
"tests_total": 140,
... | java | {
"raw_signature": "public int[] resultsArray(int[] nums, int k) {",
"container": "Solution",
"callable": "resultsArray",
"parameters": [
{
"name": "nums",
"type": "int[]"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int[]",
"signature_source": "leetcode/cod... |
3,256 | maximum-value-sum-by-placing-three-rooks-i | Hard | You are given a m x n 2D array board representing a chessboard, where board[i][j] represents the value of the cell (i, j).
Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other.
Return the maximum sum of the cell values on which... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(board = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]) == 150\n assert candidate(board = [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]) == -15\n assert candidate(board = [[-3, 1, 1, 1], [-3, 1, -3, 1], [-3, 2, 1, 1]]) == 4\n assert ca... | [
"[[-3,1,1,1],[-3,1,-3,1],[-3,2,1,1]]",
"[[1,2,3],[4,5,6],[7,8,9]]",
"[[1,1,1],[1,1,1],[1,1,1]]"
] | [
"Store the largest 3 values for each row.",
"Select any 3 rows and brute force all combinations."
] | {
"canonical_parameter_names": [
"board"
],
"leetcode_dataset_entry_point": "Solution().maximumValueSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:37",
"tests_total": 144,
"test... | java | {
"raw_signature": "public long maximumValueSum(int[][] board) {",
"container": "Solution",
"callable": "maximumValueSum",
"parameters": [
{
"name": "board",
"type": "int[][]"
}
],
"return_type": "long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippe... |
3,257 | maximum-value-sum-by-placing-three-rooks-ii | Hard | You are given a m x n 2D array board representing a chessboard, where board[i][j] represents the value of the cell (i, j).
Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other.
Return the maximum sum of the cell values on which... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(board = [[5, -2, 3, 7], [1, 8, -1, 2], [-4, 4, -3, 6], [3, 7, 5, -9]]) == 20\n assert candidate(board = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 3\n assert candidate(board = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [1... | [
"[[-3,1,1,1],[-3,1,-3,1],[-3,2,1,1]]",
"[[1,2,3],[4,5,6],[7,8,9]]",
"[[1,1,1],[1,1,1],[1,1,1]]"
] | [
"Save the top 3 largest values in each row.",
"Select any row, and select any of the three values stored in it.",
"Get the top 4 values from all of the other 3 largest values of the other rows, which do not share the same column as the selected value.",
"Brute force the selection of 2 positions from the top 4... | {
"canonical_parameter_names": [
"board"
],
"leetcode_dataset_entry_point": "Solution().maximumValueSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:40",
"tests_total": 81,
"tests... | java | {
"raw_signature": "public long maximumValueSum(int[][] board) {",
"container": "Solution",
"callable": "maximumValueSum",
"parameters": [
{
"name": "board",
"type": "int[][]"
}
],
"return_type": "long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippe... |
3,258 | count-substrings-that-satisfy-k-constraint-i | Easy | You are given a binary string s and an integer k.
A binary string satisfies the k-constraint if either of the following conditions holds:
- The number of 0's in the string is at most k.
- The number of 1's in the string is at most k.
Return an integer denoting the number of substrings of s that satisfy the k-constra... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"0101010101\",k = 5) == 55\n assert candidate(s = \"11111\",k = 1) == 15\n assert candidate(s = \"00000\",k = 2) == 15\n assert candidate(s = \"101010101010\",k = 4) == 72\n assert candidate(s = \"100100100\",k = 3) == 4... | [
"\"10101\"\n1",
"\"1010101\"\n2",
"\"11111\"\n1"
] | [
"Using a brute force approach, check each index until a substring satisfying the k-constraint is found, then increment."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().countKConstraintSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:42",
"tests_tota... | java | {
"raw_signature": "public int countKConstraintSubstrings(String s, int k) {",
"container": "Solution",
"callable": "countKConstraintSubstrings",
"parameters": [
{
"name": "s",
"type": "String"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_so... |
3,259 | maximum-energy-boost-from-two-drinks | Medium | You are given two integer arrays energyDrinkA and energyDrinkB of the same length n by a futuristic sports scientist. These arrays represent the energy boosts per hour provided by two different energy drinks, A and B, respectively.
You want to maximize your total energy boost by drinking one energy drink per hour. How... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(energyDrinkA = [1, 1, 1, 1, 1, 1],energyDrinkB = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(energyDrinkA = [1, 100000, 1],energyDrinkB = [100000, 1, 100000]) == 200001\n assert candidate(energyDrinkA = [4, 1, 1],energyDrinkB = [1,... | [
"[1,3,1]\n[3,1,1]",
"[4,1,1]\n[1,1,3]"
] | [
"Can we solve it using dynamic programming?",
"Define dpA[i] as the maximum energy boost if we consider only the first i + 1 hours such that in the last hour, we drink the energy drink A.",
"Similarly define dpB[i].",
"dpA[i] = max(dpA[i - 1], dpB[i - 2]) + energyDrinkA[i]",
"Similarly, fill dpB.",
"The a... | {
"canonical_parameter_names": [
"energyDrinkA",
"energyDrinkB"
],
"leetcode_dataset_entry_point": "Solution().maxEnergyBoost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:45",
"... | java | {
"raw_signature": "public long maxEnergyBoost(int[] energyDrinkA, int[] energyDrinkB) {",
"container": "Solution",
"callable": "maxEnergyBoost",
"parameters": [
{
"name": "energyDrinkA",
"type": "int[]"
},
{
"name": "energyDrinkB",
"type": "int[]"
}
],
"return_type":... |
3,260 | find-the-largest-palindrome-divisible-by-k | Hard | You are given two positive integers n and k.
An integer x is called k-palindromic if:
- x is a palindrome.
- x is divisible by k.
Return the largest integer having n digits (as a string) that is k-palindromic.
Note that the integer must not have leading zeros.
Example 1:
Input: n = 3, k = 5
Output: "595"
Explanat... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 1,k = 4) == \"8\"\n assert candidate(n = 6,k = 9) == \"999999\"\n assert candidate(n = 6,k = 7) == \"999999\"\n assert candidate(n = 3,k = 5) == \"595\"\n assert candidate(n = 5,k = 6) == \"89898\"\n assert candidate(n... | [
"3\n5",
"1\n4",
"5\n6"
] | [
"It must have a solution since we can have all digits equal to k.",
"Use string dp, store modulus along with length of number currently formed.",
"Is it possible to solve greedily using divisibility rules?"
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().largestPalindrome",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:47",
"tests_total": 49,
... | java | {
"raw_signature": "public String largestPalindrome(int n, int k) {",
"container": "Solution",
"callable": "largestPalindrome",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "String",
"signature_source": "leetcode/c... |
3,261 | count-substrings-that-satisfy-k-constraint-ii | Hard | You are given a binary string s and an integer k.
You are also given a 2D integer array queries, where queries[i] = [l_i, r_i].
A binary string satisfies the k-constraint if either of the following conditions holds:
- The number of 0's in the string is at most k.
- The number of 1's in the string is at most k.
Retu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"010101\",k = 1,queries = [[0, 5], [1, 4], [2, 3]]) == [15, 9, 3]\n assert candidate(s = \"111111\",k = 3,queries = [[0, 5], [1, 4], [2, 3]]) == [21, 10, 3]\n assert candidate(s = \"000000\",k = 3,queries = [[0, 5], [1, 4], [2... | [
"\"0001111\"\n2\n[[0,6]]",
"\"010101\"\n1\n[[0,5],[1,4],[2,3]]"
] | [
"Answering online queries is tough. Try to answer them offline since the queries are known beforehand.",
"For each index, how do you calculate the left boundary so that the given condition is satisfied?",
"Using the precomputed left boundaries and a range data structure, you can now answer the queries optimally... | {
"canonical_parameter_names": [
"s",
"k",
"queries"
],
"leetcode_dataset_entry_point": "Solution().countKConstraintSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:50"... | java | {
"raw_signature": "public long[] countKConstraintSubstrings(String s, int k, int[][] queries) {",
"container": "Solution",
"callable": "countKConstraintSubstrings",
"parameters": [
{
"name": "s",
"type": "String"
},
{
"name": "k",
"type": "int"
},
{
"name": "qu... |
3,264 | final-array-state-after-k-multiplication-operations-i | Easy | You are given an integer array nums, an integer k, and an integer multiplier.
You need to perform k operations on nums. In each operation:
- Find the minimum value x in nums. If there are multiple occurrences of the minimum value, select the one that appears first.
- Replace the selected minimum value x with x * mult... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [3],k = 1,multiplier = 5) == [15]\n assert candidate(nums = [5, 5, 5, 5],k = 4,multiplier = 2) == [10, 10, 10, 10]\n assert candidate(nums = [10, 9, 8, 7],k = 4,multiplier = 1) == [10, 9, 8, 7]\n assert candidate(nums = [... | [
"[2,1,3,5,6]\n5\n2",
"[1,2]\n3\n4"
] | [
"Maintain sorted pairs (nums[index], index) in a priority queue.",
"Simulate the operation k times."
] | {
"canonical_parameter_names": [
"nums",
"k",
"multiplier"
],
"leetcode_dataset_entry_point": "Solution().getFinalState",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:52",
"te... | java | {
"raw_signature": "public int[] getFinalState(int[] nums, int k, int multiplier) {",
"container": "Solution",
"callable": "getFinalState",
"parameters": [
{
"name": "nums",
"type": "int[]"
},
{
"name": "k",
"type": "int"
},
{
"name": "multiplier",
"type":... |
3,265 | count-almost-equal-pairs-i | Medium | You are given an array nums consisting of positive integers.
We call two integers x and y in this problem almost equal if both integers can become equal after performing the following operation at most once:
- Choose either x or y and swap any two digits within the chosen number.
Return the number of indices i and j... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == 0\n assert candidate(nums = [101, 110, 111, 1001, 1100]) == 5\n assert candidate(nums = [12, 21, 13, 31, 14]) == 2\n assert candidate(nums = [12, 21, 13, 31, 23, 32, 45, 5... | [
"[3,12,30,17,21]",
"[1,1,1,1,1]",
"[123,231]"
] | [
"Since the constraint on the number of elements is small, you can check all pairs in the array.",
"For each pair, perform an operation on one of the elements and check if it becomes equal to the other."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:54",
"tests_total": 123,
"tests_drop... | java | {
"raw_signature": "public int countPairs(int[] nums) {",
"container": "Solution",
"callable": "countPairs",
"parameters": [
{
"name": "nums",
"type": "int[]"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,267 | count-almost-equal-pairs-ii | Hard | Attention: In this version, the number of operations that can be performed, has been increased to twice.
You are given an array nums consisting of positive integers.
We call two integers x and y almost equal if both integers can become equal after performing the following operation at most twice:
- Choose either x o... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [123, 321, 213, 132]) == 6\n assert candidate(nums = [1111, 2222, 3333, 4444]) == 0\n assert candidate(nums = [12, 21, 13, 31, 23, 32]) == 3\n assert candidate(nums = [111, 222, 333, 444, 555]) == 0\n assert candidate(... | [
"[1023,2310,2130,213]",
"[1,10,100]"
] | [
"For each element, find all possible integers we can get by applying the operations.",
"Store the frequencies of all the integers in a hashmap."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:18:59",
"tests_total": 132,
"tests_drop... | java | {
"raw_signature": "public int countPairs(int[] nums) {",
"container": "Solution",
"callable": "countPairs",
"parameters": [
{
"name": "nums",
"type": "int[]"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,270 | find-the-key-of-the-numbers | Easy | You are given three positive integers num1, num2, and num3.
The key of num1, num2, and num3 is defined as a four-digit number such that:
- Initially, if any number has less than four digits, it is padded with leading zeros.
- The i^th digit (1 <= i <= 4) of the key is generated by taking the smallest digit among the ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num1 = 9999,num2 = 9999,num3 = 9999) == 9999\n assert candidate(num1 = 1000,num2 = 1000,num3 = 1000) == 1000\n assert candidate(num1 = 12,num2 = 345,num3 = 6789) == 12\n assert candidate(num1 = 5555,num2 = 5555,num3 = 6666) == 5... | [
"1\n10\n1000",
"987\n879\n798",
"1\n2\n3"
] | [] | {
"canonical_parameter_names": [
"num1",
"num2",
"num3"
],
"leetcode_dataset_entry_point": "Solution().generateKey",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:04",
"tests_t... | java | {
"raw_signature": "public int generateKey(int num1, int num2, int num3) {",
"container": "Solution",
"callable": "generateKey",
"parameters": [
{
"name": "num1",
"type": "int"
},
{
"name": "num2",
"type": "int"
},
{
"name": "num3",
"type": "int"
}
]... |
3,271 | hash-divided-string | Medium | You are given a string s of length n and an integer k, where n is a multiple of k. Your task is to hash the string s into a new string called result, which has a length of n / k.
First, divide s into n / k substrings, each with a length of k. Then, initialize result as an empty string.
For each substring in order fro... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aaaa\",k = 2) == \"aa\"\n assert candidate(s = \"mnopqr\",k = 3) == \"nw\"\n assert candidate(s = \"hellohellohellohello\",k = 5) == \"vvvv\"\n assert candidate(s = \"ababababab\",k = 2) == \"bbbbb\"\n assert candidate(... | [
"\"abcd\"\n2",
"\"mxz\"\n3"
] | [
"Try to find each substring.",
"Use a for loop to find hashedChar of each substring.",
"Find the answer using hashedChar of each substring."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().stringHash",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:06",
"tests_total": 38,
"tests... | java | {
"raw_signature": "public String stringHash(String s, int k) {",
"container": "Solution",
"callable": "stringHash",
"parameters": [
{
"name": "s",
"type": "String"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "String",
"signature_source": "leetcode/codeSnipp... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.