question_id
int64
1
3.24k
task_id
stringlengths
3
77
difficulty
stringclasses
3 values
problem_description
stringlengths
193
3.69k
canonical_tests
dict
public_tests
listlengths
1
5
hints
listlengths
0
8
metadata
dict
language
stringclasses
9 values
interface
dict
2,352
equal-row-and-column-pairs
Medium
Given a 0-indexed n x n integer matrix grid, return the number of pairs (r_i, c_j) such that row r_i and column c_j are equal. A row and column pair is considered equal if they contain the same elements in the same order (i.e., an equal array). Example 1: Input: grid = [[3,2,1],[1,7,6],[2,7,7]] Output: 1 Explanation...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 9\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 9\n assert candidate(grid = [[5]]) == 1\n assert candidate(grid = [[3, 2, 1], [1, 7, 6], [2, 7, 7]]) == 1\n assert...
[ "[[3,2,1],[1,7,6],[2,7,7]]", "[[3,1,2,2],[1,4,4,5],[2,4,2,2],[2,4,2,2]]" ]
[ "We can use nested loops to compare every row against every column.", "Another loop is necessary to compare the row and column element by element.", "It is also possible to hash the arrays and compare the hashed values instead." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().equalPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:43", "tests_total": 64, "tests_dropp...
cpp
{ "raw_signature": "int equalPairs(vector<vector<int>>& grid) {", "container": "Solution", "callable": "equalPairs", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeS...
2,354
number-of-excellent-pairs
Hard
You are given a 0-indexed positive integer array nums and a positive integer k. A pair of numbers (num1, num2) is called excellent if the following conditions are satisfied: - Both the numbers num1 and num2 exist in the array nums. - The sum of the number of set bits in num1 OR num2 and num1 AND num2 is greater than ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [2, 4, 8, 16],k = 3) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 4) == 93\n assert candidate(nums = [1, 2, 4, 8, 16, 32],k = 3) == 0\n asse...
[ "[1,2,3,1]\n3", "[5,1,1]\n10" ]
[ "Can you find a different way to describe the second condition?", "The sum of the number of set bits in (num1 OR num2) and (num1 AND num2) is equal to the sum of the number of set bits in num1 and num2." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().countExcellentPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:45", "tests_total": ...
cpp
{ "raw_signature": "long long countExcellentPairs(vector<int>& nums, int k) {", "container": "Solution", "callable": "countExcellentPairs", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "long long", "sig...
2,357
make-array-zero-by-subtracting-equal-amounts
Easy
You are given a non-negative integer array nums. In one operation, you must: - Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums. - Subtract x from every positive element in nums. Return the minimum number of operations to make every element in nums equal to 0. Ex...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [1, 5, 0, 3, 5]) == 3\n assert candidate(nums = [0, 1, 0, 1, 0]) == 1\n assert candidate(nums = [1]) == 1\n assert c...
[ "[1,5,0,3,5]", "[0]" ]
[ "It is always best to set x as the smallest non-zero element in nums.", "Elements with the same value will always take the same number of operations to become 0. Contrarily, elements with different values will always take a different number of operations to become 0.", "The answer is the number of unique non-ze...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:50", "tests_total": 116, "tes...
cpp
{ "raw_signature": "int minimumOperations(vector<int>& nums) {", "container": "Solution", "callable": "minimumOperations", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
2,358
maximum-number-of-groups-entering-a-competition
Medium
You are given a positive integer array grades which represents the grades of students in a university. You would like to enter all these students into a competition in ordered non-empty groups, such that the ordering meets the following conditions: - The sum of the grades of students in the i^th group is less than the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grades = [10, 6, 12, 7, 3, 5]) == 3\n assert candidate(grades = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 4\n assert candidate(grades = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 4\n assert candidate(grades = [1]) == 1\n assert c...
[ "[10,6,12,7,3,5]", "[8,8]" ]
[ "Would it be easier to place the students into valid groups after sorting them based on their grades in ascending order?", "Notice that, after sorting, we can separate them into groups of sizes 1, 2, 3, and so on.", "If the last group is invalid, we can merge it with the previous group.", "This creates the ma...
{ "canonical_parameter_names": [ "grades" ], "leetcode_dataset_entry_point": "Solution().maximumGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:52", "tests_total": 84, "tests_...
cpp
{ "raw_signature": "int maximumGroups(vector<int>& grades) {", "container": "Solution", "callable": "maximumGroups", "parameters": [ { "name": "grades", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
2,359
find-closest-node-to-given-two-nodes
Medium
You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge. The graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from i, then edges[i] == -1. You...
{ "language": "python", "source": "def check(candidate):\n assert candidate(edges = [5, -1, 3, 4, 5, 6, -1, -1, 4, 3],node1 = 0,node2 = 0) == 0\n assert candidate(edges = [4, 3, 0, 5, 3, -1],node1 = 4,node2 = 0) == 4\n assert candidate(edges = [1, 2, 0, -1],node1 = 0,node2 = 2) == 0\n assert candidate(e...
[ "[2,2,3,-1]\n0\n1", "[1,2,-1]\n0\n2" ]
[ "How can you find the shortest distance from one node to all nodes in the graph?", "Use BFS to find the shortest distance from both node1 and node2 to all nodes in the graph. Then iterate over all nodes, and find the node with the minimum max distance." ]
{ "canonical_parameter_names": [ "edges", "node1", "node2" ], "leetcode_dataset_entry_point": "Solution().closestMeetingNode", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:55", ...
cpp
{ "raw_signature": "int closestMeetingNode(vector<int>& edges, int node1, int node2) {", "container": "Solution", "callable": "closestMeetingNode", "parameters": [ { "name": "edges", "type": "vector<int>&" }, { "name": "node1", "type": "int" }, { "name": "node2"...
2,360
longest-cycle-in-a-graph
Hard
You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge. The graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from node i, then edges[i] == -1....
{ "language": "python", "source": "def check(candidate):\n assert candidate(edges = [-1, 2, 0, 1, -1]) == -1\n assert candidate(edges = [1, 2, 0, 4, -1]) == 3\n assert candidate(edges = [5, 4, 5, 4, 5, 4]) == 2\n assert candidate(edges = [1, 0, -1, -1]) == 2\n assert candidate(edges = [1, 0, 0, 0, 1]...
[ "[3,3,4,2,3]", "[2,-1,3,1]" ]
[ "How many cycles can each node at most be part of?", "Each node can be part of at most one cycle. Start from each node and find the cycle that it is part of if there is any. Save the already visited nodes to not repeat visiting the same cycle multiple times." ]
{ "canonical_parameter_names": [ "edges" ], "leetcode_dataset_entry_point": "Solution().longestCycle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:58", "tests_total": 109, "tests_d...
cpp
{ "raw_signature": "int longestCycle(vector<int>& edges) {", "container": "Solution", "callable": "longestCycle", "parameters": [ { "name": "edges", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,363
merge-similar-items
Easy
You are given two 2D integer arrays, items1 and items2, representing two sets of items. Each array items has the following properties: - items[i] = [value_i, weight_i] where value_i represents the value and weight_i represents the weight of the i^th item. - The value of each item in items is unique. Return a 2D integ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(items1 = [[1, 3], [2, 2]],items2 = [[7, 1], [2, 2], [1, 4]]) == [(1, 7), (2, 4), (7, 1)]\n assert candidate(items1 = [[1, 1000]],items2 = [[2, 1000]]) == [(1, 1000), (2, 1000)]\n assert candidate(items1 = [[1, 1], [4, 5], [3, 8]],i...
[ "[[1,1],[4,5],[3,8]]\n[[3,1],[1,5]]", "[[1,1],[3,2],[2,3]]\n[[2,1],[3,2],[1,3]]", "[[1,3],[2,2]]\n[[7,1],[2,2],[1,4]]" ]
[ "Map the weights using the corresponding values as keys.", "Make sure your output is sorted in ascending order by value." ]
{ "canonical_parameter_names": [ "items1", "items2" ], "leetcode_dataset_entry_point": "Solution().mergeSimilarItems", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:03", "tests_tot...
cpp
{ "raw_signature": "vector<vector<int>> mergeSimilarItems(vector<vector<int>>& items1, vector<vector<int>>& items2) {", "container": "Solution", "callable": "mergeSimilarItems", "parameters": [ { "name": "items1", "type": "vector<vector<int>>&" }, { "name": "items2", "type": ...
2,364
count-number-of-bad-pairs
Medium
You are given a 0-indexed integer array nums. A pair of indices (i, j) is a bad pair if i < j and j - i != nums[j] - nums[i]. Return the total number of bad pairs in nums. Example 1: Input: nums = [4,1,3,3] Output: 5 Explanation: The pair (0, 1) is a bad pair since 1 - 0 != 1 - 4. The pair (0, 2) is a bad pair since...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 15\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4,...
[ "[4,1,3,3]", "[1,2,3,4,5]" ]
[ "Would it be easier to count the number of pairs that are not bad pairs?", "Notice that (j - i != nums[j] - nums[i]) is the same as (nums[i] - i != nums[j] - j).", "Keep a counter of nums[i] - i. To be efficient, use a HashMap." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countBadPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:05", "tests_total": 132, "tests_d...
cpp
{ "raw_signature": "long long countBadPairs(vector<int>& nums) {", "container": "Solution", "callable": "countBadPairs", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...
2,365
task-scheduler-ii
Medium
You are given a 0-indexed array of positive integers tasks, representing tasks that need to be completed in order, where tasks[i] represents the type of the i^th task. You are also given a positive integer space, which represents the minimum number of days that must pass after the completion of a task before another t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 10) == 10\n assert candidate(tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],space = 1) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5],space = 5) == 5\n assert candidate(tasks = [1, 1, 1...
[ "[1,2,1,2,3,1]\n3", "[5,8,8,5]\n2" ]
[ "Try taking breaks as late as possible, such that tasks are still spaced appropriately.", "Whenever considering whether to complete the next task, if it is not the first task of its type, check how many days ago the previous task was completed and add an appropriate number of breaks." ]
{ "canonical_parameter_names": [ "tasks", "space" ], "leetcode_dataset_entry_point": "Solution().taskSchedulerII", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:07", "tests_total":...
cpp
{ "raw_signature": "long long taskSchedulerII(vector<int>& tasks, int space) {", "container": "Solution", "callable": "taskSchedulerII", "parameters": [ { "name": "tasks", "type": "vector<int>&" }, { "name": "space", "type": "int" } ], "return_type": "long long", "s...
2,366
minimum-replacements-to-sort-the-array
Hard
You are given a 0-indexed integer array nums. In one operation you can replace any element of the array with any two elements that sum to it. - For example, consider nums = [5,6,7]. In one operation, we can replace nums[1] with 2 and 4 and convert nums to [5,2,4,7]. Return the minimum number of operations to make an ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1000000000]) == 0\n assert candidate(nums = [9, 7, 5, 3, 1]) == 20\n assert candidate(nums = [10, 5, 3]) == 5\n assert candidate(nums = [100, 75, 50]) == 3\n assert candidate(nums = [1, 3, 5, 7, 9]) == 0\n asser...
[ "[3,9,3]", "[1,2,3,4,5]" ]
[ "It is optimal to never make an operation to the last element of the array.", "You can iterate from the second last element to the first. If the current value is greater than the previous bound, we want to break it into pieces so that the smaller one is as large as possible but not larger than the previous one." ...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumReplacement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:10", "tests_total": 107, "te...
cpp
{ "raw_signature": "long long minimumReplacement(vector<int>& nums) {", "container": "Solution", "callable": "minimumReplacement", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "le...
2,367
number-of-arithmetic-triplets
Easy
You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met: - i < j < k, - nums[j] - nums[i] == diff, and - nums[k] - nums[j] == diff. Return the number of unique arithmetic triplets. Example 1: Inpu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13],diff = 2) == 5\n assert candidate(nums = [5, 10, 15, 20, 25, 30],diff = 5) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],diff = 4) == 6\n assert candidate(nums = [4, 5, 6, 7, 8...
[ "[0,1,4,6,7,10]\n3", "[4,5,6,7,8,9]\n2" ]
[ "Are the constraints small enough for brute force?", "We can use three loops, each iterating through the array to go through every possible triplet. Be sure to not count duplicates." ]
{ "canonical_parameter_names": [ "nums", "diff" ], "leetcode_dataset_entry_point": "Solution().arithmeticTriplets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:12", "tests_total"...
cpp
{ "raw_signature": "int arithmeticTriplets(vector<int>& nums, int diff) {", "container": "Solution", "callable": "arithmeticTriplets", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "diff", "type": "int" } ], "return_type": "int", "signature_s...
2,368
reachable-nodes-with-restrictions
Medium
There is an undirected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given a 2D integer array edges of length n - 1 where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree. You are also given an integer array restricted which represents restricted nodes. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [2, 3], [2, 4], [4, 5]],restricted = [1, 4]) == 3\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]],restricted = [5, 7]) == 6\n assert candidate(n = 8,edges = [...
[ "7\n[[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]]\n[4,5]", "7\n[[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]]\n[4,2,1]" ]
[ "Can we find all the reachable nodes in a single traversal?", "Traverse the graph from node 0 while avoiding the nodes in restricted and do not revisit nodes that have been visited.", "Keep count of how many nodes are visited in total." ]
{ "canonical_parameter_names": [ "n", "edges", "restricted" ], "leetcode_dataset_entry_point": "Solution().reachableNodes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:15", "...
cpp
{ "raw_signature": "int reachableNodes(int n, vector<vector<int>>& edges, vector<int>& restricted) {", "container": "Solution", "callable": "reachableNodes", "parameters": [ { "name": "n", "type": "int" }, { "name": "edges", "type": "vector<vector<int>>&" }, { "...
2,369
check-if-there-is-a-valid-partition-for-the-array
Medium
You are given a 0-indexed integer array nums. You have to partition the array into one or more contiguous subarrays. We call a partition of the array valid if each of the obtained subarrays satisfies one of the following conditions: 1. The subarray consists of exactly 2, equal elements. For example, the subarray [2,2...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 4, 5]) == False\n assert candidate(nums = [2, 2, 2, 3, 3, 4, 4, 4]) == True\n assert candidate(nums = [2, 2, 3, 3, 4, 4]) == True\n assert candidate(nums = [1, 2, 3, 3, 3, 4, 5, 5]) == False\n assert candi...
[ "[4,4,4,5,6]", "[1,1,1,2]" ]
[ "How can you reduce the problem to checking if there is a valid partition for a smaller array?", "Use dynamic programming to reduce the problem until you have an empty array." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().validPartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:18", "tests_total": 134, "tests_...
cpp
{ "raw_signature": "bool validPartition(vector<int>& nums) {", "container": "Solution", "callable": "validPartition", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
2,370
longest-ideal-subsequence
Medium
You are given a string s consisting of lowercase letters and an integer k. We call a string t ideal if the following conditions are satisfied: - t is a subsequence of the string s. - The absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k. Return the length of the l...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",k = 25) == 20\n assert candidate(s = \"a\",k = 0) == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 0) == 1\n assert candidate(s = \"abcd\",k = 3) == 4\n assert candidate(s = \"zyxwvu...
[ "\"acfgbd\"\n2", "\"abcd\"\n3" ]
[ "How can you calculate the longest ideal subsequence that ends at a specific index i?", "Can you calculate it for all positions i? How can you use previously calculated answers to calculate the answer for the next position?" ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().longestIdealString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:20", "tests_total": 85, ...
cpp
{ "raw_signature": "int longestIdealString(string s, int k) {", "container": "Solution", "callable": "longestIdealString", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSn...
2,373
largest-local-values-in-a-matrix
Easy
You are given an n x n integer matrix grid. Generate an integer matrix maxLocal of size (n - 2) x (n - 2) such that: - maxLocal[i][j] is equal to the largest value of the 3 x 3 matrix in grid centered around row i + 1 and column j + 1. In other words, we want to find the largest value in every contiguous 3 x 3 matri...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[5, 8, 4, 3], [3, 5, 9, 5], [7, 6, 7, 9], [4, 8, 5, 3]]) == [[9, 9], [9, 9]]\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 2, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == [[2, 2, 2], [2, 2, 2], [2, 2, 2]]...
[ "[[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]", "[[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]" ]
[ "Use nested loops to run through all possible 3 x 3 windows in the matrix.", "For each 3 x 3 window, iterate through the values to get the maximum value within the window." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().largestLocal", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:25", "tests_total": 56, "tests_dro...
cpp
{ "raw_signature": "vector<vector<int>> largestLocal(vector<vector<int>>& grid) {", "container": "Solution", "callable": "largestLocal", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "vector<vector<int>>", "signature_source": "leetcode/codeSnippet...
2,374
node-with-highest-edge-score
Medium
You are given a directed graph with n nodes labeled from 0 to n - 1, where each node has exactly one outgoing edge. The graph is represented by a given 0-indexed integer array edges of length n, where edges[i] indicates that there is a directed edge from node i to node edges[i]. The edge score of a node i is defined ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(edges = [2, 0, 0, 2]) == 0\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 0\n assert candidate(edges = [1, 0, 0, 0, 0, 7, 7, 5]) == 7\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 0]) == 0\n assert candidate...
[ "[1,0,0,0,0,7,7,5]", "[2,0,0,2]" ]
[ "Create an array arr where arr[i] is the edge score for node i.", "How does the edge score for node edges[i] change? It increases by i.", "The edge score may not fit within a standard 32-bit integer." ]
{ "canonical_parameter_names": [ "edges" ], "leetcode_dataset_entry_point": "Solution().edgeScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:27", "tests_total": 26, "tests_dropp...
cpp
{ "raw_signature": "int edgeScore(vector<int>& edges) {", "container": "Solution", "callable": "edgeScore", "parameters": [ { "name": "edges", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,375
construct-smallest-number-from-di-string
Medium
You are given a 0-indexed string pattern of length n consisting of the characters 'I' meaning increasing and 'D' meaning decreasing. A 0-indexed string num of length n + 1 is created using the following conditions: - num consists of the digits '1' to '9', where each digit is used at most once. - If pattern[i] == 'I',...
{ "language": "python", "source": "def check(candidate):\n assert candidate(pattern = \"DDD\") == \"4321\"\n assert candidate(pattern = \"IIIDIDDD\") == \"123549876\"\n assert candidate(pattern = \"ID\") == \"132\"\n assert candidate(pattern = \"IIDDD\") == \"126543\"\n assert candidate(pattern = \"D...
[ "\"IIIDIDDD\"", "\"DDD\"" ]
[ "With the constraints, could we generate every possible string?", "Yes we can. Now we just need to check if the string meets all the conditions." ]
{ "canonical_parameter_names": [ "pattern" ], "leetcode_dataset_entry_point": "Solution().smallestNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:30", "tests_total": 116, "tes...
cpp
{ "raw_signature": "string smallestNumber(string pattern) {", "container": "Solution", "callable": "smallestNumber", "parameters": [ { "name": "pattern", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
2,376
count-special-integers
Hard
We call a positive integer special if all of its digits are distinct. Given a positive integer n, return the number of special integers that belong to the interval [1, n]. Example 1: Input: n = 20 Output: 19 Explanation: All the integers from 1 to 20, except 11, are special. Thus, there are 19 special integers. Exa...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 135) == 110\n assert candidate(n = 999) == 738\n assert candidate(n = 200) == 162\n assert candidate(n = 10000) == 5274\n assert candidate(n = 1234) == 803\n assert candidate(n = 2000) == 1242\n assert candidate(n =...
[ "20", "5", "135" ]
[ "Try to think of dynamic programming.", "Use the idea of digit dynamic programming to build the numbers, in addition to a bitmask that will tell which digits you have used so far on the number that you are building." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().countSpecialNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:32", "tests_total": 57, "tests...
cpp
{ "raw_signature": "int countSpecialNumbers(int n) {", "container": "Solution", "callable": "countSpecialNumbers", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,379
minimum-recolors-to-get-k-consecutive-black-blocks
Easy
You are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the i^th block. The characters 'W' and 'B' denote the colors white and black, respectively. You are also given an integer k, which is the desired number of consecutive black blocks. In one operation, y...
{ "language": "python", "source": "def check(candidate):\n assert candidate(blocks = \"WWWW\",k = 2) == 2\n assert candidate(blocks = \"WBBBWWBBBW\",k = 3) == 0\n assert candidate(blocks = \"WBBWWBBWBW\",k = 7) == 3\n assert candidate(blocks = \"BBBBB\",k = 3) == 0\n assert candidate(blocks = \"BWBWB...
[ "\"WBBWWBBWBW\"\n7", "\"WBWBBBW\"\n2" ]
[ "Iterate through all possible consecutive substrings of k characters.", "Find the number of changes for each substring to make all blocks black, and return the minimum of these." ]
{ "canonical_parameter_names": [ "blocks", "k" ], "leetcode_dataset_entry_point": "Solution().minimumRecolors", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:37", "tests_total": 10...
cpp
{ "raw_signature": "int minimumRecolors(string blocks, int k) {", "container": "Solution", "callable": "minimumRecolors", "parameters": [ { "name": "blocks", "type": "string" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/co...
2,380
time-needed-to-rearrange-a-binary-string
Medium
You are given a binary string s. In one second, all occurrences of "01" are simultaneously replaced with "10". This process repeats until no occurrences of "01" exist. Return the number of seconds needed to complete this process. Example 1: Input: s = "0110101" Output: 4 Explanation: After one second, s becomes "101...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == 0\n assert candidate(s = \"00110011\") == 5\n assert candidate(s = \"0000\") == 0\n assert candidate(s = \"111000\") == 0\n assert candidate(s = \"0010110\") == 4\n assert candidate(s = \"1001001\") == 4\n...
[ "\"0110101\"", "\"11100\"" ]
[ "Try replicating the steps from the problem statement.", "Perform the replacements simultaneously, and return the number of times the process repeats." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().secondsToRemoveOccurrences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:39", "tests_total": 127, ...
cpp
{ "raw_signature": "int secondsToRemoveOccurrences(string s) {", "container": "Solution", "callable": "secondsToRemoveOccurrences", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
2,381
shifting-letters-ii
Medium
You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [start_i, end_i, direction_i]. For every i, shift the characters in s from the index start_i to the index end_i (inclusive) forward if direction_i = 1, or shift the characters backward if direction_i = 0. Shifting a c...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"world\",shifts = [[0, 4, 0], [0, 4, 0], [0, 4, 0], [0, 4, 0]]) == \"sknhz\"\n assert candidate(s = \"abc\",shifts = [[0, 1, 0], [1, 2, 1], [0, 2, 1]]) == \"ace\"\n assert candidate(s = \"xyz\",shifts = [[0, 2, 0]]) == \"wxy\"...
[ "\"abc\"\n[[0,1,0],[1,2,1],[0,2,1]]", "\"dztz\"\n[[0,0,0],[1,1,1]]" ]
[ "Instead of shifting every character in each shift, could you keep track of which characters are shifted and by how much across all shifts?", "Try marking the start and ends of each shift, then perform a prefix sum of the shifts." ]
{ "canonical_parameter_names": [ "s", "shifts" ], "leetcode_dataset_entry_point": "Solution().shiftingLetters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:41", "tests_total": 94...
cpp
{ "raw_signature": "string shiftingLetters(string s, vector<vector<int>>& shifts) {", "container": "Solution", "callable": "shiftingLetters", "parameters": [ { "name": "s", "type": "string" }, { "name": "shifts", "type": "vector<vector<int>>&" } ], "return_type": "str...
2,382
maximum-segment-sum-after-removals
Hard
You are given two 0-indexed integer arrays nums and removeQueries, both of length n. For the i^th query, the element in nums at the index removeQueries[i] is removed, splitting nums into different segments. A segment is a contiguous sequence of positive integers in nums. A segment sum is the sum of every element in a ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 5, 6, 1],removeQueries = [0, 3, 2, 4, 1]) == [14, 7, 2, 2, 0]\n assert candidate(nums = [5, 1, 4, 3, 2],removeQueries = [2, 0, 4, 1, 3]) == [6, 5, 3, 3, 0]\n assert candidate(nums = [1000000000, 1000000000, 1000000000...
[ "[1,2,5,6,1]\n[0,3,2,4,1]", "[3,2,11,1]\n[3,2,1,0]" ]
[ "Use a sorted data structure to collect removal points and store the segments.", "Use a heap or priority queue to store segment sums and their corresponding boundaries.", "Make sure to remove invalid segments from the heap." ]
{ "canonical_parameter_names": [ "nums", "removeQueries" ], "leetcode_dataset_entry_point": "Solution().maximumSegmentSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:44", "test...
cpp
{ "raw_signature": "vector<long long> maximumSegmentSum(vector<int>& nums, vector<int>& removeQueries) {", "container": "Solution", "callable": "maximumSegmentSum", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "removeQueries", "type": "vector<int>&" ...
2,383
minimum-hours-of-training-to-win-a-competition
Easy
You are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively. You are also given two 0-indexed integer arrays energy and experience, both of length n. You will face n opponents in order. The energy and experien...
{ "language": "python", "source": "def check(candidate):\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [50, 50],experience = [50, 50]) == 52\n assert candidate(initialEnergy = 5,initialExperience = 3,energy = [1, 4, 3, 2],experience = [2, 6, 3, 1]) == 8\n assert candidate(initialEne...
[ "5\n3\n[1,4,3,2]\n[2,6,3,1]", "2\n4\n[1]\n[3]" ]
[ "Find the minimum number of training hours needed for the energy and experience separately, and sum the results.", "Try to increase the energy and experience until you find how much is enough to win the competition." ]
{ "canonical_parameter_names": [ "initialEnergy", "initialExperience", "energy", "experience" ], "leetcode_dataset_entry_point": "Solution().minNumberOfHours", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", ...
cpp
{ "raw_signature": "int minNumberOfHours(int initialEnergy, int initialExperience, vector<int>& energy, vector<int>& experience) {", "container": "Solution", "callable": "minNumberOfHours", "parameters": [ { "name": "initialEnergy", "type": "int" }, { "name": "initialExperience", ...
2,384
largest-palindromic-number
Medium
You are given a string num consisting of digits only. Return the largest palindromic integer (in the form of a string) that can be formed using digits taken from num. It should not contain leading zeroes. Notes: - You do not need to use all the digits of num, but you must use at least one digit. - The digits can be ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = \"1111\") == \"1111\"\n assert candidate(num = \"00000\") == \"0\"\n assert candidate(num = \"10\") == \"1\"\n assert candidate(num = \"9\") == \"9\"\n assert candidate(num = \"1111111111\") == \"1111111111\"\n asser...
[ "\"444947137\"", "\"00009\"" ]
[ "In order to form a valid palindrome, other than the middle digit in an odd-length palindrome, every digit needs to exist on both sides.", "A longer palindrome implies a larger valued palindrome. For palindromes of the same length, the larger digits should occur first.", "We can count the occurrences of each di...
{ "canonical_parameter_names": [ "num" ], "leetcode_dataset_entry_point": "Solution().largestPalindromic", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:48", "tests_total": 50, "test...
cpp
{ "raw_signature": "string largestPalindromic(string num) {", "container": "Solution", "callable": "largestPalindromic", "parameters": [ { "name": "num", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
2,386
find-the-k-sum-of-an-array
Hard
You are given an integer array nums and a positive integer k. You can choose any subsequence of the array and sum all of its elements together. We define the K-Sum of the array as the k^th largest subsequence sum that can be obtained (not necessarily distinct). Return the K-Sum of the array. A subsequence is an arra...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 100\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000],k = 7) == 0\n assert candidate(nums = [1000000000, -1000000000, 1000000000],k = 3) == 1000000000\n assert cand...
[ "[2,4,-2]\n5", "[1,-2,3,4,-10,12]\n16" ]
[ "Start from the largest sum possible, and keep finding the next largest sum until you reach the kth sum.", "Starting from a sum, what are the two next largest sums that you can obtain from it?" ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().kSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:53", "tests_total": 105, "tests_d...
cpp
{ "raw_signature": "long long kSum(vector<int>& nums, int k) {", "container": "Solution", "callable": "kSum", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "long long", "signature_source": "leetcode/code...
2,389
longest-subsequence-with-limited-sum
Easy
You are given an integer array nums of length n, and an integer array queries of length m. Return an array answer of length m where answer[i] is the maximum size of a subsequence that you can take from nums such that the sum of its elements is less than or equal to queries[i]. A subsequence is an array that can be de...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [1, 2, 3, 4, 5]) == [1, 1, 2, 2, 2]\n assert candidate(nums = [10, 20, 30],queries = [10, 25, 50, 70]) == [1, 1, 2, 3]\n assert candidate(nums = [10, 20, 30],queries = [5, 15, 25, 35]) == [0, 1, 1, ...
[ "[4,5,2,1]\n[3,10,21]", "[2,3,4,5]\n[1]" ]
[ "Solve each query independently.", "When solving a query, which elements of nums should you choose to make the subsequence as long as possible?", "Choose the smallest elements in nums that add up to a sum less than the query." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().answerQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:58", "tests_total": ...
cpp
{ "raw_signature": "vector<int> answerQueries(vector<int>& nums, vector<int>& queries) {", "container": "Solution", "callable": "answerQueries", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "queries", "type": "vector<int>&" } ], "return_type":...
2,390
removing-stars-from-a-string
Medium
You are given a string s, which contains stars *. In one operation, you can: - Choose a star in s. - Remove the closest non-star character to its left, as well as remove the star itself. Return the string after all stars have been removed. Note: - The input will be generated such that the operation is always possi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc*def*ghi*jkl*mno*pqr*stu*vwx*y*z\") == \"abdeghjkmnpqstvwz\"\n assert candidate(s = \"leet**cod*e\") == \"lecoe\"\n assert candidate(s = \"a*b*c*d*e*\") == \"\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == ...
[ "\"leet**cod*e\"", "\"erase*****\"" ]
[ "What data structure could we use to efficiently perform these removals?", "Use a stack to store the characters. Pop one character off the stack at each star. Otherwise, we push the character onto the stack." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().removeStars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:01", "tests_total": 65, "tests_dropped...
cpp
{ "raw_signature": "string removeStars(string s) {", "container": "Solution", "callable": "removeStars", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,391
minimum-amount-of-time-to-collect-garbage
Medium
You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the i^th house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, paper and glass garbage respectively. Picking up one unit of any type of garbage takes 1 minute. You ar...
{ "language": "python", "source": "def check(candidate):\n assert candidate(garbage = ['M', 'P', 'G', 'M', 'P', 'G'],travel = [1, 2, 3, 4, 5]) == 37\n assert candidate(garbage = ['P', 'G', 'M', 'P'],travel = [1, 1, 1]) == 10\n assert candidate(garbage = ['GGG', 'PPP', 'MMM', 'GGG', 'PPP', 'MMM'],travel = [...
[ "[\"G\",\"P\",\"GP\",\"GG\"]\n[2,4,3]", "[\"MMM\",\"PGM\",\"GP\"]\n[3,10]" ]
[ "Where can we save time? By not visiting all the houses.", "For each type of garbage, find the house with the highest index that has at least 1 unit of this type of garbage." ]
{ "canonical_parameter_names": [ "garbage", "travel" ], "leetcode_dataset_entry_point": "Solution().garbageCollection", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:03", "tests_to...
cpp
{ "raw_signature": "int garbageCollection(vector<string>& garbage, vector<int>& travel) {", "container": "Solution", "callable": "garbageCollection", "parameters": [ { "name": "garbage", "type": "vector<string>&" }, { "name": "travel", "type": "vector<int>&" } ], "ret...
2,392
build-a-matrix-with-conditions
Hard
You are given a positive integer k. You are also given: - a 2D integer array rowConditions of size n where rowConditions[i] = [above_i, below_i], and - a 2D integer array colConditions of size m where colConditions[i] = [left_i, right_i]. The two arrays contain integers from 1 to k. You have to build a k x k matrix ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(k = 5,rowConditions = [[1, 5], [2, 5], [3, 5], [4, 5]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5]]) == [[1, 0, 0, 0, 0], [0, 2, 0, 0, 0], [0, 0, 3, 0, 0], [0, 0, 0, 4, 0], [0, 0, 0, 0, 5]]\n assert candidate(k = 3,rowConditions =...
[ "3\n[[1,2],[3,2]]\n[[2,1],[3,2]]", "3\n[[1,2],[2,3],[3,1],[2,3]]\n[[2,1]]" ]
[ "Can you think of the problem in terms of graphs?", "What algorithm allows you to find the order of nodes in a graph?" ]
{ "canonical_parameter_names": [ "k", "rowConditions", "colConditions" ], "leetcode_dataset_entry_point": "Solution().buildMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:...
cpp
{ "raw_signature": "vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {", "container": "Solution", "callable": "buildMatrix", "parameters": [ { "name": "k", "type": "int" }, { "name": "rowConditions", "type": "vecto...
2,395
find-subarrays-with-equal-sum
Easy
Given a 0-indexed integer array nums, determine whether there exist two subarrays of length 2 with equal sum. Note that the two subarrays must begin at different indices. Return true if these subarrays exist, and false otherwise. A subarray is a contiguous non-empty sequence of elements within an array. Example 1: ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, 0, 1, -1, 0]) == True\n assert candidate(nums = [1, 1, 1, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(nums = [5, -1, 5, -1]) == True\n assert candidate(nums =...
[ "[4,2,4]", "[1,2,3,4,5]", "[0,0,0]" ]
[ "Use a counter to keep track of the subarray sums.", "Use a hashset to check if any two sums are equal." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:10", "tests_total": 119, "tests_d...
cpp
{ "raw_signature": "bool findSubarrays(vector<int>& nums) {", "container": "Solution", "callable": "findSubarrays", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
2,396
strictly-palindromic-number
Medium
An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic. Given an integer n, return true if n is strictly palindromic and false otherwise. A string is palindromic if it reads the same forward and backward. Example ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 15) == False\n assert candidate(n = 4) == False\n assert candidate(n = 9) == False\n assert candidate(n = 6) == False\n assert candidate(n = 20) == False\n assert candidate(n = 100) == False\n assert candidate(n = 1...
[ "9", "4" ]
[ "Consider the representation of the given number in the base n - 2.", "The number n in base (n - 2) is always 12, which is not palindromic." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().isStrictlyPalindromic", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:13", "tests_total": 57, "tes...
cpp
{ "raw_signature": "bool isStrictlyPalindromic(int n) {", "container": "Solution", "callable": "isStrictlyPalindromic", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,397
maximum-rows-covered-by-columns
Medium
You are given an m x n binary matrix matrix and an integer numSelect. Your goal is to select exactly numSelect distinct columns from matrix such that you cover as many rows as possible. A row is considered covered if all the 1's in that row are also part of a column that you have selected. If a row does not have any ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],numSelect = 4) == 3\n assert candidate(matrix = [[1, 1], [0, 0], [1, 0], [0, 1]],numSelect = 1) == 2\n assert candidate(matrix = [[1, 1, 1], [0, 1, 1], [1, 0, 1]],numSelect = 1) =...
[ "[[0,0,0],[1,0,1],[0,1,1],[0,0,1]]\n2", "[[1],[0]]\n1" ]
[ "Try a brute-force approach.", "Iterate through all possible sets of exactly cols columns.", "For each valid set, check how many rows are covered, and return the maximum." ]
{ "canonical_parameter_names": [ "matrix", "numSelect" ], "leetcode_dataset_entry_point": "Solution().maximumRows", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:15", "tests_total"...
cpp
{ "raw_signature": "int maximumRows(vector<vector<int>>& matrix, int numSelect) {", "container": "Solution", "callable": "maximumRows", "parameters": [ { "name": "matrix", "type": "vector<vector<int>>&" }, { "name": "numSelect", "type": "int" } ], "return_type": "int"...
2,398
maximum-number-of-robots-within-budget
Hard
You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The i^th robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also given an integer budget. The total cost of running k chosen robots is equal to max(chargeTimes) + k * s...
{ "language": "python", "source": "def check(candidate):\n assert candidate(chargeTimes = [1, 1, 1, 1, 1],runningCosts = [100000, 100000, 100000, 100000, 100000],budget = 500000) == 2\n assert candidate(chargeTimes = [7, 7, 7, 7],runningCosts = [1, 1, 1, 1],budget = 20) == 3\n assert candidate(chargeTimes ...
[ "[3,6,1,3,4]\n[2,1,3,4,5]\n25", "[11,12,19]\n[10,8,7]\n19" ]
[ "Use binary search to convert the problem into checking if we can find a specific number of consecutive robots within the budget.", "Maintain a sliding window of the consecutive robots being considered.", "Use either a map, deque, or heap to find the maximum charge times in the window efficiently." ]
{ "canonical_parameter_names": [ "chargeTimes", "runningCosts", "budget" ], "leetcode_dataset_entry_point": "Solution().maximumRobots", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20...
cpp
{ "raw_signature": "int maximumRobots(vector<int>& chargeTimes, vector<int>& runningCosts, long long budget) {", "container": "Solution", "callable": "maximumRobots", "parameters": [ { "name": "chargeTimes", "type": "vector<int>&" }, { "name": "runningCosts", "type": "vector<...
2,399
check-distances-between-same-letters
Easy
You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26. Each letter in the alphabet is numbered from 0 to 25 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, ... , 'z' -> 25). In a well-spaced...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrztuvwxyz\",distance = [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, 1]) == False\n assert candidate(s = \"zz\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
[ "\"abaccb\"\n[1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]", "\"aa\"\n[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]" ]
[ "Create an integer array of size 26 to keep track of the first occurrence of each letter.", "The number of letters between indices i and j is j - i - 1." ]
{ "canonical_parameter_names": [ "s", "distance" ], "leetcode_dataset_entry_point": "Solution().checkDistances", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:19", "tests_total": 9...
cpp
{ "raw_signature": "bool checkDistances(string s, vector<int>& distance) {", "container": "Solution", "callable": "checkDistances", "parameters": [ { "name": "s", "type": "string" }, { "name": "distance", "type": "vector<int>&" } ], "return_type": "bool", "signature...
2,400
number-of-ways-to-reach-a-position-after-exactly-k-steps
Medium
You are given two positive integers startPos and endPos. Initially, you are standing at position startPos on an infinite number line. With one step, you can move either one position to the left, or one position to the right. Given a positive integer k, return the number of different ways to reach the position endPos s...
{ "language": "python", "source": "def check(candidate):\n assert candidate(startPos = 1,endPos = 2,k = 3) == 3\n assert candidate(startPos = 10,endPos = 1,k = 15) == 455\n assert candidate(startPos = 5,endPos = 5,k = 10) == 252\n assert candidate(startPos = 10,endPos = 1,k = 9) == 1\n assert candida...
[ "1\n2\n3", "2\n5\n10" ]
[ "How many steps to the left and to the right do you need to make exactly?", "Does the order of the steps matter?", "Use combinatorics to find the number of ways to order the steps." ]
{ "canonical_parameter_names": [ "startPos", "endPos", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:21", "tes...
cpp
{ "raw_signature": "int numberOfWays(int startPos, int endPos, int k) {", "container": "Solution", "callable": "numberOfWays", "parameters": [ { "name": "startPos", "type": "int" }, { "name": "endPos", "type": "int" }, { "name": "k", "type": "int" } ...
2,401
longest-nice-subarray
Medium
You are given an array nums consisting of positive integers. We call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0. Return the length of the longest nice subarray. A subarray is a contiguous part of an array. Note that subarrays of...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 1, 5, 11, 13]) == 1\n assert candidate(nums = [31, 1, 4, 32, 16]) == 4\n assert candidate(nums = [7, 11, 13, 14, 2, 5, 3]) == 2\n assert candidate(nums = [1, 2, 4, 8, 16]) == 5\n assert candidate(nums = [16, 17, 71...
[ "[1,3,8,48,10]", "[3,1,5,11,13]" ]
[ "What is the maximum possible length of a nice subarray?", "If two numbers have bitwise AND equal to zero, they do not have any common set bit. A number x <= 10^9 only has 30 bits, hence the length of the longest nice subarray cannot exceed 30." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().longestNiceSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:24", "tests_total": 115, "t...
cpp
{ "raw_signature": "int longestNiceSubarray(vector<int>& nums) {", "container": "Solution", "callable": "longestNiceSubarray", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...
2,402
meeting-rooms-iii
Hard
You are given an integer n. There are n rooms numbered from 0 to n - 1. You are given a 2D integer array meetings where meetings[i] = [start_i, end_i] means that a meeting will be held during the half-closed time interval [start_i, end_i). All the values of start_i are unique. Meetings are allocated to rooms in the f...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,meetings = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == 0\n assert candidate(n = 5,meetings = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6]]) =...
[ "2\n[[0,10],[1,5],[2,7],[3,4]]", "3\n[[1,20],[2,10],[3,5],[4,9],[6,8]]" ]
[ "Sort meetings based on start times.", "Use two min heaps, the first one keeps track of the numbers of all the rooms that are free. The second heap keeps track of the end times of all the meetings that are happening and the room that they are in.", "Keep track of the number of times each room is used in an arra...
{ "canonical_parameter_names": [ "n", "meetings" ], "leetcode_dataset_entry_point": "Solution().mostBooked", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:27", "tests_total": 92, ...
cpp
{ "raw_signature": "int mostBooked(int n, vector<vector<int>>& meetings) {", "container": "Solution", "callable": "mostBooked", "parameters": [ { "name": "n", "type": "int" }, { "name": "meetings", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature...
2,404
most-frequent-even-element
Easy
Given an integer array nums, return the most frequent even element. If there is a tie, return the smallest one. If there is no such element, return -1. Example 1: Input: nums = [0,1,2,2,4,4,1] Output: 2 Explanation: The even elements are 0, 2, and 4. Of these, 2 and 4 appear the most. We return the smallest one, whi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [29, 47, 21, 41, 13, 37, 25, 7]) == -1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == -1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4]) == 4\n assert candidate(nums = [8, 8, 8, 8, 8, 7, 7, 7, 7...
[ "[0,1,2,2,4,4,1]", "[4,4,4,9,2,4]", "[29,47,21,41,13,37,25,7]" ]
[ "Could you count the frequency of each even element in the array?", "Would a hashmap help?" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().mostFrequentEven", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:31", "tests_total": 110, "test...
cpp
{ "raw_signature": "int mostFrequentEven(vector<int>& nums) {", "container": "Solution", "callable": "mostFrequentEven", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnipp...
2,405
optimal-partition-of-string
Medium
Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once. Return the minimum number of substrings in such a partition. Note that each character should belong to exactly one substring in a p...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefg\") == 1\n assert candidate(s = \"abac\") == 2\n assert candidate(s = \"abcdabcdeabcdefabcdefg\") == 4\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 44\n assert candidate(s = \"ababa...
[ "\"abacaba\"", "\"ssssss\"" ]
[ "Try to come up with a greedy approach.", "From left to right, extend every substring in the partition as much as possible." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().partitionString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:34", "tests_total": 103, "tests_dr...
cpp
{ "raw_signature": "int partitionString(string s) {", "container": "Solution", "callable": "partitionString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,406
divide-intervals-into-minimum-number-of-groups
Medium
You are given a 2D integer array intervals where intervals[i] = [left_i, right_i] represents the inclusive interval [left_i, right_i]. You have to divide the intervals into one or more groups such that each interval is in exactly one group, and no two intervals that are in the same group intersect each other. Return ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(intervals = [[1, 2], [3, 4], [5, 6], [7, 8]]) == 1\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 2\n assert candidate(intervals = [[1, 1000000]]) == 1\n assert candidate(intervals = [[5, 10], [6, 8], [1, 5]...
[ "[[5,10],[6,8],[1,5],[2,3],[1,10]]", "[[1,3],[5,6],[8,10],[11,13]]" ]
[ "Can you find a different way to describe the question?", "The minimum number of groups we need is equivalent to the maximum number of intervals that overlap at some point. How can you find that?" ]
{ "canonical_parameter_names": [ "intervals" ], "leetcode_dataset_entry_point": "Solution().minGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:36", "tests_total": 97, "tests_d...
cpp
{ "raw_signature": "int minGroups(vector<vector<int>>& intervals) {", "container": "Solution", "callable": "minGroups", "parameters": [ { "name": "intervals", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
2,407
longest-increasing-subsequence-ii
Hard
You are given an integer array nums and an integer k. Find the longest subsequence of nums that meets the following requirements: - The subsequence is strictly increasing and - The difference between adjacent elements in the subsequence is at most k. Return the length of the longest subsequence that meets the requir...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18],k = 10) == 3\n assert candidate(nums = [5, 4, 3, 2, 1],k = 2) == 1\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18],k = 5) == 3\n assert candidate(nums = [7, 4, 5, 1, 8, 12, 4, 7],k = 5)...
[ "[4,2,1,4,3,4,5,8,15]\n3", "[7,4,5,1,8,12,4,7]\n5", "[1,5]\n1" ]
[ "We can use dynamic programming. Let dp[i][val] be the answer using only the first i + 1 elements, and the last element in the subsequence is equal to val.", "The only value that might change between dp[i - 1] and dp[i] are dp[i - 1][val] and dp[i][val].", "Try using dp[i - 1] and the fact that the second last ...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().lengthOfLIS", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:38", "tests_total": 110, "...
cpp
{ "raw_signature": "int lengthOfLIS(vector<int>& nums, int k) {", "container": "Solution", "callable": "lengthOfLIS", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/co...
2,409
count-days-spent-together
Easy
Alice and Bob are traveling to Rome for separate business meetings. You are given 4 strings arriveAlice, leaveAlice, arriveBob, and leaveBob. Alice will be in the city from the dates arriveAlice to leaveAlice (inclusive), while Bob will be in the city from the dates arriveBob to leaveBob (inclusive). Each will be a 5-...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arriveAlice = \"03-10\",leaveAlice = \"05-20\",arriveBob = \"04-01\",leaveBob = \"04-30\") == 30\n assert candidate(arriveAlice = \"06-15\",leaveAlice = \"06-20\",arriveBob = \"06-18\",leaveBob = \"06-25\") == 3\n assert candidate(...
[ "\"08-15\"\n\"08-18\"\n\"08-16\"\n\"08-19\"", "\"10-01\"\n\"10-31\"\n\"11-01\"\n\"12-31\"" ]
[ "For a given day, determine if Alice or Bob or both are in Rome.", "Brute force all 365 days for both Alice and Bob." ]
{ "canonical_parameter_names": [ "arriveAlice", "leaveAlice", "arriveBob", "leaveBob" ], "leetcode_dataset_entry_point": "Solution().countDaysTogether", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetche...
cpp
{ "raw_signature": "int countDaysTogether(string arriveAlice, string leaveAlice, string arriveBob, string leaveBob) {", "container": "Solution", "callable": "countDaysTogether", "parameters": [ { "name": "arriveAlice", "type": "string" }, { "name": "leaveAlice", "type": "stri...
2,410
maximum-matching-of-players-with-trainers
Medium
You are given a 0-indexed integer array players, where players[i] represents the ability of the i^th player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of the j^th trainer. The i^th player can match with the j^th trainer if the player's ability is less tha...
{ "language": "python", "source": "def check(candidate):\n assert candidate(players = [1, 2, 3],trainers = [10, 11, 12]) == 3\n assert candidate(players = [10, 20, 30],trainers = [1, 2, 3]) == 0\n assert candidate(players = [1, 2, 3, 4, 5],trainers = [5, 4, 3, 2, 1]) == 5\n assert candidate(players = [1...
[ "[4,7,9]\n[8,2,5,8]", "[1,1,1]\n[10]" ]
[ "Sort both the arrays.", "Construct the matching greedily." ]
{ "canonical_parameter_names": [ "players", "trainers" ], "leetcode_dataset_entry_point": "Solution().matchPlayersAndTrainers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:43", "...
cpp
{ "raw_signature": "int matchPlayersAndTrainers(vector<int>& players, vector<int>& trainers) {", "container": "Solution", "callable": "matchPlayersAndTrainers", "parameters": [ { "name": "players", "type": "vector<int>&" }, { "name": "trainers", "type": "vector<int>&" } ...
2,411
smallest-subarrays-with-maximum-bitwise-or
Medium
You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclusive) that has the maximum possible bitwise OR. - In other words, let B_ij be the bitwise OR of the su...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035, 30517, 15258, 7629, 3814, 1907, 953, 476, 238, 119, 59, 29, 14, 7, 3, 1]) == [10, 9, 8, ...
[ "[1,0,2,1,3]", "[1,2]" ]
[ "Consider trying to solve the problem for each bit position separately.", "For each bit position, find the position of the next number that has a 1 in that position, if any.", "Take the maximum distance to such a number, including the current number.", "Iterate backwards to achieve a linear complexity." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().smallestSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:45", "tests_total": 102, "tes...
cpp
{ "raw_signature": "vector<int> smallestSubarrays(vector<int>& nums) {", "container": "Solution", "callable": "smallestSubarrays", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_source": "...
2,412
minimum-money-required-before-transactions
Hard
You are given a 0-indexed 2D integer array transactions, where transactions[i] = [cost_i, cashback_i]. The array describes transactions, where each transaction must be completed exactly once in some order. At any given moment, you have a certain amount of money. In order to complete transaction i, money >= cost_i must...
{ "language": "python", "source": "def check(candidate):\n assert candidate(transactions = [[1, 2], [3, 4], [5, 6]]) == 5\n assert candidate(transactions = [[1, 0], [2, 0], [3, 0]]) == 6\n assert candidate(transactions = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 4\n assert candidate(transactions = [[0, 0], [...
[ "[[2,1],[5,0],[4,2]]", "[[3,0],[0,3]]" ]
[ "Split transactions that have cashback greater or equal to cost apart from transactions that have cashback less than cost. You will always earn money in the first scenario.", "For transactions that have cashback greater or equal to cost, sort them by cost in descending order.", "For transactions that have cashb...
{ "canonical_parameter_names": [ "transactions" ], "leetcode_dataset_entry_point": "Solution().minimumMoney", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:48", "tests_total": 109, "...
cpp
{ "raw_signature": "long long minimumMoney(vector<vector<int>>& transactions) {", "container": "Solution", "callable": "minimumMoney", "parameters": [ { "name": "transactions", "type": "vector<vector<int>>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", ...
2,413
smallest-even-multiple
Easy
Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n. Example 1: Input: n = 5 Output: 10 Explanation: The smallest multiple of both 5 and 2 is 10. Example 2: Input: n = 6 Output: 6 Explanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multipl...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 6\n assert candidate(n = 100) == 100\n assert candidate(n = 33) == 66\n assert candidate(n = 75) == 150\n assert candidate(n = 6) == 6\n assert candidate(n = 2) == 2\n assert candidate(n = 1) == 2\n assert ...
[ "5", "6" ]
[ "A guaranteed way to find a multiple of 2 and n is to multiply them together. When is this the answer, and when is there a smaller answer?", "There is a smaller answer when n is even." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().smallestEvenMultiple", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:50", "tests_total": 91, "test...
cpp
{ "raw_signature": "int smallestEvenMultiple(int n) {", "container": "Solution", "callable": "smallestEvenMultiple", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,414
length-of-the-longest-alphabetical-continuous-substring
Medium
An alphabetical continuous string is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string "abcdefghijklmnopqrstuvwxyz". - For example, "abc" is an alphabetical continuous string, while "acb" and "za" are not. Given a string s consisting of lowercase letters onl...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 1\n assert candidate(s = \"abxyz\") == 3\n assert candidate(s = \"qrstuvwpqrstu\") == 7\n assert candidate(s = \"mnopqrstuvwxyzz\") == 14\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n ...
[ "\"abacaba\"", "\"abcde\"" ]
[ "What is the longest possible continuous substring?", "The size of the longest possible continuous substring is at most 26, so we can just brute force the answer." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().longestContinuousSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:53", "tests_total": 115, ...
cpp
{ "raw_signature": "int longestContinuousSubstring(string s) {", "container": "Solution", "callable": "longestContinuousSubstring", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
2,416
sum-of-prefix-scores-of-strings
Hard
You are given an array words of size n consisting of non-empty strings. We define the score of a string term as the number of strings words[i] such that term is a prefix of words[i]. - For example, if words = ["a", "ab", "abc", "cab"], then the score of "ab" is 2, since "ab" is a prefix of both "ab" and "abc". Retur...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['hello', 'hell', 'he', 'h']) == [12, 11, 7, 4]\n assert candidate(words = ['abc', 'ab', 'bc', 'b']) == [5, 4, 3, 2]\n assert candidate(words = ['a', 'b', 'c', 'd']) == [1, 1, 1, 1]\n assert candidate(words = ['aa', 'aaa...
[ "[\"abc\",\"ab\",\"bc\",\"b\"]", "[\"abcd\"]" ]
[ "What data structure will allow you to efficiently keep track of the score of each prefix?", "Use a Trie. Insert all the words into it, and keep a counter at each node that will tell you how many times we have visited each prefix." ]
{ "canonical_parameter_names": [ "words" ], "leetcode_dataset_entry_point": "Solution().sumPrefixScores", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:57", "tests_total": 96, "tests...
cpp
{ "raw_signature": "vector<int> sumPrefixScores(vector<string>& words) {", "container": "Solution", "callable": "sumPrefixScores", "parameters": [ { "name": "words", "type": "vector<string>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_source...
2,418
sort-the-people
Easy
You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n. For each index i, names[i] and heights[i] denote the name and height of the i^th person. Return names sorted in descending order by the people's heights. Example 1: Input: names = ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(names = ['Zoe', 'Lily', 'Rose'],heights = [150, 145, 155]) == ['Rose', 'Zoe', 'Lily']\n assert candidate(names = ['Qwen', 'Alibaba', 'Cloud'],heights = [200, 190, 180]) == ['Qwen', 'Alibaba', 'Cloud']\n assert candidate(names = ['A...
[ "[\"Mary\",\"John\",\"Emma\"]\n[180,165,170]", "[\"Alice\",\"Bob\",\"Bob\"]\n[155,185,150]" ]
[ "Find the tallest person and swap with the first person, then find the second tallest person and swap with the second person, etc. Repeat until you fix all n people." ]
{ "canonical_parameter_names": [ "names", "heights" ], "leetcode_dataset_entry_point": "Solution().sortPeople", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:02", "tests_total": 12...
cpp
{ "raw_signature": "vector<string> sortPeople(vector<string>& names, vector<int>& heights) {", "container": "Solution", "callable": "sortPeople", "parameters": [ { "name": "names", "type": "vector<string>&" }, { "name": "heights", "type": "vector<int>&" } ], "return_t...
2,419
longest-subarray-with-maximum-bitwise-and
Medium
You are given an integer array nums of size n. Consider a non-empty subarray from nums that has the maximum possible bitwise AND. - In other words, let k be the maximum value of the bitwise AND of any subarray of nums. Then, only subarrays with a bitwise AND equal to k should be considered. Return the length of the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [8, 9, 10, 11, 12, 13, 14, 15, 16]) == 1\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953]) == 1\n assert candidate(nums = [8, 9, 10, 10, 10, 8]) == 3\n assert candidate(nu...
[ "[1,2,3,3,2,2]", "[1,2,3,4]" ]
[ "Notice that the bitwise AND of two different numbers will always be strictly less than the maximum of those two numbers.", "What does that tell us about the nature of the subarray that we should choose?" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().longestSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:04", "tests_total": 42, "tests_...
cpp
{ "raw_signature": "int longestSubarray(vector<int>& nums) {", "container": "Solution", "callable": "longestSubarray", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
2,420
find-all-good-indices
Medium
You are given a 0-indexed integer array nums of size n and a positive integer k. We call an index i in the range k <= i < n - k good if the following conditions are satisfied: - The k elements that are just before the index i are in non-increasing order. - The k elements that are just after the index i are in non-dec...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5],k = 3) == [7, 8, 9]\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1],k = 2) == []\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 4, 3, 2, 1],k = 3) == []\n assert candidate(nums = [...
[ "[2,1,1,1,3,4,1]\n2", "[2,1,1,2]\n2" ]
[ "Iterate over all indices i. How do you quickly check the two conditions?", "Precompute for each index whether the conditions are satisfied on the left and the right of the index. You can do that with two iterations, from left to right and right to left." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().goodIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:07", "tests_total": 101, "...
cpp
{ "raw_signature": "vector<int> goodIndices(vector<int>& nums, int k) {", "container": "Solution", "callable": "goodIndices", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "vector<int>", "signature_sourc...
2,421
number-of-good-paths
Hard
There is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the i^th node. You are also given a 2D integer array edges where edges[i] = [a_i, b_i] ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(vals = [2, 2, 2, 2, 2],edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 15\n assert candidate(vals = [1],edges = []) == 1\n assert candidate(vals = [1, 2, 3, 4, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 5\n assert candidate(va...
[ "[1,3,2,1,3]\n[[0,1],[0,2],[2,3],[2,4]]", "[1,1,2,2,3]\n[[0,1],[1,2],[2,3],[2,4]]", "[1]\n[]" ]
[ "Can you process nodes from smallest to largest value?", "Try to build the graph from nodes with the smallest value to the largest value.", "May union find help?" ]
{ "canonical_parameter_names": [ "vals", "edges" ], "leetcode_dataset_entry_point": "Solution().numberOfGoodPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:10", "tests_total"...
cpp
{ "raw_signature": "int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {", "container": "Solution", "callable": "numberOfGoodPaths", "parameters": [ { "name": "vals", "type": "vector<int>&" }, { "name": "edges", "type": "vector<vector<int>>&" } ], "r...
2,423
remove-letter-to-equalize-frequency
Easy
You are given a 0-indexed string word, consisting of lowercase English letters. You need to select one index and remove the letter at that index from word so that the frequency of every letter present in word is equal. Return true if it is possible to remove one letter so that the frequency of all letters in word are ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"aabbccd\") == True\n assert candidate(word = \"aaabbbccc\") == False\n assert candidate(word = \"zazaza\") == False\n assert candidate(word = \"aaaaabbbbbcccc\") == False\n assert candidate(word = \"zzzzzzzz\") == Tr...
[ "\"abcc\"", "\"aazz\"" ]
[ "Brute force all letters that could be removed.", "Use a frequency array of size 26." ]
{ "canonical_parameter_names": [ "word" ], "leetcode_dataset_entry_point": "Solution().equalFrequency", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:14", "tests_total": 74, "tests_d...
cpp
{ "raw_signature": "bool equalFrequency(string word) {", "container": "Solution", "callable": "equalFrequency", "parameters": [ { "name": "word", "type": "string" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,425
bitwise-xor-of-all-pairings
Medium
You are given two 0-indexed arrays, nums1 and nums2, consisting of non-negative integers. Let there be another array, nums3, which contains the bitwise XOR of all pairings of integers between nums1 and nums2 (every integer in nums1 is paired with every integer in nums2 exactly once). Return the bitwise XOR of all inte...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [8, 16, 24, 32],nums2 = [4, 8, 12, 16, 20]) == 32\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1]) == 11\n assert candidate(nums1 = [2, 1, 3],nums2 = [10, 2, 5, 0]) == 13\n assert candidate(nums1 =...
[ "[2,1,3]\n[10,2,5,0]", "[1,2]\n[3,4]" ]
[ "Think how the count of each individual integer affects the final answer.", "If the length of nums1 is m and the length of nums2 is n, then each number in nums1 is repeated n times and each number in nums2 is repeated m times." ]
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().xorAllNums", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:17", "tests_total": 102,...
cpp
{ "raw_signature": "int xorAllNums(vector<int>& nums1, vector<int>& nums2) {", "container": "Solution", "callable": "xorAllNums", "parameters": [ { "name": "nums1", "type": "vector<int>&" }, { "name": "nums2", "type": "vector<int>&" } ], "return_type": "int", "signa...
2,426
number-of-pairs-satisfying-inequality
Hard
You are given two 0-indexed integer arrays nums1 and nums2, each of size n, and an integer diff. Find the number of pairs (i, j) such that: - 0 <= i < j <= n - 1 and - nums1[i] - nums1[j] <= nums2[i] - nums2[j] + diff. Return the number of pairs that satisfy the conditions. Example 1: Input: nums1 = [3,2,5], nums2 ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [3, -1],nums2 = [-2, 2],diff = -1) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],diff = 0) == 10\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5],diff = 50) == 10\n assert...
[ "[3,2,5]\n[2,2,1]\n1", "[3,-1]\n[-2,2]\n-1" ]
[ "Try rearranging the equation.", "Once the equation is rearranged properly, think how a segment tree or a Fenwick tree can be used to solve the rearranged equation.", "Iterate through the array backwards." ]
{ "canonical_parameter_names": [ "nums1", "nums2", "diff" ], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:20", "tes...
cpp
{ "raw_signature": "long long numberOfPairs(vector<int>& nums1, vector<int>& nums2, int diff) {", "container": "Solution", "callable": "numberOfPairs", "parameters": [ { "name": "nums1", "type": "vector<int>&" }, { "name": "nums2", "type": "vector<int>&" }, { "n...
2,427
number-of-common-factors
Easy
Given two positive integers a and b, return the number of common factors of a and b. An integer x is a common factor of a and b if x divides both a and b. Example 1: Input: a = 12, b = 6 Output: 4 Explanation: The common factors of 12 and 6 are 1, 2, 3, 6. Example 2: Input: a = 25, b = 30 Output: 2 Explanation: Th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(a = 7,b = 13) == 1\n assert candidate(a = 500,b = 500) == 12\n assert candidate(a = 42,b = 56) == 4\n assert candidate(a = 999,b = 1000) == 1\n assert candidate(a = 77,b = 14) == 2\n assert candidate(a = 98,b = 42) == 4\n ...
[ "12\n6", "25\n30" ]
[ "For each integer in range [1,1000], check if it’s divisible by both A and B." ]
{ "canonical_parameter_names": [ "a", "b" ], "leetcode_dataset_entry_point": "Solution().commonFactors", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:22", "tests_total": 107, "t...
cpp
{ "raw_signature": "int commonFactors(int a, int b) {", "container": "Solution", "callable": "commonFactors", "parameters": [ { "name": "a", "type": "int" }, { "name": "b", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type...
2,428
maximum-sum-of-an-hourglass
Medium
You are given an m x n integer matrix grid. We define an hourglass as a part of the matrix with the following form: Return the maximum sum of the elements of an hourglass. Note that an hourglass cannot be rotated and must be entirely contained within the matrix. Example 1: Input: grid = [[6,2,1,3],[4,2,1,5],[9,2,8...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[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]]) == 133\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 1\n assert candidate(grid = [[1000000, 1000000, 10...
[ "[[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]]", "[[1,2,3],[4,5,6],[7,8,9]]" ]
[ "Each 3x3 submatrix has exactly one hourglass.", "Find the sum of each hourglass in the matrix and return the largest of these values." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().maxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:24", "tests_total": 65, "tests_dropped":...
cpp
{ "raw_signature": "int maxSum(vector<vector<int>>& grid) {", "container": "Solution", "callable": "maxSum", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
2,429
minimize-xor
Medium
Given two positive integers num1 and num2, find the positive integer x such that: - x has the same number of set bits as num2, and - The value x XOR num1 is minimal. Note that XOR is the bitwise XOR operation. Return the integer x. The test cases are generated such that x is uniquely determined. The number of set b...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num1 = 1,num2 = 12) == 3\n assert candidate(num1 = 8,num2 = 3) == 9\n assert candidate(num1 = 29,num2 = 15) == 29\n assert candidate(num1 = 3,num2 = 5) == 3\n assert candidate(num1 = 7,num2 = 10) == 6\n assert candidate(nu...
[ "3\n5", "1\n12" ]
[ "To arrive at a small xor, try to turn off some bits from num1", "If there are still left bits to set, try to set them from the least significant bit" ]
{ "canonical_parameter_names": [ "num1", "num2" ], "leetcode_dataset_entry_point": "Solution().minimizeXor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:26", "tests_total": 85, ...
cpp
{ "raw_signature": "int minimizeXor(int num1, int num2) {", "container": "Solution", "callable": "minimizeXor", "parameters": [ { "name": "num1", "type": "int" }, { "name": "num2", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets",...
2,430
maximum-deletions-on-a-string
Hard
You are given a string s consisting of only lowercase English letters. In one operation, you can: - Delete the entire string s, or - Delete the first i letters of s if the first i letters of s are equal to the following i letters in s, for any i in the range 1 <= i <= s.length / 2. For example, if s = "ababc", then i...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abababababababababababababababababababababababababababababababababababababababababababababababab\") == 48\n assert candidate(s = \"aaabaab\") == 4\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...
[ "\"abcabcdabc\"", "\"aaabaab\"", "\"aaaaa\"" ]
[ "We can use dynamic programming to find the answer. Create a 0-indexed dp array where dp[i] represents the maximum number of moves needed to remove the first i + 1 letters from s.", "What should we do if there is an i where it is impossible to remove the first i + 1 letters?", "Use a sentinel value such as -1 t...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().deleteString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:28", "tests_total": 103, "tests_dropp...
cpp
{ "raw_signature": "int deleteString(string s) {", "container": "Solution", "callable": "deleteString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,432
the-employee-that-worked-on-the-longest-task
Easy
There are n employees, each with a unique id from 0 to n - 1. You are given a 2D integer array logs where logs[i] = [id_i, leaveTime_i] where: - id_i is the id of the employee that worked on the i^th task, and - leaveTime_i is the time at which the employee finished the i^th task. All the values leaveTime_i are uniqu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,logs = [[0, 1], [2, 2], [1, 3], [3, 4]]) == 0\n assert candidate(n = 2,logs = [[0, 10], [1, 20]]) == 0\n assert candidate(n = 6,logs = [[0, 2], [1, 6], [2, 10], [3, 14], [4, 18], [5, 22]]) == 1\n assert candidate(n = 5,log...
[ "10\n[[0,3],[2,5],[0,9],[1,15]]", "26\n[[1,1],[3,7],[2,12],[7,17]]", "2\n[[0,10],[1,20]]" ]
[ "Find the time of the longest task", "Store each employee’s longest task time in a hash table", "For employees that have the same longest task time, we only need the employee with the smallest ID" ]
{ "canonical_parameter_names": [ "n", "logs" ], "leetcode_dataset_entry_point": "Solution().hardestWorker", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:33", "tests_total": 99, ...
cpp
{ "raw_signature": "int hardestWorker(int n, vector<vector<int>>& logs) {", "container": "Solution", "callable": "hardestWorker", "parameters": [ { "name": "n", "type": "int" }, { "name": "logs", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_s...
2,433
find-the-original-array-of-prefix-xor
Medium
You are given an integer array pref of size n. Find and return the array arr of size n that satisfies: - pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]. Note that ^ denotes the bitwise-xor operation. It can be proven that the answer is unique. Example 1: Input: pref = [5,2,0,3,1] Output: [5,7,2,3,2] Explanation: From th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(pref = [5, 2, 0, 3, 1]) == [5, 7, 2, 3, 2]\n assert candidate(pref = [0, 0, 0, 0, 0]) == [0, 0, 0, 0, 0]\n assert candidate(pref = [0, 1, 2, 3, 4]) == [0, 1, 3, 1, 7]\n assert candidate(pref = [10, 4, 6, 3, 5]) == [10, 14, 2, 5,...
[ "[5,2,0,3,1]", "[13]" ]
[ "Consider the following equation: x ^ a = b. How can you find x?", "Notice that arr[i] ^ pref[i-1] = pref[i]. This is the same as the previous equation." ]
{ "canonical_parameter_names": [ "pref" ], "leetcode_dataset_entry_point": "Solution().findArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:35", "tests_total": 98, "tests_droppe...
cpp
{ "raw_signature": "vector<int> findArray(vector<int>& pref) {", "container": "Solution", "callable": "findArray", "parameters": [ { "name": "pref", "type": "vector<int>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
2,434
using-a-robot-to-print-the-lexicographically-smallest-string
Medium
You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty: - Remove the first character of a string s and give it to the robot. The robot will append this character to the string t. - Remove the last character of a string t and give ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbcc\") == \"aabbcc\"\n assert candidate(s = \"bdda\") == \"addb\"\n assert candidate(s = \"cba\") == \"abc\"\n assert candidate(s = \"bac\") == \"abc\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcd...
[ "\"zza\"", "\"bac\"", "\"bdda\"" ]
[ "If there are some character “a” ’ s in the string, they can be written on paper before anything else.", "Every character in the string before the last “a” should be written in reversed order.", "After the robot writes every “a” on paper, the same holds for other characters “b”, ”c”, …etc." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().robotWithString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:38", "tests_total": 61, "tests_dro...
cpp
{ "raw_signature": "string robotWithString(string s) {", "container": "Solution", "callable": "robotWithString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,435
paths-in-matrix-whose-sum-is-divisible-by-k
Hard
You are given a 0-indexed m x n integer matrix grid and an integer k. You are currently at position (0, 0) and you want to reach position (m - 1, n - 1) moving only down or right. Return the number of paths where the sum of the elements on the path is divisible by k. Since the answer may be very large, return it modul...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[10, 10, 10], [10, 10, 10], [10, 10, 10]],k = 5) == 6\n assert candidate(grid = [[100, 100], [100, 100]],k = 5) == 2\n assert candidate(grid = [[1, 2, 3], [4, 5, 6]],k = 2) == 3\n assert candidate(grid = [[7, 3, 4, 9], [...
[ "[[5,2,4],[3,0,5],[0,7,2]]\n3", "[[0,0]]\n5", "[[7,3,4,9],[2,3,6,2],[2,3,7,0]]\n1" ]
[ "The actual numbers in grid do not matter. What matters are the remainders you get when you divide the numbers by k.", "We can use dynamic programming to solve this problem. What can we use as states?", "Let dp[i][j][value] represent the number of paths where the sum of the elements on the path has a remainder ...
{ "canonical_parameter_names": [ "grid", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:40", "tests_total": 74, ...
cpp
{ "raw_signature": "int numberOfPaths(vector<vector<int>>& grid, int k) {", "container": "Solution", "callable": "numberOfPaths", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_s...
2,437
number-of-valid-clock-times
Easy
You are given a string of length 5 called time, representing the current time on a digital clock in the format "hh:mm". The earliest possible time is "00:00" and the latest possible time is "23:59". In the string time, the digits represented by the ? symbol are unknown, and must be replaced with a digit from 0 to 9. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(time = \"23:?0\") == 6\n assert candidate(time = \"23:5?\") == 10\n assert candidate(time = \"09:5?\") == 10\n assert candidate(time = \"23:?9\") == 6\n assert candidate(time = \"1?:?0\") == 60\n assert candidate(time = \"...
[ "\"?5:00\"", "\"0?:0?\"", "\"??:??\"" ]
[ "Brute force all possible clock times.", "Checking if a clock time is valid can be done with Regex." ]
{ "canonical_parameter_names": [ "time" ], "leetcode_dataset_entry_point": "Solution().countTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:44", "tests_total": 114, "tests_dropp...
cpp
{ "raw_signature": "int countTime(string time) {", "container": "Solution", "callable": "countTime", "parameters": [ { "name": "time", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,438
range-product-queries-of-powers
Medium
Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in non-decreasing order, and there is only one way to form the array. You are also given a 0-indexed 2D integer array queries, where queries[i] = [left_i, right_i]....
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 10,queries = [[0, 0], [1, 1], [0, 2]]) == [2, 8, 16]\n assert candidate(n = 1023,queries = [[0, 9], [3, 5]]) == [371842544, 4096]\n assert candidate(n = 1023,queries = [[0, 9], [4, 5], [2, 8]]) == [371842544, 512, 359738130]\n ...
[ "15\n[[0,1],[2,2],[0,3]]", "2\n[[0,0]]" ]
[ "The powers array can be created using the binary representation of n.", "Once powers is formed, the products can be taken using brute force." ]
{ "canonical_parameter_names": [ "n", "queries" ], "leetcode_dataset_entry_point": "Solution().productQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:47", "tests_total": 90...
cpp
{ "raw_signature": "vector<int> productQueries(int n, vector<vector<int>>& queries) {", "container": "Solution", "callable": "productQueries", "parameters": [ { "name": "n", "type": "int" }, { "name": "queries", "type": "vector<vector<int>>&" } ], "return_type": "vect...
2,439
minimize-maximum-of-array
Medium
You are given a 0-indexed array nums comprising of n non-negative integers. In one operation, you must: - Choose an integer i such that 1 <= i < n and nums[i] > 0. - Decrease nums[i] by 1. - Increase nums[i - 1] by 1. Return the minimum possible value of the maximum integer of nums after performing any number of ope...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 9, 1, 9, 1]) == 5\n assert candidate(nums = [1, 1000000000]) == 500000001\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [9, 7, 5, 3, 1]...
[ "[3,7,1,6]", "[10,1]" ]
[ "Try a binary search approach.", "Perform a binary search over the minimum value that can be achieved for the maximum number of the array.", "In each binary search iteration, iterate through the array backwards, greedily decreasing the current element until it is within the limit." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimizeArrayValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:49", "tests_total": 114, "te...
cpp
{ "raw_signature": "int minimizeArrayValue(vector<int>& nums) {", "container": "Solution", "callable": "minimizeArrayValue", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeS...
2,440
create-components-with-same-value
Hard
There is an undirected tree with n nodes labeled from 0 to n - 1. You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the i^th node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10],edges = [[0, 1], [1, 2], [2, 3]]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5]]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2]...
[ "[6,2,2,2,6]\n[[0,1],[1,2],[1,3],[3,4]]", "[2]\n[]" ]
[ "Consider all divisors of the sum of values." ]
{ "canonical_parameter_names": [ "nums", "edges" ], "leetcode_dataset_entry_point": "Solution().componentValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:51", "tests_total": 4...
cpp
{ "raw_signature": "int componentValue(vector<int>& nums, vector<vector<int>>& edges) {", "container": "Solution", "callable": "componentValue", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "edges", "type": "vector<vector<int>>&" } ], "return_...
2,441
largest-positive-integer-that-exists-with-its-negative
Easy
Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array. Return the positive integer k. If there is no such integer, return -1. Example 1: Input: nums = [-1,2,-3,3] Output: 3 Explanation: 3 is the only valid k we can find in the array. E...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, -4, -3, -2]) == 4\n assert candidate(nums = [1000, -1000, 500, -500, 250, -250, 125, -125]) == 1000\n assert candidate(nums = [5, 4, 3, 2, 1, -1]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, -5, -4, -3,...
[ "[-1,2,-3,3]", "[-1,10,6,7,-7,1]", "[-10,8,6,7,-2,-3]" ]
[ "What data structure can help you to determine if an element exists?", "Would a hash table help?" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findMaxK", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:54", "tests_total": 116, "tests_droppe...
cpp
{ "raw_signature": "int findMaxK(vector<int>& nums) {", "container": "Solution", "callable": "findMaxK", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,442
count-number-of-distinct-integers-after-reverse-operations
Medium
You are given an array nums consisting of positive integers. You have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers in nums. Return the number of distinct integers in the final array. Example 1: Input: nums = [1,13...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 2]) == 1\n assert candidate(nums = [123, 321, 111, 222]) == 4\n assert candidate(nums = [100, 200, 300, 400]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [9, 99, 99...
[ "[1,13,10,12,31]", "[2,2,2]" ]
[ "What data structure allows us to insert numbers and find the number of distinct numbers in it?", "Try using a set, insert all the numbers and their reverse into it, and return its size." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countDistinctIntegers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:56", "tests_total": 103, ...
cpp
{ "raw_signature": "int countDistinctIntegers(vector<int>& nums) {", "container": "Solution", "callable": "countDistinctIntegers", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode...
2,443
sum-of-number-and-its-reverse
Medium
Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise. Example 1: Input: num = 443 Output: true Explanation: 172 + 271 = 443 so we return true. Example 2: Input: num = 63 Output: false Explanation: 63 cannot be expressed as t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = 443) == True\n assert candidate(num = 181) == True\n assert candidate(num = 99999) == False\n assert candidate(num = 1001) == True\n assert candidate(num = 0) == True\n assert candidate(num = 63) == False\n assert...
[ "443", "63", "181" ]
[ "The constraints are small enough that we can check every number.", "To reverse a number, first convert it to a string. Then, create a new string that is the reverse of the first one. Finally, convert the new string back into a number." ]
{ "canonical_parameter_names": [ "num" ], "leetcode_dataset_entry_point": "Solution().sumOfNumberAndReverse", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:58", "tests_total": 177, "...
cpp
{ "raw_signature": "bool sumOfNumberAndReverse(int num) {", "container": "Solution", "callable": "sumOfNumberAndReverse", "parameters": [ { "name": "num", "type": "int" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,444
count-subarrays-with-fixed-bounds
Hard
You are given an integer array nums and two integers minK and maxK. A fixed-bound subarray of nums is a subarray that satisfies the following conditions: - The minimum value in the subarray is equal to minK. - The maximum value in the subarray is equal to maxK. Return the number of fixed-bound subarrays. A subarray...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],minK = 3,maxK = 7) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],minK = 3,maxK = 7) == 1\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5],minK = 2,maxK = 4) == 4\n assert ca...
[ "[1,3,5,2,7,5]\n1\n5", "[1,1,1,1]\n1\n1" ]
[ "Can you solve the problem if all the numbers in the array were between minK and maxK inclusive?", "Think of the inclusion-exclusion principle.", "Divide the array into multiple subarrays such that each number in each subarray is between minK and maxK inclusive, solve the previous problem for each subarray, and...
{ "canonical_parameter_names": [ "nums", "minK", "maxK" ], "leetcode_dataset_entry_point": "Solution().countSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:00", "test...
cpp
{ "raw_signature": "long long countSubarrays(vector<int>& nums, int minK, int maxK) {", "container": "Solution", "callable": "countSubarrays", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "minK", "type": "int" }, { "name": "maxK", ...
2,446
determine-if-two-events-have-conflict
Easy
You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where: - event1 = [startTime_1, endTime_1] and - event2 = [startTime_2, endTime_2]. Event times are valid 24 hours format in the form of HH:MM. A conflict happens when two events have some non-em...
{ "language": "python", "source": "def check(candidate):\n assert candidate(event1 = ['10:00', '11:00'],event2 = ['14:00', '15:00']) == False\n assert candidate(event1 = ['00:00', '23:59'],event2 = ['12:00', '12:01']) == True\n assert candidate(event1 = ['00:00', '23:59'],event2 = ['12:00', '12:00']) == Tr...
[ "[\"01:15\",\"02:00\"]\n[\"02:00\",\"03:00\"]", "[\"01:00\",\"02:00\"]\n[\"01:20\",\"03:00\"]", "[\"10:00\",\"11:00\"]\n[\"14:00\",\"15:00\"]" ]
[ "Parse time format to some integer interval first", "How would you determine if two intervals overlap?" ]
{ "canonical_parameter_names": [ "event1", "event2" ], "leetcode_dataset_entry_point": "Solution().haveConflict", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:05", "tests_total": ...
cpp
{ "raw_signature": "bool haveConflict(vector<string>& event1, vector<string>& event2) {", "container": "Solution", "callable": "haveConflict", "parameters": [ { "name": "event1", "type": "vector<string>&" }, { "name": "event2", "type": "vector<string>&" } ], "return_t...
2,447
number-of-subarrays-with-gcd-equal-to-k
Medium
Given an integer array nums and an integer k, return the number of subarrays of nums where the greatest common divisor of the subarray's elements is k. A subarray is a contiguous non-empty sequence of elements within an array. The greatest common divisor of an array is the largest integer that evenly divides all the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 11\n assert candidate(nums = [7, 14, 21, 28, 35],k = 7) == 11\n assert candidate(nums = [5, 10, 15, 20, 25],k = 5) == 11\n assert candidate(nums = [9, 3, 1, 2, 6, 3],k = 3) == 4\n assert...
[ "[9,3,1,2,6,3]\n3", "[4]\n7" ]
[ "The constraints on nums.length are small. It is possible to check every subarray.", "To calculate GCD, you can use a built-in function or the Euclidean Algorithm." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().subarrayGCD", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:07", "tests_total": 124, "...
cpp
{ "raw_signature": "int subarrayGCD(vector<int>& nums, int k) {", "container": "Solution", "callable": "subarrayGCD", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/co...
2,448
minimum-cost-to-make-array-equal
Hard
You are given two 0-indexed arrays nums and cost consisting each of n positive integers. You can do the following operation any number of times: - Increase or decrease any element of the array nums by 1. The cost of doing one operation on the i^th element is cost[i]. Return the minimum total cost such that all the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [6, 1, 3, 9, 3],cost = [2, 1, 2, 1, 2]) == 14\n assert candidate(nums = [1, 3, 5, 2],cost = [2, 3, 1, 14]) == 8\n assert candidate(nums = [2, 2, 2, 2, 2],cost = [4, 2, 8, 1, 3]) == 0\n assert candidate(nums = [6, 1, 9],co...
[ "[1,3,5,2]\n[2,3,1,14]", "[2,2,2,2,2]\n[4,2,8,1,3]" ]
[ "Changing the elements into one of the numbers already existing in the array nums is optimal.", "Try finding the cost of changing the array into each element, and return the minimum value." ]
{ "canonical_parameter_names": [ "nums", "cost" ], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:10", "tests_total": 109, "t...
cpp
{ "raw_signature": "long long minCost(vector<int>& nums, vector<int>& cost) {", "container": "Solution", "callable": "minCost", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "cost", "type": "vector<int>&" } ], "return_type": "long long", "sig...
2,449
minimum-number-of-operations-to-make-arrays-similar
Hard
You are given two positive integer arrays nums and target, of the same length. In one operation, you can choose any two distinct indices i and j where 0 <= i, j < nums.length and: - set nums[i] = nums[i] + 2 and - set nums[j] = nums[j] - 2. Two arrays are considered to be similar if the frequency of each element is ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 3, 3, 3],target = [1, 5, 1, 5]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1],target = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [3, 3, 3, 3],target = [5, 1, 5, 1]) == 2\n assert candidate(nums = [100000, 50000...
[ "[8,12,6]\n[2,14,10]", "[1,2,5]\n[4,1,3]", "[1,1,1,1,1]\n[1,1,1,1,1]" ]
[ "Solve for even and odd numbers separately.", "Greedily match smallest even element from nums to smallest even element from target, then similarly next smallest element and so on.", "Similarly, match odd elements too." ]
{ "canonical_parameter_names": [ "nums", "target" ], "leetcode_dataset_entry_point": "Solution().makeSimilar", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:12", "tests_total": 107...
cpp
{ "raw_signature": "long long makeSimilar(vector<int>& nums, vector<int>& target) {", "container": "Solution", "callable": "makeSimilar", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "target", "type": "vector<int>&" } ], "return_type": "long l...
2,451
odd-string-difference
Easy
You are given an array of equal-length strings words. Assume that the length of each string is n. Each string words[i] can be converted into a difference integer array difference[i] of length n - 1 where difference[i][j] = words[i][j+1] - words[i][j] where 0 <= j <= n - 2. Note that the difference between two letters ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['adc', 'wzy', 'abc']) == \"abc\"\n assert candidate(words = ['zzz', 'zyx', 'zwy', 'zvx']) == \"zzz\"\n assert candidate(words = ['zzz', 'zyz', 'zxz', 'wyz']) == \"zzz\"\n assert candidate(words = ['aaa', 'bob', 'ccc', '...
[ "[\"adc\",\"wzy\",\"abc\"]", "[\"aaa\",\"bob\",\"ccc\",\"ddd\"]" ]
[ "Find the difference integer array for each string.", "Compare them to find the odd one out." ]
{ "canonical_parameter_names": [ "words" ], "leetcode_dataset_entry_point": "Solution().oddString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:17", "tests_total": 80, "tests_dropp...
cpp
{ "raw_signature": "string oddString(vector<string>& words) {", "container": "Solution", "callable": "oddString", "parameters": [ { "name": "words", "type": "vector<string>&" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnipp...
2,452
words-within-two-edits-of-dictionary
Medium
You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length. In one edit you can take a word from queries, and change any letter in it to any other letter. Find all words from queries that, after a maximum of two edits, equal some word...
{ "language": "python", "source": "def check(candidate):\n assert candidate(queries = ['test', 'text', 'sett'],dictionary = ['test', 'text', 'sett', 'best']) == ['test', 'text', 'sett']\n assert candidate(queries = ['abc', 'bcd', 'cde'],dictionary = ['xyz', 'zyx', 'abc']) == ['abc']\n assert candidate(quer...
[ "[\"word\",\"note\",\"ants\",\"wood\"]\n[\"wood\",\"joke\",\"moat\"]", "[\"yes\"]\n[\"not\"]" ]
[ "Try brute-forcing the problem.", "For each word in queries, try comparing to each word in dictionary.", "If there is a maximum of two edit differences, the word should be present in answer." ]
{ "canonical_parameter_names": [ "queries", "dictionary" ], "leetcode_dataset_entry_point": "Solution().twoEditWords", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:19", "tests_tot...
cpp
{ "raw_signature": "vector<string> twoEditWords(vector<string>& queries, vector<string>& dictionary) {", "container": "Solution", "callable": "twoEditWords", "parameters": [ { "name": "queries", "type": "vector<string>&" }, { "name": "dictionary", "type": "vector<string>&" ...
2,453
destroy-sequential-targets
Medium
You are given a 0-indexed array nums consisting of positive integers, representing targets on a number line. You are also given an integer space. You have a machine which can destroy targets. Seeding the machine with some nums[i] allows it to destroy all targets with values that can be represented as nums[i] + c * spa...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000000],space = 1000000000) == 1000000000\n assert candidate(nums = [1, 3, 5, 2, 4, 6],space = 2) == 1\n assert candidate(nums = [6, 2, 5],space = 100) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],s...
[ "[3,7,8,1,1,5]\n2", "[1,3,5,2,4,6]\n2", "[6,2,5]\n100" ]
[ "Keep track of nums[i] modulo k.", "Iterate over nums in sorted order." ]
{ "canonical_parameter_names": [ "nums", "space" ], "leetcode_dataset_entry_point": "Solution().destroyTargets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:21", "tests_total": 1...
cpp
{ "raw_signature": "int destroyTargets(vector<int>& nums, int space) {", "container": "Solution", "callable": "destroyTargets", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "space", "type": "int" } ], "return_type": "int", "signature_source"...
2,454
next-greater-element-iv
Hard
You are given a 0-indexed array of non-negative integers nums. For each integer in nums, you must find its respective second greater integer. The second greater integer of nums[i] is nums[j] such that: - j > i - nums[j] > nums[i] - There exists exactly one index k such that nums[k] > nums[i] and i < k < j. If there ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == [2, 5, 3, 6, 4, 7, 5, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 5]) == [2, 5, 5, -1, -1]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [-1, -1, -1, -1, -1, -1, -1, -...
[ "[2,4,0,9,6]", "[3,3]" ]
[ "Move forward in nums and store the value in a non-increasing stack for the first greater value.", "Move the value in the stack to an ordered data structure for the second greater value.", "Move value from the ordered data structure for the answer." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().secondGreaterElement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:24", "tests_total": 224, "...
cpp
{ "raw_signature": "vector<int> secondGreaterElement(vector<int>& nums) {", "container": "Solution", "callable": "secondGreaterElement", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_sour...
2,455
average-value-of-even-numbers-that-are-divisible-by-three
Easy
Given an integer array nums of positive integers, return the average value of all even integers that are divisible by 3. Note that the average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer. Example 1: Input: nums = [1,3,6,10,12,15] Output: 9 Explanation: 6 and 12 are...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == 18\n assert candidate(nums = [3, 9, 15, 21, 27, 33]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12]) == 9\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44,...
[ "[1,3,6,10,12,15]", "[1,2,4,7,10]" ]
[ "What is the property of a number if it is divisible by both 2 and 3 at the same time?", "It is equivalent to finding all the numbers that are divisible by 6." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().averageValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:26", "tests_total": 124, "tests_dr...
cpp
{ "raw_signature": "int averageValue(vector<int>& nums) {", "container": "Solution", "callable": "averageValue", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,456
most-popular-video-creator
Medium
You are given two string arrays creators and ids, and an integer array views, all of length n. The i^th video on a platform was created by creators[i], has an id of ids[i], and has views[i] views. The popularity of a creator is the sum of the number of views on all of the creator's videos. Find the creator with the hi...
{ "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 ...
[ "[\"alice\",\"bob\",\"alice\",\"chris\"]\n[\"one\",\"two\",\"three\",\"four\"]\n[5,10,5,4]", "[\"alice\",\"alice\",\"alice\"]\n[\"a\",\"b\",\"c\"]\n[1,2,2]" ]
[ "Use a hash table to store and categorize videos based on their creator.", "For each creator, iterate through all their videos and use three variables to keep track of their popularity, their most popular video, and the id of their most popular video." ]
{ "canonical_parameter_names": [ "creators", "ids", "views" ], "leetcode_dataset_entry_point": "Solution().mostPopularCreator", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:29",...
cpp
{ "raw_signature": "vector<vector<string>> mostPopularCreator(vector<string>& creators, vector<string>& ids, vector<int>& views) {", "container": "Solution", "callable": "mostPopularCreator", "parameters": [ { "name": "creators", "type": "vector<string>&" }, { "name": "ids", ...
2,457
minimum-addition-to-make-integer-beautiful
Medium
You are given two positive integers n and target. An integer is considered beautiful if the sum of its digits is less than or equal to target. Return the minimum non-negative integer x such that n + x is beautiful. The input will be generated such that it is always possible to make n beautiful. Example 1: Input: n ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 1000000000000,target = 1) == 0\n assert candidate(n = 1,target = 1) == 0\n assert candidate(n = 99999,target = 5) == 1\n assert candidate(n = 8888,target = 32) == 0\n assert candidate(n = 888888888,target = 24) == 1111112...
[ "16\n6", "467\n6", "1\n1" ]
[ "Think about each digit independently.", "Turn the rightmost non-zero digit to zero until the digit sum is greater than target." ]
{ "canonical_parameter_names": [ "n", "target" ], "leetcode_dataset_entry_point": "Solution().makeIntegerBeautiful", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:31", "tests_total...
cpp
{ "raw_signature": "long long makeIntegerBeautiful(long long n, int target) {", "container": "Solution", "callable": "makeIntegerBeautiful", "parameters": [ { "name": "n", "type": "long long" }, { "name": "target", "type": "int" } ], "return_type": "long long", "sig...
2,460
apply-operations-to-an-array
Easy
You are given a 0-indexed array nums of size n consisting of non-negative integers. You need to apply n - 1 operations to this array where, in the i^th operation (0-indexed), you will apply the following on the i^th element of nums: - If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Oth...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [6, 5, 4, 3, 2, 1]) == [6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1, 2, 3, 2, 3, 2]) == [1, 2, 3, 2, 3, 2]\n assert candidate(nums = [2, 2, 0, 0, 1, 1, 1]) == [4, 2, 1, 0, 0, 0, 0]\n assert candidate(nums = [10, 10, 0,...
[ "[1,2,2,1,1,0]", "[0,1]" ]
[ "Iterate over the array and simulate the described process." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().applyOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:38", "tests_total": 123, "tests...
cpp
{ "raw_signature": "vector<int> applyOperations(vector<int>& nums) {", "container": "Solution", "callable": "applyOperations", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_source": "leet...
2,461
maximum-sum-of-distinct-subarrays-with-length-k
Medium
You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions: - The length of the subarray is k, and - All the elements of the subarray are distinct. Return the maximum subarray sum of all the subarrays that meet the conditions. If...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 40\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 55\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 1) == 5\n assert candidate(nums = [1, 2,...
[ "[1,5,4,2,9,9,9]\n3", "[4,4,4]\n3" ]
[ "Which elements change when moving from the subarray of size k that ends at index i to the subarray of size k that ends at index i + 1?", "Only two elements change, the element at i + 1 is added into the subarray, and the element at i - k + 1 gets removed from the subarray.", "Iterate through each subarray of s...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumSubarraySum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:41", "tests_total": 1...
cpp
{ "raw_signature": "long long maximumSubarraySum(vector<int>& nums, int k) {", "container": "Solution", "callable": "maximumSubarraySum", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "long long", "signa...
2,462
total-cost-to-hire-k-workers
Medium
You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the i^th worker. You are also given two integers k and candidates. We want to hire exactly k workers according to the following rules: - You will run k sessions and hire exactly one worker in each session. - In each hiring session, cho...
{ "language": "python", "source": "def check(candidate):\n assert candidate(costs = [10, 10, 10, 10, 10],k = 4,candidates = 2) == 40\n assert candidate(costs = [10, 10, 10, 10, 10],k = 5,candidates = 5) == 50\n assert candidate(costs = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 5,candidates = 5) == 10\n assert ...
[ "[17,12,10,2,7,2,11,20,8]\n3\n4", "[1,2,4,1]\n3\n3" ]
[ "Maintain two minheaps: one for the left and one for the right.", "Compare the top element from two heaps and remove the appropriate one.", "Add a new element to the heap and maintain its size as k." ]
{ "canonical_parameter_names": [ "costs", "k", "candidates" ], "leetcode_dataset_entry_point": "Solution().totalCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:43", "tests...
cpp
{ "raw_signature": "long long totalCost(vector<int>& costs, int k, int candidates) {", "container": "Solution", "callable": "totalCost", "parameters": [ { "name": "costs", "type": "vector<int>&" }, { "name": "k", "type": "int" }, { "name": "candidates", "t...
2,463
minimum-total-distance-traveled
Hard
There are some robots and factories on the X-axis. You are given an integer array robot where robot[i] is the position of the i^th robot. You are also given a 2D integer array factory where factory[j] = [position_j, limit_j] indicates that position_j is the position of the j^th factory and that the j^th factory can rep...
{ "language": "python", "source": "def check(candidate):\n assert candidate(robot = [5, 1, 3],factory = [[2, 3]]) == 5\n assert candidate(robot = [5, 5, 5, 5],factory = [[5, 4]]) == 0\n assert candidate(robot = [-3, 0, 3],factory = [[-2, 1], [2, 1], [5, 2]]) == 5\n assert candidate(robot = [-1, -3, 2, 4...
[ "[0,4,6]\n[[2,2],[6,2]]", "[1,-1]\n[[-2,1],[2,1]]" ]
[ "Sort robots and factories by their positions.", "After sorting, notice that each factory should repair some subsegment of robots.", "Find the minimum total distance to repair first i robots with first j factories." ]
{ "canonical_parameter_names": [ "robot", "factory" ], "leetcode_dataset_entry_point": "Solution().minimumTotalDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:45", "tests_...
cpp
{ "raw_signature": "long long minimumTotalDistance(vector<int>& robot, vector<vector<int>>& factory) {", "container": "Solution", "callable": "minimumTotalDistance", "parameters": [ { "name": "robot", "type": "vector<int>&" }, { "name": "factory", "type": "vector<vector<int>>...
2,465
number-of-distinct-averages
Easy
You are given a 0-indexed integer array nums of even length. As long as nums is not empty, you must repetitively: - Find the minimum number in nums and remove it. - Find the maximum number in nums and remove it. - Calculate the average of the two removed numbers. The average of two numbers a and b is (a + b) / 2. -...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 1\n assert candidate(nums = [50, 50, 50, 50]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 2, 3, 4]) == 1\n assert candidate(nums = [0, 100, 5...
[ "[4,1,4,0,3,5]", "[1,100]" ]
[ "Try sorting the array.", "Store the averages being calculated, and find the distinct ones." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().distinctAverages", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:50", "tests_total": 113, "test...
cpp
{ "raw_signature": "int distinctAverages(vector<int>& nums) {", "container": "Solution", "callable": "distinctAverages", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnipp...
2,466
count-ways-to-build-good-strings
Medium
Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following: - Append the character '0' zero times. - Append the character '1' one times. This can be performed any number of times. A good string is a string constructed...
{ "language": "python", "source": "def check(candidate):\n assert candidate(low = 5,high = 7,zero = 1,one = 1) == 224\n assert candidate(low = 100,high = 200,zero = 10,one = 20) == 28513\n assert candidate(low = 5,high = 10,zero = 2,one = 4) == 16\n assert candidate(low = 10,high = 15,zero = 3,one = 2) ...
[ "3\n3\n1\n1", "2\n3\n1\n2" ]
[ "Calculate the number of good strings with length less or equal to some constant x.", "Apply dynamic programming using the group size of consecutive zeros and ones." ]
{ "canonical_parameter_names": [ "low", "high", "zero", "one" ], "leetcode_dataset_entry_point": "Solution().countGoodStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:...
cpp
{ "raw_signature": "int countGoodStrings(int low, int high, int zero, int one) {", "container": "Solution", "callable": "countGoodStrings", "parameters": [ { "name": "low", "type": "int" }, { "name": "high", "type": "int" }, { "name": "zero", "type": "int"...
2,467
most-profitable-path-in-a-tree
Medium
There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree. At every node i, there is a gate. You are also given an array of even integers am...
{ "language": "python", "source": "def check(candidate):\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],bob = 3,amount = [10, 10, 10, 10, 10, 10, 10]) == 30\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],bob = 5,amount = [100, -50, -25, 200, -300, 150]) == 250...
[ "[[0,1],[1,2],[1,3],[3,4]]\n3\n[-2,4,2,-4,6]", "[[0,1]]\n1\n[-7280,2350]" ]
[ "Bob travels along a fixed path (from node “bob” to node 0).", "Calculate Alice’s distance to each node via DFS.", "We can calculate Alice’s score along a path ending at some node easily using Hints 1 and 2." ]
{ "canonical_parameter_names": [ "edges", "bob", "amount" ], "leetcode_dataset_entry_point": "Solution().mostProfitablePath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:54", ...
cpp
{ "raw_signature": "int mostProfitablePath(vector<vector<int>>& edges, int bob, vector<int>& amount) {", "container": "Solution", "callable": "mostProfitablePath", "parameters": [ { "name": "edges", "type": "vector<vector<int>>&" }, { "name": "bob", "type": "int" }, {...
2,468
split-message-based-on-limit
Hard
You are given a string, message, and a positive integer, limit. You must split message into one or more parts based on limit. Each resulting part should have the suffix "<a/b>", where "b" is to be replaced with the total number of parts and "a" is to be replaced with the index of the part, starting from 1 and going up...
{ "language": "python", "source": "def check(candidate):\n assert candidate(message = \"abcdefghij\",limit = 3) == []\n assert candidate(message = \"abc\",limit = 5) == []\n assert candidate(message = \"short message\",limit = 15) == ['short mess<1/2>', 'age<2/2>']\n assert candidate(message = \"hello w...
[ "\"this is really a very awesome message\"\n9", "\"short message\"\n15" ]
[ "Could you solve the problem if you knew how many digits the total number of parts has?", "Try all possible lengths of the total number of parts, and see if the string can be split such that the total number of parts has that length.", "Binary search can be used for each part length to find the precise number o...
{ "canonical_parameter_names": [ "message", "limit" ], "leetcode_dataset_entry_point": "Solution().splitMessage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:57", "tests_total": ...
cpp
{ "raw_signature": "vector<string> splitMessage(string message, int limit) {", "container": "Solution", "callable": "splitMessage", "parameters": [ { "name": "message", "type": "string" }, { "name": "limit", "type": "int" } ], "return_type": "vector<string>", "signa...
2,469
convert-the-temperature
Easy
You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius. You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit]. Return the array ans. Answers within 10^-5 of the actual answer will be accepte...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat...
[ "36.50", "122.11" ]
[ "Implement formulas that are given in the statement." ]
{ "canonical_parameter_names": [ "celsius" ], "leetcode_dataset_entry_point": "Solution().convertTemperature", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:59", "tests_total": 39, "...
cpp
{ "raw_signature": "vector<double> convertTemperature(double celsius) {", "container": "Solution", "callable": "convertTemperature", "parameters": [ { "name": "celsius", "type": "double" } ], "return_type": "vector<double>", "signature_source": "leetcode/codeSnippets", "type_source":...
2,470
number-of-subarrays-with-lcm-equal-to-k
Medium
Given an integer array nums and an integer k, return the number of subarrays of nums where the least common multiple of the subarray's elements is k. A subarray is a contiguous non-empty sequence of elements within an array. The least common multiple of an array is the smallest positive integer that is divisible by a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7],k = 7) == 15\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 15\n assert candidate(nums = [7, 3, 9, 12, 15],k = 60) == 1\n assert candidate(nums = [3, 6, 2, 7, 1],k = 6) == 4\n assert candidate(nums...
[ "[3,6,2,7,1]\n6", "[3]\n2" ]
[ "The constraints on nums.length are small. It is possible to check every subarray.", "To calculate LCM, you can use a built-in function or the formula lcm(a, b) = a * b / gcd(a, b).", "As you calculate the LCM of more numbers, it can only become greater. Once it becomes greater than k, you know that any larger ...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().subarrayLCM", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:01", "tests_total": 128, "...
cpp
{ "raw_signature": "int subarrayLCM(vector<int>& nums, int k) {", "container": "Solution", "callable": "subarrayLCM", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/co...
2,472
maximum-number-of-non-overlapping-palindrome-substrings
Hard
You are given a string s and a positive integer k. Select a set of non-overlapping substrings from the string s that satisfy the following conditions: - The length of each substring is at least k. - Each substring is a palindrome. Return the maximum number of substrings in an optimal selection. A substring is a con...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"racecar\",k = 2) == 1\n assert candidate(s = \"mnoonm\",k = 2) == 1\n assert candidate(s = \"zzzzzz\",k = 1) == 6\n assert candidate(s = \"abcde\",k = 3) == 0\n assert candidate(s = \"abcdeedcba\",k = 2) == 1\n asser...
[ "\"abaccdbbd\"\n3", "\"adbcda\"\n2" ]
[ "Try to use dynamic programming to solve the problem.", "let dp[i] be the answer for the prefix s[0…i].", "The final answer to the problem will be dp[n-1]. How do you compute this dp?" ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().maxPalindromes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:06", "tests_total": 109, "...
cpp
{ "raw_signature": "int maxPalindromes(string s, int k) {", "container": "Solution", "callable": "maxPalindromes", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets",...
2,475
number-of-unequal-triplets-in-array
Easy
You are given a 0-indexed array of positive integers nums. Find the number of triplets (i, j, k) that meet the following conditions: - 0 <= i < j < k < nums.length - nums[i], nums[j], and nums[k] are pairwise distinct. - In other words, nums[i] != nums[j], nums[i] != nums[k], and nums[j] != nums[k]. Return the numb...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 20\n assert candidate(nums = [1, 2, 2, 3, 4]) == 7\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7]) == 96\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = ...
[ "[4,4,2,4,3]", "[1,1,1,1,1]" ]
[ "The constraints are very small. Can we try every triplet?", "Yes, we can. Use three loops to iterate through all the possible triplets, ensuring the condition i < j < k holds." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().unequalTriplets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:10", "tests_total": 74, "tests_...
cpp
{ "raw_signature": "int unequalTriplets(vector<int>& nums) {", "container": "Solution", "callable": "unequalTriplets", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
2,477
minimum-fuel-cost-to-report-to-the-capital
Medium
There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exactly n - 1 roads. The capital city is city 0. You are given a 2D integer array roads where roads[i] = [a_i, b_i] denotes that there exists a bidirectional road connecting...
{ "language": "python", "source": "def check(candidate):\n assert candidate(roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],seats = 4) == 6\n assert candidate(roads = [[0, 1], [0, 2], [0, 3]],seats = 5) == 3\n assert candidate(roads = [[0, 1], [1, 2], [2, 3], [3, 4]],seats = 3) == 5\n assert ca...
[ "[[0,1],[0,2],[0,3]]\n5", "[[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]]\n2", "[]\n1" ]
[ "Can you record the size of each subtree?", "If n people meet on the same node, what is the minimum number of cars needed?" ]
{ "canonical_parameter_names": [ "roads", "seats" ], "leetcode_dataset_entry_point": "Solution().minimumFuelCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:16", "tests_total":...
cpp
{ "raw_signature": "long long minimumFuelCost(vector<vector<int>>& roads, int seats) {", "container": "Solution", "callable": "minimumFuelCost", "parameters": [ { "name": "roads", "type": "vector<vector<int>>&" }, { "name": "seats", "type": "int" } ], "return_type": "...
2,478
number-of-beautiful-partitions
Hard
You are given a string s that consists of the digits '1' to '9' and two integers k and minLength. A partition of s is called beautiful if: - s is partitioned into k non-intersecting substrings. - Each substring has a length of at least minLength. - Each substring starts with a prime digit and ends with a non-prime di...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"52372938462673572\",k = 4,minLength = 2) == 0\n assert candidate(s = \"33333\",k = 1,minLength = 1) == 0\n assert candidate(s = \"23542185131\",k = 3,minLength = 3) == 1\n assert candidate(s = \"3312958\",k = 3,minLength =...
[ "\"23542185131\"\n3\n2", "\"23542185131\"\n3\n3", "\"3312958\"\n3\n1" ]
[ "Try using a greedy approach where you take as many digits as possible from the left of the string for each partition.", "You can also use a dynamic programming approach, let an array dp where dp[i] is the solution of the problem for the prefix of the string ending at index i, the answer of the problem will be dp...
{ "canonical_parameter_names": [ "s", "k", "minLength" ], "leetcode_dataset_entry_point": "Solution().beautifulPartitions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:18", "...
cpp
{ "raw_signature": "int beautifulPartitions(string s, int k, int minLength) {", "container": "Solution", "callable": "beautifulPartitions", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "int" }, { "name": "minLength", "type": "i...
2,481
minimum-cuts-to-divide-a-circle
Easy
A valid cut in a circle can be: - A cut that is represented by a straight line that touches two points on the edge of the circle and passes through its center, or - A cut that is represented by a straight line that touches one point on the edge of the circle and its center. Some valid and invalid cuts are shown in th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 3\n assert candidate(n = 100) == 50\n assert candidate(n = 4) == 2\n assert candidate(n = 99) == 99\n assert candidate(n = 17) == 17\n assert candidate(n = 2) == 1\n assert candidate(n = 1) == 0\n assert ca...
[ "4", "3" ]
[ "Think about odd and even values separately.", "When will we not have to cut the circle at all?" ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().numberOfCuts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:23", "tests_total": 44, "tests_droppe...
cpp
{ "raw_signature": "int numberOfCuts(int n) {", "container": "Solution", "callable": "numberOfCuts", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,482
difference-between-ones-and-zeros-in-row-and-column
Medium
You are given a 0-indexed m x n binary matrix grid. A 0-indexed m x n difference matrix diff is created with the following procedure: - Let the number of ones in the i^th row be onesRow_i. - Let the number of ones in the j^th column be onesCol_j. - Let the number of zeros in the i^th row be zerosRow_i. - Let the numb...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 0, 1, 0]]) == [[1, -1, 1, -1], [1, -1, 1, -1], [1, -1, 1, -1]]\n assert candidate(grid = [[0, 1, 1], [1, 0, 1], [0, 0, 1]]) == [[0, 0, 4], [0, 0, 4], [-2, -2, 2]]\n assert candidate(grid = [[...
[ "[[0,1,1],[1,0,1],[0,0,1]]", "[[1,1,1],[1,1,1]]" ]
[ "You need to reuse information about a row or a column many times. Try storing it to avoid computing it multiple times.", "Use an array to store the number of 1’s in each row and another array to store the number of 1’s in each column. Once you know the number of 1’s in each row or column, you can also easily cal...
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().onesMinusZeros", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:25", "tests_total": 67, "tests_d...
cpp
{ "raw_signature": "vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {", "container": "Solution", "callable": "onesMinusZeros", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "vector<vector<int>>", "signature_source": "leetcode/codeSni...
2,483
minimum-penalty-for-a-shop
Medium
You are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y': - if the i^th character is 'Y', it means that customers come at the i^th hour - whereas 'N' indicates that no customers come at the i^th hour. If the shop closes at the j^th hour (0 <=...
{ "language": "python", "source": "def check(candidate):\n assert candidate(customers = \"YNYNYN\") == 1\n assert candidate(customers = \"YNNYNYYNYN\") == 1\n assert candidate(customers = \"NNYNNYNNYNNYNN\") == 0\n assert candidate(customers = \"YYYYNNYYYYNNYYYYNNYYYYNNNN\") == 22\n assert candidate(...
[ "\"YYNY\"", "\"NNNNN\"", "\"YYYY\"" ]
[ "At any index, the penalty is the sum of prefix count of ‘N’ and suffix count of ‘Y’.", "Enumerate all indices and find the minimum such value." ]
{ "canonical_parameter_names": [ "customers" ], "leetcode_dataset_entry_point": "Solution().bestClosingTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:27", "tests_total": 152, "...
cpp
{ "raw_signature": "int bestClosingTime(string customers) {", "container": "Solution", "callable": "bestClosingTime", "parameters": [ { "name": "customers", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
2,484
count-palindromic-subsequences
Hard
Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 10^9 + 7. Note: - A string is palindromic if it reads the same forward and backward. - A subsequence is a string that can be derived from another string by deleting some...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"100100100\") == 34\n assert candidate(s = \"9876543210\") == 0\n assert candidate(s = \"54321012345\") == 30\n assert candidate(s = \"12345678900987654321\") == 240\n assert candidate(s = \"00000000000000000000\") == 15...
[ "\"103301\"", "\"0000000\"", "\"9999900000\"" ]
[ "There are 100 possibilities for the first two characters of the palindrome.", "Iterate over all characters, letting the current character be the center of the palindrome." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().countPalindromes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:30", "tests_total": 149, "tests_d...
cpp
{ "raw_signature": "int countPalindromes(string s) {", "container": "Solution", "callable": "countPalindromes", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }