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,485 | find-the-pivot-integer | Easy | Given a positive integer n, find the pivot integer x such that:
- The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively.
Return the pivot integer x. If no such integer exists, return -1. It is guaranteed that there will be at most one pivot index for the given ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 8) == 6\n assert candidate(n = 3) == -1\n assert candidate(n = 4) == -1\n assert candidate(n = 1) == 1\n assert candidate(n = 1000) == -1\n assert candidate(n = 10) == -1\n assert candidate(n = 625) == -1\n asser... | [
"8",
"1",
"4"
] | [
"Can you use brute force to check every number from 1 to n if any of them is the pivot integer?",
"If you know the sum of [1: pivot], how can you efficiently calculate the sum of the other parts?"
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().pivotInteger",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:54:32",
"tests_total": 52,
"tests_droppe... | cpp | {
"raw_signature": "int pivotInteger(int n) {",
"container": "Solution",
"callable": "pivotInteger",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,486 | append-characters-to-string-to-make-subsequence | Medium | You are given two strings s and t consisting of only lowercase English letters.
Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s.
A subsequence is a string that can be derived from another string by deleting some or no characters without changing th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcdefgh\",t = \"ghijkl\") == 4\n assert candidate(s = \"ababab\",t = \"bbba\") == 1\n assert candidate(s = \"abcd\",t = \"xyz\") == 3\n assert candidate(s = \"aaaa\",t = \"a\") == 0\n assert candidate(s = \"abcd\",t = ... | [
"\"coaching\"\n\"coding\"",
"\"abcde\"\n\"a\"",
"\"z\"\n\"abcde\""
] | [
"Find the longest prefix of t that is a subsequence of s.",
"Use two variables to keep track of your location in s and t. If the characters match, increment both variables. Otherwise, only increment the variable for s.",
"The remaining characters in t must be appended to the end of s."
] | {
"canonical_parameter_names": [
"s",
"t"
],
"leetcode_dataset_entry_point": "Solution().appendCharacters",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:54:34",
"tests_total": 153,
... | cpp | {
"raw_signature": "int appendCharacters(string s, string t) {",
"container": "Solution",
"callable": "appendCharacters",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "t",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/code... |
2,488 | count-subarrays-with-median-k | Hard | You are given an array nums of size n consisting of distinct integers from 1 to n and a positive integer k.
Return the number of non-empty subarrays in nums that have a median equal to k.
Note:
- The median of an array is the middle element after sorting the array in ascending order. If the array is of even length, ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 3, 1],k = 3) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 10\n assert candidate(nums = [5, 1, 4, 3, 2],k = 3) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6],k = 4) == 5\n assert candi... | [
"[3,2,1,4,5]\n4",
"[2,3,1]\n3"
] | [
"Consider changing the numbers that are strictly greater than k in the array to 1, the numbers that are strictly smaller than k to -1, and k to 0.",
"After the change, what property does a subarray with median k have in the new array?",
"An array with median k should have a sum equal to either 0 or 1 in the new... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().countSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:54:39",
"tests_total": 79,
... | cpp | {
"raw_signature": "int countSubarrays(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "countSubarrays",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetc... |
2,490 | circular-sentence | Easy | A sentence is a list of words that are separated by a single space with no leading or trailing spaces.
- For example, "Hello World", "HELLO", "hello world hello world" are all sentences.
Words consist of only uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different.
A... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(sentence = \"sentence ence sent\") == False\n assert candidate(sentence = \"hello olleh\") == True\n assert candidate(sentence = \"Aa Aa\") == False\n assert candidate(sentence = \"ab ba\") == True\n assert candidate(sentence... | [
"\"leetcode exercises sound delightful\"",
"\"eetcode\"",
"\"Leetcode is cool\""
] | [
"Check the character before the empty space and the character after the empty space.",
"Check the first character and the last character of the sentence."
] | {
"canonical_parameter_names": [
"sentence"
],
"leetcode_dataset_entry_point": "Solution().isCircularSentence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:54:44",
"tests_total": 220,
... | cpp | {
"raw_signature": "bool isCircularSentence(string sentence) {",
"container": "Solution",
"callable": "isCircularSentence",
"parameters": [
{
"name": "sentence",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
2,491 | divide-players-into-teams-of-equal-skill | Medium | You are given a positive integer array skill of even length n where skill[i] denotes the skill of the i^th player. Divide the players into n / 2 teams of size 2 such that the total skill of each team is equal.
The chemistry of a team is equal to the product of the skills of the players on that team.
Return the sum of... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(skill = [1, 1000, 1, 1000, 1, 1000, 1, 1000]) == 4000\n assert candidate(skill = [1, 1, 2, 2, 3, 3, 4, 4]) == 20\n assert candidate(skill = [1, 1, 2, 3]) == -1\n assert candidate(skill = [1, 2, 3, 4, 5, 6, 7, 8]) == 60\n asse... | [
"[3,2,5,1,3,4]",
"[3,4]",
"[1,1,2,3]"
] | [
"Try sorting the skill array.",
"It is always optimal to pair the weakest available player with the strongest available player."
] | {
"canonical_parameter_names": [
"skill"
],
"leetcode_dataset_entry_point": "Solution().dividePlayers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:54:46",
"tests_total": 122,
"tests_... | cpp | {
"raw_signature": "long long dividePlayers(vector<int>& skill) {",
"container": "Solution",
"callable": "dividePlayers",
"parameters": [
{
"name": "skill",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
2,492 | minimum-score-of-a-path-between-two-cities | Medium | You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [a_i, b_i, distance_i] indicates that there is a bidirectional road between cities a_i and b_i with a distance equal to distance_i. The cities graph is not necessarily connected.
The scor... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,roads = [[1, 2, 10], [2, 3, 15], [3, 4, 20], [4, 5, 25], [1, 5, 30]]) == 10\n assert candidate(n = 6,roads = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 5]]) == 1\n assert candidate(n = 4,roads = [[1, 2, 2], [1, 3, 4]... | [
"4\n[[1,2,9],[2,3,6],[2,4,5],[1,4,7]]",
"4\n[[1,2,2],[1,3,4],[3,4,7]]"
] | [
"Can you solve the problem if the whole graph is connected?",
"Notice that if the graph is connected, you can always use any edge of the graph in your path.",
"How to solve the general problem in a similar way? Remove all the nodes that are not connected to 1 and n, then apply the previous solution in the new g... | {
"canonical_parameter_names": [
"n",
"roads"
],
"leetcode_dataset_entry_point": "Solution().minScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:54:48",
"tests_total": 65,
"tes... | cpp | {
"raw_signature": "int minScore(int n, vector<vector<int>>& roads) {",
"container": "Solution",
"callable": "minScore",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "roads",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": ... |
2,493 | divide-nodes-into-the-maximum-number-of-groups | Hard | You are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n.
You are also given a 2D integer array edges, where edges[i] = [a_i,b_i] indicates that there is a bidirectional edge between nodes a_i and b_i. Notice that the given graph may be disconnected.... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 1], [4, 5]]) == -1\n assert candidate(n = 4,edges = [[1, 2], [3, 4]]) == 4\n assert candidate(n = 6,edges = [[1, 2], [1, 4], [1, 5], [2, 6], [2, 3], [4, 6]]) == 4\n assert candidate(n = 3,edges... | [
"6\n[[1,2],[1,4],[1,5],[2,6],[2,3],[4,6]]",
"3\n[[1,2],[2,3],[3,1]]"
] | [
"If the graph is not bipartite, it is not possible to group the nodes.",
"Notice that we can solve the problem for each connected component independently, and the final answer will be just the sum of the maximum number of groups in each component.",
"Finally, to solve the problem for each connected component, w... | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().magnificentSets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:54:50",
"tests_total": 83,... | cpp | {
"raw_signature": "int magnificentSets(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "magnificentSets",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signa... |
2,496 | maximum-value-of-a-string-in-an-array | Easy | The value of an alphanumeric string can be defined as:
- The numeric representation of the string in base 10, if it comprises of digits only.
- The length of the string, otherwise.
Given an array strs of alphanumeric strings, return the maximum value of any string in strs.
Example 1:
Input: strs = ["alic3","bob","3... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(strs = ['xyz', 'xyzz', 'xyzzz', 'xyzzzz']) == 6\n assert candidate(strs = ['a1', 'b2', 'c3', '1a', '2b', '3c']) == 2\n assert candidate(strs = ['abc', '123', 'a1b2c3', '000']) == 123\n assert candidate(strs = ['123456789', '9876... | [
"[\"alic3\",\"bob\",\"3\",\"4\",\"00000\"]",
"[\"1\",\"01\",\"001\",\"0001\"]"
] | [
"For strings comprising only of digits, convert them into integers.",
"For all other strings, calculate their length."
] | {
"canonical_parameter_names": [
"strs"
],
"leetcode_dataset_entry_point": "Solution().maximumValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:54:55",
"tests_total": 109,
"tests_dr... | cpp | {
"raw_signature": "int maximumValue(vector<string>& strs) {",
"container": "Solution",
"callable": "maximumValue",
"parameters": [
{
"name": "strs",
"type": "vector<string>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
2,497 | maximum-star-sum-of-a-graph | Medium | There is an undirected graph consisting of n nodes numbered from 0 to n - 1. 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] denotes that there exists an undirected edge connecting nodes a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(vals = [5, -2, 3, 1],edges = [[0, 1], [0, 2], [0, 3]],k = 3) == 9\n assert candidate(vals = [1, 2, 3],edges = [[0, 1], [1, 2]],k = 0) == 3\n assert candidate(vals = [1, 2, 3, 4, 10, -10, -20],edges = [[0, 1], [1, 2], [1, 3], [3, 4]... | [
"[1,2,3,4,10,-10,-20]\n[[0,1],[1,2],[1,3],[3,4],[3,5],[3,6]]\n2",
"[-5]\n[]\n0"
] | [
"A star graph doesn’t necessarily include all of its neighbors.",
"For each node, sort its neighbors in descending order and take k max valued neighbors."
] | {
"canonical_parameter_names": [
"vals",
"edges",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxStarSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:54:58",
"tests_tota... | cpp | {
"raw_signature": "int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {",
"container": "Solution",
"callable": "maxStarSum",
"parameters": [
{
"name": "vals",
"type": "vector<int>&"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
},
{
"na... |
2,498 | frog-jump-ii | Medium | You are given a 0-indexed integer array stones sorted in strictly increasing order representing the positions of stones in a river.
A frog, initially on the first stone, wants to travel to the last stone and then return to the first stone. However, it can jump to any stone at most once.
The length of a jump is the ab... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(stones = [0, 10, 15, 20, 25]) == 15\n assert candidate(stones = [0, 1, 2, 3, 4, 5]) == 2\n assert candidate(stones = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(stones = [0, 2, 5, 6, 7]) == 5\n assert candidat... | [
"[0,2,5,6,7]",
"[0,3,9]"
] | [
"One of the optimal strategies will be to jump to every stone.",
"Skipping just one stone in every forward jump and jumping to those skipped stones in backward jump can minimize the maximum jump."
] | {
"canonical_parameter_names": [
"stones"
],
"leetcode_dataset_entry_point": "Solution().maxJump",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:00",
"tests_total": 106,
"tests_dropp... | cpp | {
"raw_signature": "int maxJump(vector<int>& stones) {",
"container": "Solution",
"callable": "maxJump",
"parameters": [
{
"name": "stones",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,499 | minimum-total-cost-to-make-arrays-unequal | Hard | You are given two 0-indexed integer arrays nums1 and nums2, of equal length n.
In one operation, you can swap the values of any two indices of nums1. The cost of this operation is the sum of the indices.
Find the minimum total cost of performing the given operation any number of times such that nums1[i] != nums2[i] f... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 2],nums2 = [1, 2, 2]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2]) == 0\n assert candidate(nums1 = [1, 2],nums2 = [2, 1]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 2,... | [
"[1,2,3,4,5]\n[1,2,3,4,5]",
"[2,2,2,1,3]\n[1,2,2,3,3]",
"[1,2,2]\n[1,2,2]"
] | [
"How can we check which indices of nums1 will be considered for swapping? How to minimize the number of such operations?",
"It can be seen that greedily swapping values of indices where nums1[i] == nums2[i] is the most optimal choice. How many values cannot be swapped this way?",
"Find which indices we will swa... | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().minimumTotalCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:03",
"tests_total"... | cpp | {
"raw_signature": "long long minimumTotalCost(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "minimumTotalCost",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type... |
2,500 | delete-greatest-value-in-each-row | Easy | You are given an m x n matrix grid consisting of positive integers.
Perform the following operation until grid becomes empty:
- Delete the element with the greatest value from each row. If multiple such elements exist, delete any of them.
- Add the maximum of deleted elements to the answer.
Note that the number of c... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 3\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == 24\n assert candidate(grid = [[5, 1, 3], [4, 2, 6], [7, 8, 9]]) == 24\n assert candidate(grid = [[5, 1, 3], [9, 3, 5]... | [
"[[1,2,4],[3,3,1]]",
"[[10]]"
] | [
"Iterate from the first to the last row and if there exist some unmarked cells, take a maximum from them and mark that cell as visited.",
"Add a maximum of newly marked cells to answer and repeat that operation until the whole matrix becomes marked."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().deleteGreatestValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:05",
"tests_total": 93,
"te... | cpp | {
"raw_signature": "int deleteGreatestValue(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "deleteGreatestValue",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source... |
2,501 | longest-square-streak-in-an-array | Medium | You are given an integer array nums. A subsequence of nums is called a square streak if:
- The length of the subsequence is at least 2, and
- after sorting the subsequence, each element (except the first element) is the square of the previous number.
Return the length of the longest square streak in nums, or return -... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 16, 256, 65536]) == 4\n assert candidate(nums = [6, 36, 1296, 46656]) == 3\n assert candidate(nums = [2, 3, 5, 6, 7]) == -1\n assert candidate(nums = [4, 16, 256, 65536, 2]) == 5\n assert candidate(nums = [2, 3, 4,... | [
"[4,3,6,16,8,2]",
"[2,3,5,6,7]"
] | [
"With the constraints, the length of the longest square streak possible is 5.",
"Store the elements of nums in a set to quickly check if it exists."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().longestSquareStreak",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:07",
"tests_total": 132,
"t... | cpp | {
"raw_signature": "int longestSquareStreak(vector<int>& nums) {",
"container": "Solution",
"callable": "longestSquareStreak",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
2,503 | maximum-number-of-points-from-grid-queries | Hard | You are given an m x n integer matrix grid and an array queries of size k.
Find an array answer of size k such that for each integer queries[i] you start in the top left cell of the matrix and repeat the following process:
- If queries[i] is strictly greater than the value of the current cell that you are in, then yo... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],queries = [2, 3]) == [9, 9]\n assert candidate(grid = [[1, 2, 3], [2, 5, 7], [3, 5, 1]],queries = [5, 6, 2]) == [5, 8, 1]\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],queries ... | [
"[[1,2,3],[2,5,7],[3,5,1]]\n[5,6,2]",
"[[5,2,1],[1,1,2]]\n[3]"
] | [
"The queries are all given to you beforehand so you can answer them in any order you want.",
"Sort the queries knowing their original order to be able to build the answer array.",
"Run a BFS on the graph and answer the queries in increasing order."
] | {
"canonical_parameter_names": [
"grid",
"queries"
],
"leetcode_dataset_entry_point": "Solution().maxPoints",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:11",
"tests_total": 103,... | cpp | {
"raw_signature": "vector<int> maxPoints(vector<vector<int>>& grid, vector<int>& queries) {",
"container": "Solution",
"callable": "maxPoints",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
},
{
"name": "queries",
"type": "vector<int>&"
}
],
"retur... |
2,506 | count-pairs-of-similar-strings | Easy | You are given a 0-indexed string array words.
Two strings are similar if they consist of the same characters.
- For example, "abca" and "cba" are similar since both consist of characters 'a', 'b', and 'c'.
- However, "abacba" and "bcfd" are not similar since they do not consist of the same characters.
Return the num... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['aabbcc', 'abc', 'ab', 'a', 'b', 'c']) == 1\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'aab', 'aba', 'baa']) == 3\n assert candidate(words = ['aabbcc', 'abc', 'aabb', 'aaabbbcc', 'abcabc']) == 6\n assert candidate... | [
"[\"aba\",\"aabb\",\"abcd\",\"bac\",\"aabc\"]",
"[\"aabb\",\"ab\",\"ba\"]",
"[\"nba\",\"cba\",\"dba\"]"
] | [
"How can you check if two strings are similar?",
"Use a hashSet to store the character of each string."
] | {
"canonical_parameter_names": [
"words"
],
"leetcode_dataset_entry_point": "Solution().similarPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:15",
"tests_total": 101,
"tests_d... | cpp | {
"raw_signature": "int similarPairs(vector<string>& words) {",
"container": "Solution",
"callable": "similarPairs",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
2,507 | smallest-value-after-replacing-with-sum-of-prime-factors | Medium | You are given a positive integer n.
Continuously replace n with the sum of its prime factors.
- Note that if a prime factor divides n multiple times, it should be included in the sum as many times as it divides n.
Return the smallest value n will take on.
Example 1:
Input: n = 15
Output: 5
Explanation: Initially, ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3) == 3\n assert candidate(n = 15) == 5\n assert candidate(n = 100) == 5\n assert candidate(n = 44) == 5\n assert candidate(n = 28) == 11\n assert candidate(n = 97) == 97\n assert candidate(n = 99999) == 31\n ass... | [
"15",
"3"
] | [
"Every time you replace n, it will become smaller until it is a prime number, where it will keep the same value each time you replace it.",
"n decreases logarithmically, allowing you to simulate the process.",
"To find the prime factors, iterate through all numbers less than n from least to greatest and find th... | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().smallestValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:18",
"tests_total": 45,
"tests_dropp... | cpp | {
"raw_signature": "int smallestValue(int n) {",
"container": "Solution",
"callable": "smallestValue",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,508 | add-edges-to-make-degrees-of-all-nodes-even | Hard | There is an undirected graph consisting of n nodes numbered from 1 to n. You are given the integer n and a 2D array edges where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i. The graph can be disconnected.
You can add at most two additional edges (possibly none) to this graph so that ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,edges = [[1, 2], [1, 3], [1, 4]]) == False\n assert candidate(n = 7,edges = [[1, 2], [3, 4], [5, 6], [6, 7]]) == False\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == True... | [
"5\n[[1,2],[2,3],[3,4],[4,2],[1,4],[2,5]]",
"4\n[[1,2],[3,4]]",
"4\n[[1,2],[1,3],[1,4]]"
] | [
"Notice that each edge that we add changes the degree of exactly 2 nodes.",
"The number of nodes with an odd degree in the original graph should be either 0, 2, or 4. Try to work on each of these cases."
] | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().isPossible",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:20",
"tests_total": 82,
"t... | cpp | {
"raw_signature": "bool isPossible(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "isPossible",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type": "bool",
"signature_sou... |
2,509 | cycle-length-queries-in-a-tree | Hard | You are given an integer n. There is a complete binary tree with 2^n - 1 nodes. The root of that tree is the node with the value 1, and every node with a value val in the range [1, 2^{n - 1} - 1] has two children where:
- The left node has the value 2 * val, and
- The right node has the value 2 * val + 1.
You are als... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,queries = [[31, 15], [10, 18], [9, 20]]) == [2, 6, 6]\n assert candidate(n = 3,queries = [[5, 3], [4, 7], [2, 3]]) == [4, 5, 3]\n assert candidate(n = 5,queries = [[15, 7], [10, 14], [3, 12]]) == [2, 7, 3]\n assert candida... | [
"3\n[[5,3],[4,7],[2,3]]",
"2\n[[1,2]]"
] | [
"Find the distance between nodes “a” and “b”.",
"distance(a, b) = depth(a) + depth(b) - 2 * depth(LCA(a, b)). Where depth(a) denotes depth from root to node “a” and LCA(a, b) denotes the lowest common ancestor of nodes “a” and “b”.",
"To find LCA(a, b), iterate over all ancestors of node “a” and check if it is ... | {
"canonical_parameter_names": [
"n",
"queries"
],
"leetcode_dataset_entry_point": "Solution().cycleLengthQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:23",
"tests_total"... | cpp | {
"raw_signature": "vector<int> cycleLengthQueries(int n, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "cycleLengthQueries",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "queries",
"type": "vector<vector<int>>&"
}
],
"return_type... |
2,511 | maximum-enemy-forts-that-can-be-captured | Easy | You are given a 0-indexed integer array forts of length n representing the positions of several forts. forts[i] can be -1, 0, or 1 where:
- -1 represents there is no fort at the i^th position.
- 0 indicates there is an enemy fort at the i^th position.
- 1 indicates the fort at the i^th the position is under your comma... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(forts = [1, 0, 1, 0, -1, 0, 1]) == 1\n assert candidate(forts = [-1, 0, 0, 0, 0, 1]) == 4\n assert candidate(forts = [0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(forts = [-1, 0, 0, 1, 0, 0, -1]) == 2\n assert candidate(fort... | [
"[1,0,0,-1,0,0,0,0,1]",
"[0,0,1,-1]"
] | [
"For each fort under your command, check if you can move the army from here.",
"If yes, find the closest empty positions satisfying all criteria.",
"How can two-pointers be used to solve this problem optimally?"
] | {
"canonical_parameter_names": [
"forts"
],
"leetcode_dataset_entry_point": "Solution().captureForts",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:27",
"tests_total": 100,
"tests_d... | cpp | {
"raw_signature": "int captureForts(vector<int>& forts) {",
"container": "Solution",
"callable": "captureForts",
"parameters": [
{
"name": "forts",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,512 | reward-top-k-students | Medium | You are given two string arrays positive_feedback and negative_feedback, containing the words denoting positive and negative feedback, respectively. Note that no word is both positive and negative.
Initially every student has 0 points. Each positive word in a feedback report increases the points of a student by 3, whe... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(positive_feedback = ['smart', 'brilliant', 'studious'],negative_feedback = ['not'],report = ['this student is studious', 'the student is smart'],student_id = [1, 2],k = 2) == [1, 2]\n assert candidate(positive_feedback = ['good', 'exc... | [
"[\"smart\",\"brilliant\",\"studious\"]\n[\"not\"]\n[\"this student is studious\",\"the student is smart\"]\n[1,2]\n2",
"[\"smart\",\"brilliant\",\"studious\"]\n[\"not\"]\n[\"this student is not studious\",\"the student is smart\"]\n[1,2]\n2"
] | [
"Hash the positive and negative feedback words separately.",
"Calculate the points for each student’s feedback.",
"Sort the students accordingly to find the top k among them."
] | {
"canonical_parameter_names": [
"positive_feedback",
"negative_feedback",
"report",
"student_id",
"k"
],
"leetcode_dataset_entry_point": "Solution().topStudents",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnipp... | cpp | {
"raw_signature": "vector<int> topStudents(vector<string>& positive_feedback, vector<string>& negative_feedback, vector<string>& report, vector<int>& student_id, int k) {",
"container": "Solution",
"callable": "topStudents",
"parameters": [
{
"name": "positive_feedback",
"type": "vector<string>... |
2,513 | minimize-the-maximum-of-two-arrays | Medium | We have two arrays arr1 and arr2 which are initially empty. You need to add positive integers to them such that they satisfy all the following conditions:
- arr1 contains uniqueCnt1 distinct positive integers, each of which is not divisible by divisor1.
- arr2 contains uniqueCnt2 distinct positive integers, each of wh... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(divisor1 = 2,divisor2 = 7,uniqueCnt1 = 1,uniqueCnt2 = 3) == 4\n assert candidate(divisor1 = 2,divisor2 = 4,uniqueCnt1 = 8,uniqueCnt2 = 2) == 15\n assert candidate(divisor1 = 100,divisor2 = 101,uniqueCnt1 = 100000000,uniqueCnt2 = 10... | [
"2\n7\n1\n3",
"3\n5\n2\n1",
"2\n4\n8\n2"
] | [
"Use binary search to find smallest maximum element.",
"Add numbers divisible by x in nums2 and vice versa."
] | {
"canonical_parameter_names": [
"divisor1",
"divisor2",
"uniqueCnt1",
"uniqueCnt2"
],
"leetcode_dataset_entry_point": "Solution().minimizeSet",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "... | cpp | {
"raw_signature": "int minimizeSet(int divisor1, int divisor2, int uniqueCnt1, int uniqueCnt2) {",
"container": "Solution",
"callable": "minimizeSet",
"parameters": [
{
"name": "divisor1",
"type": "int"
},
{
"name": "divisor2",
"type": "int"
},
{
"name": "uniqu... |
2,515 | shortest-distance-to-target-string-in-a-circular-array | Easy | You are given a 0-indexed circular string array words and a string target. A circular array means that the array's end connects to the array's beginning.
- Formally, the next element of words[i] is words[(i + 1) % n] and the previous element of words[i] is words[(i - 1 + n) % n], where n is the length of words.
Start... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['abc', 'def', 'ghi'],target = \"xyz\",startIndex = 1) == -1\n assert candidate(words = ['apple', 'banana', 'cherry', 'date'],target = \"banana\",startIndex = 2) == 1\n assert candidate(words = ['cat', 'dog', 'bird', 'fish'... | [
"[\"hello\",\"i\",\"am\",\"leetcode\",\"hello\"]\n\"hello\"\n1",
"[\"a\",\"b\",\"leetcode\"]\n\"leetcode\"\n0",
"[\"i\",\"eat\",\"leetcode\"]\n\"ate\"\n0"
] | [
"You have two options, either move straight to the left or move straight to the right.",
"Find the first target word and record the distance.",
"Choose the one with the minimum distance."
] | {
"canonical_parameter_names": [
"words",
"target",
"startIndex"
],
"leetcode_dataset_entry_point": "Solution().closestTarget",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:34",... | cpp | {
"raw_signature": "int closestTarget(vector<string>& words, string target, int startIndex) {",
"container": "Solution",
"callable": "closestTarget",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
},
{
"name": "target",
"type": "string"
},
{
"name"... |
2,516 | take-k-of-each-character-from-left-and-right | Medium | You are given a string s consisting of the characters 'a', 'b', and 'c' and a non-negative integer k. Each minute, you may take either the leftmost character of s, or the rightmost character of s.
Return the minimum number of minutes needed for you to take at least k of each character, or return -1 if it is not possib... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abacbacbacb\",k = 2) == 6\n assert candidate(s = \"baccbaccbacc\",k = 2) == 6\n assert candidate(s = \"abcabcabcabcabc\",k = 3) == 9\n assert candidate(s = \"aabbaacc\",k = 2) == 6\n assert candidate(s = \"abc\",k = 0) ... | [
"\"aabaaaacaabc\"\n2",
"\"a\"\n1"
] | [
"Start by counting the frequency of each character and checking if it is possible.",
"If you take x characters from the left side, what is the minimum number of characters you need to take from the right side? Find this for all values of x in the range 0 ≤ x ≤ s.length.",
"Use a two-pointers approach to avoid c... | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().takeCharacters",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:37",
"tests_total": 129,
"... | cpp | {
"raw_signature": "int takeCharacters(string s, int k) {",
"container": "Solution",
"callable": "takeCharacters",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",... |
2,517 | maximum-tastiness-of-candy-basket | Medium | You are given an array of positive integers price where price[i] denotes the price of the i^th candy and a positive integer k.
The store sells baskets of k distinct candies. The tastiness of a candy basket is the smallest absolute difference of the prices of any two candies in the basket.
Return the maximum tastiness... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(price = [1000000000, 1, 2, 3, 4, 5],k = 3) == 4\n assert candidate(price = [1000000000, 1, 1000000000, 1, 1000000000],k = 3) == 0\n assert candidate(price = [10, 20, 30, 40, 50],k = 3) == 20\n assert candidate(price = [13, 5, 1,... | [
"[13,5,1,8,21,2]\n3",
"[1,3,1]\n2",
"[7,7,7,7]\n2"
] | [
"The answer is binary searchable.",
"For some x, we can use a greedy strategy to check if it is possible to pick k distinct candies with tastiness being at least x.",
"Sort prices and iterate from left to right. For some price[i] check if the price difference between the last taken candy and price[i] is at leas... | {
"canonical_parameter_names": [
"price",
"k"
],
"leetcode_dataset_entry_point": "Solution().maximumTastiness",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:39",
"tests_total": 81... | cpp | {
"raw_signature": "int maximumTastiness(vector<int>& price, int k) {",
"container": "Solution",
"callable": "maximumTastiness",
"parameters": [
{
"name": "price",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": ... |
2,518 | number-of-great-partitions | Hard | You are given an array nums consisting of positive integers and an integer k.
Partition the array into two ordered groups such that each element is in exactly one group. A partition is called great if the sum of elements of each group is greater than or equal to k.
Return the number of distinct great partitions. Sinc... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40],k = 50) == 2\n assert candidate(nums = [1, 1, 1, 1],k = 2) == 6\n assert candidate(nums = [2, 4, 6, 8, 10],k = 11) == 12\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 25) == 252\n assert... | [
"[1,2,3,4]\n4",
"[3,3,3]\n4",
"[6,6]\n2"
] | [
"If the sum of the array is smaller than 2*k, then it is impossible to find a great partition.",
"Solve the reverse problem, that is, find the number of partitions where the sum of elements of at least one of the two groups is smaller than k."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().countPartitions",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:41",
"tests_total": 101,... | cpp | {
"raw_signature": "int countPartitions(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "countPartitions",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "lee... |
2,520 | count-the-digits-that-divide-a-number | Easy | Given an integer num, return the number of digits in num that divide num.
An integer val divides nums if nums % val == 0.
Example 1:
Input: num = 7
Output: 1
Explanation: 7 divides itself, hence the answer is 1.
Example 2:
Input: num = 121
Output: 2
Explanation: 121 is divisible by 1, but not 2. Since 1 occurs twi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = 111111111) == 9\n assert candidate(num = 666) == 3\n assert candidate(num = 999) == 3\n assert candidate(num = 222) == 3\n assert candidate(num = 1122) == 4\n assert candidate(num = 123456789) == 3\n assert candid... | [
"7",
"121",
"1248"
] | [
"Use mod by 10 to retrieve the least significant digit of the number",
"Divide the number by 10, then round it down so that the second least significant digit becomes the least significant digit of the number",
"Use your language’s mod operator to see if a number is a divisor of another."
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().countDigits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:46",
"tests_total": 73,
"tests_dropp... | cpp | {
"raw_signature": "int countDigits(int num) {",
"container": "Solution",
"callable": "countDigits",
"parameters": [
{
"name": "num",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,521 | distinct-prime-factors-of-product-of-array | Medium | Given an array of positive integers nums, return the number of distinct prime factors in the product of the elements of nums.
Note that:
- A number greater than 1 is called prime if it is divisible by only 1 and itself.
- An integer val1 is a factor of another integer val2 if val2 / val1 is an integer.
Example 1:
I... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100, 200, 300, 400]) == 3\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [1000, 500, 250, 125]) == 2\n assert candidate(nums = [2, 3, 5, 7, 11, 13]) == 6\n assert candidate(nu... | [
"[2,4,3,7,10,6]",
"[2,4,8,16]"
] | [
"Do not multiply all the numbers together, as the product is too big to store.",
"Think about how each individual number's prime factors contribute to the prime factors of the product of the entire array.",
"Find the prime factors of each element in nums, and store all of them in a set to avoid duplicates."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().distinctPrimeFactors",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:48",
"tests_total": 115,
"... | cpp | {
"raw_signature": "int distinctPrimeFactors(vector<int>& nums) {",
"container": "Solution",
"callable": "distinctPrimeFactors",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
2,522 | partition-string-into-substrings-with-values-at-most-k | Medium | You are given a string s consisting of digits from 1 to 9 and an integer k.
A partition of a string s is called good if:
- Each digit of s is part of exactly one substring.
- The value of each substring is less than or equal to k.
Return the minimum number of substrings in a good partition of s. If no good partition... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"473289651\",k = 10) == 9\n assert candidate(s = \"2222222222222222222\",k = 2) == 19\n assert candidate(s = \"987654321\",k = 10) == 9\n assert candidate(s = \"999\",k = 1000) == 1\n assert candidate(s = \"999999999\",k... | [
"\"165462\"\n60",
"\"238182\"\n5"
] | [] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().minimumPartition",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:50",
"tests_total": 109,
... | cpp | {
"raw_signature": "int minimumPartition(string s, int k) {",
"container": "Solution",
"callable": "minimumPartition",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippe... |
2,523 | closest-prime-numbers-in-range | Medium | Given two positive integers left and right, find the two integers num1 and num2 such that:
- left <= num1 < num2 <= right .
- Both num1 and num2 are prime numbers.
- num2 - num1 is the minimum amongst all other pairs satisfying the above conditions.
Return the positive integer array ans = [num1, num2]. If there are m... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(left = 500,right = 550) == [521, 523]\n assert candidate(left = 1000,right = 1100) == [1019, 1021]\n assert candidate(left = 10000,right = 10020) == [10007, 10009]\n assert candidate(left = 1000,right = 1010) == [-1, -1]\n as... | [
"10\n19",
"4\n6"
] | [
"Use Sieve of Eratosthenes to mark numbers that are primes.",
"Iterate from right to left and find pair with the minimum distance between marked numbers."
] | {
"canonical_parameter_names": [
"left",
"right"
],
"leetcode_dataset_entry_point": "Solution().closestPrimes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:53",
"tests_total": 95... | cpp | {
"raw_signature": "vector<int> closestPrimes(int left, int right) {",
"container": "Solution",
"callable": "closestPrimes",
"parameters": [
{
"name": "left",
"type": "int"
},
{
"name": "right",
"type": "int"
}
],
"return_type": "vector<int>",
"signature_source": "l... |
2,525 | categorize-box-according-to-criteria | Easy | Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box.
- The box is "Bulky" if:
- Any of the dimensions of the box is greater or equal to 10^4.
- Or, the volume of the box is greater or equal to 10^9.
-... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(length = 100000,width = 100000,height = 100000,mass = 1000) == \"Both\"\n assert candidate(length = 10000,width = 10,height = 10,mass = 1) == \"Bulky\"\n assert candidate(length = 5000,width = 2000,height = 1000,mass = 50) == \"Bul... | [
"1000\n35\n700\n300",
"200\n50\n800\n50"
] | [
"Use conditional statements to find the right category of the box."
] | {
"canonical_parameter_names": [
"length",
"width",
"height",
"mass"
],
"leetcode_dataset_entry_point": "Solution().categorizeBox",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20... | cpp | {
"raw_signature": "string categorizeBox(int length, int width, int height, int mass) {",
"container": "Solution",
"callable": "categorizeBox",
"parameters": [
{
"name": "length",
"type": "int"
},
{
"name": "width",
"type": "int"
},
{
"name": "height",
"ty... |
2,527 | find-xor-beauty-of-array | Medium | You are given a 0-indexed integer array nums.
The effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]).
The xor-beauty of the array is the XORing of the effective values of all the possible triplets of indices (i, j, k) where 0 <= i, j, k < n.
Return the xor-beauty of nums.
Not... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 14\n assert candidate(nums = [15, 45, 20, 2, 34, 35, 5, 44, 32, 30]) == 34\n assert candidate(nums = [1, 4]) =... | [
"[1,4]",
"[15,45,20,2,34,35,5,44,32,30]"
] | [
"Try to simplify the given expression.",
"Try constructing the answer bit by bit."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().xorBeauty",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:55:57",
"tests_total": 97,
"tests_droppe... | cpp | {
"raw_signature": "int xorBeauty(vector<int>& nums) {",
"container": "Solution",
"callable": "xorBeauty",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,528 | maximize-the-minimum-powered-city | Hard | You are given a 0-indexed integer array stations of length n, where stations[i] represents the number of power stations in the i^th city.
Each power station can provide power to every city in a fixed range. In other words, if the range is denoted by r, then a power station at city i can provide power to all cities j s... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(stations = [1, 2, 4, 5, 0],r = 1,k = 2) == 5\n assert candidate(stations = [0, 0, 0, 0, 0],r = 2,k = 5) == 5\n assert candidate(stations = [0, 0, 0, 0, 0],r = 2,k = 10) == 10\n assert candidate(stations = [1, 3, 5, 7, 9],r = 2,k... | [
"[1,2,4,5,0]\n1\n2",
"[4,4,4,4]\n0\n3"
] | [
"Pre calculate the number of stations on each city using Line Sweep.",
"Use binary search to maximize the minimum."
] | {
"canonical_parameter_names": [
"stations",
"r",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxPower",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:00",
"tests_total"... | cpp | {
"raw_signature": "long long maxPower(vector<int>& stations, int r, int k) {",
"container": "Solution",
"callable": "maxPower",
"parameters": [
{
"name": "stations",
"type": "vector<int>&"
},
{
"name": "r",
"type": "int"
},
{
"name": "k",
"type": "int"
... |
2,529 | maximum-count-of-positive-integer-and-negative-integer | Easy | Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers.
- In other words, if the number of positive integers in nums is pos and the number of negative integers is neg, then return the maximum of pos and neg.
Note that 0 is nei... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [-2, -1, -1, 1, 2, 3]) == 3\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0]) == 10\n assert candidate(nums = [5, 20, 66, 1314]) ==... | [
"[-2,-1,-1,1,2,3]",
"[-3,-2,-1,0,0,1,2]",
"[5,20,66,1314]"
] | [
"Count how many positive integers and negative integers are in the array.",
"Since the array is sorted, can we use the binary search?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maximumCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:02",
"tests_total": 96,
"tests_dro... | cpp | {
"raw_signature": "int maximumCount(vector<int>& nums) {",
"container": "Solution",
"callable": "maximumCount",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,530 | maximal-score-after-applying-k-operations | Medium | You are given a 0-indexed integer array nums and an integer k. You have a starting score of 0.
In one operation:
1. choose an index i such that 0 <= i < nums.length,
2. increase your score by nums[i], and
3. replace nums[i] with ceil(nums[i] / 3).
Return the maximum possible score you can attain after applying exact... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [9, 9, 9, 9, 9],k = 4) == 36\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 6) == 30\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 1) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) ... | [
"[10,10,10,10,10]\n5",
"[1,10,3,3,3]\n3"
] | [
"It is always optimal to select the greatest element in the array.",
"Use a heap to query for the maximum in O(log n) time."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxKelements",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:05",
"tests_total": 89,
"... | cpp | {
"raw_signature": "long long maxKelements(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "maxKelements",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "long long",
"signature_source"... |
2,531 | make-number-of-distinct-characters-equal | Medium | You are given two 0-indexed strings word1 and word2.
A move consists of choosing two indices i and j such that 0 <= i < word1.length and 0 <= j < word2.length and swapping word1[i] with word2[j].
Return true if it is possible to get the number of distinct characters in word1 and word2 to be equal with exactly one mov... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word1 = \"abcde\",word2 = \"fghij\") == True\n assert candidate(word1 = \"xyz\",word2 = \"zyx\") == True\n assert candidate(word1 = \"aaa\",word2 = \"bbb\") == True\n assert candidate(word1 = \"ac\",word2 = \"b\") == False\n ... | [
"\"ac\"\n\"b\"",
"\"abcc\"\n\"aab\"",
"\"abcde\"\n\"fghij\""
] | [
"Create a frequency array of the letters of each string.",
"There are 26*26 possible pairs of letters to swap. Can we try them all?",
"Iterate over all possible pairs of letters and check if swapping them will yield two strings that have the same number of distinct characters. Use the frequency array for the ch... | {
"canonical_parameter_names": [
"word1",
"word2"
],
"leetcode_dataset_entry_point": "Solution().isItPossible",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:07",
"tests_total": 11... | cpp | {
"raw_signature": "bool isItPossible(string word1, string word2) {",
"container": "Solution",
"callable": "isItPossible",
"parameters": [
{
"name": "word1",
"type": "string"
},
{
"name": "word2",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "lee... |
2,532 | time-to-cross-a-bridge | Hard | There are k workers who want to move n boxes from the right (old) warehouse to the left (new) warehouse. You are given the two integers n and k, and a 2D integer array time of size k x 4 where time[i] = [right_i, pick_i, left_i, put_i].
The warehouses are separated by a river and connected by a bridge. Initially, all ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 2,k = 1,time = [[1, 2, 3, 4]]) == 16\n assert candidate(n = 5,k = 5,time = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8]]) == 54\n assert candidate(n = 7,k = 4,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, ... | [
"1\n3\n[[1,1,2,1],[1,1,3,1],[1,1,4,1]]",
"3\n2\n[[1,9,1,8],[10,10,10,10]]"
] | [
"Try simulating this process.",
"We can use a priority queue to query over the least efficient worker."
] | {
"canonical_parameter_names": [
"n",
"k",
"time"
],
"leetcode_dataset_entry_point": "Solution().findCrossingTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:09",
"tests_to... | cpp | {
"raw_signature": "int findCrossingTime(int n, int k, vector<vector<int>>& time) {",
"container": "Solution",
"callable": "findCrossingTime",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
},
{
"name": "time",
"type": "vector... |
2,535 | difference-between-element-sum-and-digit-sum-of-an-array | Easy | You are given a positive integer array nums.
- The element sum is the sum of all the elements in nums.
- The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums.
Return the absolute difference between the element sum and digit sum of nums.
Note that the absolute difference between t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1]) == 0\n assert candidate(nums = [10, 11, 12, 13]) == 36\n assert candidate(nums = [1, 15, 6, 3]) == 9\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [10, 100, 1000]) == 1107\n assert cand... | [
"[1,15,6,3]",
"[1,2,3,4]"
] | [
"Use a simple for loop to iterate each number.",
"How you can get the digit for each number?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().differenceOfSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:16",
"tests_total": 99,
"tests_... | cpp | {
"raw_signature": "int differenceOfSum(vector<int>& nums) {",
"container": "Solution",
"callable": "differenceOfSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
2,536 | increment-submatrices-by-one | Medium | You are given a positive integer n, indicating that we initially have an n x n 0-indexed integer matrix mat filled with zeroes.
You are also given a 2D integer array query. For each query[i] = [row1_i, col1_i, row2_i, col2_i], you should do the following operation:
- Add 1 to every element in the submatrix with the t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,queries = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) == [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]\n assert candidate(n = 1,queries = [[0, 0, 0, 0]]) == [[1... | [
"3\n[[1,1,2,2],[0,0,1,1]]",
"2\n[[0,0,1,1]]"
] | [
"Imagine each row as a separate array. Instead of updating the whole submatrix together, we can use prefix sum to update each row separately.",
"For each query, iterate over the rows i in the range [row1, row2] and add 1 to prefix sum S[i][col1], and subtract 1 from S[i][col2 + 1].",
"After doing this operation... | {
"canonical_parameter_names": [
"n",
"queries"
],
"leetcode_dataset_entry_point": "Solution().rangeAddQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:19",
"tests_total": 7... | cpp | {
"raw_signature": "vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "rangeAddQueries",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "queries",
"type": "vector<vector<int>>&"
}
],
"return_ty... |
2,537 | count-the-number-of-good-subarrays | Medium | Given an integer array nums and an integer k, return the number of good subarrays of nums.
A subarray arr is good if there are at least k pairs of indices (i, j) such that i < j and arr[i] == arr[j].
A subarray is a contiguous non-empty sequence of elements within an array.
Example 1:
Input: nums = [1,1,1,1,1], k =... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 15) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 0\n assert candidate(nums = [10, 20, 30, 10, 20, 30, 10],k = 3) == 3\n assert candidate(nums = [10, 10, 10, ... | [
"[1,1,1,1,1]\n10",
"[3,1,4,3,2,2,4]\n2"
] | [
"For a fixed index l, try to find the minimum value of index r, such that the subarray is not good",
"When a number is added to a subarray, it increases the number of pairs by its previous appearances.",
"When a number is removed from the subarray, it decreases the number of pairs by its remaining appearances."... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().countGood",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:21",
"tests_total": 116,
"te... | cpp | {
"raw_signature": "long long countGood(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "countGood",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "long long",
"signature_source": "lee... |
2,538 | difference-between-maximum-and-minimum-price-sum | Hard | There exists an undirected and initially unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree.
Each node has an associated price. You are given an i... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4]],price = [5, 4, 3, 2, 1]) == 12\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4]],price = [5, 10, 20, 30, 40]) == 55\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [1... | [
"6\n[[0,1],[1,2],[1,3],[3,4],[3,5]]\n[9,8,7,6,10,5]",
"3\n[[0,1],[1,2]]\n[1,1,1]"
] | [
"The minimum price sum is always the price of a rooted node.",
"Let’s root the tree at vertex 0 and find the answer from this perspective.",
"In the optimal answer maximum price is the sum of the prices of nodes on the path from “u” to “v” where either “u” or “v” is the parent of the second one or neither is a ... | {
"canonical_parameter_names": [
"n",
"edges",
"price"
],
"leetcode_dataset_entry_point": "Solution().maxOutput",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:24",
"tests_tota... | cpp | {
"raw_signature": "long long maxOutput(int n, vector<vector<int>>& edges, vector<int>& price) {",
"container": "Solution",
"callable": "maxOutput",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
},
{
"name": "p... |
2,540 | minimum-common-value | Easy | Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1.
Note that an integer is said to be common to nums1 and nums2 if both arrays have at least one occurrence of that integer.
Exampl... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 2, 3],nums2 = [2, 2]) == 2\n assert candidate(nums1 = [10, 20, 30],nums2 = [5, 15, 25, 35]) == -1\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1]) == 1\n assert candidate(nums1 = [1, 3, 5, 7],nums2 = ... | [
"[1,2,3]\n[2,4]",
"[1,2,3,6]\n[2,3,4,5]"
] | [
"Try to use a set.",
"Otherwise, try to use a two-pointer approach."
] | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().getCommon",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:26",
"tests_total": 103,
... | cpp | {
"raw_signature": "int getCommon(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "getCommon",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type": "int",
"signatu... |
2,541 | minimum-operations-to-make-array-equal-ii | Medium | You are given two integer arrays nums1 and nums2 of equal length n and an integer k. You can perform the following operation on nums1:
- Choose two indexes i and j and increment nums1[i] by k and decrement nums1[j] by k. In other words, nums1[i] = nums1[i] + k and nums1[j] = nums1[j] - k.
nums1 is said to be equal to... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [3, 8, 5, 2],nums2 = [2, 4, 1, 6],k = 1) == -1\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [10, 10, 10, 10],k = 5) == -1\n assert candidate(nums1 = [1, 2, 3, 4],nums2 = [1, 2, 3, 4],k = 2) == 0\n assert candidate(num... | [
"[4,3,1,4]\n[1,3,7,1]\n3",
"[3,8,5,2]\n[2,4,1,6]\n1"
] | [
"What are the cases for which we cannot make nums1 == nums2?",
"For minimum moves, if nums1[i] < nums2[i], then we should never decrement nums1[i]. If nums1[i] > nums2[i], then we should never increment nums1[i]."
] | {
"canonical_parameter_names": [
"nums1",
"nums2",
"k"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:29",
"tests_... | cpp | {
"raw_signature": "long long minOperations(vector<int>& nums1, vector<int>& nums2, int k) {",
"container": "Solution",
"callable": "minOperations",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
},
{
"name... |
2,542 | maximum-subsequence-score | Medium | You are given two 0-indexed integer arrays nums1 and nums2 of equal length n and a positive integer k. You must choose a subsequence of indices from nums1 of length k.
For chosen indices i_0, i_1, ..., i_{k - 1}, your score is defined as:
- The sum of the selected elements from nums1 multiplied with the minimum of th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],k = 2) == 15\n assert candidate(nums1 = [100000, 0, 0, 0, 0],nums2 = [1, 100000, 1, 100000, 1],k = 1) == 100000\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5]... | [
"[1,3,3,2]\n[2,1,3,4]\n3",
"[4,2,3,1,1]\n[7,5,10,9,6]\n1"
] | [
"How can we use sorting here?",
"Try sorting the two arrays based on second array.",
"Loop through nums2 and compute the max product given the minimum is nums2[i]. Update the answer accordingly."
] | {
"canonical_parameter_names": [
"nums1",
"nums2",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:31",
"tests_total... | cpp | {
"raw_signature": "long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {",
"container": "Solution",
"callable": "maxScore",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
},
{
"name": "k",
... |
2,543 | check-if-point-is-reachable | Hard | There exists an infinitely large grid. You are currently at point (1, 1), and you need to reach the point (targetX, targetY) using a finite number of steps.
In one step, you can move from point (x, y) to any one of the following points:
- (x, y - x)
- (x - y, y)
- (2 * x, y)
- (x, 2 * y)
Given two integers targetX a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(targetX = 7,targetY = 3) == True\n assert candidate(targetX = 6,targetY = 9) == False\n assert candidate(targetX = 16,targetY = 8) == True\n assert candidate(targetX = 3,targetY = 5) == True\n assert candidate(targetX = 10,ta... | [
"6\n9",
"4\n7"
] | [
"Let’s go in reverse order, from (targetX, targetY) to (1, 1). So, now we can move from (x, y) to (x+y, y), (x, y+x), (x/2, y) if x is even, and (x, y/2) if y is even.",
"When is it optimal to use the third and fourth operations?",
"Think how GCD of (x, y) is affected if we apply the first two operations.",
"... | {
"canonical_parameter_names": [
"targetX",
"targetY"
],
"leetcode_dataset_entry_point": "Solution().isReachable",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:34",
"tests_total":... | cpp | {
"raw_signature": "bool isReachable(int targetX, int targetY) {",
"container": "Solution",
"callable": "isReachable",
"parameters": [
{
"name": "targetX",
"type": "int"
},
{
"name": "targetY",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcode/... |
2,544 | alternating-digit-sum | Easy | You are given a positive integer n. Each digit of n has a sign according to the following rules:
- The most significant digit is assigned a positive sign.
- Each other digit has an opposite sign to its adjacent digits.
Return the sum of all digits with their corresponding sign.
Example 1:
Input: n = 521
Output: 4
E... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 987654321) == 5\n assert candidate(n = 123) == 2\n assert candidate(n = 987) == 8\n assert candidate(n = 9) == 9\n assert candidate(n = 123456789) == 5\n assert candidate(n = 111) == 1\n assert candidate(n = 1) == 1... | [
"521",
"111",
"886996"
] | [
"The first step is to loop over the digits. We can convert the integer into a string, an array of digits, or just loop over its digits.",
"Keep a variable sign that initially equals 1 and a variable answer that initially equals 0.",
"Each time you loop over a digit i, add sign * i to answer, then multiply sign ... | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().alternateDigitSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:36",
"tests_total": 57,
"tests_d... | cpp | {
"raw_signature": "int alternateDigitSum(int n) {",
"container": "Solution",
"callable": "alternateDigitSum",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,545 | sort-the-students-by-their-kth-score | Medium | There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the i^th student got in the j^th exam. The matrix score contains distinct integers only.
You are also given an integer k. Sort the students (i.e., ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(score = [[90, 80, 70], [60, 50, 40], [30, 20, 10]],k = 1) == [[90, 80, 70], [60, 50, 40], [30, 20, 10]]\n assert candidate(score = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]],k = 3) == [[3, 4, 5, 6], [2, 3, 4, 5], [1, 2, 3, 4]]\n as... | [
"[[10,6,9,1],[7,5,11,2],[4,8,3,15]]\n2",
"[[3,4],[5,6]]\n0"
] | [
"Find the row with the highest score in the kth exam and swap it with the first row.",
"After fixing the first row, perform the same operation for the rest of the rows, and the matrix's rows will get sorted one by one."
] | {
"canonical_parameter_names": [
"score",
"k"
],
"leetcode_dataset_entry_point": "Solution().sortTheStudents",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:38",
"tests_total": 83,... | cpp | {
"raw_signature": "vector<vector<int>> sortTheStudents(vector<vector<int>>& score, int k) {",
"container": "Solution",
"callable": "sortTheStudents",
"parameters": [
{
"name": "score",
"type": "vector<vector<int>>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type":... |
2,546 | apply-bitwise-operations-to-make-strings-equal | Medium | You are given two 0-indexed binary strings s and target of the same length n. You can do the following operation on s any number of times:
- Choose two different indices i and j where 0 <= i, j < n.
- Simultaneously, replace s[i] with (s[i] OR s[j]) and s[j] with (s[i] XOR s[j]).
For example, if s = "0110", you can c... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1001\",target = \"1001\") == True\n assert candidate(s = \"1010\",target = \"0110\") == True\n assert candidate(s = \"11\",target = \"00\") == False\n assert candidate(s = \"0000\",target = \"0000\") == True\n assert ca... | [
"\"1010\"\n\"0110\"",
"\"11\"\n\"00\""
] | [
"Think of when it is impossible to convert the string to the target.",
"If exactly one of the strings is having all 0’s, then it is impossible. And it is possible in all other cases. Why is that true?"
] | {
"canonical_parameter_names": [
"s",
"target"
],
"leetcode_dataset_entry_point": "Solution().makeStringsEqual",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:41",
"tests_total": 9... | cpp | {
"raw_signature": "bool makeStringsEqual(string s, string target) {",
"container": "Solution",
"callable": "makeStringsEqual",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "target",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "l... |
2,547 | minimum-cost-to-split-an-array | Hard | You are given an integer array nums and an integer k.
Split the array into some number of non-empty subarrays. The cost of a split is the sum of the importance value of each subarray in the split.
Let trimmed(subarray) be the version of the subarray where all numbers which appear only once are removed.
- For example... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],k = 4) == 14\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1],k = 1) == 7\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5) == 15\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2,... | [
"[1,2,1,2,1,3,3]\n2",
"[1,2,1,2,1]\n2",
"[1,2,1,2,1]\n5"
] | [
"Let's denote dp[r] = minimum cost to partition the first r elements of nums. What would be the transitions of such dynamic programming?",
"dp[r] = min(dp[l] + importance(nums[l..r])) over all 0 <= l < r. This already gives us an O(n^3) approach, as importance can be calculated in linear time, and there are a tot... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().minCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:43",
"tests_total": 122,
"test... | cpp | {
"raw_signature": "int minCost(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "minCost",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippe... |
2,549 | count-distinct-numbers-on-board | Easy | You are given a positive integer n, that is initially placed on a board. Every day, for 10^9 days, you perform the following procedure:
- For each number x present on the board, find all numbers 1 <= i <= n such that x % i == 1.
- Then, place those numbers on the board.
Return the number of distinct integers present ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 99) == 98\n assert candidate(n = 20) == 19\n assert candidate(n = 100) == 99\n assert candidate(n = 1) == 1\n assert candidate(n = 10) == 9\n assert candidate(n = 5) == 4\n assert c... | [
"5",
"3"
] | [
"For n > 2, n % (n - 1) == 1 thus n - 1 will be added on the board the next day.",
"As the operations are performed for so long time, all the numbers lesser than n except 1 will be added to the board.",
"What will happen if n == 1?"
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().distinctIntegers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:48",
"tests_total": 50,
"tests_dr... | cpp | {
"raw_signature": "int distinctIntegers(int n) {",
"container": "Solution",
"callable": "distinctIntegers",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,551 | put-marbles-in-bags | Hard | You have k bags. You are given a 0-indexed integer array weights where weights[i] is the weight of the i^th marble. You are also given the integer k.
Divide the marbles into the k bags according to the following rules:
- No bag is empty.
- If the i^th marble and j^th marble are in a bag, then all marbles with an inde... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(weights = [1, 1, 1, 1, 1, 1, 1, 1],k = 4) == 0\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 40\n assert candidate(weights = [1, 1, 1, 1, 1],k = 5) == 0\n assert candidate(weights = [5, 5, 5, 5, 5, 5],k ... | [
"[1,3,5,1]\n2",
"[1,3]\n2"
] | [
"Each bag will contain a subarray, and only the endpoints of these subarrays matter.",
"Each subarray only contributes two numbers to the sum. Use this property to choose the subarrays optimally.",
"Try to use a priority queue."
] | {
"canonical_parameter_names": [
"weights",
"k"
],
"leetcode_dataset_entry_point": "Solution().putMarbles",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:50",
"tests_total": 87,
... | cpp | {
"raw_signature": "long long putMarbles(vector<int>& weights, int k) {",
"container": "Solution",
"callable": "putMarbles",
"parameters": [
{
"name": "weights",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "long long",
"signature_sourc... |
2,552 | count-increasing-quadruplets | Hard | Given a 0-indexed integer array nums of size n containing all numbers from 1 to n, return the number of increasing quadruplets.
A quadruplet (i, j, k, l) is increasing if:
- 0 <= i < j < k < l < n, and
- nums[i] < nums[k] < nums[j] < nums[l].
Example 1:
Input: nums = [1,3,2,4,5]
Output: 2
Explanation:
- When i = 0,... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == 2\n assert candidate(nums = [4, 3, 2, 1]) == 0\n assert candidate(nums = [4, 3, 2, 1, 5, 6]) == 0\n assert candidate(nums = [3, 1, 4, 2, 5, 6, 9, 7, 8, 10]) == 18\n assert candidate(nums = [5, 2, 3,... | [
"[1,3,2,4,5]",
"[1,2,3,4]"
] | [
"Can you loop over all possible (j, k) and find the answer?",
"We can pre-compute all possible (i, j) and (k, l) and store them in 2 matrices.",
"The answer will the sum of prefix[j][k] * suffix[k][j]."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countQuadruplets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:52",
"tests_total": 90,
"tests... | cpp | {
"raw_signature": "long long countQuadruplets(vector<int>& nums) {",
"container": "Solution",
"callable": "countQuadruplets",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
2,553 | separate-the-digits-in-an-array | Easy | Given an array of positive integers nums, return an array answer that consists of the digits of each integer in nums after separating them in the same order they appear in nums.
To separate the digits of an integer is to get all the digits it has in the same order.
- For example, for the integer 10921, the separation... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10921, 456, 78]) == [1, 0, 9, 2, 1, 4, 5, 6, 7, 8]\n assert candidate(nums = [98765, 43210, 11111, 22222]) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2]\n assert candidate(nums = [98765, 43210]) == [9, 8, ... | [
"[13,25,83,77]",
"[7,1,3,9]"
] | [
"Convert each number into a list and append that list to the answer.",
"You can convert the integer into a string to do that easily."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().separateDigits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:55",
"tests_total": 110,
"tests_... | cpp | {
"raw_signature": "vector<int> separateDigits(vector<int>& nums) {",
"container": "Solution",
"callable": "separateDigits",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
2,554 | maximum-number-of-integers-to-choose-from-a-range-i | Medium | You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules:
- The chosen integers have to be in the range [1, n].
- Each integer can be chosen at most once.
- The chosen integers should not be in the array banned.
- The sum of the chosen inte... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(banned = [11],n = 7,maxSum = 50) == 7\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7],n = 8,maxSum = 1) == 0\n assert candidate(banned = [1, 6, 5],n = 5,maxSum = 6) == 2\n assert candidate(banned = [2, 4, 6, 8],n = 10,maxSum =... | [
"[1,6,5]\n5\n6",
"[1,2,3,4,5,6,7]\n8\n1",
"[11]\n7\n50"
] | [
"Keep the banned numbers that are less than or equal to n in a set.",
"Loop over the numbers from 1 to n and if the number is not banned, use it.",
"Keep adding numbers while they are not banned, and their sum is less than or equal to k."
] | {
"canonical_parameter_names": [
"banned",
"n",
"maxSum"
],
"leetcode_dataset_entry_point": "Solution().maxCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:56:57",
"tests_tot... | cpp | {
"raw_signature": "int maxCount(vector<int>& banned, int n, int maxSum) {",
"container": "Solution",
"callable": "maxCount",
"parameters": [
{
"name": "banned",
"type": "vector<int>&"
},
{
"name": "n",
"type": "int"
},
{
"name": "maxSum",
"type": "int"
... |
2,555 | maximize-win-from-two-segments | Medium | There are some prizes on the X-axis. You are given an integer array prizePositions that is sorted in non-decreasing order, where prizePositions[i] is the position of the i^th prize. There could be different prizes at the same position on the line. You are also given an integer k.
You are allowed to select two segments... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(prizePositions = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 10\n assert candidate(prizePositions = [1, 3, 5, 7, 9],k = 1) == 2\n assert candidate(prizePositions = [5, 5, 5, 5, 5],k = 1) == 5\n assert candidate(prizePositions = [5,... | [
"[1,1,2,2,3,3,5]\n2",
"[1,2,3,4]\n0"
] | [
"Try solving the problem for one interval.",
"Using the solution with one interval, how can you combine that with a second interval?"
] | {
"canonical_parameter_names": [
"prizePositions",
"k"
],
"leetcode_dataset_entry_point": "Solution().maximizeWin",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:00",
"tests_total"... | cpp | {
"raw_signature": "int maximizeWin(vector<int>& prizePositions, int k) {",
"container": "Solution",
"callable": "maximizeWin",
"parameters": [
{
"name": "prizePositions",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_s... |
2,556 | disconnect-path-in-a-binary-matrix-by-at-most-one-flip | Medium | You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1) that has the value 1. The matrix is disconnected if there is no path from (0, 0) to (m - 1, n - 1).
You can flip the value of at most one (possibly none) cell. You cannot flip th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 0, 1], [1, 0, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1], [1, 0, 0], [1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 0], [1, 0, 0, 0], [1, 1, 1, 0], [1, 0, 1, 1]]) == Tr... | [
"[[1,1,1],[1,0,0],[1,1,1]]",
"[[1,1,1],[1,0,1],[1,1,1]]"
] | [
"We can consider the grid a graph with edges between adjacent cells.",
"If you can find two non-intersecting paths from (0, 0) to (m - 1, n - 1) then the answer is false. Otherwise, it is always true."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().isPossibleToCutPath",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:02",
"tests_total": 81,
"te... | cpp | {
"raw_signature": "bool isPossibleToCutPath(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "isPossibleToCutPath",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_sour... |
2,558 | take-gifts-from-the-richest-pile | Easy | You are given an integer array gifts denoting the number of gifts in various piles. Every second, you do the following:
- Choose the pile with the maximum number of gifts.
- If there is more than one pile with the maximum number of gifts, choose any.
- Reduce the number of gifts in the pile to the floor of the square ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(gifts = [25, 64, 9, 4, 100],k = 4) == 29\n assert candidate(gifts = [16, 81, 49],k = 3) == 20\n assert candidate(gifts = [1, 1, 1, 1],k = 4) == 4\n assert candidate(gifts = [49, 36, 25, 16, 9],k = 5) == 25\n assert candidate(... | [
"[25,64,9,4,100]\n4",
"[1,1,1,1]\n4"
] | [
"How can you keep track of the largest gifts in the array",
"What is an efficient way to find the square root of a number?",
"Can you keep adding up the values of the gifts while ensuring they are in a certain order?",
"Can we use a priority queue or heap here?"
] | {
"canonical_parameter_names": [
"gifts",
"k"
],
"leetcode_dataset_entry_point": "Solution().pickGifts",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:07",
"tests_total": 108,
"t... | cpp | {
"raw_signature": "long long pickGifts(vector<int>& gifts, int k) {",
"container": "Solution",
"callable": "pickGifts",
"parameters": [
{
"name": "gifts",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "long long",
"signature_source": "l... |
2,559 | count-vowel-strings-in-ranges | Medium | You are given a 0-indexed array of strings words and a 2D array of integers queries.
Each query queries[i] = [l_i, r_i] asks us to find the number of strings present at the indices ranging from l_i to r_i (both inclusive) of words that start and end with a vowel.
Return an array ans of size queries.length, where ans[... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['aeiou', 'bcd', 'cde', 'ua'],queries = [[0, 0], [1, 2], [0, 3]]) == [1, 0, 2]\n assert candidate(words = ['aeiou', 'bcd', 'cde', 'dea'],queries = [[0, 3], [1, 2], [2, 2]]) == [1, 0, 0]\n assert candidate(words = ['aeiou', ... | [
"[\"aba\",\"bcb\",\"ece\",\"aa\",\"e\"]\n[[0,2],[1,4],[1,1]]",
"[\"a\",\"e\",\"i\"]\n[[0,2],[0,1],[2,2]]"
] | [
"Precompute the prefix sum of strings that start and end with vowels.",
"Use unordered_set to store vowels.",
"Check if the first and last characters of the string are present in the vowels set.",
"Subtract prefix sum for range [l-1, r] to find the number of strings starting and ending with vowels."
] | {
"canonical_parameter_names": [
"words",
"queries"
],
"leetcode_dataset_entry_point": "Solution().vowelStrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:10",
"tests_total": ... | cpp | {
"raw_signature": "vector<int> vowelStrings(vector<string>& words, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "vowelStrings",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
},
{
"name": "queries",
"type": "vector<vector<int>>&"
}... |
2,560 | house-robber-iv | Medium | There are several consecutive houses along a street, each of which has some money inside. There is also a robber, who wants to steal money from the homes, but he refuses to steal from adjacent homes.
The capability of the robber is the maximum amount of money he steals from one house of all the houses he robbed.
You ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 9\n assert candidate(nums = [10, 1, 1, 10, 1, 1, 10],k = 3) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k ... | [
"[2,3,5,9]\n2",
"[2,7,9,3,1]\n2"
] | [
"Can we use binary search to find the minimum value of a non-contiguous subsequence of a given size k?",
"Initialize the search range with the minimum and maximum elements of the input array.",
"Use a check function to determine if it is possible to select k non-consecutive elements that are less than or equal ... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().minCapability",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:12",
"tests_total": 105,
... | cpp | {
"raw_signature": "int minCapability(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "minCapability",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcod... |
2,561 | rearranging-fruits | Hard | You have two fruit baskets containing n fruits each. You are given two 0-indexed integer arrays basket1 and basket2 representing the cost of fruit in each basket. You want to make both baskets equal. To do so, you can use the following operation as many times as you want:
- Choose two indices i and j, and swap the i^t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(basket1 = [1000000000, 1000000000],basket2 = [1000000000, 1000000000]) == 0\n assert candidate(basket1 = [2, 3, 4, 1],basket2 = [3, 2, 5, 1]) == -1\n assert candidate(basket1 = [1, 1, 2, 2],basket2 = [2, 2, 1, 1]) == 0\n assert ... | [
"[4,2,2,2]\n[1,4,1,2]",
"[2,3,4,1]\n[3,2,5,1]"
] | [
"Create two frequency maps for both arrays, and find the minimum element among all elements of both arrays.",
"Check if the sum of frequencies of an element in both arrays is odd, if so return -1",
"Store the elements that need to be swapped in a vector, and sort it.",
"Can we reduce swapping cost with the he... | {
"canonical_parameter_names": [
"basket1",
"basket2"
],
"leetcode_dataset_entry_point": "Solution().minCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:14",
"tests_total": 109... | cpp | {
"raw_signature": "long long minCost(vector<int>& basket1, vector<int>& basket2) {",
"container": "Solution",
"callable": "minCost",
"parameters": [
{
"name": "basket1",
"type": "vector<int>&"
},
{
"name": "basket2",
"type": "vector<int>&"
}
],
"return_type": "long l... |
2,562 | find-the-array-concatenation-value | Easy | You are given a 0-indexed integer array nums.
The concatenation of two numbers is the number formed by concatenating their numerals.
- For example, the concatenation of 15, 49 is 1549.
The concatenation value of nums is initially equal to 0. Perform this operation until nums becomes empty:
- If nums has a size grea... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 14, 13, 8, 12]) == 673\n assert candidate(nums = [1, 1, 1, 1]) == 22\n assert candidate(nums = [111, 222, 333, 444, 555]) == 334332\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 315\n assert candidate(n... | [
"[7,52,2,4]",
"[5,14,13,8,12]"
] | [
"Consider simulating the process to calculate the answer",
"iterate until the array becomes empty. In each iteration, concatenate the first element to the last element and add their concatenation value to the answer.",
"Don’t forget to handle cases when one element is left in the end, not two elements."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findTheArrayConcVal",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:16",
"tests_total": 120,
"t... | cpp | {
"raw_signature": "long long findTheArrayConcVal(vector<int>& nums) {",
"container": "Solution",
"callable": "findTheArrayConcVal",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
2,563 | count-the-number-of-fair-pairs | Medium | Given a 0-indexed integer array nums of size n and two integers lower and upper, return the number of fair pairs.
A pair (i, j) is fair if:
- 0 <= i < j < n, and
- lower <= nums[i] + nums[j] <= upper
Example 1:
Input: nums = [0,1,7,4,4,5], lower = 3, upper = 6
Output: 6
Explanation: There are 6 fair pairs: (0,3), (... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000],lower = 0,upper = 0) == 2\n assert candidate(nums = [0, 1, 7, 4, 4, 5],lower = 3,upper = 6) == 6\n assert candidate(nums = [5, 5, 5, 5, 5],lower = 10,upper = 10) == 10\n as... | [
"[0,1,7,4,4,5]\n3\n6",
"[1,7,9,2,5]\n11\n11"
] | [
"Sort the array in ascending order.",
"For each number in the array, keep track of the smallest and largest numbers in the array that can form a fair pair with this number.",
"As you move to larger number, both boundaries move down."
] | {
"canonical_parameter_names": [
"nums",
"lower",
"upper"
],
"leetcode_dataset_entry_point": "Solution().countFairPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:18",
"te... | cpp | {
"raw_signature": "long long countFairPairs(vector<int>& nums, int lower, int upper) {",
"container": "Solution",
"callable": "countFairPairs",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "lower",
"type": "int"
},
{
"name": "upper",
... |
2,564 | substring-xor-queries | Medium | You are given a binary string s, and a 2D integer array queries where queries[i] = [first_i, second_i].
For the i^th query, find the shortest substring of s whose decimal value, val, yields second_i when bitwise XORed with first_i. In other words, val ^ first_i == second_i.
The answer to the i^th query is the endpoin... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1\",queries = [[4, 5]]) == [[0, 0]]\n assert candidate(s = \"1100110011\",queries = [[15, 0], [7, 8], [3, 12], [5, 10]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"0101\",queries = [[12, 8]]) == [[-1... | [
"\"101101\"\n[[0,5],[1,2]]",
"\"0101\"\n[[12,8]]",
"\"1\"\n[[4,5]]"
] | [
"You do not need to consider substrings having lengths greater than 30.",
"Pre-process all substrings with lengths not greater than 30, and add the best endpoints to a dictionary."
] | {
"canonical_parameter_names": [
"s",
"queries"
],
"leetcode_dataset_entry_point": "Solution().substringXorQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:21",
"tests_total... | cpp | {
"raw_signature": "vector<vector<int>> substringXorQueries(string s, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "substringXorQueries",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "queries",
"type": "vector<vector<int>>&"
}
]... |
2,565 | subsequence-with-the-minimum-score | Hard | You are given two strings s and t.
You are allowed to remove any number of characters from the string t.
The score of the string is 0 if no characters are removed from the string t, otherwise:
- Let left be the minimum index among all removed characters.
- Let right be the maximum index among all removed characters.... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcd\",t = \"abcde\") == 1\n assert candidate(s = \"hello\",t = \"world\") == 5\n assert candidate(s = \"abcdefghij\",t = \"fihgjedcba\") == 8\n assert candidate(s = \"abcde\",t = \"edcba\") == 4\n assert candidate(s = ... | [
"\"abacaba\"\n\"bzaa\"",
"\"cde\"\n\"xyz\""
] | [
"Maintain two pointers: i and j. We need to perform a similar operation: while t[0:i] + t[j:n] is not a subsequence of the string s, increase j.",
"We can check the condition greedily. Create the array leftmost[i] which denotes minimum index k, such that in prefix s[0:k] exists subsequence t[0:i]. Similarly, we d... | {
"canonical_parameter_names": [
"s",
"t"
],
"leetcode_dataset_entry_point": "Solution().minimumScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:23",
"tests_total": 130,
"te... | cpp | {
"raw_signature": "int minimumScore(string s, string t) {",
"container": "Solution",
"callable": "minimumScore",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "t",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets... |
2,566 | maximum-difference-by-remapping-a-digit | Easy | You are given an integer num. You know that Bob will sneakily remap one of the 10 possible digits (0 to 9) to another digit.
Return the difference between the maximum and minimum values Bob can make by remapping exactly one digit in num.
Notes:
- When Bob remaps a digit d1 to another digit d2, Bob replaces all occur... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = 11891) == 99009\n assert candidate(num = 123321) == 900009\n assert candidate(num = 55555555) == 99999999\n assert candidate(num = 111111) == 999999\n assert candidate(num = 88888888) == 99999999\n assert candidate(n... | [
"11891",
"90"
] | [
"Try to remap the first non-nine digit to 9 to obtain the maximum number.",
"Try to remap the first non-zero digit to 0 to obtain the minimum number."
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().minMaxDifference",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:26",
"tests_total": 111,
"tests... | cpp | {
"raw_signature": "int minMaxDifference(int num) {",
"container": "Solution",
"callable": "minMaxDifference",
"parameters": [
{
"name": "num",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,567 | minimum-score-by-changing-two-elements | Medium | You are given an integer array nums.
- The low score of nums is the minimum absolute difference between any two integers.
- The high score of nums is the maximum absolute difference between any two integers.
- The score of nums is the sum of the high and low scores.
Return the minimum score after changing two element... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 100, 1000, 10000, 100000]) == 990\n assert candidate(nums = [1, 4, 7, 8, 5]) == 3\n assert candidate(nums = [1, 4, 3]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5,... | [
"[1,4,7,8,5]",
"[1,4,3]"
] | [
"Changing the minimum or maximum values will only minimize the score.",
"Think about what all possible pairs of minimum and maximum values can be changed to form the minimum score."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minimizeSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:28",
"tests_total": 82,
"tests_drop... | cpp | {
"raw_signature": "int minimizeSum(vector<int>& nums) {",
"container": "Solution",
"callable": "minimizeSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,568 | minimum-impossible-or | Medium | You are given a 0-indexed integer array nums.
We say that an integer x is expressible from nums if there exist some integers 0 <= index_1 < index_2 < ... < index_k < nums.length for which nums[index_1] | nums[index_2] | ... | nums[index_k] = x. In other words, an integer is expressible if it can be written as the bitw... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 3, 2]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16]) == 32\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 2048\n assert candidate(nums = [2, 1]) == 4\n assert candidate(nums = [7, 14... | [
"[2,1]",
"[5,3,2]"
] | [
"Think about forming numbers in the powers of 2 using their bit representation.",
"The minimum power of 2 not present in the array will be the first number that could not be expressed using the given operation."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minImpossibleOR",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:31",
"tests_total": 108,
"tests... | cpp | {
"raw_signature": "int minImpossibleOR(vector<int>& nums) {",
"container": "Solution",
"callable": "minImpossibleOR",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
2,569 | handling-sum-queries-after-update | Hard | You are given two 0-indexed arrays nums1 and nums2 and a 2D array queries of queries. There are three types of queries:
1. For a query of type 1, queries[i] = [1, l, r]. Flip the values from 0 to 1 and from 1 to 0 in nums1 from index l to index r. Both l and r are 0-indexed.
2. For a query of type 2, queries[i] = [2, ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [1],nums2 = [5],queries = [[2, 0, 0], [3, 0, 0]]) == [5]\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [10, 20, 30, 40, 50],queries = [[2, 5, 0], [3, 0, 0], [1, 0, 2], [2, 3, 0], [3, 0, 0]]) == [175, 181]\n assert cand... | [
"[1,0,1]\n[0,0,0]\n[[1,1,1],[2,1,0],[3,0,0]]",
"[1]\n[5]\n[[2,0,0],[3,0,0]]"
] | [
"Use the Lazy Segment Tree to process the queries quickly."
] | {
"canonical_parameter_names": [
"nums1",
"nums2",
"queries"
],
"leetcode_dataset_entry_point": "Solution().handleQuery",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:33",
"te... | cpp | {
"raw_signature": "vector<long long> handleQuery(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "handleQuery",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>... |
2,570 | merge-two-2d-arrays-by-summing-values | Easy | You are given two 2D integer arrays nums1 and nums2.
- nums1[i] = [id_i, val_i] indicate that the number with the id id_i has a value equal to val_i.
- nums2[i] = [id_i, val_i] indicate that the number with the id id_i has a value equal to val_i.
Each array contains unique ids and is sorted in ascending order by id.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [[1, 2], [2, 3], [4, 5]],nums2 = [[1, 4], [3, 2], [4, 1]]) == [(1, 6), (2, 3), (3, 2), (4, 6)]\n assert candidate(nums1 = [[2, 4], [3, 6], [5, 5]],nums2 = [[1, 3], [4, 3]]) == [(1, 3), (2, 4), (3, 6), (4, 3), (5, 5)]\n asse... | [
"[[1,2],[2,3],[4,5]]\n[[1,4],[3,2],[4,1]]",
"[[2,4],[3,6],[5,5]]\n[[1,3],[4,3]]"
] | [
"Use a dictionary/hash map to keep track of the indices and their sum values."
] | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().mergeArrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:35",
"tests_total": 93,... | cpp | {
"raw_signature": "vector<vector<int>> mergeArrays(vector<vector<int>>& nums1, vector<vector<int>>& nums2) {",
"container": "Solution",
"callable": "mergeArrays",
"parameters": [
{
"name": "nums1",
"type": "vector<vector<int>>&"
},
{
"name": "nums2",
"type": "vector<vector<i... |
2,571 | minimum-operations-to-reduce-an-integer-to-0 | Medium | You are given a positive integer n, you can do the following operation any number of times:
- Add or subtract a power of 2 from n.
Return the minimum number of operations to make n equal to 0.
A number x is power of 2 if x == 2^i where i >= 0.
Example 1:
Input: n = 39
Output: 3
Explanation: We can do the following... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 63) == 2\n assert candidate(n = 100) == 3\n assert candidate(n = 50000) == 6\n assert candidate(n = 4) == 1\n assert candidate(n = 64) == 1\n assert candidate(n = 16) == 1\n assert ... | [
"39",
"54"
] | [
"Can we set/unset the bits in binary representation?",
"If there are multiple adjacent ones, how can we optimally add and subtract in 2 operations such that all ones get unset?",
"Bonus: Try to solve the problem with higher constraints: n ≤ 10^18."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:37",
"tests_total": 60,
"tests_dropp... | cpp | {
"raw_signature": "int minOperations(int n) {",
"container": "Solution",
"callable": "minOperations",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,572 | count-the-number-of-square-free-subsets | Medium | You are given a positive integer 0-indexed array nums.
A subset of the array nums is square-free if the product of its elements is a square-free integer.
A square-free integer is an integer that is divisible by no square number other than 1.
Return the number of square-free non-empty subsets of the array nums. Since... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 147483633.0\n assert candidate(nums = [2, 3, 5, 7, 11]) == 31.0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == ... | [
"[3,4,4,5]",
"[1]"
] | [
"There are 10 primes before number 30.",
"Label primes from {2, 3, … 29} with {0,1, … 9} and let DP(i, mask) denote the number of subsets before index: i with the subset of taken primes: mask.",
"If the mask and prime factorization of nums[i] have a common prime, then it is impossible to add to the current subs... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().squareFreeSubsets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:39",
"tests_total": 103,
"tes... | cpp | {
"raw_signature": "int squareFreeSubsets(vector<int>& nums) {",
"container": "Solution",
"callable": "squareFreeSubsets",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
2,573 | find-the-string-with-lcp | Hard | We define the lcp matrix of any 0-indexed string word of n lowercase English letters as an n x n grid such that:
- lcp[i][j] is equal to the length of the longest common prefix between the substrings word[i,n-1] and word[j,n-1].
Given an n x n matrix lcp, return the alphabetically smallest string word that correspond... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(lcp = [[4, 3, 2, 1], [3, 3, 2, 1], [2, 2, 2, 1], [1, 1, 1, 3]]) == \"\"\n assert candidate(lcp = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) == \"\"\n assert candidate(lcp = [[4, 0, 2, 0], [0, 3, 0, 1], [2, 0, 2, 0], ... | [
"[[4,0,2,0],[0,3,0,1],[2,0,2,0],[0,1,0,1]]",
"[[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,1]]",
"[[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,3]]"
] | [
"Use the LCP array to determine which groups of elements must be equal.",
"Match the smallest letter to the group that contains the smallest unassigned index.",
"Build the LCP matrix of the resulting string then check if it is equal to the target LCP."
] | {
"canonical_parameter_names": [
"lcp"
],
"leetcode_dataset_entry_point": "Solution().findTheString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:42",
"tests_total": 75,
"tests_dro... | cpp | {
"raw_signature": "string findTheString(vector<vector<int>>& lcp) {",
"container": "Solution",
"callable": "findTheString",
"parameters": [
{
"name": "lcp",
"type": "vector<vector<int>>&"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leet... |
2,574 | left-and-right-sum-differences | Easy | You are given a 0-indexed integer array nums of size n.
Define two arrays leftSum and rightSum where:
- leftSum[i] is the sum of elements to the left of the index i in the array nums. If there is no such element, leftSum[i] = 0.
- rightSum[i] is the sum of elements to the right of the index i in the array nums. If th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == [10, 1, 6, 11, 14]\n assert candidate(nums = [1]) == [0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [54, 51, 46, 39, 30, 19, 6, 9, 26, 45]\n assert candidate(nums = [10, 20, 30]) == ... | [
"[10,4,8,3]",
"[1]"
] | [
"For each index i, maintain two variables leftSum and rightSum.",
"Iterate on the range j: [0 … i - 1] and add nums[j] to the leftSum and similarly iterate on the range j: [i + 1 … nums.length - 1] and add nums[j] to the rightSum."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().leftRightDifference",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:44",
"tests_total": 131,
"t... | cpp | {
"raw_signature": "vector<int> leftRightDifference(vector<int>& nums) {",
"container": "Solution",
"callable": "leftRightDifference",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source... |
2,576 | find-the-maximum-number-of-marked-indices | Medium | You are given a 0-indexed integer array nums.
Initially, all of the indices are unmarked. You are allowed to make this operation any number of times:
- Pick two different unmarked indices i and j such that 2 * nums[i] <= nums[j], then mark i and j.
Return the maximum possible number of marked indices in nums using t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 6\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 10\n assert candidate(nums = [7, 6, 8]) == 0\n assert candidate(nums = [1000000000, ... | [
"[3,5,2,4]",
"[9,2,5,4]",
"[7,6,8]"
] | [
"Think about how to check that performing k operations is possible.",
"To perform k operations, it’s optimal to use the smallest k elements and the largest k elements and think about how to match them.",
"It’s optimal to match the ith smallest number with the k-i + 1 largest number.",
"Now we need to binary s... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxNumOfMarkedIndices",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:49",
"tests_total": 119,
... | cpp | {
"raw_signature": "int maxNumOfMarkedIndices(vector<int>& nums) {",
"container": "Solution",
"callable": "maxNumOfMarkedIndices",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
2,577 | minimum-time-to-visit-a-cell-in-a-grid | Hard | You are given a m x n matrix grid consisting of non-negative integers where grid[row][col] represents the minimum time required to be able to visit the cell (row, col), which means you can visit the cell (row, col) only when the time you visit it is greater than or equal to grid[row][col].
You are standing in the top-... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 2, 4], [3, 2, 1], [1, 0, 4]]) == -1\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 4\n assert candidate(grid = [[0, 0], [0, 1]]) == 2\n assert candidate(grid = [[0, 1, 3, 2], [5, 1, 2, 5], [4, 3, 8, ... | [
"[[0,1,3,2],[5,1,2,5],[4,3,8,6]]",
"[[0,2,4],[3,2,1],[1,0,4]]"
] | [
"Try using some algorithm that can find the shortest paths on a graph.",
"Consider the case where you have to go back and forth between two cells of the matrix to unlock some other cells."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().minimumTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:51",
"tests_total": 114,
"tests_dro... | cpp | {
"raw_signature": "int minimumTime(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "minimumTime",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
2,578 | split-with-minimum-sum | Easy | Given a positive integer num, split it into two non-negative integers num1 and num2 such that:
- The concatenation of num1 and num2 is a permutation of num.
- In other words, the sum of the number of occurrences of each digit in num1 and num2 is equal to the number of occurrences of that digit in num.
- num1 and num... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = 10) == 1\n assert candidate(num = 687) == 75\n assert candidate(num = 4325) == 59\n assert candidate(num = 1234) == 37\n assert candidate(num = 222) == 24\n assert candidate(num = 1000000000) == 1\n assert candida... | [
"4325",
"687"
] | [
"Sort the digits of num in non decreasing order.",
"Assign digits to num1 and num2 alternatively."
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().splitNum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:54",
"tests_total": 98,
"tests_dropped"... | cpp | {
"raw_signature": "int splitNum(int num) {",
"container": "Solution",
"callable": "splitNum",
"parameters": [
{
"name": "num",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,579 | count-total-number-of-colored-cells | Medium | There exists an infinitely large two-dimensional grid of uncolored unit cells. You are given a positive integer n, indicating that you must do the following routine for n minutes:
- At the first minute, color any arbitrary unit cell blue.
- Every minute thereafter, color blue every uncolored cell that touches a blue c... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3) == 13\n assert candidate(n = 100000) == 19999800001\n assert candidate(n = 100) == 19801\n assert candidate(n = 10000) == 199980001\n assert candidate(n = 2) == 5\n assert candidate(n = 1) == 1\n assert candidate... | [
"1",
"2"
] | [
"Derive a mathematical relation between total number of colored cells and the time elapsed in minutes."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().coloredCells",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:56",
"tests_total": 37,
"tests_droppe... | cpp | {
"raw_signature": "long long coloredCells(int n) {",
"container": "Solution",
"callable": "coloredCells",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,581 | count-number-of-possible-root-nodes | Hard | Alice has an undirected tree with n nodes labeled from 0 to n - 1. The tree is represented as 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.
Alice wants Bob to find the root of the tree. She allows Bob to make several guesses ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(edges = [[0, 1], [0, 2], [0, 3]],guesses = [[0, 1], [0, 2], [0, 3]],k = 2) == 4\n assert candidate(edges = [[0, 1], [0, 2]],guesses = [[0, 1]],k = 1) == 2\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [4, 2]],guesses = [[1, 3... | [
"[[0,1],[1,2],[1,3],[4,2]]\n[[1,3],[0,1],[1,0],[2,4]]\n3",
"[[0,1],[1,2],[2,3],[3,4]]\n[[1,0],[3,4],[2,1],[3,2]]\n1"
] | [
"How can we check if any node can be the root?",
"Can we use this information to check its neighboring nodes?",
"When we traverse from current node to a neighboring node, how will we update our answer?"
] | {
"canonical_parameter_names": [
"edges",
"guesses",
"k"
],
"leetcode_dataset_entry_point": "Solution().rootCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:58",
"tests_to... | cpp | {
"raw_signature": "int rootCount(vector<vector<int>>& edges, vector<vector<int>>& guesses, int k) {",
"container": "Solution",
"callable": "rootCount",
"parameters": [
{
"name": "edges",
"type": "vector<vector<int>>&"
},
{
"name": "guesses",
"type": "vector<vector<int>>&"
... |
2,582 | pass-the-pillow | Easy | There are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Once the pillow reaches the end of the line, the direction changes, and people continue passing the pillow... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 2,time = 5) == 2\n assert candidate(n = 10,time = 15) == 4\n assert candidate(n = 500,time = 750) == 249\n assert candidate(n = 2,time = 1) == 2\n assert candidate(n = 7,time = 20) == 5\n assert candidate(n = 8,time = ... | [
"4\n5",
"3\n2"
] | [
"Maintain two integer variables, direction and i, where direction denotes the current direction in which the pillow should pass, and i denotes an index of the person holding the pillow.",
"While time is positive, update the current index with the current direction. If the index reaches the end of the line, multip... | {
"canonical_parameter_names": [
"n",
"time"
],
"leetcode_dataset_entry_point": "Solution().passThePillow",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:01",
"tests_total": 94,
... | cpp | {
"raw_signature": "int passThePillow(int n, int time) {",
"container": "Solution",
"callable": "passThePillow",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "time",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
... |
2,584 | split-the-array-to-make-coprime-products | Hard | You are given a 0-indexed integer array nums of length n.
A split at an index i where 0 <= i <= n - 2 is called valid if the product of the first i + 1 elements and the product of the remaining elements are coprime.
- For example, if nums = [2, 3, 3], then a split at the index i = 0 is valid because 2 and 9 are copri... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [60, 1, 2, 3]) == -1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == -1\n assert candidate(nums = [2, 3, 5, 7, 11, 13]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12]) == -1\n assert candidate(nums = ... | [
"[4,7,8,15,3,5]",
"[4,7,15,8,3,5]"
] | [
"Two numbers with GCD equal to 1 have no common prime divisor.",
"Find the prime factorization of the left and right sides and check if they share a prime divisor."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findValidSplit",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:06",
"tests_total": 107,
"tests_... | cpp | {
"raw_signature": "int findValidSplit(vector<int>& nums) {",
"container": "Solution",
"callable": "findValidSplit",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"... |
2,585 | number-of-ways-to-earn-points | Hard | There is a test that has n types of questions. You are given an integer target and a 0-indexed 2D integer array types where types[i] = [count_i, marks_i] indicates that there are count_i questions of the i^th type, and each one of them is worth marks_i points.
Return the number of ways you can earn exactly target poin... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(target = 10,types = [[2, 5], [1, 3]]) == 1\n assert candidate(target = 1,types = [[1, 1]]) == 1\n assert candidate(target = 30,types = [[5, 10], [3, 5], [2, 15]]) == 5\n assert candidate(target = 750,types = [[50, 15], [50, 25],... | [
"6\n[[6,1],[3,2],[2,3]]",
"5\n[[50,1],[50,2],[50,5]]",
"18\n[[6,1],[3,2],[2,3]]"
] | [
"Use Dynamic Programming",
"Let ways[i][points] be the number of ways to score a given number of points after solving some questions of the first i types.",
"ways[i][points] is equal to the sum of ways[i-1][points - solved * marks[i] over 0 <= solved <= count_i"
] | {
"canonical_parameter_names": [
"target",
"types"
],
"leetcode_dataset_entry_point": "Solution().waysToReachTarget",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:08",
"tests_tota... | cpp | {
"raw_signature": "int waysToReachTarget(int target, vector<vector<int>>& types) {",
"container": "Solution",
"callable": "waysToReachTarget",
"parameters": [
{
"name": "target",
"type": "int"
},
{
"name": "types",
"type": "vector<vector<int>>&"
}
],
"return_type": "... |
2,586 | count-the-number-of-vowel-strings-in-range | Easy | You are given a 0-indexed array of string words and two integers left and right.
A string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are 'a', 'e', 'i', 'o', and 'u'.
Return the number of vowel strings words[i] where i belongs to the inclusive ra... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['sky', 'fly', 'why'],left = 0,right = 2) == 0\n assert candidate(words = ['apple', 'banana', 'orange', 'umbrella'],left = 0,right = 3) == 3\n assert candidate(words = ['are', 'amy', 'u'],left = 0,right = 2) == 2\n asser... | [
"[\"are\",\"amy\",\"u\"]\n0\n2",
"[\"hey\",\"aeo\",\"mu\",\"ooo\",\"artro\"]\n1\n4"
] | [
"consider iterating over all strings from left to right and use an if condition to check if the first character and last character are vowels."
] | {
"canonical_parameter_names": [
"words",
"left",
"right"
],
"leetcode_dataset_entry_point": "Solution().vowelStrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:11",
"test... | cpp | {
"raw_signature": "int vowelStrings(vector<string>& words, int left, int right) {",
"container": "Solution",
"callable": "vowelStrings",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
},
{
"name": "left",
"type": "int"
},
{
"name": "right",
... |
2,587 | rearrange-array-to-maximize-prefix-score | Medium | You are given a 0-indexed integer array nums. You can rearrange the elements of nums to any order (including the given order).
Let prefix be the array containing the prefix sums of nums after rearranging it. In other words, prefix[i] is the sum of the elements from 0 to i in nums after rearranging it. The score of num... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, -1, 3, 2, -4, 0, 2]) == 7\n assert candidate(nums = [-1]) == 0\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == 5\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [5, -2, 3, 1, -4, 7]) == 6\n ass... | [
"[2,-1,0,1,-3,3,-3]",
"[-2,-3,0]"
] | [
"The best order of the array is in decreasing order.",
"Sort the array in decreasing order and count the number of positive values in the prefix sum array."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:13",
"tests_total": 105,
"tests_droppe... | cpp | {
"raw_signature": "int maxScore(vector<int>& nums) {",
"container": "Solution",
"callable": "maxScore",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,588 | count-the-number-of-beautiful-subarrays | Medium | You are given a 0-indexed integer array nums. In one operation, you can:
- Choose two different indices i and j such that 0 <= i, j < nums.length.
- Choose a non-negative integer k such that the k^th bit (0-indexed) in the binary representation of nums[i] and nums[j] is 1.
- Subtract 2^k from nums[i] and nums[j].
A s... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 25\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953]) == 0\n assert candidate(nums = [1, 0, 1, 0, 1]) == 6\n assert candidate(nums = [2, ... | [
"[4,3,1,2,4]",
"[1,10,4]"
] | [
"A subarray is beautiful if its xor is equal to zero.",
"Compute the prefix xor for every index, then the xor of subarray [left, right] is equal to zero if prefix_xor[left] ^ perfix_xor[right] == 0",
"Iterate from left to right and maintain a hash table to count the number of indices equal to the current prefix... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().beautifulSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:16",
"tests_total": 121,
"te... | cpp | {
"raw_signature": "long long beautifulSubarrays(vector<int>& nums) {",
"container": "Solution",
"callable": "beautifulSubarrays",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "le... |
2,589 | minimum-time-to-complete-all-tasks | Hard | There is a computer that can run an unlimited number of tasks at the same time. You are given a 2D integer array tasks where tasks[i] = [start_i, end_i, duration_i] indicates that the i^th task should run for a total of duration_i seconds (not necessarily continuous) within the inclusive time range [start_i, end_i].
Y... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(tasks = [[1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1]]) == 2\n assert candidate(tasks = [[1, 100, 50], [50, 150, 50], [100, 200, 50]]) == 99\n assert candidate(tasks = [[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1]]) == 5\n ... | [
"[[2,3,1],[4,5,1],[1,5,2]]",
"[[1,3,2],[2,5,3],[5,6,2]]"
] | [
"Sort the tasks in ascending order of end time",
"Since there are only up to 2000 time points to consider, you can check them one by one",
"It is always beneficial to run the task as late as possible so that later tasks can run simultaneously."
] | {
"canonical_parameter_names": [
"tasks"
],
"leetcode_dataset_entry_point": "Solution().findMinimumTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:18",
"tests_total": 112,
"test... | cpp | {
"raw_signature": "int findMinimumTime(vector<vector<int>>& tasks) {",
"container": "Solution",
"callable": "findMinimumTime",
"parameters": [
{
"name": "tasks",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "le... |
2,591 | distribute-money-to-maximum-children | Easy | You are given an integer money denoting the amount of money (in dollars) that you have and another integer children denoting the number of children that you must distribute the money to.
You have to distribute the money according to the following rules:
- All money must be distributed.
- Everyone must receive at leas... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(money = 150,children = 15) == 14\n assert candidate(money = 100,children = 5) == 4\n assert candidate(money = 15,children = 3) == 1\n assert candidate(money = 31,children = 3) == 2\n assert candidate(money = 7,children = 2) =... | [
"20\n3",
"16\n2"
] | [
"Can we distribute the money according to the rules if we give 'k' children exactly 8 dollars?",
"Brute force to find the largest possible value of k, or return -1 if there doesn’t exist any such k."
] | {
"canonical_parameter_names": [
"money",
"children"
],
"leetcode_dataset_entry_point": "Solution().distMoney",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:20",
"tests_total": 47... | cpp | {
"raw_signature": "int distMoney(int money, int children) {",
"container": "Solution",
"callable": "distMoney",
"parameters": [
{
"name": "money",
"type": "int"
},
{
"name": "children",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnip... |
2,592 | maximize-greatness-of-an-array | Medium | You are given a 0-indexed integer array nums. You are allowed to permute nums into a new array perm of your choosing.
We define the greatness of nums be the number of indices 0 <= i < nums.length for which perm[i] > nums[i].
Return the maximum possible greatness you can achieve after permuting nums.
Example 1:
Inpu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 6\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5]) == 5\n assert candidate(nums = [1... | [
"[1,3,5,2,1,3,1]",
"[1,2,3,4]"
] | [
"Can we use sorting and two pointers here?",
"Assign every element the next bigger unused element as many times as possible."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maximizeGreatness",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:23",
"tests_total": 86,
"test... | cpp | {
"raw_signature": "int maximizeGreatness(vector<int>& nums) {",
"container": "Solution",
"callable": "maximizeGreatness",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
2,593 | find-score-of-an-array-after-marking-all-elements | Medium | You are given an array nums consisting of positive integers.
Starting with score = 0, apply the following algorithm:
- Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index.
- Add the value of the chosen integer to score.
- Mark the chosen element and i... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [1, 1000000]) == 1\n assert candidate(nums = [1000000, 1, 1000000, 1, 1000000]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 25\n assert candidat... | [
"[2,1,3,4,5,2]",
"[2,3,5,1,3,2]"
] | [
"Try simulating the process of marking the elements and their adjacent.",
"If there is an element that was already marked, then you skip it."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:25",
"tests_total": 112,
"tests_dropp... | cpp | {
"raw_signature": "long long findScore(vector<int>& nums) {",
"container": "Solution",
"callable": "findScore",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
2,594 | minimum-time-to-repair-cars | Medium | You are given an integer array ranks representing the ranks of some mechanics. ranks_i is the rank of the i^th mechanic. A mechanic with a rank r can repair n cars in r * n^2 minutes.
You are also given an integer cars representing the total number of cars waiting in the garage to be repaired.
Return the minimum time... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(ranks = [1],cars = 1000000) == 1000000000000\n assert candidate(ranks = [10],cars = 100) == 100000\n assert candidate(ranks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cars = 20) == 25\n assert candidate(ranks = [5, 1, 8],cars = 6) == 16\... | [
"[4,2,3,1]\n10",
"[5,1,8]\n6"
] | [
"For a predefined fixed time, can all the cars be repaired?",
"Try using binary search on the answer."
] | {
"canonical_parameter_names": [
"ranks",
"cars"
],
"leetcode_dataset_entry_point": "Solution().repairCars",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:27",
"tests_total": 92,
... | cpp | {
"raw_signature": "long long repairCars(vector<int>& ranks, int cars) {",
"container": "Solution",
"callable": "repairCars",
"parameters": [
{
"name": "ranks",
"type": "vector<int>&"
},
{
"name": "cars",
"type": "int"
}
],
"return_type": "long long",
"signature_sou... |
2,595 | number-of-even-and-odd-bits | Easy | You are given a positive integer n.
Let even denote the number of even indices in the binary representation of n with value 1.
Let odd denote the number of odd indices in the binary representation of n with value 1.
Note that bits are indexed from right to left in the binary representation of a number.
Return the a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 8) == [0, 1]\n assert candidate(n = 3) == [1, 1]\n assert candidate(n = 1000) == [2, 4]\n assert candidate(n = 63) == [3, 3]\n assert candidate(n = 255) == [4, 4]\n assert candidate(n = 15) == [2, 2]\n assert candid... | [
"50",
"2"
] | [
"Maintain two integer variables, even and odd, to count the number of even and odd indices in the binary representation of integer n.",
"Divide n by 2 while n is positive, and if n modulo 2 is 1, add 1 to its corresponding variable."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().evenOddBit",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:30",
"tests_total": 62,
"tests_dropped"... | cpp | {
"raw_signature": "vector<int> evenOddBit(int n) {",
"container": "Solution",
"callable": "evenOddBit",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,596 | check-knight-tour-configuration | Medium | There is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the board exactly once.
You are given an n x n integer matrix grid consisting of distinct integers from the range [0, n * n - 1] where grid[row][col] indicates that the cell ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 5, 2], [6, 3, 1], [8, 7, 4]]) == False\n assert candidate(grid = [[0, 12, 3, 14, 5], [19, 2, 15, 4, 13], [6, 23, 8, 17, 16], [22, 11, 10, 9, 18], [7, 24, 21, 1, 20]]) == False\n assert candidate(grid = [[0, 5, 2], [3, 8... | [
"[[0,11,16,5,20],[17,4,19,10,15],[12,1,8,21,6],[3,18,23,14,9],[24,13,2,7,22]]",
"[[0,3,6],[5,8,1],[2,7,4]]"
] | [
"It is enough to check if each move of the knight is valid.",
"Try all cases of the knight's movements to check if a move is valid."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().checkValidGrid",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:32",
"tests_total": 54,
"tests_d... | cpp | {
"raw_signature": "bool checkValidGrid(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "checkValidGrid",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leet... |
2,597 | the-number-of-beautiful-subsets | Medium | You are given an array nums of positive integers and a positive integer k.
A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k.
Return the number of non-empty beautiful subsets of the array nums.
A subset of nums is an array that can be obtained by deleting some (... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90],k = 5) == 6764\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],k = 1) == 6764\n assert candidate(nums = [10, 2... | [
"[2,4,6]\n2",
"[1]\n1"
] | [
"Sort the array nums and create another array cnt of size nums[i].",
"Use backtracking to generate all the beautiful subsets. If cnt[nums[i] - k] is positive, then it is impossible to add nums[i] in the subset, and we just move to the next index. Otherwise, it is also possible to add nums[i] in the subset, in thi... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().beautifulSubsets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:34",
"tests_total": 74,... | cpp | {
"raw_signature": "int beautifulSubsets(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "beautifulSubsets",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "l... |
2,598 | smallest-missing-non-negative-integer-after-operations | Medium | You are given a 0-indexed integer array nums and an integer value.
In one operation, you can add or subtract value from any element of nums.
- For example, if nums = [1,2,3] and value = 2, you can choose to subtract value from nums[0] to make nums = [-1,2,3].
The MEX (minimum excluded) of an array is the smallest mi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [0, 1, 2, 3, 4, 5],value = 1) == 6\n assert candidate(nums = [0, 0, 0, 0],value = 3) == 1\n assert candidate(nums = [10, 15, 20, 25, 30],value = 5) == 1\n assert candidate(nums = [-1, -2, -3, -4],value = 2) == 4\n asse... | [
"[1,-10,7,13,6,8]\n5",
"[1,-10,7,13,6,8]\n7"
] | [
"Think about using modular arithmetic.",
"if x = nums[i] (mod value), then we can make nums[i] equal to x after some number of operations",
"How does finding the frequency of (nums[i] mod value) help?"
] | {
"canonical_parameter_names": [
"nums",
"value"
],
"leetcode_dataset_entry_point": "Solution().findSmallestInteger",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:37",
"tests_tota... | cpp | {
"raw_signature": "int findSmallestInteger(vector<int>& nums, int value) {",
"container": "Solution",
"callable": "findSmallestInteger",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "value",
"type": "int"
}
],
"return_type": "int",
"signatu... |
2,600 | k-items-with-the-maximum-sum | Easy | There is a bag that consists of items, each item has a number 1, 0, or -1 written on it.
You are given four non-negative integers numOnes, numZeros, numNegOnes, and k.
The bag initially contains:
- numOnes items with 1s written on them.
- numZeroes items with 0s written on them.
- numNegOnes items with -1s written o... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(numOnes = 25,numZeros = 25,numNegOnes = 0,k = 50) == 25\n assert candidate(numOnes = 0,numZeros = 50,numNegOnes = 0,k = 10) == 0\n assert candidate(numOnes = 3,numZeros = 2,numNegOnes = 0,k = 2) == 2\n assert candidate(numOnes =... | [
"3\n2\n0\n2",
"3\n2\n0\n4"
] | [
"It is always optimal to take items with the number 1 written on them as much as possible.",
"If k > numOnes, after taking all items with the number 1, it is always optimal to take items with the number 0 written on them as much as possible.",
"If k > numOnes + numZeroes we are forced to take k - numOnes - numZ... | {
"canonical_parameter_names": [
"numOnes",
"numZeros",
"numNegOnes",
"k"
],
"leetcode_dataset_entry_point": "Solution().kItemsWithMaximumSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2... | cpp | {
"raw_signature": "int kItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k) {",
"container": "Solution",
"callable": "kItemsWithMaximumSum",
"parameters": [
{
"name": "numOnes",
"type": "int"
},
{
"name": "numZeros",
"type": "int"
},
{
"name":... |
2,601 | prime-subtraction-operation | Medium | You are given a 0-indexed integer array nums of length n.
You can perform the following operation as many times as you want:
- Pick an index i that you haven’t picked before, and pick a prime p strictly less than nums[i], then subtract p from nums[i].
Return true if you can make nums a strictly increasing array usin... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 9, 6, 10]) == True\n assert candidate(nums = [999, 998, 997, 996, 995]) == True\n assert candidate(nums = [5, 8, 3]) == False\n assert candidate(nums = [100, 99, 98, 97, 96]) == True\n assert candidate(nums = [2, 3... | [
"[4,9,6,10]",
"[6,8,11,12]",
"[5,8,3]"
] | [
"Think about if we have many primes to subtract from nums[i]. Which prime is more optimal?",
"The most optimal prime to subtract from nums[i] is the one that makes nums[i] the smallest as possible and greater than nums[i-1]."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().primeSubOperation",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:44",
"tests_total": 157,
"tes... | cpp | {
"raw_signature": "bool primeSubOperation(vector<int>& nums) {",
"container": "Solution",
"callable": "primeSubOperation",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeS... |
2,602 | minimum-operations-to-make-all-array-elements-equal | Medium | You are given an array nums consisting of positive integers.
You are also given an integer array queries of size m. For the i^th query, you want to make all of the elements of nums equal to queries[i]. You can perform the following operation on the array any number of times:
- Increase or decrease an element of the a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1000000000],queries = [1000000000, 1, 999999999]) == [0, 999999999, 1]\n assert candidate(nums = [2, 9, 6, 3],queries = [10]) == [20]\n assert candidate(nums = [1, 1, 1, 1, 1],queries = [1, 2, 3]) == [0, 5, 10]\n assert ... | [
"[3,1,6,8]\n[1,5]",
"[2,9,6,3]\n[10]"
] | [
"For each query, you should decrease all elements greater than queries[i] and increase all elements less than queries[i].",
"The answer is the sum of absolute differences between queries[i] and every element of the array. How do you calculate that optimally?"
] | {
"canonical_parameter_names": [
"nums",
"queries"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:46",
"tests_total": ... | cpp | {
"raw_signature": "vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {",
"container": "Solution",
"callable": "minOperations",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "queries",
"type": "vector<int>&"
}
],
"return_... |
2,603 | collect-coins-in-a-tree | Hard | There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given an integer n and a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree. You are also given an array coins of size n where coins[i] can be... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(coins = [0, 0, 1, 0, 1, 0],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5]]) == 0\n assert candidate(coins = [0, 0, 0, 0, 0, 0, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 0\n assert candidate(coins = [1, 0, 0, ... | [
"[1,0,0,0,0,1]\n[[0,1],[1,2],[2,3],[3,4],[4,5]]",
"[0,0,0,1,1,0,0,1]\n[[0,1],[0,2],[1,3],[1,4],[2,5],[5,6],[5,7]]"
] | [
"All leaves that do not have a coin are redundant and can be deleted from the tree.",
"Remove the leaves that do not have coins on them, so that the resulting tree will have a coin on every leaf.",
"In the remaining tree, remove each leaf node and its parent from the tree. The remaining nodes in the tree are th... | {
"canonical_parameter_names": [
"coins",
"edges"
],
"leetcode_dataset_entry_point": "Solution().collectTheCoins",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:48",
"tests_total":... | cpp | {
"raw_signature": "int collectTheCoins(vector<int>& coins, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "collectTheCoins",
"parameters": [
{
"name": "coins",
"type": "vector<int>&"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"ret... |
2,605 | form-smallest-number-from-two-digit-arrays | Easy | Given two arrays of unique digits nums1 and nums2, return the smallest number that contains at least one digit from each array.
Example 1:
Input: nums1 = [4,1,3], nums2 = [5,7]
Output: 15
Explanation: The number 15 contains the digit 1 from nums1 and the digit 5 from nums2. It can be proven that 15 is the smallest nu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 4, 5]) == 3\n assert candidate(nums1 = [1, 2],nums2 = [3, 4]) == 13\n assert candidate(nums1 = [1, 9],nums2 = [2, 8]) == 12\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9]) == 16\n ... | [
"[4,1,3]\n[5,7]",
"[3,5,2,6]\n[3,1,7]"
] | [
"How many digits will the resulting number have at most?",
"The resulting number will have either one or two digits. Try to find when each case is possible."
] | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().minNumber",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:53",
"tests_total": 97,
... | cpp | {
"raw_signature": "int minNumber(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "minNumber",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type": "int",
"signatu... |
2,606 | find-the-substring-with-maximum-cost | Medium | You are given a string s, a string chars of distinct characters and an integer array vals of the same length as chars.
The cost of the substring is the sum of the values of each character in the substring. The cost of an empty string is considered 0.
The value of the character is defined in the following way:
- If t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"programming\",chars = \"pg\",vals = [-1, -2]) == 99\n assert candidate(s = \"a\",chars = \"a\",vals = [-1]) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",chars = \"abcdefghijklmnopqrstuvwxyz\",vals = [-26, -25, -... | [
"\"adaa\"\n\"d\"\n[-1000]",
"\"abc\"\n\"abc\"\n[-1,-1,-1]"
] | [
"Create a new integer array where arr[i] denotes the value of character s[i].",
"We can use Kadane’s maximum subarray sum algorithm to find the maximum cost."
] | {
"canonical_parameter_names": [
"s",
"chars",
"vals"
],
"leetcode_dataset_entry_point": "Solution().maximumCostSubstring",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:55",
"... | cpp | {
"raw_signature": "int maximumCostSubstring(string s, string chars, vector<int>& vals) {",
"container": "Solution",
"callable": "maximumCostSubstring",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "chars",
"type": "string"
},
{
"name": "vals",
... |
2,607 | make-k-subarray-sums-equal | Medium | You are given a 0-indexed integer array arr and an integer k. The array arr is circular. In other words, the first element of the array is the next element of the last element, and the last element of the array is the previous element of the first element.
You can do the following operation any number of times:
- Pic... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5],k = 1) == 6\n assert candidate(arr = [5, 5, 5, 5, 5],k = 2) == 0\n assert candidate(arr = [1, 4, 1, 3],k = 2) == 1\n assert candidate(arr = [10, 20, 30, 40, 50],k = 5) == 0\n assert candidate(arr = [5, 5... | [
"[1,4,1,3]\n2",
"[2,5,5,7]\n3"
] | [
"Think about gcd(n, k). How will it help to calculate the answer?",
"indices i and j are in the same group if gcd(n, k) mod i = gcd(n, k) mod j. Each group should have equal elements. Think about the minimum number of operations for each group",
"The minimum number of operations for each group equals the summat... | {
"canonical_parameter_names": [
"arr",
"k"
],
"leetcode_dataset_entry_point": "Solution().makeSubKSumEqual",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:58",
"tests_total": 102,... | cpp | {
"raw_signature": "long long makeSubKSumEqual(vector<int>& arr, int k) {",
"container": "Solution",
"callable": "makeSubKSumEqual",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "long long",
"signature_s... |
2,608 | shortest-cycle-in-a-graph | Hard | There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D integer array edges, where edges[i] = [u_i, v_i] denotes an edge between vertex u_i and vertex v_i. Every vertex pair is connected by at most one edge, and no vertex has an... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5]]) == 4\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [0, 4]]) == 4\n assert candidate(n = 3,edges = [[0, 1], [1, 2], [2, 0]])... | [
"7\n[[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]]",
"4\n[[0,1],[0,2]]"
] | [
"How can BFS be used?",
"For each vertex u, calculate the length of the shortest cycle that contains vertex u using BFS"
] | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().findShortestCycle",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:00",
"tests_total": 6... | cpp | {
"raw_signature": "int findShortestCycle(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "findShortestCycle",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"s... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.