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,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... | rust | {
"raw_signature": "pub fn min_cost(nums: Vec<i32>) -> i32 {",
"container": "Solution",
"callable": "min_cost",
"parameters": [
{
"name": "nums",
"type": "Vec<i32>"
}
],
"return_type": "i32",
"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... | rust | {
"raw_signature": "pub fn permute(n: i32, k: i64) -> Vec<i32> {",
"container": "Solution",
"callable": "permute",
"parameters": [
{
"name": "n",
"type": "i32"
},
{
"name": "k",
"type": "i64"
}
],
"return_type": "Vec<i32>",
"signature_source": "leetcode/codeSnippets... |
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,
... | rust | {
"raw_signature": "pub fn largest_integer(nums: Vec<i32>, k: i32) -> i32 {",
"container": "Solution",
"callable": "largest_integer",
"parameters": [
{
"name": "nums",
"type": "Vec<i32>"
},
{
"name": "k",
"type": "i32"
}
],
"return_type": "i32",
"signature_source": ... |
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... | rust | {
"raw_signature": "pub fn longest_palindromic_subsequence(s: String, k: i32) -> i32 {",
"container": "Solution",
"callable": "longest_palindromic_subsequence",
"parameters": [
{
"name": "s",
"type": "String"
},
{
"name": "k",
"type": "i32"
}
],
"return_type": "i32",
... |
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,... | rust | {
"raw_signature": "pub fn max_sum(nums: Vec<i32>, k: i32, m: i32) -> i32 {",
"container": "Solution",
"callable": "max_sum",
"parameters": [
{
"name": "nums",
"type": "Vec<i32>"
},
{
"name": "k",
"type": "i32"
},
{
"name": "m",
"type": "i32"
}
],
... |
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... | rust | {
"raw_signature": "pub fn generate_string(str1: String, str2: String) -> String {",
"container": "Solution",
"callable": "generate_string",
"parameters": [
{
"name": "str1",
"type": "String"
},
{
"name": "str2",
"type": "String"
}
],
"return_type": "String",
"signa... |
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_... | rust | {
"raw_signature": "pub fn num_of_unplaced_fruits(fruits: Vec<i32>, baskets: Vec<i32>) -> i32 {",
"container": "Solution",
"callable": "num_of_unplaced_fruits",
"parameters": [
{
"name": "fruits",
"type": "Vec<i32>"
},
{
"name": "baskets",
"type": "Vec<i32>"
}
],
"ret... |
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... | rust | {
"raw_signature": "pub fn find_max_sum(nums1: Vec<i32>, nums2: Vec<i32>, k: i32) -> Vec<i64> {",
"container": "Solution",
"callable": "find_max_sum",
"parameters": [
{
"name": "nums1",
"type": "Vec<i32>"
},
{
"name": "nums2",
"type": "Vec<i32>"
},
{
"name": "k"... |
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_... | rust | {
"raw_signature": "pub fn num_of_unplaced_fruits(fruits: Vec<i32>, baskets: Vec<i32>) -> i32 {",
"container": "Solution",
"callable": "num_of_unplaced_fruits",
"parameters": [
{
"name": "fruits",
"type": "Vec<i32>"
},
{
"name": "baskets",
"type": "Vec<i32>"
}
],
"ret... |
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... | rust | {
"raw_signature": "pub fn max_subarrays(n: i32, conflicting_pairs: Vec<Vec<i32>>) -> i64 {",
"container": "Solution",
"callable": "max_subarrays",
"parameters": [
{
"name": "n",
"type": "i32"
},
{
"name": "conflicting_pairs",
"type": "Vec<Vec<i32>>"
}
],
"return_type... |
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_... | rust | {
"raw_signature": "pub fn total_numbers(digits: Vec<i32>) -> i32 {",
"container": "Solution",
"callable": "total_numbers",
"parameters": [
{
"name": "digits",
"type": "Vec<i32>"
}
],
"return_type": "i32",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnip... |
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":... | rust | {
"raw_signature": "pub fn longest_common_prefix(words: Vec<String>, k: i32) -> Vec<i32> {",
"container": "Solution",
"callable": "longest_common_prefix",
"parameters": [
{
"name": "words",
"type": "Vec<String>"
},
{
"name": "k",
"type": "i32"
}
],
"return_type": "Vec... |
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"... | rust | {
"raw_signature": "pub fn max_sum(nums: Vec<i32>) -> i32 {",
"container": "Solution",
"callable": "max_sum",
"parameters": [
{
"name": "nums",
"type": "Vec<i32>"
}
],
"return_type": "i32",
"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... | rust | {
"raw_signature": "pub fn solve_queries(nums: Vec<i32>, queries: Vec<i32>) -> Vec<i32> {",
"container": "Solution",
"callable": "solve_queries",
"parameters": [
{
"name": "nums",
"type": "Vec<i32>"
},
{
"name": "queries",
"type": "Vec<i32>"
}
],
"return_type": "Vec<i... |
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... | rust | {
"raw_signature": "pub fn min_zero_array(nums: Vec<i32>, queries: Vec<Vec<i32>>) -> i32 {",
"container": "Solution",
"callable": "min_zero_array",
"parameters": [
{
"name": "nums",
"type": "Vec<i32>"
},
{
"name": "queries",
"type": "Vec<Vec<i32>>"
}
],
"return_type":... |
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,
... | rust | {
"raw_signature": "pub fn beautiful_numbers(l: i32, r: i32) -> i32 {",
"container": "Solution",
"callable": "beautiful_numbers",
"parameters": [
{
"name": "l",
"type": "i32"
},
{
"name": "r",
"type": "i32"
}
],
"return_type": "i32",
"signature_source": "leetcode/co... |
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_... | rust | {
"raw_signature": "pub fn max_containers(n: i32, w: i32, max_weight: i32) -> i32 {",
"container": "Solution",
"callable": "max_containers",
"parameters": [
{
"name": "n",
"type": "i32"
},
{
"name": "w",
"type": "i32"
},
{
"name": "max_weight",
"type": "i3... |
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... | rust | {
"raw_signature": "pub fn number_of_components(properties: Vec<Vec<i32>>, k: i32) -> i32 {",
"container": "Solution",
"callable": "number_of_components",
"parameters": [
{
"name": "properties",
"type": "Vec<Vec<i32>>"
},
{
"name": "k",
"type": "i32"
}
],
"return_type... |
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,
"... | rust | {
"raw_signature": "pub fn min_time(skill: Vec<i32>, mana: Vec<i32>) -> i64 {",
"container": "Solution",
"callable": "min_time",
"parameters": [
{
"name": "skill",
"type": "Vec<i32>"
},
{
"name": "mana",
"type": "Vec<i32>"
}
],
"return_type": "i64",
"signature_sourc... |
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... | rust | {
"raw_signature": "pub fn min_operations(queries: Vec<Vec<i32>>) -> i64 {",
"container": "Solution",
"callable": "min_operations",
"parameters": [
{
"name": "queries",
"type": "Vec<Vec<i32>>"
}
],
"return_type": "i64",
"signature_source": "leetcode/codeSnippets",
"type_source": "lee... |
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... | rust | {
"raw_signature": "pub fn reverse_degree(s: String) -> i32 {",
"container": "Solution",
"callable": "reverse_degree",
"parameters": [
{
"name": "s",
"type": "String"
}
],
"return_type": "i32",
"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,
... | rust | {
"raw_signature": "pub fn max_active_sections_after_trade(s: String) -> i32 {",
"container": "Solution",
"callable": "max_active_sections_after_trade",
"parameters": [
{
"name": "s",
"type": "String"
}
],
"return_type": "i32",
"signature_source": "leetcode/codeSnippets",
"type_sourc... |
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... | rust | {
"raw_signature": "pub fn minimum_cost(nums: Vec<i32>, cost: Vec<i32>, k: i32) -> i64 {",
"container": "Solution",
"callable": "minimum_cost",
"parameters": [
{
"name": "nums",
"type": "Vec<i32>"
},
{
"name": "cost",
"type": "Vec<i32>"
},
{
"name": "k",
"... |
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... | rust | {
"raw_signature": "pub fn max_active_sections_after_trade(s: String, queries: Vec<Vec<i32>>) -> Vec<i32> {",
"container": "Solution",
"callable": "max_active_sections_after_trade",
"parameters": [
{
"name": "s",
"type": "String"
},
{
"name": "queries",
"type": "Vec<Vec<i32>>... |
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... | rust | {
"raw_signature": "pub fn min_costs(cost: Vec<i32>) -> Vec<i32> {",
"container": "Solution",
"callable": "min_costs",
"parameters": [
{
"name": "cost",
"type": "Vec<i32>"
}
],
"return_type": "Vec<i32>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippe... |
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,
... | rust | {
"raw_signature": "pub fn longest_palindrome(s: String, t: String) -> i32 {",
"container": "Solution",
"callable": "longest_palindrome",
"parameters": [
{
"name": "s",
"type": "String"
},
{
"name": "t",
"type": "String"
}
],
"return_type": "i32",
"signature_source"... |
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,
... | rust | {
"raw_signature": "pub fn longest_palindrome(s: String, t: String) -> i32 {",
"container": "Solution",
"callable": "longest_palindrome",
"parameters": [
{
"name": "s",
"type": "String"
},
{
"name": "t",
"type": "String"
}
],
"return_type": "i32",
"signature_source"... |
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... | rust | {
"raw_signature": "pub fn min_operations(nums: Vec<i32>, x: i32, k: i32) -> i64 {",
"container": "Solution",
"callable": "min_operations",
"parameters": [
{
"name": "nums",
"type": "Vec<i32>"
},
{
"name": "x",
"type": "i32"
},
{
"name": "k",
"type": "i32"... |
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... | typescript | {
"raw_signature": "function shortestDistanceAfterQueries(n: number, queries: number[][]): number[] {",
"container": null,
"callable": "shortestDistanceAfterQueries",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "queries",
"type": "number[][]"
}
],
"re... |
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... | typescript | {
"raw_signature": "function shortestDistanceAfterQueries(n: number, queries: number[][]): number[] {",
"container": null,
"callable": "shortestDistanceAfterQueries",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "queries",
"type": "number[][]"
}
],
"re... |
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... | typescript | {
"raw_signature": "function finalPositionOfSnake(n: number, commands: string[]): number {",
"container": null,
"callable": "finalPositionOfSnake",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "commands",
"type": "string[]"
}
],
"return_type": "number"... |
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... | typescript | {
"raw_signature": "function countOfPairs(nums: number[]): number {",
"container": null,
"callable": "countOfPairs",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"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... | typescript | {
"raw_signature": "function countOfPairs(nums: number[]): number {",
"container": null,
"callable": "countOfPairs",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"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,
... | typescript | {
"raw_signature": "function resultsArray(nums: number[], k: number): number[] {",
"container": null,
"callable": "resultsArray",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number[]",
"signature_sourc... |
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,
... | typescript | {
"raw_signature": "function resultsArray(nums: number[], k: number): number[] {",
"container": null,
"callable": "resultsArray",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number[]",
"signature_sourc... |
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... | typescript | {
"raw_signature": "function maximumValueSum(board: number[][]): number {",
"container": null,
"callable": "maximumValueSum",
"parameters": [
{
"name": "board",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/co... |
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... | typescript | {
"raw_signature": "function maximumValueSum(board: number[][]): number {",
"container": null,
"callable": "maximumValueSum",
"parameters": [
{
"name": "board",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/co... |
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... | typescript | {
"raw_signature": "function countKConstraintSubstrings(s: string, k: number): number {",
"container": null,
"callable": "countKConstraintSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"s... |
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",
"... | typescript | {
"raw_signature": "function maxEnergyBoost(energyDrinkA: number[], energyDrinkB: number[]): number {",
"container": null,
"callable": "maxEnergyBoost",
"parameters": [
{
"name": "energyDrinkA",
"type": "number[]"
},
{
"name": "energyDrinkB",
"type": "number[]"
}
],
"... |
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,
... | typescript | {
"raw_signature": "function largestPalindrome(n: number, k: number): string {",
"container": null,
"callable": "largestPalindrome",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "string",
"signature_source": ... |
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"... | typescript | {
"raw_signature": "function countKConstraintSubstrings(s: string, k: number, queries: number[][]): number[] {",
"container": null,
"callable": "countKConstraintSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "number"
},
{
... |
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... | typescript | {
"raw_signature": "function getFinalState(nums: number[], k: number, multiplier: number): number[] {",
"container": null,
"callable": "getFinalState",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
},
{
"name": "multipli... |
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... | typescript | {
"raw_signature": "function countPairs(nums: number[]): number {",
"container": null,
"callable": "countPairs",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"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... | typescript | {
"raw_signature": "function countPairs(nums: number[]): number {",
"container": null,
"callable": "countPairs",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"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... | typescript | {
"raw_signature": "function generateKey(num1: number, num2: number, num3: number): number {",
"container": null,
"callable": "generateKey",
"parameters": [
{
"name": "num1",
"type": "number"
},
{
"name": "num2",
"type": "number"
},
{
"name": "num3",
"type... |
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... | typescript | {
"raw_signature": "function stringHash(s: string, k: number): string {",
"container": null,
"callable": "stringHash",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "string",
"signature_source": "leetcode/code... |
3,272 | find-the-count-of-good-integers | 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.
An integer is called good if its digits can be rearranged to form a k-palindromic integer. For example, for k = 2, 2020 can be rearranged to form the k-palindromic integer 2002, whereas 1... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,k = 8) == 5221\n assert candidate(n = 10,k = 9) == 4610368\n assert candidate(n = 1,k = 4) == 2\n assert candidate(n = 6,k = 9) == 1248\n assert candidate(n = 9,k = 1) == 41457015\n assert candidate(n = 8,k = 2) == 5... | [
"3\n5",
"1\n4",
"5\n6"
] | [
"How to generate all K-palindromic strings of length n? Do we need to go through all n digits?",
"Use permutations to calculate the number of possible rearrangements."
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().countGoodIntegers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:08",
"tests_total": 56,
... | typescript | {
"raw_signature": "function countGoodIntegers(n: number, k: number): number {",
"container": null,
"callable": "countGoodIntegers",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_source": ... |
3,273 | minimum-amount-of-damage-dealt-to-bob | Hard | You are given an integer power and two integer arrays damage and health, both having length n.
Bob has n enemies, where enemy i will deal Bob damage[i] points of damage per second while they are alive (i.e. health[i] > 0).
Every second, after the enemies deal damage to Bob, he chooses one of the enemies that is still... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(power = 2,damage = [1, 1, 1, 1, 1],health = [1, 2, 3, 4, 5]) == 22\n assert candidate(power = 100,damage = [10, 20, 30],health = [100, 100, 100]) == 100\n assert candidate(power = 4,damage = [1, 2, 3, 4],health = [4, 5, 6, 8]) == 3... | [
"4\n[1,2,3,4]\n[4,5,6,8]",
"1\n[1,1,1,1]\n[1,2,3,4]",
"8\n[40]\n[59]"
] | [
"Can we use sorting here along with a custom comparator?",
"For any two enemies i and j with damages damage[i] and damage[j], and time to take each of them down t_i and t_j, when is it better to choose enemy i over enemy j first?"
] | {
"canonical_parameter_names": [
"power",
"damage",
"health"
],
"leetcode_dataset_entry_point": "Solution().minDamage",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:11",
"test... | typescript | {
"raw_signature": "function minDamage(power: number, damage: number[], health: number[]): number {",
"container": null,
"callable": "minDamage",
"parameters": [
{
"name": "power",
"type": "number"
},
{
"name": "damage",
"type": "number[]"
},
{
"name": "health",... |
3,274 | check-if-two-chessboard-squares-have-the-same-color | Easy | You are given two strings, coordinate1 and coordinate2, representing the coordinates of a square on an 8 x 8 chessboard.
Below is the chessboard for reference.
Return true if these two squares have the same color and false otherwise.
The coordinate will always represent a valid chessboard square. The coordinate will... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(coordinate1 = \"g7\",coordinate2 = \"f8\") == True\n assert candidate(coordinate1 = \"a1\",coordinate2 = \"c3\") == True\n assert candidate(coordinate1 = \"e5\",coordinate2 = \"g7\") == True\n assert candidate(coordinate1 = \"b2... | [
"\"a1\"\n\"c3\"",
"\"a1\"\n\"h3\""
] | [
"The color of the chessboard is black the sum of row coordinates and column coordinates is even. Otherwise, it's white."
] | {
"canonical_parameter_names": [
"coordinate1",
"coordinate2"
],
"leetcode_dataset_entry_point": "Solution().checkTwoChessboards",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:13",
... | typescript | {
"raw_signature": "function checkTwoChessboards(coordinate1: string, coordinate2: string): boolean {",
"container": null,
"callable": "checkTwoChessboards",
"parameters": [
{
"name": "coordinate1",
"type": "string"
},
{
"name": "coordinate2",
"type": "string"
}
],
"r... |
3,275 | k-th-nearest-obstacle-queries | Medium | There is an infinite 2D plane.
You are given a positive integer k. You are also given a 2D array queries, which contains the following queries:
- queries[i] = [x, y]: Build an obstacle at coordinate (x, y) in the plane. It is guaranteed that there is no obstacle at this coordinate when this query is made.
After each... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(queries = [[5, 5], [4, 4], [3, 3]],k = 1) == [10, 8, 6]\n assert candidate(queries = [[-1000000000, 1000000000], [1000000000, -1000000000]],k = 1) == [2000000000, 2000000000]\n assert candidate(queries = [[-1, 1], [0, 0], [1, -1]],... | [
"[[1,2],[3,4],[2,3],[-3,0]]\n2",
"[[5,5],[4,4],[3,3]]\n1"
] | [
"Consider if there are more than k obstacles. Can the k + 1^th obstacle ever be the answer to any query?",
"Maintain a max heap of size k, thus heap will contain minimum element at the top in that queue.",
"Remove top element and insert new element from input array if current max is larger than this."
] | {
"canonical_parameter_names": [
"queries",
"k"
],
"leetcode_dataset_entry_point": "Solution().resultsArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:17",
"tests_total": 85,
... | typescript | {
"raw_signature": "function resultsArray(queries: number[][], k: number): number[] {",
"container": null,
"callable": "resultsArray",
"parameters": [
{
"name": "queries",
"type": "number[][]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number[]",
"signa... |
3,276 | select-cells-in-grid-with-maximum-score | Hard | You are given a 2D matrix grid consisting of positive integers.
You have to select one or more cells from the matrix such that the following conditions are satisfied:
- No two selected cells are in the same row of the matrix.
- The values in the set of selected cells are unique.
Your score will be the sum of the val... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 5\n assert candidate(grid = [[8, 7, 6], [8, 3, 2]]) == 15\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 1]]) == 12\n assert candidate(grid = [[5, 9, 1], [9... | [
"[[1,2,3],[4,3,2],[1,1,1]]",
"[[8,7,6],[8,3,2]]"
] | [
"Sort all the cells in the grid by their values and keep track of their original positions.",
"Try dynamic programming with the following states: the current cell that we might select and a bitmask representing all the rows from which we have already selected a cell so far."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().maxScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:19",
"tests_total": 97,
"tests_dropped... | typescript | {
"raw_signature": "function maxScore(grid: number[][]): number {",
"container": null,
"callable": "maxScore",
"parameters": [
{
"name": "grid",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,277 | maximum-xor-score-subarray-queries | Hard | You are given an array nums of n integers, and a 2D integer array queries of size q, where queries[i] = [l_i, r_i].
For each query, you must find the maximum XOR score of any subarray of nums[l_i..r_i].
The XOR score of an array a is found by repeatedly applying the following operations on a so that only one element ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [0, 7, 3, 2, 8, 5, 1],queries = [[0, 3], [1, 5], [2, 4], [2, 6], [5, 6]]) == [7, 14, 11, 14, 5]\n assert candidate(nums = [2, 8, 4, 32, 16, 1],queries = [[0, 2], [1, 4], [0, 5]]) == [12, 60, 60]\n assert candidate(nums = [10... | [
"[2,8,4,32,16,1]\n[[0,2],[1,4],[0,5]]",
"[0,7,3,2,8,5,1]\n[[0,3],[1,5],[2,4],[2,6],[5,6]]"
] | [
"Precompute the XOR score of every subarray.",
"Try to find a relationship between XOR score of nums[i..j], nums[i..j + 1], nums[i..j + 2], …. Do you notice any pattern?",
"If dp[i][j] is the XOR score of subarray nums[i..j], dp[i][j] = dp[i - 1][j] XOR dp[i - 1][j + 1]."
] | {
"canonical_parameter_names": [
"nums",
"queries"
],
"leetcode_dataset_entry_point": "Solution().maximumSubarrayXor",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:22",
"tests_tot... | typescript | {
"raw_signature": "function maximumSubarrayXor(nums: number[], queries: number[][]): number[] {",
"container": null,
"callable": "maximumSubarrayXor",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "queries",
"type": "number[][]"
}
],
"return_type"... |
3,280 | convert-date-to-binary | Easy | You are given a string date representing a Gregorian calendar date in the yyyy-mm-dd format.
date can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in year-month-day format.
Return the binary represe... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(date = \"1950-06-30\") == \"11110011110-110-11110\"\n assert candidate(date = \"1912-04-20\") == \"11101111000-100-10100\"\n assert candidate(date = \"2080-02-29\") == \"100000100000-10-11101\"\n assert candidate(date = \"2023-1... | [
"\"2080-02-29\"",
"\"1900-01-01\""
] | [] | {
"canonical_parameter_names": [
"date"
],
"leetcode_dataset_entry_point": "Solution().convertDateToBinary",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:27",
"tests_total": 87,
"te... | typescript | {
"raw_signature": "function convertDateToBinary(date: string): string {",
"container": null,
"callable": "convertDateToBinary",
"parameters": [
{
"name": "date",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/code... |
3,281 | maximize-score-of-numbers-in-ranges | Medium | You are given an array of integers start and an integer d, representing n intervals [start[i], start[i] + d].
You are asked to choose n integers where the i^th integer must belong to the i^th interval. The score of the chosen integers is defined as the minimum absolute difference between any two integers that have bee... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(start = [5, 10, 15, 20, 25],d = 4) == 6\n assert candidate(start = [1, 10, 20, 30],d = 9) == 12\n assert candidate(start = [10, 20, 30, 40, 50],d = 15) == 13\n assert candidate(start = [100, 200, 300, 400, 500],d = 50) == 112\n ... | [
"[6,0,3]\n2",
"[2,6,13,13]\n5"
] | [
"Can we use binary search here?",
"Suppose that the answer is x. We can find a valid configuration of integers by sorting start, the first integer should be start[0], then each subsequent integer should be the smallest one in [start[i], start[i] + d] that is greater than last_chosen_value + x.",
"Binary search ... | {
"canonical_parameter_names": [
"start",
"d"
],
"leetcode_dataset_entry_point": "Solution().maxPossibleScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:30",
"tests_total": 10... | typescript | {
"raw_signature": "function maxPossibleScore(start: number[], d: number): number {",
"container": null,
"callable": "maxPossibleScore",
"parameters": [
{
"name": "start",
"type": "number[]"
},
{
"name": "d",
"type": "number"
}
],
"return_type": "number",
"signature... |
3,282 | reach-end-of-array-with-max-score | Medium | You are given an integer array nums of length n.
Your goal is to start at index 0 and reach index n - 1. You can only jump to indices greater than your current index.
The score for a jump from index i to index j is calculated as (j - i) * nums[i].
Return the maximum possible total score by the time you reach the las... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 3, 5, 6, 7, 8]) == 23\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 90\n assert candidate(nums = [2, 4, 6, 8, 10]) == 20\n assert candidate(nums = [4, 3, 1, 3, 2]) == 16\n assert candidate(nums = [1... | [
"[1,3,1,5]",
"[4,3,1,3,2]"
] | [
"It can be proven that from each index i, the optimal solution is to jump to the nearest index j > i such that nums[j] > nums[i]."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findMaximumScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:33",
"tests_total": 99,
"tests... | typescript | {
"raw_signature": "function findMaximumScore(nums: number[]): number {",
"container": null,
"callable": "findMaximumScore",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSn... |
3,285 | find-indices-of-stable-mountains | Easy | There are n mountains in a row, and each mountain has a height. You are given an integer array height where height[i] represents the height of mountain i, and an integer threshold.
A mountain is called stable if the mountain just before it (if it exists) has a height strictly greater than threshold. Note that mountain... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ... | [
"[1,2,3,4,5]\n2",
"[10,1,10,1,10]\n3",
"[10,1,10,1,10]\n10"
] | [] | {
"canonical_parameter_names": [
"height",
"threshold"
],
"leetcode_dataset_entry_point": "Solution().stableMountains",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:40",
"tests_to... | typescript | {
"raw_signature": "function stableMountains(height: number[], threshold: number): number[] {",
"container": null,
"callable": "stableMountains",
"parameters": [
{
"name": "height",
"type": "number[]"
},
{
"name": "threshold",
"type": "number"
}
],
"return_type": "num... |
3,286 | find-a-safe-walk-through-a-grid | Medium | You are given an m x n binary matrix grid and an integer health.
You start on the upper-left corner (0, 0) and would like to get to the lower-right corner (m - 1, n - 1).
You can move up, down, left, or right from one cell to another adjacent cell as long as your health remains positive.
Cells (i, j) with grid[i][j]... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 1, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 1, 0]],health = 1) == True\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]],health = 1) == True\n assert candidate(grid = [[1, 1, 1], [1, 0, 1], [1, 1, 1]],health = 5) ... | [
"[[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]]\n1",
"[[0,1,1,0,0,0],[1,0,1,0,0,0],[0,1,1,1,0,1],[0,0,1,0,1,0]]\n3",
"[[1,1,1],[1,0,1],[1,1,1]]\n5"
] | [
"Use 01 BFS."
] | {
"canonical_parameter_names": [
"grid",
"health"
],
"leetcode_dataset_entry_point": "Solution().findSafeWalk",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:42",
"tests_total": 81... | typescript | {
"raw_signature": "function findSafeWalk(grid: number[][], health: number): boolean {",
"container": null,
"callable": "findSafeWalk",
"parameters": [
{
"name": "grid",
"type": "number[][]"
},
{
"name": "health",
"type": "number"
}
],
"return_type": "boolean",
"sig... |
3,287 | find-the-maximum-sequence-value-of-array | Hard | You are given an integer array nums and a positive integer k.
The value of a sequence seq of size 2 * x is defined as:
- (seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 * x - 1]).
Return the maximum value of any subsequence of nums having size 2 * k.
Example 1:
Input: nums = [2,6,... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 7, 9, 11],k = 3) == 8\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 0\n assert candidate(nums = [31, 15, 7, 3, 1],k = 2) == 28\n assert candidate(nums = [26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16... | [
"[2,6,7]\n1",
"[4,2,5,6,7]\n2"
] | [
"Find all the possible OR till each i with k elements backward and forward."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:44",
"tests_total": 65,
"test... | typescript | {
"raw_signature": "function maxValue(nums: number[], k: number): number {",
"container": null,
"callable": "maxValue",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_source": "leetcod... |
3,288 | length-of-the-longest-increasing-path | Hard | You are given a 2D array of integers coordinates of length n and an integer k, where 0 <= k < n.
coordinates[i] = [x_i, y_i] indicates the point (x_i, y_i) in a 2D plane.
An increasing path of length m is defined as a list of points (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_m, y_m) such that:
- x_i < x_{i + 1} and... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]],k = 4) == 7\n assert candidate(coordinates = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5]],k = 4) == 1\n assert candidate(coordinates = [[10, 9], [9, 8], [8, 7], [7... | [
"[[3,1],[2,2],[4,1],[0,0],[5,3]]\n1",
"[[2,1],[7,0],[5,6]]\n2"
] | [
"Only keep coordinates with both x and y being strictly less than coordinates[k].",
"Sort them by x’s, in the case of equal, the y values should be decreasing.",
"Calculate LIS only using y values.",
"Do the same for coordinates with both x and y being strictly larger than coordinates[k]."
] | {
"canonical_parameter_names": [
"coordinates",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxPathLength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:47",
"tests_total":... | typescript | {
"raw_signature": "function maxPathLength(coordinates: number[][], k: number): number {",
"container": null,
"callable": "maxPathLength",
"parameters": [
{
"name": "coordinates",
"type": "number[][]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
... |
3,289 | the-two-sneaky-numbers-of-digitville | Easy | In the town of Digitville, there was a list of numbers called nums containing integers from 0 to n - 1. Each number was supposed to appear exactly once in the list, however, two mischievous numbers sneaked in an additional time, making the list longer than usual.
As the town detective, your task is to find these two s... | {
"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 ... | [
"[0,1,1,0]",
"[0,3,2,1,3,2]",
"[7,1,5,4,3,4,6,0,9,5,8,2]"
] | [
"To solve the problem without the extra space, we need to think about how many times each number occurs in relation to the index."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().getSneakyNumbers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:50",
"tests_total": 74,
"tests... | typescript | {
"raw_signature": "function getSneakyNumbers(nums: number[]): number[] {",
"container": null,
"callable": "getSneakyNumbers",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number[]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/co... |
3,290 | maximum-multiplication-score | Medium | You are given an integer array a of size 4 and another integer array b of size at least 4.
You need to choose 4 indices i_0, i_1, i_2, and i_3 from the array b such that i_0 < i_1 < i_2 < i_3. Your score will be equal to the value a[0] * b[i_0] + a[1] * b[i_1] + a[2] * b[i_2] + a[3] * b[i_3].
Return the maximum score... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(a = [0, 0, 0, 0],b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(a = [1, 2, 3, 4],b = [10, 20, 30, 40, 50, 60, 70, 80]) == 700\n assert candidate(a = [10, 20, 30, 40],b = [1, 2, 3, 4]) == 300\n assert candidate(a = ... | [
"[3,2,5,6]\n[2,-6,4,-5,-3,2,-7]",
"[-1,4,5,-2]\n[-5,-1,-3,-2,-4]"
] | [
"Try using dynamic programming.",
"Consider a dp with the following states: The current position in the array b, and the number of indices considered."
] | {
"canonical_parameter_names": [
"a",
"b"
],
"leetcode_dataset_entry_point": "Solution().maxScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:52",
"tests_total": 104,
"tests_... | typescript | {
"raw_signature": "function maxScore(a: number[], b: number[]): number {",
"container": null,
"callable": "maxScore",
"parameters": [
{
"name": "a",
"type": "number[]"
},
{
"name": "b",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/... |
3,291 | minimum-number-of-valid-strings-to-form-target-i | Medium | You are given an array of strings words and a string target.
A string x is called valid if x is a prefix of any string in words.
Return the minimum number of valid strings that can be concatenated to form target. If it is not possible to form target, return -1.
Example 1:
Input: words = ["abc","aaaaa","bcdef"], tar... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['abc'],target = \"abcabc\") == 2\n assert candidate(words = ['ab', 'ba'],target = \"abab\") == 2\n assert candidate(words = ['a', 'b', 'c', 'd'],target = \"abcdabcdabcd\") == 12\n assert candidate(words = ['abcde', 'fgh... | [
"[\"abc\",\"aaaaa\",\"bcdef\"]\n\"aabcdabc\"",
"[\"abababab\",\"ab\"]\n\"ababaababa\"",
"[\"abcdef\"]\n\"xyz\""
] | [
"Let dp[i] be the minimum cost to form the prefix of length i of target.",
"If target[(i + 1)..j] matches any prefix, update the range dp[(i + 1)..j] to minimum between original value and dp[i] + 1.",
"Use a Trie to check prefix matching."
] | {
"canonical_parameter_names": [
"words",
"target"
],
"leetcode_dataset_entry_point": "Solution().minValidStrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:55",
"tests_total"... | typescript | {
"raw_signature": "function minValidStrings(words: string[], target: string): number {",
"container": null,
"callable": "minValidStrings",
"parameters": [
{
"name": "words",
"type": "string[]"
},
{
"name": "target",
"type": "string"
}
],
"return_type": "number",
"s... |
3,292 | minimum-number-of-valid-strings-to-form-target-ii | Hard | You are given an array of strings words and a string target.
A string x is called valid if x is a prefix of any string in words.
Return the minimum number of valid strings that can be concatenated to form target. If it is not possible to form target, return -1.
Example 1:
Input: words = ["abc","aaaaa","bcdef"], tar... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['abc'],target = \"abcabc\") == 2\n assert candidate(words = ['a'],target = \"a\") == 1\n assert candidate(words = ['a', 'aa', 'aaa'],target = \"aaaaaaaa\") == 3\n assert candidate(words = ['xyz'],target = \"xyz\") == 1\... | [
"[\"abc\",\"aaaaa\",\"bcdef\"]\n\"aabcdabc\"",
"[\"abababab\",\"ab\"]\n\"ababaababa\"",
"[\"abcdef\"]\n\"xyz\""
] | [
"Let dp[i] be the minimum cost to form the prefix of length i of target.",
"Use Rabin-Karp to hash every prefix and store it in a HashSet.",
"Use Binary search to find the longest substring starting at index i (target[i..j]) that has a hash present in the HashSet.",
"Inverse Modulo precomputation can optimise... | {
"canonical_parameter_names": [
"words",
"target"
],
"leetcode_dataset_entry_point": "Solution().minValidStrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:19:57",
"tests_total"... | typescript | {
"raw_signature": "function minValidStrings(words: string[], target: string): number {",
"container": null,
"callable": "minValidStrings",
"parameters": [
{
"name": "words",
"type": "string[]"
},
{
"name": "target",
"type": "string"
}
],
"return_type": "number",
"s... |
3,295 | report-spam-message | Medium | You are given an array of strings message and an array of strings bannedWords.
An array of words is considered spam if there are at least two words in it that exactly match any word in bannedWords.
Return true if the array message is spam, and false otherwise.
Example 1:
Input: message = ["hello","world","leetcode"... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(message = ['spam', 'egg', 'ham'],bannedWords = ['spam', 'bacon', 'egg']) == True\n assert candidate(message = ['spam', 'eggs', 'spam'],bannedWords = ['spam']) == True\n assert candidate(message = ['spam', 'spam', 'spam'],bannedWord... | [
"[\"hello\",\"world\",\"leetcode\"]\n[\"world\",\"hello\"]",
"[\"hello\",\"programming\",\"fun\"]\n[\"world\",\"programming\",\"leetcode\"]"
] | [
"Use hash set."
] | {
"canonical_parameter_names": [
"message",
"bannedWords"
],
"leetcode_dataset_entry_point": "Solution().reportSpam",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:00",
"tests_tota... | typescript | {
"raw_signature": "function reportSpam(message: string[], bannedWords: string[]): boolean {",
"container": null,
"callable": "reportSpam",
"parameters": [
{
"name": "message",
"type": "string[]"
},
{
"name": "bannedWords",
"type": "string[]"
}
],
"return_type": "bool... |
3,296 | minimum-number-of-seconds-to-make-mountain-height-zero | Medium | You are given an integer mountainHeight denoting the height of a mountain.
You are also given an integer array workerTimes representing the work time of workers in seconds.
Each worker may reduce the mountain's height by any non-negative integer amount. If worker i reduces the height by x, then:
- reducing the first... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mountainHeight = 15,workerTimes = [5, 5, 5]) == 75\n assert candidate(mountainHeight = 15,workerTimes = [1, 2, 3]) == 30\n assert candidate(mountainHeight = 15,workerTimes = [1, 2, 3, 4, 5]) == 18\n assert candidate(mountainHeig... | [
"4\n[2,1,1]",
"10\n[3,2,2,4]",
"5\n[1]"
] | [
"Can we use binary search to solve this problem?",
"Do a binary search on the number of seconds to check if it's enough to reduce the mountain height to 0 or less with all workers working simultaneously."
] | {
"canonical_parameter_names": [
"mountainHeight",
"workerTimes"
],
"leetcode_dataset_entry_point": "Solution().minNumberOfSeconds",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:02"... | typescript | {
"raw_signature": "function minNumberOfSeconds(mountainHeight: number, workerTimes: number[]): number {",
"container": null,
"callable": "minNumberOfSeconds",
"parameters": [
{
"name": "mountainHeight",
"type": "number"
},
{
"name": "workerTimes",
"type": "number[]"
}
... |
3,297 | count-substrings-that-can-be-rearranged-to-contain-a-string-i | Medium | You are given two strings word1 and word2.
A string x is called valid if x can be rearranged to have word2 as a prefix.
Return the total number of valid substrings of word1.
Example 1:
Input: word1 = "bcca", word2 = "abc"
Output: 1
Explanation:
The only valid substring is "bcca" which can be rearranged to "abcc" ha... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word1 = \"banana\",word2 = \"ban\") == 4\n assert candidate(word1 = \"abc\",word2 = \"abcd\") == 0\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == 1\n assert candidate(word1 =... | [
"\"bcca\"\n\"abc\"",
"\"abcabc\"\n\"abc\"",
"\"abcabc\"\n\"aaabc\""
] | [
"Store the frequency of each character for all prefixes.",
"Use Binary Search."
] | {
"canonical_parameter_names": [
"word1",
"word2"
],
"leetcode_dataset_entry_point": "Solution().validSubstringCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:04",
"tests_tot... | typescript | {
"raw_signature": "function validSubstringCount(word1: string, word2: string): number {",
"container": null,
"callable": "validSubstringCount",
"parameters": [
{
"name": "word1",
"type": "string"
},
{
"name": "word2",
"type": "string"
}
],
"return_type": "number",
... |
3,298 | count-substrings-that-can-be-rearranged-to-contain-a-string-ii | Hard | You are given two strings word1 and word2.
A string x is called valid if x can be rearranged to have word2 as a prefix.
Return the total number of valid substrings of word1.
Note that the memory limits in this problem are smaller than usual, so you must implement a solution with a linear runtime complexity.
Example... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word1 = \"bcca\",word2 = \"abc\") == 1\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == 1\n assert candidate(word1 = \"aabbcc\",word2 = \"abc\") == 4\n assert candidate(word1 =... | [
"\"bcca\"\n\"abc\"",
"\"abcabc\"\n\"abc\"",
"\"abcabc\"\n\"aaabc\""
] | [
"Use sliding window along with two-pointer here.",
"Use constant space to store the frequency of characters."
] | {
"canonical_parameter_names": [
"word1",
"word2"
],
"leetcode_dataset_entry_point": "Solution().validSubstringCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:07",
"tests_tot... | typescript | {
"raw_signature": "function validSubstringCount(word1: string, word2: string): number {",
"container": null,
"callable": "validSubstringCount",
"parameters": [
{
"name": "word1",
"type": "string"
},
{
"name": "word2",
"type": "string"
}
],
"return_type": "number",
... |
3,300 | minimum-element-after-replacement-with-digit-sum | Easy | You are given an integer array nums.
You replace each element in nums with the sum of its digits.
Return the minimum element in nums after all replacements.
Example 1:
Input: nums = [10,12,13,14]
Output: 1
Explanation:
nums becomes [1, 3, 4, 5] after all replacements, with minimum element 1.
Example 2:
Input: num... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [9999, 1001, 1111]) == 2\n assert candidate(nums = [111, 222, 333]) == 3\n assert candidate(nums = [1234, 4321, 2134, 3412]) == 10\n assert candidate(nums = [10, 12, 13, 14]) == 1\n assert candidate(nums = [100, 200, 3... | [
"[10,12,13,14]",
"[1,2,3,4]",
"[999,19,199]"
] | [
"Convert to string and calculate the sum for each element."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minElement",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:12",
"tests_total": 109,
"tests_drop... | typescript | {
"raw_signature": "function minElement(nums: number[]): number {",
"container": null,
"callable": "minElement",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,301 | maximize-the-total-height-of-unique-towers | Medium | You are given an array maximumHeight, where maximumHeight[i] denotes the maximum height the i^th tower can be assigned.
Your task is to assign a height to each tower so that:
1. The height of the i^th tower is a positive integer and does not exceed maximumHeight[i].
2. No two towers have the same height.
Return the ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(maximumHeight = [2, 3, 4, 3]) == 10\n assert candidate(maximumHeight = [5, 5, 5, 5, 5]) == 15\n assert candidate(maximumHeight = [1, 2, 3, 4, 5]) == 15\n assert candidate(maximumHeight = [1000000000, 999999999, 999999998, 999999... | [
"[2,3,4,3]",
"[15,10]",
"[2,2,1]"
] | [
"Sort the array maximumHeight in descending order.",
"After sorting, it can be seen that the maximum height that we can assign to the i^th element is min(maximumHeight[i], maximumHeight[i - 1] - 1)."
] | {
"canonical_parameter_names": [
"maximumHeight"
],
"leetcode_dataset_entry_point": "Solution().maximumTotalSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:14",
"tests_total": 73,
... | typescript | {
"raw_signature": "function maximumTotalSum(maximumHeight: number[]): number {",
"container": null,
"callable": "maximumTotalSum",
"parameters": [
{
"name": "maximumHeight",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": ... |
3,302 | find-the-lexicographically-smallest-valid-sequence | Medium | You are given two strings word1 and word2.
A string x is called almost equal to y if you can change at most one character in x to make it identical to y.
A sequence of indices seq is called valid if:
- The indices are sorted in ascending order.
- Concatenating the characters at these indices in word1 in the same ord... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word1 = \"hello\",word2 = \"heo\") == [0, 1, 2]\n assert candidate(word1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word2 = \"abc\") == []\n assert candidate(word1 = \"abcdefg\",word2 = \"bdf\") == [0, 3, 5]\n... | [
"\"vbcca\"\n\"abc\"",
"\"bacdc\"\n\"abc\"",
"\"aaaaaa\"\n\"aaabc\"",
"\"abc\"\n\"ab\""
] | [
"Let dp[i] be the longest suffix of word2 that exists as a subsequence of suffix of the substring of word1 starting at index i.",
"If dp[i + 1] < m and word1[i] == word2[m - dp[i + 1] - 1],dp[i] = dp[i + 1] + 1. Otherwise, dp[i] = dp[i + 1].",
"For each index i, greedily select characters using the dp array to ... | {
"canonical_parameter_names": [
"word1",
"word2"
],
"leetcode_dataset_entry_point": "Solution().validSequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:17",
"tests_total": 1... | typescript | {
"raw_signature": "function validSequence(word1: string, word2: string): number[] {",
"container": null,
"callable": "validSequence",
"parameters": [
{
"name": "word1",
"type": "string"
},
{
"name": "word2",
"type": "string"
}
],
"return_type": "number[]",
"signatu... |
3,303 | find-the-occurrence-of-first-almost-equal-substring | Hard | You are given two strings s and pattern.
A string x is called almost equal to y if you can change at most one character in x to make it identical to y.
Return the smallest starting index of a substring in s that is almost equal to pattern. If no such index exists, return -1.
A substring is a contiguous non-empty seq... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"mississippi\",pattern = \"missiippi\") == -1\n assert candidate(s = \"abcd\",pattern = \"dba\") == -1\n assert candidate(s = \"abcdefg\",pattern = \"bcdffg\") == 1\n assert candidate(s = \"mississippi\",pattern = \"misosip... | [
"\"abcdefg\"\n\"bcdffg\"",
"\"ababbababa\"\n\"bacaba\"",
"\"abcd\"\n\"dba\"",
"\"dde\"\n\"d\""
] | [
"Let dp1[i] represent the maximum length of a substring of s starting at index i that is also a prefix of pattern.",
"Let dp2[i] represent the maximum length of a substring of s ending at index i that is also a suffix of pattern.",
"Consider a window of size pattern.length. If dp1[i] + i == i + pattern.length -... | {
"canonical_parameter_names": [
"s",
"pattern"
],
"leetcode_dataset_entry_point": "Solution().minStartingIndex",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:20",
"tests_total": ... | typescript | {
"raw_signature": "function minStartingIndex(s: string, pattern: string): number {",
"container": null,
"callable": "minStartingIndex",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "pattern",
"type": "string"
}
],
"return_type": "number",
"signature... |
3,304 | find-the-k-th-character-in-string-game-i | Easy | Alice and Bob are playing a game. Initially, Alice has a string word = "a".
You are given a positive integer k.
Now Bob will ask Alice to perform the following operation forever:
- Generate a new string by changing each character in word to its next character in the English alphabet, and append it to the original wo... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(k = 27) == \"d\"\n assert candidate(k = 1) == \"a\"\n assert candidate(k = 7) == \"c\"\n assert candidate(k = 500) == \"h\"\n assert candidate(k = 26) == \"d\"\n assert candidate(k = 5) == \"b\"\n assert candidate(k = 1... | [
"5",
"10"
] | [
"The constraints are small. Construct the string by simulating the operations."
] | {
"canonical_parameter_names": [
"k"
],
"leetcode_dataset_entry_point": "Solution().kthCharacter",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:22",
"tests_total": 37,
"tests_droppe... | typescript | {
"raw_signature": "function kthCharacter(k: number): string {",
"container": null,
"callable": "kthCharacter",
"parameters": [
{
"name": "k",
"type": "number"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,305 | count-of-substrings-containing-every-vowel-and-k-consonants-i | Medium | You are given a string word and a non-negative integer k.
Return the total number of substrings of word that contain every vowel ('a', 'e', 'i', 'o', and 'u') at least once and exactly k consonants.
Example 1:
Input: word = "aeioqq", k = 1
Output: 0
Explanation:
There is no substring with every vowel.
Example 2:
I... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word = \"uuuaaeiooouueiiaaoou\",k = 3) == 0\n assert candidate(word = \"aeiouaeiouaeiouaeiou\",k = 0) == 136\n assert candidate(word = \"aeiouzzzzz\",k = 5) == 1\n assert candidate(word = \"aeioqq\",k = 1) == 0\n assert candi... | [
"\"aeioqq\"\n1",
"\"aeiou\"\n0",
"\"ieaouqqieaouqq\"\n1"
] | [
"Use a HashMap and check all the substrings."
] | {
"canonical_parameter_names": [
"word",
"k"
],
"leetcode_dataset_entry_point": "Solution().countOfSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:24",
"tests_total": 67... | typescript | {
"raw_signature": "function countOfSubstrings(word: string, k: number): number {",
"container": null,
"callable": "countOfSubstrings",
"parameters": [
{
"name": "word",
"type": "string"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_sou... |
3,306 | count-of-substrings-containing-every-vowel-and-k-consonants-ii | Medium | You are given a string word and a non-negative integer k.
Return the total number of substrings of word that contain every vowel ('a', 'e', 'i', 'o', and 'u') at least once and exactly k consonants.
Example 1:
Input: word = "aeioqq", k = 1
Output: 0
Explanation:
There is no substring with every vowel.
Example 2:
I... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word = \"qwertyuiopasdfghjklzxcvbnmaeiou\",k = 10) == 4\n assert candidate(word = \"uoieaouoieaouoieaouoieaoiueaouieaouieaouieao\",k = 4) == 0\n assert candidate(word = \"aeiouzzzzz\",k = 5) == 1\n assert candidate(word = \"aeio... | [
"\"aeioqq\"\n1",
"\"aeiou\"\n0",
"\"ieaouqqieaouqq\"\n1"
] | [
"We can use sliding window and binary search.",
"For each index r, find the maximum l such that both conditions are satisfied using binary search."
] | {
"canonical_parameter_names": [
"word",
"k"
],
"leetcode_dataset_entry_point": "Solution().countOfSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:27",
"tests_total": 68... | typescript | {
"raw_signature": "function countOfSubstrings(word: string, k: number): number {",
"container": null,
"callable": "countOfSubstrings",
"parameters": [
{
"name": "word",
"type": "string"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_sou... |
3,307 | find-the-k-th-character-in-string-game-ii | Hard | Alice and Bob are playing a game. Initially, Alice has a string word = "a".
You are given a positive integer k. You are also given an integer array operations, where operations[i] represents the type of the i^th operation.
Now Bob will ask Alice to perform all operations in sequence:
- If operations[i] == 0, append ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(k = 20,operations = [1, 0, 1, 0, 1]) == \"c\"\n assert candidate(k = 15,operations = [1, 0, 1, 0]) == \"b\"\n assert candidate(k = 10,operations = [0, 1, 0, 1]) == \"b\"\n assert candidate(k = 3,operations = [0, 1]) == \"b\"\n ... | [
"5\n[0,0,0]",
"10\n[0,1,0,1]"
] | [
"Try to replay the operations k^th character was part of.",
"The k^th character is only affected if it is present in the first half of the string."
] | {
"canonical_parameter_names": [
"k",
"operations"
],
"leetcode_dataset_entry_point": "Solution().kthCharacter",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:29",
"tests_total": 4... | typescript | {
"raw_signature": "function kthCharacter(k: number, operations: number[]): string {",
"container": null,
"callable": "kthCharacter",
"parameters": [
{
"name": "k",
"type": "number"
},
{
"name": "operations",
"type": "number[]"
}
],
"return_type": "string",
"signatu... |
3,309 | maximum-possible-number-by-binary-concatenation | Medium | You are given an array of integers nums of size 3.
Return the maximum possible number whose binary representation can be formed by concatenating the binary representation of all elements in nums in some order.
Note that the binary representation of any number does not contain leading zeros.
Example 1:
Input: nums =... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [64, 1, 127]) == 32704\n assert candidate(nums = [7, 5, 3]) == 253\n assert candidate(nums = [127, 127, 127]) == 2097151\n assert candidate(nums = [32, 16, 8]) == 17440\n assert candidate(nums = [1, 5, 7]) == 125\n ... | [
"[1,2,3]",
"[2,8,16]"
] | [
"How many possible concatenation orders are there?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxGoodNumber",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:31",
"tests_total": 91,
"tests_dr... | typescript | {
"raw_signature": "function maxGoodNumber(nums: number[]): number {",
"container": null,
"callable": "maxGoodNumber",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets... |
3,310 | remove-methods-from-project | Medium | You are maintaining a project that has n methods numbered from 0 to n - 1.
You are given two integers n and k, and a 2D integer array invocations, where invocations[i] = [a_i, b_i] indicates that method a_i invokes method b_i.
There is a known bug in method k. Method k, along with any method invoked by it, either dir... | {
"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 ... | [
"4\n1\n[[1,2],[0,1],[3,2]]",
"5\n0\n[[1,2],[0,2],[0,1],[3,4]]",
"3\n2\n[[1,2],[0,1],[2,0]]"
] | [
"Use DFS from node k.",
"Mark all the nodes visited from node k, and then check if they can be visited from the other nodes."
] | {
"canonical_parameter_names": [
"n",
"k",
"invocations"
],
"leetcode_dataset_entry_point": "Solution().remainingMethods",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:34",
"t... | typescript | {
"raw_signature": "function remainingMethods(n: number, k: number, invocations: number[][]): number[] {",
"container": null,
"callable": "remainingMethods",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "k",
"type": "number"
},
{
"name": "invocat... |
3,312 | sorted-gcd-pair-queries | Hard | You are given an integer array nums of length n and an integer array queries.
Let gcdPairs denote an array obtained by calculating the GCD of all possible pairs (nums[i], nums[j]), where 0 <= i < j < n, and then sorting these values in ascending order.
For each query queries[i], you need to find the element at index ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 4, 2, 1],queries = [5, 3, 1, 0]) == [4, 2, 1, 1]\n assert candidate(nums = [5, 10, 15],queries = [0, 1, 2]) == [5, 5, 5]\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1, 1, 1, 1,... | [
"[2,3,4]\n[0,2,2]",
"[4,4,2,1]\n[5,3,1,0]",
"[2,2]\n[0,0]"
] | [
"Try counting the number of pairs that have a GCD of g",
"Use inclusion-exclusion."
] | {
"canonical_parameter_names": [
"nums",
"queries"
],
"leetcode_dataset_entry_point": "Solution().gcdValues",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:39",
"tests_total": 85,
... | typescript | {
"raw_signature": "function gcdValues(nums: number[], queries: number[]): number[] {",
"container": null,
"callable": "gcdValues",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "queries",
"type": "number[]"
}
],
"return_type": "number[]",
"signa... |
3,314 | construct-the-minimum-bitwise-array-i | Easy | You are given an array nums consisting of n prime integers.
You need to construct an array ans of length n, such that, for each index i, the bitwise OR of ans[i] and ans[i] + 1 is equal to nums[i], i.e. ans[i] OR (ans[i] + 1) == nums[i].
Additionally, you must minimize each value of ans[i] in the resulting array.
If... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [3, 7, 11, 13]) == [1, 3, 9, 12]\n assert candidate(nums = [41, 43, 47, 53]) == [40, 41, 39, 52]\n assert candidate(nums = [2, 3, 5, 7]) == [-1, 1, 4, 3]\n assert candidate(nums = [11, 13, 31]) == [9, 12, 15]\n assert ... | [
"[2,3,5,7]",
"[11,13,31]"
] | [
"The constraints are small, allowing you to iterate over all potential values for ans[i] directly."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minBitwiseArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:44",
"tests_total": 124,
"tests... | typescript | {
"raw_signature": "function minBitwiseArray(nums: number[]): number[] {",
"container": null,
"callable": "minBitwiseArray",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number[]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/code... |
3,315 | construct-the-minimum-bitwise-array-ii | Medium | You are given an array nums consisting of n prime integers.
You need to construct an array ans of length n, such that, for each index i, the bitwise OR of ans[i] and ans[i] + 1 is equal to nums[i], i.e. ans[i] OR (ans[i] + 1) == nums[i].
Additionally, you must minimize each value of ans[i] in the resulting array.
If... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [41, 43, 47, 53]) == [40, 41, 39, 52]\n assert candidate(nums = [29, 37, 41, 43]) == [28, 36, 40, 41]\n assert candidate(nums = [2, 3, 5, 7]) == [-1, 1, 4, 3]\n assert candidate(nums = [11, 13, 31]) == [9, 12, 15]\n as... | [
"[2,3,5,7]",
"[11,13,31]"
] | [
"Consider the binary representation of nums[i].",
"Answer is -1 for even nums[i].",
"Try unsetting a single bit from nums[i]."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minBitwiseArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:47",
"tests_total": 226,
"tests... | typescript | {
"raw_signature": "function minBitwiseArray(nums: number[]): number[] {",
"container": null,
"callable": "minBitwiseArray",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number[]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/code... |
3,316 | find-maximum-removals-from-source-string | Medium | You are given a string source of size n, a string pattern that is a subsequence of source, and a sorted integer array targetIndices that contains distinct numbers in the range [0, n - 1].
We define an operation as removing a character at an index idx from source such that:
- idx is an element of targetIndices.
- patt... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(source = \"abbaa\",pattern = \"aba\",targetIndices = [0, 1, 2]) == 1\n assert candidate(source = \"abracadabra\",pattern = \"abc\",targetIndices = [0, 1, 5, 7, 10]) == 3\n assert candidate(source = \"bcda\",pattern = \"d\",targetIn... | [
"\"abbaa\"\n\"aba\"\n[0,1,2]",
"\"bcda\"\n\"d\"\n[0,3]",
"\"dda\"\n\"dda\"\n[0,1,2]",
"\"yeyeykyded\"\n\"yeyyd\"\n[0,2,3,4]"
] | [
"Use dynamic programming.",
"At each index in targetIndices, make the choice to remove or not remove the character."
] | {
"canonical_parameter_names": [
"source",
"pattern",
"targetIndices"
],
"leetcode_dataset_entry_point": "Solution().maxRemovals",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:4... | typescript | {
"raw_signature": "function maxRemovals(source: string, pattern: string, targetIndices: number[]): number {",
"container": null,
"callable": "maxRemovals",
"parameters": [
{
"name": "source",
"type": "string"
},
{
"name": "pattern",
"type": "string"
},
{
"name"... |
3,317 | find-the-number-of-possible-ways-for-an-event | Hard | You are given three integers n, x, and y.
An event is being held for n performers. When a performer arrives, they are assigned to one of the x stages. All performers assigned to the same stage will perform together as a band, though some stages might remain empty.
After all performances are completed, the jury will a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 500,x = 250,y = 250) == 604049962\n assert candidate(n = 6,x = 6,y = 6) == 150265836\n assert candidate(n = 4,x = 2,y = 4) == 232\n assert candidate(n = 500,x = 5,y = 20) == 955685646\n assert candidate(n = 100,x = 10,y =... | [
"1\n2\n3",
"5\n2\n1",
"3\n3\n4"
] | [
"Fix the number of stages.",
"Assign the Performers to the stages.",
"Use inclusion-exclusion to ensure that no stage has 0 performers."
] | {
"canonical_parameter_names": [
"n",
"x",
"y"
],
"leetcode_dataset_entry_point": "Solution().numberOfWays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:51",
"tests_total": 9... | typescript | {
"raw_signature": "function numberOfWays(n: number, x: number, y: number): number {",
"container": null,
"callable": "numberOfWays",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "x",
"type": "number"
},
{
"name": "y",
"type": "number"
... |
3,318 | find-x-sum-of-all-k-long-subarrays-i | Easy | You are given an array nums of n integers and two integers k and x.
The x-sum of an array is calculated by the following procedure:
- Count the occurrences of all elements in the array.
- Keep only the occurrences of the top x most frequent elements. If two elements have the same number of occurrences, the element wi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4,x = 4) == [10, 14, 18, 22, 26, 30, 34]\n assert candidate(nums = [10, 20, 30, 40, 50],k = 1,x = 1) == [10, 20, 30, 40, 50]\n assert candidate(nums = [1, 1, 2, 2, 3, 4, 2, 3],k = 6,x = 2)... | [
"[1,1,2,2,3,4,2,3]\n6\n2",
"[3,8,7,8,7,5]\n2\n2"
] | [
"Implement the x-sum function. Then, run x-sum on every subarray of nums of size k."
] | {
"canonical_parameter_names": [
"nums",
"k",
"x"
],
"leetcode_dataset_entry_point": "Solution().findXSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:53",
"tests_total": 19... | typescript | {
"raw_signature": "function findXSum(nums: number[], k: number, x: number): number[] {",
"container": null,
"callable": "findXSum",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
},
{
"name": "x",
"type": "number"
... |
3,320 | count-the-number-of-winning-sequences | Hard | Alice and Bob are playing a fantasy battle game consisting of n rounds where they summon one of three magical creatures each round: a Fire Dragon, a Water Serpent, or an Earth Golem. In each round, players simultaneously summon their creature and are awarded points as follows:
- If one player summons a Fire Dragon and... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"WFWFWFWFWFWFWFWFWFWF\") == 730500\n assert candidate(s = \"WFW\") == 6\n assert candidate(s = \"FWEFWEFW\") == 157\n assert candidate(s = \"FWFWFWFWFWFWFWFWFWFW\") == 730500\n assert candidate(s = \"EWE\") == 6\n ass... | [
"\"FFF\"",
"\"FWEFW\""
] | [
"Use dynamic programming.",
"For 0 < i < n - 1, -n < j < n, and k in {’F’, ‘W’, ‘E’}, let dp[i][j][k] be the number of sequences consisting of the first i moves such that the difference between bob’s points and alice’s point is equal to j and the i^th move that Bob played is k.",
"The answer is the sum of dp[n ... | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().countWinningSequences",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:20:58",
"tests_total": 30,
"tes... | typescript | {
"raw_signature": "function countWinningSequences(s: string): number {",
"container": null,
"callable": "countWinningSequences",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSn... |
3,321 | find-x-sum-of-all-k-long-subarrays-ii | Hard | You are given an array nums of n integers and two integers k and x.
The x-sum of an array is calculated by the following procedure:
- Count the occurrences of all elements in the array.
- Keep only the occurrences of the top x most frequent elements. If two elements have the same number of occurrences, the element wi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 4,x = 2) == [70, 90, 110, 130, 150, 170, 190]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5],k = 3,x = 1) == [15, 15, 15, 15, 15]\n assert candidate(nums = [10, 20, 20, 10, 30, ... | [
"[1,1,2,2,3,4,2,3]\n6\n2",
"[3,8,7,8,7,5]\n2\n2"
] | [
"Use sliding window.",
"Use two sets ordered by frequency. One of the sets will only contain the top x frequent elements, and the second will contain all other elements.",
"Update the two sets whenever you slide the window, and maintain a sum of the elements in the set with x elements"
] | {
"canonical_parameter_names": [
"nums",
"k",
"x"
],
"leetcode_dataset_entry_point": "Solution().findXSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:01",
"tests_total": 19... | typescript | {
"raw_signature": "function findXSum(nums: number[], k: number, x: number): number[] {",
"container": null,
"callable": "findXSum",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
},
{
"name": "x",
"type": "number"
... |
3,324 | find-the-sequence-of-strings-appeared-on-the-screen | Medium | You are given a string target.
Alice is going to type target on her computer using a special keyboard that has only two keys:
- Key 1 appends the character "a" to the string on the screen.
- Key 2 changes the last character of the string on the screen to its next character in the English alphabet. For example, "c" ch... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(target = \"abcdefg\") == ['a', 'aa', 'ab', 'aba', 'abb', 'abc', 'abca', 'abcb', 'abcc', 'abcd', 'abcda', 'abcdb', 'abcdc', 'abcdd', 'abcde', 'abcdea', 'abcdeb', 'abcdec', 'abcded', 'abcdee', 'abcdef', 'abcdefa', 'abcdefb', 'abcdefc', 'ab... | [
"\"abc\"",
"\"he\""
] | [
"Append the character 'a' using key 1.",
"Convert it to the required character using key 2."
] | {
"canonical_parameter_names": [
"target"
],
"leetcode_dataset_entry_point": "Solution().stringSequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:07",
"tests_total": 41,
"tests... | typescript | {
"raw_signature": "function stringSequence(target: string): string[] {",
"container": null,
"callable": "stringSequence",
"parameters": [
{
"name": "target",
"type": "string"
}
],
"return_type": "string[]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSn... |
3,325 | count-substrings-with-k-frequency-characters-i | Medium | Given a string s and an integer k, return the total number of substrings of s where at least one character appears at least k times.
Example 1:
Input: s = "abacb", k = 2
Output: 4
Explanation:
The valid substrings are:
- "aba" (character 'a' appears 2 times).
- "abac" (character 'a' appears 2 times).
- "abacb" (chara... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"pqr\",k = 1) == 6\n assert candidate(s = \"aabbccc\",k = 3) == 5\n assert candidate(s = \"aaabb\",k = 3) == 3\n assert candidate(s = \"zzzzzz\",k = 4) == 6\n assert candidate(s = \"abcde\",k = 1) == 15\n assert candi... | [
"\"abacb\"\n2",
"\"abcde\"\n1"
] | [
"Fix the left index of the substring.",
"For the fixed left index, find the first right index for which substring s[left..right] satisfies the condition.",
"Every substring that starts at left and ends after right satisfies the condition."
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().numberOfSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:09",
"tests_total": 102,... | typescript | {
"raw_signature": "function numberOfSubstrings(s: string, k: number): number {",
"container": null,
"callable": "numberOfSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_source"... |
3,326 | minimum-division-operations-to-make-array-non-decreasing | Medium | You are given an integer array nums.
Any positive divisor of a natural number x that is strictly less than x is called a proper divisor of x. For example, 2 is a proper divisor of 4, while 6 is not a proper divisor of 6.
You are allowed to perform an operation any number of times on nums, where in each operation you ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 3, 4, 6, 9]) == 0\n assert candidate(nums = [9, 3, 1]) == -1\n assert candidate(nums = [1, 1, 1, 1]) == 0\n assert candidate(nums = [10, 5, 3]) == -1\n assert candidate(nums = [3, 9, 27]) == 0\n assert candidate... | [
"[25,7]",
"[7,7,6]",
"[1,1,1,1]"
] | [
"Iterate backward from the last index.",
"Each number can be divided by its largest proper divisor to yield its smallest prime divisor."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:16",
"tests_total": 116,
"tests_d... | typescript | {
"raw_signature": "function minOperations(nums: number[]): number {",
"container": null,
"callable": "minOperations",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets... |
3,327 | check-if-dfs-strings-are-palindromes | Hard | You are given a tree rooted at node 0, consisting of n nodes numbered from 0 to n - 1. The tree is represented by an array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.
You are also given a string s of length n, where s[i] is the character assigned to node i.
Co... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(parent = [-1, 0, 1, 2, 2],s = \"abcba\") == [False, False, False, True, True]\n assert candidate(parent = [-1, 0, 0, 1, 2],s = \"aaaab\") == [True, True, False, True, True]\n assert candidate(parent = [-1, 0, 0, 0, 0, 0, 0],s = \"a... | [
"[-1,0,0,1,1,2]\n\"aababa\"",
"[-1,0,0,0,0]\n\"aabcb\""
] | [
"Perform the dfs described from the root of tree, and store the order in which nodes are visited into an array.",
"For any node in the tree, the nodes in its subtree will form a contiguous subarray within the DFS traversal array.",
"Use Manacher’s algorithm to compute the answer for each node in constant time."... | {
"canonical_parameter_names": [
"parent",
"s"
],
"leetcode_dataset_entry_point": "Solution().findAnswer",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:19",
"tests_total": 39,
"... | typescript | {
"raw_signature": "function findAnswer(parent: number[], s: string): boolean[] {",
"container": null,
"callable": "findAnswer",
"parameters": [
{
"name": "parent",
"type": "number[]"
},
{
"name": "s",
"type": "string"
}
],
"return_type": "boolean[]",
"signature_sou... |
3,330 | find-the-original-typed-string-i | Easy | Alice is attempting to type a specific string on her computer. However, she tends to be clumsy and may press a key for too long, resulting in a character being typed multiple times.
Although Alice tried to focus on her typing, she is aware that she may still have done this at most once.
You are given a string word, w... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word = \"aaabbbccc\") == 7\n assert candidate(word = \"abbcccc\") == 5\n assert candidate(word = \"mississippi\") == 4\n assert candidate(word = \"zzzzzzz\") == 7\n assert candidate(word = \"zzzzzzzzzz\") == 10\n assert ca... | [
"\"abbcccc\"",
"\"abcd\"",
"\"aaaa\""
] | [
"Any group of consecutive characters might have been the mistake."
] | {
"canonical_parameter_names": [
"word"
],
"leetcode_dataset_entry_point": "Solution().possibleStringCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:24",
"tests_total": 54,
"te... | typescript | {
"raw_signature": "function possibleStringCount(word: string): number {",
"container": null,
"callable": "possibleStringCount",
"parameters": [
{
"name": "word",
"type": "string"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/code... |
3,331 | find-subtree-sizes-after-changes | Medium | You are given a tree rooted at node 0 that consists of n nodes numbered from 0 to n - 1. The tree is represented by an array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.
You are also given a string s of length n, where s[i] is the character assigned to node i.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(parent = [-1, 0, 0, 0, 0],s = \"abcde\") == [5, 1, 1, 1, 1]\n assert candidate(parent = [-1, 0, 4, 0, 1],s = \"abbba\") == [5, 2, 1, 1, 1]\n assert candidate(parent = [-1, 0, 1, 2, 3, 0, 2],s = \"abacaba\") == [7, 1, 4, 1, 1, 1, 1]... | [
"[-1,0,0,1,1,1]\n\"abaabc\"",
"[-1,0,4,0,1]\n\"abbba\""
] | [
"Perform a depth-first search on the tree, starting from the root.",
"During the DFS, keep track of the most recent node where each character from 'a' to 'z' has been seen."
] | {
"canonical_parameter_names": [
"parent",
"s"
],
"leetcode_dataset_entry_point": "Solution().findSubtreeSizes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:26",
"tests_total": 6... | typescript | {
"raw_signature": "function findSubtreeSizes(parent: number[], s: string): number[] {",
"container": null,
"callable": "findSubtreeSizes",
"parameters": [
{
"name": "parent",
"type": "number[]"
},
{
"name": "s",
"type": "string"
}
],
"return_type": "number[]",
"sig... |
3,332 | maximum-points-tourist-can-earn | Medium | You are given two integers, n and k, along with two 2D integer arrays, stayScore and travelScore.
A tourist is visiting a country with n cities, where each city is directly connected to every other city. The tourist's journey consists of exactly k 0-indexed days, and they can choose any city as their starting point.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,k = 5,stayScore = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8], [5, 6, 7, 8, 9]],travelScore = [[0, 1, 2, 3, 4], [1, 0, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 0, 1], [4, 3, 2, 1, 0]]) == 35\n assert candidat... | [
"2\n1\n[[2,3]]\n[[0,2],[1,0]]",
"3\n2\n[[3,4,2],[2,1,2]]\n[[0,2,1],[2,0,4],[3,2,0]]"
] | [
"Use DP.",
"dp[i][j] is the maximum score that you can achieve in your last i actions by starting from city j."
] | {
"canonical_parameter_names": [
"n",
"k",
"stayScore",
"travelScore"
],
"leetcode_dataset_entry_point": "Solution().maxScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:... | typescript | {
"raw_signature": "function maxScore(n: number, k: number, stayScore: number[][], travelScore: number[][]): number {",
"container": null,
"callable": "maxScore",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "k",
"type": "number"
},
{
"name": "st... |
3,333 | find-the-original-typed-string-ii | Hard | Alice is attempting to type a specific string on her computer. However, she tends to be clumsy and may press a key for too long, resulting in a character being typed multiple times.
You are given a string word, which represents the final output displayed on Alice's screen. You are also given a positive integer k.
Ret... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word = \"aaaaaa\",k = 1) == 6\n assert candidate(word = \"aaabbcccddddeeeeeffffffggggghhhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooo\",k = 100) == 0\n assert candidate(word = \"aabbccc\",k = 5) == 8\n assert candidate(word = \"aaaabb... | [
"\"aabbccdd\"\n7",
"\"aabbccdd\"\n8",
"\"aaabbb\"\n3"
] | [
"Instead of solving for at least k, can we solve for at most k - 1 length?"
] | {
"canonical_parameter_names": [
"word",
"k"
],
"leetcode_dataset_entry_point": "Solution().possibleStringCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:31",
"tests_total": ... | typescript | {
"raw_signature": "function possibleStringCount(word: string, k: number): number {",
"container": null,
"callable": "possibleStringCount",
"parameters": [
{
"name": "word",
"type": "string"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature... |
3,334 | find-the-maximum-factor-score-of-array | Medium | You are given an integer array nums.
The factor score of an array is defined as the product of the LCM and GCD of all elements of that array.
Return the maximum factor score of nums after removing at most one element from it.
Note that both the LCM and GCD of a single number are the number itself, and the factor sco... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 20, 30]) == 600\n assert candidate(nums = [2, 3, 5, 7, 11, 13]) == 30030\n assert candidate(nums = [1, 1, 1, 1]) == 1\n assert candidate(nums = [2, 3, 5, 7, 11]) == 2310\n assert candidate(nums = [12, 15, 18, 21])... | [
"[2,4,8,16]",
"[1,2,3,4,5]",
"[3]"
] | [
"Use brute force approach with two loops.",
"Optimize using prefix and suffix arrays."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:34",
"tests_total": 120,
"tests_droppe... | typescript | {
"raw_signature": "function maxScore(nums: number[]): number {",
"container": null,
"callable": "maxScore",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,335 | total-characters-in-string-after-transformations-i | Medium | You are given a string s and an integer t, representing the number of transformations to perform. In one transformation, every character in s is replaced according to the following rules:
- If the character is 'z', replace it with the string "ab".
- Otherwise, replace it with the next character in the alphabet. For ex... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcd\",t = 5) == 4\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = 5) == 31\n assert candidate(s = \"azbk\",t = 1) == 5\n assert candidate(s = \"abcdef\",t = 5) == 6\n assert candidate(s = \"abcdefg\",t = 5) =... | [
"\"abcyy\"\n2",
"\"azbk\"\n1"
] | [
"Maintain the frequency of each character."
] | {
"canonical_parameter_names": [
"s",
"t"
],
"leetcode_dataset_entry_point": "Solution().lengthAfterTransformations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:36",
"tests_tota... | typescript | {
"raw_signature": "function lengthAfterTransformations(s: string, t: number): number {",
"container": null,
"callable": "lengthAfterTransformations",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "t",
"type": "number"
}
],
"return_type": "number",
"s... |
3,336 | find-the-number-of-subsequences-with-equal-gcd | Hard | You are given an integer array nums.
Your task is to find the number of pairs of non-empty subsequences (seq1, seq2) of nums that satisfy the following conditions:
- The subsequences seq1 and seq2 are disjoint, meaning no index of nums is common between them.
- The GCD of the elements of seq1 is equal to the GCD of t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 20, 30]) == 2\n assert candidate(nums = [2, 3, 5, 7, 11, 13]) == 260\n assert candidate(nums = [1, 1, 1, 1]) == 50\n assert candidate(nums = [2, 3, 5, 7, 11]) == 50\n assert candidate(nums = [2, 4, 6, 8, 10]) == 6... | [
"[1,2,3,4]",
"[10,20,30]",
"[1,1,1,1]"
] | [
"Use dynamic programming to store number of subsequences up till index i with GCD g1 and g2."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().subsequencePairCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:39",
"tests_total": 106,
"... | typescript | {
"raw_signature": "function subsequencePairCount(nums: number[]): number {",
"container": null,
"callable": "subsequencePairCount",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcod... |
3,337 | total-characters-in-string-after-transformations-ii | Hard | You are given a string s consisting of lowercase English letters, an integer t representing the number of transformations to perform, and an array nums of size 26. In one transformation, every character in s is replaced according to the following rules:
- Replace s[i] with the next nums[s[i] - 'a'] consecutive charact... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"xyz\",t = 3,nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3]) == 11\n assert candidate(s = \"a\",t = 1000000000,nums = [25, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1... | [
"\"abcyy\"\n2\n[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2]",
"\"azbk\"\n1\n[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]"
] | [
"Model the problem as a matrix multiplication problem.",
"Use exponentiation to quickly multiply matrices."
] | {
"canonical_parameter_names": [
"s",
"t",
"nums"
],
"leetcode_dataset_entry_point": "Solution().lengthAfterTransformations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:41",
... | typescript | {
"raw_signature": "function lengthAfterTransformations(s: string, t: number, nums: number[]): number {",
"container": null,
"callable": "lengthAfterTransformations",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "t",
"type": "number"
},
{
"name":... |
3,340 | check-balanced-string | Easy | You are given a string num consisting of only digits. A string of digits is called balanced if the sum of the digits at even indices is equal to the sum of digits at odd indices.
Return true if num is balanced, otherwise return false.
Example 1:
Input: num = "1234"
Output: false
Explanation:
- The sum of digits at e... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = \"1111\") == True\n assert candidate(num = \"4321\") == False\n assert candidate(num = \"654321\") == False\n assert candidate(num = \"55555\") == False\n assert candidate(num = \"9876543210\") == False\n assert cand... | [
"\"1234\"",
"\"24123\""
] | [] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().isBalanced",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:45",
"tests_total": 103,
"tests_dropp... | typescript | {
"raw_signature": "function isBalanced(num: string): boolean {",
"container": null,
"callable": "isBalanced",
"parameters": [
{
"name": "num",
"type": "string"
}
],
"return_type": "boolean",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
3,341 | find-minimum-time-to-reach-last-room-i | Medium | There is a dungeon with n x m rooms arranged as a grid.
You are given a 2D array moveTime of size n x m, where moveTime[i][j] represents the minimum time in seconds after which the room opens and can be moved to. You start from the room (0, 0) at time t = 0 and can move to an adjacent room. Moving between adjacent roo... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(moveTime = [[0, 2, 3], [3, 1, 1], [2, 1, 3]]) == 6\n assert candidate(moveTime = [[0, 1], [1, 2]]) == 3\n assert candidate(moveTime = [[0, 1000000000], [1000000000, 0]]) == 1000000002\n assert candidate(moveTime = [[0, 2, 3], [1... | [
"[[0,4],[4,4]]",
"[[0,0,0],[0,0,0]]",
"[[0,1],[1,2]]"
] | [
"Use shortest path algorithms."
] | {
"canonical_parameter_names": [
"moveTime"
],
"leetcode_dataset_entry_point": "Solution().minTimeToReach",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:47",
"tests_total": 87,
"tes... | typescript | {
"raw_signature": "function minTimeToReach(moveTime: number[][]): number {",
"container": null,
"callable": "minTimeToReach",
"parameters": [
{
"name": "moveTime",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcod... |
3,342 | find-minimum-time-to-reach-last-room-ii | Medium | There is a dungeon with n x m rooms arranged as a grid.
You are given a 2D array moveTime of size n x m, where moveTime[i][j] represents the minimum time in seconds when you can start moving to that room. You start from the room (0, 0) at time t = 0 and can move to an adjacent room. Moving between adjacent rooms takes... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(moveTime = [[0, 0, 0, 0], [0, 0, 0, 0]]) == 6\n assert candidate(moveTime = [[0, 1], [1, 2]]) == 4\n assert candidate(moveTime = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 6\n assert candidate(moveTime = [[0, 3, 2], [4, 1, 5], [2, 6,... | [
"[[0,4],[4,4]]",
"[[0,0,0,0],[0,0,0,0]]",
"[[0,1],[1,2]]"
] | [
"Use shortest path algorithms with a state for the last move being odd or even indexed."
] | {
"canonical_parameter_names": [
"moveTime"
],
"leetcode_dataset_entry_point": "Solution().minTimeToReach",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:21:50",
"tests_total": 81,
"tes... | typescript | {
"raw_signature": "function minTimeToReach(moveTime: number[][]): number {",
"container": null,
"callable": "minTimeToReach",
"parameters": [
{
"name": "moveTime",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcod... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.