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 |
|---|---|---|---|---|---|---|---|---|---|
1,780 | check-if-number-is-a-sum-of-powers-of-three | Medium | Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false.
An integer y is a power of three if there exists an integer x such that y == 3^x.
Example 1:
Input: n = 12
Output: true
Explanation: 12 = 3^1 + 3^2
Example 2:
Input: n = 91
Output: true... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 59049) == True\n assert candidate(n = 3) == True\n assert candidate(n = 729) == True\n assert candidate(n = 12) == True\n assert candidate(n = 243) == True\n assert candidate(n = 21) == False\n assert candidate(n = ... | [
"12",
"91",
"21"
] | [
"Let's note that the maximum power of 3 you'll use in your soln is 3^16",
"The number can not be represented as a sum of powers of 3 if it's ternary presentation has a 2 in it"
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().checkPowersOfThree",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:30:33",
"tests_total": 110,
"tests... | cpp | {
"raw_signature": "bool checkPowersOfThree(int n) {",
"container": "Solution",
"callable": "checkPowersOfThree",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,781 | sum-of-beauty-of-all-substrings | Medium | The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.
- For example, the beauty of "abaacc" is 3 - 1 = 2.
Given a string s, return the sum of beauty of all of its substrings.
Example 1:
Input: s = "aabcb"
Output: 5
Explanation: The substrings with non-zero ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"xyzzxyzzxyzz\") == 87\n assert candidate(s = \"aaabbbccc\") == 29\n assert candidate(s = \"aabcb\") == 5\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(s = \"abcdedcba\") == 16\n asser... | [
"\"aabcb\"",
"\"aabcbaa\""
] | [
"Maintain a prefix sum for the frequencies of characters.",
"You can iterate over all substring then iterate over the alphabet and find which character appears most and which appears least using the prefix sum array"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().beautySum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:30:35",
"tests_total": 103,
"tests_dropped"... | cpp | {
"raw_signature": "int beautySum(string s) {",
"container": "Solution",
"callable": "beautySum",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,782 | count-pairs-of-nodes | Hard | You are given an undirected graph defined by an integer n, the number of nodes, and a 2D integer array edges, the edges in the graph, where edges[i] = [u_i, v_i] indicates that there is an undirected edge between u_i and v_i. You are also given an integer array queries.
Let incident(a, b) be defined as the number of e... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,edges = [[1, 2], [2, 4], [1, 3], [2, 3], [2, 1]],queries = [2, 3]) == [6, 5]\n assert candidate(n = 5,edges = [[1, 5], [1, 5], [3, 4], [2, 5], [1, 3], [5, 1], [2, 3], [2, 5]],queries = [1, 2, 3, 4, 5]) == [10, 10, 9, 8, 6]\n ... | [
"4\n[[1,2],[2,4],[1,3],[2,3],[2,1]]\n[2,3]",
"5\n[[1,5],[1,5],[3,4],[2,5],[1,3],[5,1],[2,3],[2,5]]\n[1,2,3,4,5]"
] | [
"We want to count pairs (x,y) such that degree[x] + degree[y] - occurrences(x,y) > k",
"Think about iterating on x, and counting the number of valid y to pair with x.",
"You can consider at first that the (- occurrences(x,y)) isn't there, or it is 0 at first for all y. Count the valid y this way.",
"Then you ... | {
"canonical_parameter_names": [
"n",
"edges",
"queries"
],
"leetcode_dataset_entry_point": "Solution().countPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:30:37",
"tests_t... | cpp | {
"raw_signature": "vector<int> countPairs(int n, vector<vector<int>>& edges, vector<int>& queries) {",
"container": "Solution",
"callable": "countPairs",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
},
{
"nam... |
1,784 | check-if-binary-string-has-at-most-one-segment-of-ones | Easy | Given a binary string s without leading zeros, return true if s contains at most one contiguous segment of ones. Otherwise, return false.
Example 1:
Input: s = "1001"
Output: false
Explanation: The string has two segments of size 1.
Example 2:
Input: s = "110"
Output: true
Constraints:
- 1 <= s.length <= 100
- s[... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1111\") == True\n assert candidate(s = \"1000001\") == False\n assert candidate(s = \"111\") == True\n assert candidate(s = \"11110000\") == True\n assert candidate(s = \"100000\") == True\n assert candidate(s = \"11... | [
"\"1001\"",
"\"110\""
] | [
"It's guaranteed to have at least one segment",
"The string size is small so you can count all segments of ones with no that have no adjacent ones."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().checkOnesSegment",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:30:40",
"tests_total": 113,
"tests_d... | cpp | {
"raw_signature": "bool checkOnesSegment(string s) {",
"container": "Solution",
"callable": "checkOnesSegment",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,785 | minimum-elements-to-add-to-form-a-given-sum | Medium | You are given an integer array nums and two integers limit and goal. The array nums has an interesting property that abs(nums[i]) <= limit.
Return the minimum number of elements you need to add to make the sum of the array equal to goal. The array must maintain its property that abs(nums[i]) <= limit.
Note that abs(x... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, -1, 1],limit = 3,goal = -4) == 2\n assert candidate(nums = [1, -10, 9, 1],limit = 100,goal = 0) == 1\n assert candidate(nums = [0, 0, 0],limit = 1,goal = 3) == 3\n assert candidate(nums = [0, 0, 0, 0],limit = 5,goal =... | [
"[1,-1,1]\n3\n-4",
"[1,-10,9,1]\n100\n0"
] | [
"Try thinking about the problem as if the array is empty. Then you only need to form goal using elements whose absolute value is <= limit.",
"You can greedily set all of the elements except one to limit or -limit, so the number of elements you need is ceil(abs(goal)/ limit).",
"You can \"normalize\" goal by off... | {
"canonical_parameter_names": [
"nums",
"limit",
"goal"
],
"leetcode_dataset_entry_point": "Solution().minElements",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:30:42",
"tests_... | cpp | {
"raw_signature": "int minElements(vector<int>& nums, int limit, int goal) {",
"container": "Solution",
"callable": "minElements",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "limit",
"type": "int"
},
{
"name": "goal",
"type": "i... |
1,786 | number-of-restricted-paths-from-first-to-last-node | Medium | There is an undirected weighted connected graph. You are given a positive integer n which denotes that the graph has n nodes labeled from 1 to n, and an array edges where each edges[i] = [u_i, v_i, weight_i] denotes that there is an edge between nodes u_i and v_i with weight equal to weight_i.
A path from node start t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,edges = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 1, 4]]) == 1\n assert candidate(n = 3,edges = [[1, 2, 5], [1, 3, 6], [2, 3, 1]]) == 2\n assert candidate(n = 7,edges = [[1, 3, 1], [4, 1, 2], [7, 3, 4], [2, 5, 3], [5, 6, 1], [6, ... | [
"5\n[[1,2,3],[1,3,3],[2,3,1],[1,4,2],[5,2,2],[3,5,1],[5,4,10]]",
"7\n[[1,3,1],[4,1,2],[7,3,4],[2,5,3],[5,6,1],[6,7,2],[7,5,3],[2,6,4]]"
] | [
"Run a Dijkstra from node numbered n to compute distance from the last node.",
"Consider all edges [u, v] one by one and direct them such that distance of u to n > distance of v to n. If both u and v are at the same distance from n, discard this edge.",
"Now this problem reduces to computing the number of paths... | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().countRestrictedPaths",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:30:45",
"tests_total"... | cpp | {
"raw_signature": "int countRestrictedPaths(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "countRestrictedPaths",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type": "int"... |
1,787 | make-the-xor-of-all-segments-equal-to-zero | Hard | You are given an array nums and an integer k. The XOR of a segment [left, right] where left <= right is the XOR of all the elements with indices between left and right, inclusive: nums[left] XOR nums[left+1] XOR ... XOR nums[right].
Return the minimum number of elements to change in the array such that the XOR of all ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == 0\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 5) == 6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5],k = 5) == 1\n assert candidate(nums = [1, 3, 5, 7, 9... | [
"[1,2,0,3,0]\n1",
"[3,4,5,2,1,7,3,4,7]\n3",
"[1,2,4,1,2,5,1,2,6]\n3"
] | [
"Let's note that for the XOR of all segments with size K to be equal to zeros, nums[i] has to be equal to nums[i+k]",
"Basically, we need to make the first K elements have XOR = 0 and then modify them."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().minChanges",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:30:47",
"tests_total": 113,
"t... | cpp | {
"raw_signature": "int minChanges(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "minChanges",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/code... |
1,790 | check-if-one-string-swap-can-make-strings-equal | Easy | You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.
Return true if it is possible to make both strings equal by performing at most one string swap on exactly one of the strings.... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s1 = \"attack\",s2 = \"defend\") == False\n assert candidate(s1 = \"bank\",s2 = \"kanb\") == True\n assert candidate(s1 = \"abcde\",s2 = \"abced\") == True\n assert candidate(s1 = \"abcd\",s2 = \"abdc\") == True\n assert cand... | [
"\"bank\"\n\"kanb\"",
"\"attack\"\n\"defend\"",
"\"kelb\"\n\"kelb\""
] | [
"The answer is false if the number of nonequal positions in the strings is not equal to 0 or 2.",
"Check that these positions have the same set of characters."
] | {
"canonical_parameter_names": [
"s1",
"s2"
],
"leetcode_dataset_entry_point": "Solution().areAlmostEqual",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:30:52",
"tests_total": 108,
... | cpp | {
"raw_signature": "bool areAlmostEqual(string s1, string s2) {",
"container": "Solution",
"callable": "areAlmostEqual",
"parameters": [
{
"name": "s1",
"type": "string"
},
{
"name": "s2",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/co... |
1,791 | find-center-of-star-graph | Easy | There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.
You are given a 2D integer array edges where each edges[i] = [u_i, v_i] indicates that there is an edge between... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(edges = [[3, 1], [1, 2], [1, 4], [1, 5]]) == 1\n assert candidate(edges = [[7, 3], [7, 4], [7, 2], [7, 5], [7, 6], [7, 1]]) == 7\n assert candidate(edges = [[4, 3], [5, 3], [2, 3], [1, 3]]) == 3\n assert candidate(edges = [[1, 2... | [
"[[1,2],[2,3],[4,2]]",
"[[1,2],[5,1],[1,3],[1,4]]"
] | [
"The center is the only node that has more than one edge.",
"The center is also connected to all other nodes.",
"Any two edges must have a common node, which is the center."
] | {
"canonical_parameter_names": [
"edges"
],
"leetcode_dataset_entry_point": "Solution().findCenter",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:30:54",
"tests_total": 58,
"tests_drop... | cpp | {
"raw_signature": "int findCenter(vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "findCenter",
"parameters": [
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,792 | maximum-average-pass-ratio | Medium | There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [pass_i, total_i]. You know beforehand that in the i^th class, there are total_i total students, but only pass_i number of students will pass the exam.
You are also gi... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat... | [
"[[1,2],[3,5],[2,2]]\n2",
"[[2,4],[3,9],[4,5],[2,10]]\n4"
] | [
"Pay attention to how much the pass ratio changes when you add a student to the class. If you keep adding students, what happens to the change in pass ratio? The more students you add to a class, the smaller the change in pass ratio becomes.",
"Since the change in the pass ratio is always decreasing with the more... | {
"canonical_parameter_names": [
"classes",
"extraStudents"
],
"leetcode_dataset_entry_point": "Solution().maxAverageRatio",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:30:57",
"tes... | cpp | {
"raw_signature": "double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {",
"container": "Solution",
"callable": "maxAverageRatio",
"parameters": [
{
"name": "classes",
"type": "vector<vector<int>>&"
},
{
"name": "extraStudents",
"type": "int"
}
],
... |
1,793 | maximum-score-of-a-good-subarray | Hard | You are given an array of integers nums (0-indexed) and an integer k.
The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j.
Return the maximum possible score of a good subarray.
Example 1:
Input: nums = [1,4,3,7,4,5], k = 3... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 4, 5, 4, 1, 1, 1],k = 0) == 20\n assert candidate(nums = [10, 10, 10, 10, 10],k = 2) == 50\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == 25\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 10... | [
"[1,4,3,7,4,5]\n3",
"[5,5,4,5,4,1,1,1]\n0"
] | [
"Try thinking about the prefix before index k and the suffix after index k as two separate arrays.",
"Using two pointers or binary search, we can find the maximum prefix of each array where the numbers are less than or equal to a certain value"
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().maximumScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:30:59",
"tests_total": 98,
"... | cpp | {
"raw_signature": "int maximumScore(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "maximumScore",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/... |
1,796 | second-largest-digit-in-a-string | Easy | Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist.
An alphanumeric string is a string consisting of lowercase English letters and digits.
Example 1:
Input: s = "dfa12321afd"
Output: 2
Explanation: The digits that appear in s are [1, 2, 3]. The sec... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"9876543210\") == 8\n assert candidate(s = \"same1same1same1\") == -1\n assert candidate(s = \"abcdefghij0\") == -1\n assert candidate(s = \"abc1111\") == -1\n assert candidate(s = \"1a\") == -1\n assert candidate(s =... | [
"\"dfa12321afd\"",
"\"abc1111\""
] | [
"First of all, get the distinct characters since we are only interested in those",
"Let's note that there might not be any digits."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().secondHighest",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:04",
"tests_total": 131,
"tests_drop... | cpp | {
"raw_signature": "int secondHighest(string s) {",
"container": "Solution",
"callable": "secondHighest",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,798 | maximum-number-of-consecutive-values-you-can-make | Medium | You are given an integer array coins of length n which represents the n coins that you own. The value of the i^th coin is coins[i]. You can make some value x if you can choose some of your n coins such that their values sum up to x.
Return the maximum number of consecutive integer values that you can make with your co... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(coins = [1, 3]) == 2\n assert candidate(coins = [1, 2, 5]) == 4\n assert candidate(coins = [2, 2, 2, 2]) == 1\n assert candidate(coins = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 56\n assert candidate(coins = [1]) == 2\n assert ... | [
"[1,3]",
"[1,1,1,4]",
"[1,4,10,3,1]"
] | [
"If you can make the first x values and you have a value v, then you can make all the values ≤ v + x",
"Sort the array of coins. You can always make the value 0 so you can start with x = 0.",
"Process the values starting from the smallest and stop when there is a value that cannot be achieved with the current x... | {
"canonical_parameter_names": [
"coins"
],
"leetcode_dataset_entry_point": "Solution().getMaximumConsecutive",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:07",
"tests_total": 98,
... | cpp | {
"raw_signature": "int getMaximumConsecutive(vector<int>& coins) {",
"container": "Solution",
"callable": "getMaximumConsecutive",
"parameters": [
{
"name": "coins",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
1,800 | maximum-ascending-subarray-sum | Easy | Given an array of positive integers nums, return the maximum possible sum of an strictly increasing subarray in nums.
A subarray is defined as a contiguous sequence of numbers in an array.
Example 1:
Input: nums = [10,20,30,5,10,50]
Output: 65
Explanation: [5,10,50] is the ascending subarray with the maximum sum of ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100, 99, 98, 97, 96]) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [10]) == 10\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [100, 1, 2, 3, 100, 2, ... | [
"[10,20,30,5,10,50]",
"[10,20,30,40,50]",
"[12,17,15,13,10,11,12]"
] | [
"It is fast enough to check all possible subarrays",
"The end of each ascending subarray will be the start of the next"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxAscendingSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:09",
"tests_total": 128,
"tests... | cpp | {
"raw_signature": "int maxAscendingSum(vector<int>& nums) {",
"container": "Solution",
"callable": "maxAscendingSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
1,801 | number-of-orders-in-the-backlog | Medium | You are given a 2D integer array orders, where each orders[i] = [price_i, amount_i, orderType_i] denotes that amount_iorders have been placed of type orderType_i at the price price_i. The orderType_i is:
- 0 if it is a batch of buy orders, or
- 1 if it is a batch of sell orders.
Note that orders[i] represents a batch... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(orders = [[7, 1000000000, 1], [15, 3, 0], [5, 999999995, 0], [5, 1, 1]]) == 999999984\n assert candidate(orders = [[1, 10, 0], [1, 10, 1], [1, 10, 0], [1, 10, 1]]) == 0\n assert candidate(orders = [[100, 1, 0], [200, 2, 0], [300, 3... | [
"[[10,5,0],[15,2,1],[25,1,1],[30,4,0]]",
"[[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]"
] | [
"Store the backlog buy and sell orders in two heaps, the buy orders in a max heap by price and the sell orders in a min heap by price.",
"Store the orders in batches and update the fields according to new incoming orders. Each batch should only take 1 \"slot\" in the heap."
] | {
"canonical_parameter_names": [
"orders"
],
"leetcode_dataset_entry_point": "Solution().getNumberOfBacklogOrders",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:11",
"tests_total": 11... | cpp | {
"raw_signature": "int getNumberOfBacklogOrders(vector<vector<int>>& orders) {",
"container": "Solution",
"callable": "getNumberOfBacklogOrders",
"parameters": [
{
"name": "orders",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
... |
1,802 | maximum-value-at-a-given-index-in-a-bounded-array | Medium | You are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions:
- nums.length == n
- nums[i] is a positive integer where 0 <= i < n.
- abs(nums[i] - nums[i+1]) <= 1 where 0 <= i < n-1.
- The sum of all the elements of nums does not e... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 1,index = 0,maxSum = 1) == 1\n assert candidate(n = 10,index = 5,maxSum = 50) == 7\n assert candidate(n = 6,index = 1,maxSum = 10) == 3\n assert candidate(n = 1000000000,index = 500000000,maxSum = 1000000000) == 1\n asser... | [
"4\n2\n6",
"6\n1\n10"
] | [
"What if the problem was instead determining if you could generate a valid array with nums[index] == target?",
"To generate the array, set nums[index] to target, nums[index-i] to target-i, and nums[index+i] to target-i. Then, this will give the minimum possible sum, so check if the sum is less than or equal to ma... | {
"canonical_parameter_names": [
"n",
"index",
"maxSum"
],
"leetcode_dataset_entry_point": "Solution().maxValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:14",
"tests_tota... | cpp | {
"raw_signature": "int maxValue(int n, int index, int maxSum) {",
"container": "Solution",
"callable": "maxValue",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "index",
"type": "int"
},
{
"name": "maxSum",
"type": "int"
}
],
"return_t... |
1,803 | count-pairs-with-xor-in-a-range | Hard | Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.
A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.
Example 1:
Input: nums = [1,4,2,7], low = 2, high = 6
Output: 6
Explanation: All nice pairs (i, j) are as follow... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 7, 9],low = 1,high = 10) == 8\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9],low = 3,high = 7) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],low = 15,high = 25) == 1\n assert candidate(nums = [9, 8, 4... | [
"[1,4,2,7]\n2\n6",
"[9,8,4,2,1]\n5\n14"
] | [
"Let's note that we can count all pairs with XOR ≤ K, so the answer would be to subtract the number of pairs withs XOR < low from the number of pairs with XOR ≤ high.",
"For each value, find out the number of values when you XOR it with the result is ≤ K using a trie."
] | {
"canonical_parameter_names": [
"nums",
"low",
"high"
],
"leetcode_dataset_entry_point": "Solution().countPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:16",
"tests_tot... | cpp | {
"raw_signature": "int countPairs(vector<int>& nums, int low, int high) {",
"container": "Solution",
"callable": "countPairs",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "low",
"type": "int"
},
{
"name": "high",
"type": "int"
... |
1,805 | number-of-different-integers-in-a-string | Easy | You are given a string word that consists of digits and lowercase English letters.
You will replace every non-digit character with a space. For example, "a123bc34d8ef34" will become " 123 34 8 34". Notice that you are left with some integers that are separated by at least one space: "123", "34", "8", and "34".
Return... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word = \"a1b2c3d4e5f6g7h8i9j0\") == 10\n assert candidate(word = \"a123bc34d8ef34\") == 3\n assert candidate(word = \"a1a2a3a4a5a6a7a8a9a0\") == 10\n assert candidate(word = \"100leetcode\") == 1\n assert candidate(word = \"a... | [
"\"a123bc34d8ef34\"",
"\"leet1234code234\"",
"\"a1b01c001\""
] | [
"Try to split the string so that each integer is in a different string.",
"Try to remove each integer's leading zeroes and compare the strings to find how many of them are unique."
] | {
"canonical_parameter_names": [
"word"
],
"leetcode_dataset_entry_point": "Solution().numDifferentIntegers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:18",
"tests_total": 124,
"... | cpp | {
"raw_signature": "int numDifferentIntegers(string word) {",
"container": "Solution",
"callable": "numDifferentIntegers",
"parameters": [
{
"name": "word",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"... |
1,806 | minimum-number-of-operations-to-reinitialize-a-permutation | Medium | You are given an even integer n. You initially have a permutation perm of size n where perm[i] == i (0-indexed).
In one operation, you will create a new array arr, and for each i:
- If i % 2 == 0, then arr[i] = perm[i / 2].
- If i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2].
You will then assign arr to perm.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 8) == 3\n assert candidate(n = 4) == 2\n assert candidate(n = 12) == 10\n assert candidate(n = 14) == 12\n assert candidate(n = 16) == 4\n assert candidate(n = 18) == 8\n assert candidate(n = 6) == 4\n assert can... | [
"2",
"4",
"6"
] | [
"It is safe to assume the number of operations isn't more than n",
"The number is small enough to apply a brute force solution."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().reinitializePermutation",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:20",
"tests_total": 38,
"t... | cpp | {
"raw_signature": "int reinitializePermutation(int n) {",
"container": "Solution",
"callable": "reinitializePermutation",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,807 | evaluate-the-bracket-pairs-of-a-string | Medium | You are given a string s that contains some bracket pairs, with each pair containing a non-empty key.
- For example, in the string "(name)is(age)yearsold", there are two bracket pairs that contain the keys "name" and "age".
You know the values of a wide range of keys. This is represented by a 2D string array knowledg... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"(a)(a)(a)aaa\",knowledge = [['a', 'yes']]) == \"yesyesyesaaa\"\n assert candidate(s = \"hi(name)\",knowledge = [['a', 'b']]) == \"hi?\"\n assert candidate(s = \"(a)(a)(a)aaa\",knowledge = [['a', 'yes']]) == \"yesyesyesaaa\"\n... | [
"\"(name)is(age)yearsold\"\n[[\"name\",\"bob\"],[\"age\",\"two\"]]",
"\"hi(name)\"\n[[\"a\",\"b\"]]",
"\"(a)(a)(a)aaa\"\n[[\"a\",\"yes\"]]"
] | [
"Process pairs from right to left to handle repeats",
"Keep track of the current enclosed string using another string"
] | {
"canonical_parameter_names": [
"s",
"knowledge"
],
"leetcode_dataset_entry_point": "Solution().evaluate",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:23",
"tests_total": 113,
... | cpp | {
"raw_signature": "string evaluate(string s, vector<vector<string>>& knowledge) {",
"container": "Solution",
"callable": "evaluate",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "knowledge",
"type": "vector<vector<string>>&"
}
],
"return_type": "strin... |
1,812 | determine-color-of-a-chessboard-square | Easy | You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.
Return true if the square is white, and false if the square is black.
The coordinate will always represent a valid chessboard square. The coordinate will always have the letter ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(coordinates = \"d5\") == True\n assert candidate(coordinates = \"e4\") == True\n assert candidate(coordinates = \"b8\") == False\n assert candidate(coordinates = \"b2\") == False\n assert candidate(coordinates = \"a1\") == Fa... | [
"\"a1\"",
"\"h3\"",
"\"c7\""
] | [
"Convert the coordinates to (x, y) - that is, \"a1\" is (1, 1), \"d7\" is (4, 7).",
"Try add the numbers together and look for a pattern."
] | {
"canonical_parameter_names": [
"coordinates"
],
"leetcode_dataset_entry_point": "Solution().squareIsWhite",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:27",
"tests_total": 74,
"t... | cpp | {
"raw_signature": "bool squareIsWhite(string coordinates) {",
"container": "Solution",
"callable": "squareIsWhite",
"parameters": [
{
"name": "coordinates",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
1,813 | sentence-similarity-iii | Medium | You are given two strings sentence1 and sentence2, each representing a sentence composed of words. A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of only uppercase and lowercase English characters.
Two sentences s1 and s2 are considered similar... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(sentence1 = \"Similar sentences\",sentence2 = \"Similar similar sentences\") == True\n assert candidate(sentence1 = \"Start end\",sentence2 = \"Start middle end\") == True\n assert candidate(sentence1 = \"Eating right now\",sentenc... | [
"\"My name is Haley\"\n\"My Haley\"",
"\"of\"\n\"A lot of words\"",
"\"Eating right now\"\n\"Eating\""
] | [
"One way to look at it is to find one sentence as a concatenation of a prefix and suffix from the other sentence.",
"Get the longest common prefix between them and the longest common suffix."
] | {
"canonical_parameter_names": [
"sentence1",
"sentence2"
],
"leetcode_dataset_entry_point": "Solution().areSentencesSimilar",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:29",
"t... | cpp | {
"raw_signature": "bool areSentencesSimilar(string sentence1, string sentence2) {",
"container": "Solution",
"callable": "areSentencesSimilar",
"parameters": [
{
"name": "sentence1",
"type": "string"
},
{
"name": "sentence2",
"type": "string"
}
],
"return_type": "boo... |
1,814 | count-nice-pairs-in-an-array | Medium | You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x. For example, rev(123) = 321, and rev(120) = 21. A pair of indices (i, j) is nice if it satisfies all of the following conditions:
- 0 <= i < j < nums.length
- nums[i] + rev(nums[j]) ==... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 45\n assert candidate(nums = [100, 200, 300, 400]) == 0\n assert candidate(nums = [123, 321, 213, 132, 231, 312]) == 2\n assert candidate(nums = [123, 321, 213, 132]) == 1\n assert ca... | [
"[42,11,1,97]",
"[13,10,35,24,76]"
] | [
"The condition can be rearranged to (nums[i] - rev(nums[i])) == (nums[j] - rev(nums[j])).",
"Transform each nums[i] into (nums[i] - rev(nums[i])). Then, count the number of (i, j) pairs that have equal values.",
"Keep a map storing the frequencies of values that you have seen so far. For each i, check if nums[i... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countNicePairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:32",
"tests_total": 107,
"tests_... | cpp | {
"raw_signature": "int countNicePairs(vector<int>& nums) {",
"container": "Solution",
"callable": "countNicePairs",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"... |
1,815 | maximum-number-of-groups-getting-fresh-donuts | Hard | There is a donuts shop that bakes donuts in batches of batchSize. They have a rule where they must serve all of the donuts of a batch before serving any donuts of the next batch. You are given an integer batchSize and an integer array groups, where groups[i] denotes that there is a group of groups[i] customers that wil... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(batchSize = 7,groups = [7, 14, 21, 28, 35, 42, 49]) == 7\n assert candidate(batchSize = 2,groups = [2, 2, 2, 2, 2, 2]) == 6\n assert candidate(batchSize = 7,groups = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 12\n assert candidate... | [
"3\n[1,2,3,4,5,6]",
"4\n[1,3,2,5,2,2,1,6]"
] | [
"The maximum number of happy groups is the maximum number of partitions you can split the groups into such that the sum of group sizes in each partition is 0 mod batchSize. At most one partition is allowed to have a different remainder (the first group will get fresh donuts anyway).",
"Suppose you have an array f... | {
"canonical_parameter_names": [
"batchSize",
"groups"
],
"leetcode_dataset_entry_point": "Solution().maxHappyGroups",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:34",
"tests_tot... | cpp | {
"raw_signature": "int maxHappyGroups(int batchSize, vector<int>& groups) {",
"container": "Solution",
"callable": "maxHappyGroups",
"parameters": [
{
"name": "batchSize",
"type": "int"
},
{
"name": "groups",
"type": "vector<int>&"
}
],
"return_type": "int",
"signa... |
1,816 | truncate-sentence | Easy | A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation).
- For example, "Hello World", "HELLO", and "hello world hello world" are all sentences.
You are given a sentence s and an ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"I love to code\",k = 3) == \"I love to\"\n assert candidate(s = \"Python is great\",k = 2) == \"Python is\"\n assert candidate(s = \"Python programming is fun\",k = 2) == \"Python programming\"\n assert candidate(s = \"A q... | [
"\"Hello how are you Contestant\"\n4",
"\"What is the solution to this problem\"\n4",
"\"chopper is not a tanuki\"\n5"
] | [
"It's easier to solve this problem on an array of strings so parse the string to an array of words",
"After return the first k words as a sentence"
] | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().truncateSentence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:36",
"tests_total": 94,
... | cpp | {
"raw_signature": "string truncateSentence(string s, int k) {",
"container": "Solution",
"callable": "truncateSentence",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "string",
"signature_source": "leetcode/code... |
1,817 | finding-the-users-active-minutes | Medium | You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [ID_i, time_i] indicates that the user with ID_i performed an action at the minute time_i.
Multiple users can perform actions simultaneously, and a single user can perform m... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(logs = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]],k = 3) == [0, 0, 3]\n assert candidate(logs = [[10, 1], [11, 2], [10, 2], [11, 3], [10, 3], [11, 4]],k = 4) == [0, 0, 2, 0]\n assert candidate(logs = [... | [
"[[0,5],[1,2],[0,2],[0,5],[1,3]]\n5",
"[[1,1],[2,2],[2,3]]\n4"
] | [
"Try to find the number of different minutes when action happened for each user.",
"For each user increase the value of the answer array index which matches the UAM for this user."
] | {
"canonical_parameter_names": [
"logs",
"k"
],
"leetcode_dataset_entry_point": "Solution().findingUsersActiveMinutes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:39",
"tests_to... | cpp | {
"raw_signature": "vector<int> findingUsersActiveMinutes(vector<vector<int>>& logs, int k) {",
"container": "Solution",
"callable": "findingUsersActiveMinutes",
"parameters": [
{
"name": "logs",
"type": "vector<vector<int>>&"
},
{
"name": "k",
"type": "int"
}
],
"ret... |
1,818 | minimum-absolute-sum-difference | Medium | You are given two positive integer arrays nums1 and nums2, both of length n.
The absolute sum difference of arrays nums1 and nums2 is defined as the sum of |nums1[i] - nums2[i]| for each 0 <= i < n (0-indexed).
You can replace at most one element of nums1 with any other element in nums1 to minimize the absolute sum d... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [100000, 100000, 100000],nums2 = [1, 1, 1]) == 299997\n assert candidate(nums1 = [1, 7, 5],nums2 = [2, 3, 5]) == 3\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [1, 1, 1, 1]) == 16\n assert candidate(nums1 = [100000, 1... | [
"[1,7,5]\n[2,3,5]",
"[2,4,6,8,10]\n[2,4,6,8,10]",
"[1,10,4,4,2,7]\n[9,3,5,1,7,4]"
] | [
"Go through each element and test the optimal replacements.",
"There are only 2 possible replacements for each element (higher and lower) that are optimal."
] | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().minAbsoluteSumDiff",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:41",
"tests_tota... | cpp | {
"raw_signature": "int minAbsoluteSumDiff(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "minAbsoluteSumDiff",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type":... |
1,819 | number-of-different-subsequences-gcds | Hard | You are given an array nums that consists of positive integers.
The GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly.
- For example, the GCD of the sequence [4,6,16] is 2.
A subsequence of an array is a sequence that can be formed by removing some el... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [6, 10, 3]) == 5\n assert candidate(nums = [2, 4, 6, 8, 10]) == 5\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [5, 15, 40, 5, 6]) == 7\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 102... | [
"[6,10,3]",
"[5,15,40,5,6]"
] | [
"Think of how to check if a number x is a gcd of a subsequence.",
"If there is such subsequence, then all of it will be divisible by x. Moreover, if you divide each number in the subsequence by x , then the gcd of the resulting numbers will be 1.",
"Adding a number to a subsequence cannot increase its gcd. So, ... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countDifferentSubsequenceGCDs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:44",
"tests_total":... | cpp | {
"raw_signature": "int countDifferentSubsequenceGCDs(vector<int>& nums) {",
"container": "Solution",
"callable": "countDifferentSubsequenceGCDs",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_so... |
1,822 | sign-of-the-product-of-an-array | Easy | Implement a function signFunc(x) that returns:
- 1 if x is positive.
- -1 if x is negative.
- 0 if x is equal to 0.
You are given an integer array nums. Let product be the product of all values in the array nums.
Return signFunc(product).
Example 1:
Input: nums = [-1,-2,-3,-4,3,2,1]
Output: 1
Explanation: The prod... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [-1]) == -1\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [0, 0, 0]) == 0\n assert candidate(nums = [-99, -98, -97, -96, -95, -94, -93, -92, -91, -90]) == 1\n assert candidate(nums = [100, -100, 100]) =... | [
"[-1,-2,-3,-4,3,2,1]",
"[1,5,0,2,-3]",
"[-1,1,-1,1,-1]"
] | [
"If there is a 0 in the array the answer is 0",
"To avoid overflow make all the negative numbers -1 and all positive numbers 1 and calculate the prod"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().arraySign",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:49",
"tests_total": 96,
"tests_droppe... | cpp | {
"raw_signature": "int arraySign(vector<int>& nums) {",
"container": "Solution",
"callable": "arraySign",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,823 | find-the-winner-of-the-circular-game | Medium | There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the i^th friend brings you to the (i+1)^th friend for 1 <= i < n, and moving clockwise from the n^th friend brings you to the 1^st friend.
The rules of ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3,k = 1) == 3\n assert candidate(n = 3,k = 3) == 2\n assert candidate(n = 5,k = 2) == 3\n assert candidate(n = 7,k = 3) == 4\n assert candidate(n = 7,k = 1) == 7\n assert candidate(n = 6,k = 5) == 1\n assert candida... | [
"5\n2",
"6\n5"
] | [
"Simulate the process.",
"Maintain in a circular list the people who are still in the circle and the current person you are standing at.",
"In each turn, count k people and remove the last person from the list."
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().findTheWinner",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:51",
"tests_total": 83,
"te... | cpp | {
"raw_signature": "int findTheWinner(int n, int k) {",
"container": "Solution",
"callable": "findTheWinner",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type... |
1,824 | minimum-sideway-jumps | Medium | There is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n. A frog starts at point 0 in the second lane and wants to jump to point n. However, there could be obstacles along the way.
You are given an array obstacles of length n + 1 where each obstacles[i] (ranging from 0 to 3) describes an ob... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(obstacles = [0, 1, 0, 0, 2, 0, 0, 3, 0, 0]) == 1\n assert candidate(obstacles = [0, 0, 0, 0, 0, 0]) == 0\n assert candidate(obstacles = [0, 3, 2, 1, 0, 3, 2, 1, 0]) == 4\n assert candidate(obstacles = [0, 0, 1, 0, 0, 2, 0, 0, 3,... | [
"[0,1,2,3,0]",
"[0,1,1,3,3,0]",
"[0,2,1,0,3,0]"
] | [
"At a given point, there are only 3 possible states for where the frog can be.",
"Check all the ways to move from one point to the next and update the minimum side jumps for each lane."
] | {
"canonical_parameter_names": [
"obstacles"
],
"leetcode_dataset_entry_point": "Solution().minSideJumps",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:54",
"tests_total": 132,
"tes... | cpp | {
"raw_signature": "int minSideJumps(vector<int>& obstacles) {",
"container": "Solution",
"callable": "minSideJumps",
"parameters": [
{
"name": "obstacles",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
1,827 | minimum-operations-to-make-the-array-increasing | Easy | You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1.
- For example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3,3].
Return the minimum number of operations needed to make nums strictly increasing.
An array nums... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 20\n assert candidate(nums = [10000, 1, 1, 1, 1]) == 40006\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 25\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [10, 9, 8, 7,... | [
"[1,1,1]",
"[1,5,2,4,1]",
"[8]"
] | [
"nums[i+1] must be at least equal to nums[i] + 1.",
"Think greedily. You don't have to increase nums[i+1] beyond nums[i]+1.",
"Iterate on i and set nums[i] = max(nums[i-1]+1, nums[i]) ."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:31:58",
"tests_total": 118,
"tests_d... | cpp | {
"raw_signature": "int minOperations(vector<int>& nums) {",
"container": "Solution",
"callable": "minOperations",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,828 | queries-on-number-of-points-inside-a-circle | Medium | You are given an array points where points[i] = [x_i, y_i] is the coordinates of the i^th point on a 2D plane. Multiple points can have the same coordinates.
You are also given an array queries where queries[j] = [x_j, y_j, r_j] describes a circle centered at (x_j, y_j) with a radius of r_j.
For each query queries[j]... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[1, 2, 2], [2, 2, 2], [4, 3, 2], [4, 3, 3]]) == [2, 3, 2, 4]\n assert candidate(points = [[1, 3], [3, 3], [5, 3], [2, 2]],queries = [[2, 3, 1], [4, 3, 1], [1, 1, 2]]) == [3,... | [
"[[1,3],[3,3],[5,3],[2,2]]\n[[2,3,1],[4,3,1],[1,1,2]]",
"[[1,1],[2,2],[3,3],[4,4],[5,5]]\n[[1,2,2],[2,2,2],[4,3,2],[4,3,3]]"
] | [
"For a point to be inside a circle, the euclidean distance between it and the circle's center needs to be less than or equal to the radius.",
"Brute force for each circle and iterate overall points and find those inside it."
] | {
"canonical_parameter_names": [
"points",
"queries"
],
"leetcode_dataset_entry_point": "Solution().countPoints",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:00",
"tests_total": ... | cpp | {
"raw_signature": "vector<int> countPoints(vector<vector<int>>& points, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "countPoints",
"parameters": [
{
"name": "points",
"type": "vector<vector<int>>&"
},
{
"name": "queries",
"type": "vector<vector<int... |
1,829 | maximum-xor-for-each-query | Medium | You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times:
1. Find a non-negative integer k < 2^maximumBit such that nums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR k is maximized. k is the answer to the i^th query.
2. Remove the las... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 3, 4, 7],maximumBit = 3) == [5, 2, 6, 5]\n assert candidate(nums = [0, 1, 1, 3],maximumBit = 2) == [0, 3, 2, 3]\n assert candidate(nums = [1, 2, 4, 8, 16],maximumBit = 5) == [0, 16, 24, 28, 30]\n assert candidate(nums... | [
"[0,1,1,3]\n2",
"[2,3,4,7]\n3",
"[0,1,2,2,5,7]\n3"
] | [
"Note that the maximum possible XOR result is always 2^(maximumBit) - 1",
"So the answer for a prefix is the XOR of that prefix XORed with 2^(maximumBit)-1"
] | {
"canonical_parameter_names": [
"nums",
"maximumBit"
],
"leetcode_dataset_entry_point": "Solution().getMaximumXor",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:03",
"tests_total... | cpp | {
"raw_signature": "vector<int> getMaximumXor(vector<int>& nums, int maximumBit) {",
"container": "Solution",
"callable": "getMaximumXor",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "maximumBit",
"type": "int"
}
],
"return_type": "vector<int... |
1,832 | check-if-the-sentence-is-pangram | Easy | A pangram is a sentence where every letter of the English alphabet appears at least once.
Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.
Example 1:
Input: sentence = "thequickbrownfoxjumpsoverthelazydog"
Output: true
Explanation: sentence ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(sentence = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == True\n assert candidate(sentence = \"quickbrownfoxjumpsoverthelazydog\") == True\n assert candidate(sentence = \"aaaaabbbbbccccc\") == False\n assert candid... | [
"\"thequickbrownfoxjumpsoverthelazydog\"",
"\"leetcode\""
] | [
"Iterate over the string and mark each character as found (using a boolean array, bitmask, or any other similar way).",
"Check if the number of found characters equals the alphabet length."
] | {
"canonical_parameter_names": [
"sentence"
],
"leetcode_dataset_entry_point": "Solution().checkIfPangram",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:05",
"tests_total": 98,
"tes... | cpp | {
"raw_signature": "bool checkIfPangram(string sentence) {",
"container": "Solution",
"callable": "checkIfPangram",
"parameters": [
{
"name": "sentence",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,833 | maximum-ice-cream-bars | Medium | It is a sweltering summer day, and a boy wants to buy some ice cream bars.
At the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the i^th ice cream bar in coins. The boy initially has coins coins to spend, and he wants to buy as many ice cream bars as possib... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(costs = [1, 3, 2, 4, 1],coins = 7) == 4\n assert candidate(costs = [10, 6, 8, 7, 7, 8],coins = 5) == 0\n assert candidate(costs = [1],coins = 1) == 1\n assert candidate(costs = [1, 6, 3, 1, 2, 5],coins = 20) == 6\n assert can... | [
"[1,3,2,4,1]\n7",
"[10,6,8,7,7,8]\n5",
"[1,6,3,1,2,5]\n20"
] | [
"It is always optimal to buy the least expensive ice cream bar first.",
"Sort the prices so that the cheapest ice cream bar comes first."
] | {
"canonical_parameter_names": [
"costs",
"coins"
],
"leetcode_dataset_entry_point": "Solution().maxIceCream",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:07",
"tests_total": 75,... | cpp | {
"raw_signature": "int maxIceCream(vector<int>& costs, int coins) {",
"container": "Solution",
"callable": "maxIceCream",
"parameters": [
{
"name": "costs",
"type": "vector<int>&"
},
{
"name": "coins",
"type": "int"
}
],
"return_type": "int",
"signature_source": "l... |
1,834 | single-threaded-cpu | Medium | You are given n tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTime_i, processingTime_i] means that the i^th task will be available to process at enqueueTime_i and will take processingTime_ito finish processing.
You have a single-threaded CPU that can process at most on... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(tasks = [[1, 3], [2, 2], [3, 1], [4, 4]]) == [0, 2, 1, 3]\n assert candidate(tasks = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [0, 1, 2, 3, 4]\n assert candidate(tasks = [[1, 3], [2, 5], [8, 2], [7, 4], [10, 2]]) == [0, 1, 2, 4,... | [
"[[1,2],[2,4],[3,2],[4,1]]",
"[[7,10],[7,12],[7,5],[7,4],[7,2]]"
] | [
"To simulate the problem we first need to note that if at any point in time there are no enqueued tasks we need to wait to the smallest enqueue time of a non-processed element",
"We need a data structure like a min-heap to support choosing the task with the smallest processing time from all the enqueued tasks"
] | {
"canonical_parameter_names": [
"tasks"
],
"leetcode_dataset_entry_point": "Solution().getOrder",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:10",
"tests_total": 109,
"tests_dropp... | cpp | {
"raw_signature": "vector<int> getOrder(vector<vector<int>>& tasks) {",
"container": "Solution",
"callable": "getOrder",
"parameters": [
{
"name": "tasks",
"type": "vector<vector<int>>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
1,835 | find-xor-sum-of-all-pairs-bitwise-and | Hard | The XOR sum of a list is the bitwise XOR of all its elements. If the list only contains one element, then its XOR sum will be equal to this element.
- For example, the XOR sum of [1,2,3,4] is equal to 1 XOR 2 XOR 3 XOR 4 = 4, and the XOR sum of [3] is equal to 3.
You are given two 0-indexed arrays arr1 and arr2 that ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr1 = [1, 2, 3],arr2 = [6, 5]) == 0\n assert candidate(arr1 = [1, 1, 1, 1, 1],arr2 = [1, 1, 1, 1, 1]) == 1\n assert candidate(arr1 = [1, 3, 5, 7, 9],arr2 = [2, 4, 6, 8, 10]) == 0\n assert candidate(arr1 = [1000000000],arr2 = [1... | [
"[1,2,3]\n[6,5]",
"[12]\n[4]"
] | [
"Think about (a&b) ^ (a&c). Can you simplify this expression?",
"It is equal to a&(b^c). Then, (arr1[i]&arr2[0])^(arr1[i]&arr2[1]).. = arr1[i]&(arr2[0]^arr2[1]^arr[2]...).",
"Let arr2XorSum = (arr2[0]^arr2[1]^arr2[2]...), arr1XorSum = (arr1[0]^arr1[1]^arr1[2]...) so the final answer is (arr2XorSum&arr1[0]) ^ (a... | {
"canonical_parameter_names": [
"arr1",
"arr2"
],
"leetcode_dataset_entry_point": "Solution().getXORSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:12",
"tests_total": 103,
... | cpp | {
"raw_signature": "int getXORSum(vector<int>& arr1, vector<int>& arr2) {",
"container": "Solution",
"callable": "getXORSum",
"parameters": [
{
"name": "arr1",
"type": "vector<int>&"
},
{
"name": "arr2",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_s... |
1,837 | sum-of-digits-in-base-k | Easy | Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k.
After converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10.
Example 1:
Input: n = 34, k = 6
Output: 9
Explanation: 34 (base 10) expressed i... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 64,k = 2) == 1\n assert candidate(n = 7,k = 3) == 3\n assert candidate(n = 42,k = 5) == 6\n assert candidate(n = 50,k = 4) == 5\n assert candidate(n = 100,k = 3) == 4\n assert candidate(n = 10,k = 10) == 1\n assert ... | [
"34\n6",
"10\n10"
] | [
"Convert the given number into base k."
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().sumBase",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:17",
"tests_total": 87,
"tests_dr... | cpp | {
"raw_signature": "int sumBase(int n, int k) {",
"container": "Solution",
"callable": "sumBase",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "l... |
1,838 | frequency-of-the-most-frequent-element | Medium | The frequency of an element is the number of times it occurs in an array.
You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1.
Return the maximum possible frequency of an element after performing at most k operations.
Ex... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 4],k = 5) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 25) == 7\n assert candidate(nums = [5, 5, 5, 5, 5],k = 10) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4],k = 7) == 6\n assert c... | [
"[1,2,4]\n5",
"[1,4,8,13]\n5",
"[3,9,6]\n2"
] | [
"Note that you can try all values in a brute force manner and find the maximum frequency of that value.",
"To find the maximum frequency of a value consider the biggest elements smaller than or equal to this value"
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxFrequency",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:19",
"tests_total": 99,
"... | cpp | {
"raw_signature": "int maxFrequency(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "maxFrequency",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/... |
1,839 | longest-substring-of-all-vowels-in-order | Medium | A string is considered beautiful if it satisfies the following conditions:
- Each of the 5 English vowels ('a', 'e', 'i', 'o', 'u') must appear at least once in it.
- The letters must be sorted in alphabetical order (i.e. all 'a's before 'e's, all 'e's before 'i's, etc.).
For example, strings "aeiou" and "aaaaaaeiiii... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word = \"aeiaaioaaaaeiiaaaiiiiiouuuooaauuaeiuuuuuuuuuuuuuuuuuuuuaaa\") == 0\n assert candidate(word = \"aeiaaioaaaaeiiaaaiiiiiouuuaauuaeiu\") == 0\n assert candidate(word = \"aeiaaioaaaaeiiaaaiiiiiouuuuuuuuuuuuuuuuuuuuaaaaaaeiou\")... | [
"\"aeiaaioaaaaeiiiiouuuooaauuaeiu\"",
"\"aeeeiiiioooauuuaeiou\"",
"\"a\""
] | [
"Start from each 'a' and find the longest beautiful substring starting at that index.",
"Based on the current character decide if you should include the next character in the beautiful substring."
] | {
"canonical_parameter_names": [
"word"
],
"leetcode_dataset_entry_point": "Solution().longestBeautifulSubstring",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:22",
"tests_total": 20,... | cpp | {
"raw_signature": "int longestBeautifulSubstring(string word) {",
"container": "Solution",
"callable": "longestBeautifulSubstring",
"parameters": [
{
"name": "word",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,840 | maximum-building-height | Hard | You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from 1 to n.
However, there are city restrictions on the heights of the new buildings:
- The height of each building must be a non-negative integer.
- The height of the first building must be 0.
- The height differe... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,restrictions = []) == 5\n assert candidate(n = 5,restrictions = [[2, 1], [4, 1]]) == 2\n assert candidate(n = 100,restrictions = [[10, 5], [50, 25], [90, 10]]) == 37\n assert candidate(n = 1000000,restrictions = [[500000, ... | [
"5\n[[2,1],[4,1]]",
"6\n[]",
"10\n[[5,3],[2,5],[7,4],[10,3]]"
] | [
"Is it possible to find the max height if given the height range of a particular building?",
"You can find the height range of a restricted building by doing 2 passes from the left and right."
] | {
"canonical_parameter_names": [
"n",
"restrictions"
],
"leetcode_dataset_entry_point": "Solution().maxBuilding",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:24",
"tests_total": ... | cpp | {
"raw_signature": "int maxBuilding(int n, vector<vector<int>>& restrictions) {",
"container": "Solution",
"callable": "maxBuilding",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "restrictions",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
... |
1,844 | replace-all-digits-with-characters | Easy | You are given a 0-indexed string s that has lowercase English letters in its even indices and digits in its odd indices.
You must perform an operation shift(c, x), where c is a character and x is a digit, that returns the x^th character after c.
- For example, shift('a', 5) = 'f' and shift('x', 0) = 'x'.
For every o... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"x1y2z3a4b5c6d7e8f9g0\") == \"xyy{z}aebgcidkemfogg\"\n assert candidate(s = \"x5y5z5\") == \"x}y~z\"\n assert candidate(s = \"a9b8c7d6e5f4g3h2i1j0\") == \"ajbjcjdjejfjgjhjijjj\"\n assert candidate(s = \"a9b9c9d9\") == \"aj... | [
"\"a1c1e1\"",
"\"a1b2c3d4e\""
] | [
"We just need to replace every even positioned character with the character s[i] positions ahead of the character preceding it",
"Get the position of the preceeding character in alphabet then advance it s[i] positions and get the character at that position"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().replaceDigits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:29",
"tests_total": 115,
"tests_drop... | cpp | {
"raw_signature": "string replaceDigits(string s) {",
"container": "Solution",
"callable": "replaceDigits",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,846 | maximum-element-after-decreasing-and-rearranging | Medium | You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions:
- The value of the first element in arr must be 1.
- The absolute difference between any 2 adjacent elements must be less than or equal to 1. In other words, abs(arr[i] - arr[i - 1]) <... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [3, 2, 1]) == 3\n assert candidate(arr = [5, 4, 3, 2, 1]) == 5\n assert candidate(arr = [1, 1000000000, 2, 3, 4]) == 5\n assert candidate(arr = [9, 7, 5, 3, 1]) == 5\n assert candidate(arr = [5, 5, 5, 5, 5]) == 5\n a... | [
"[2,2,1,2,1]",
"[100,1,1000]",
"[1,2,3,4,5]"
] | [
"Sort the Array.",
"Decrement each element to the largest integer that satisfies the conditions."
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().maximumElementAfterDecrementingAndRearranging",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:31",
... | cpp | {
"raw_signature": "int maximumElementAfterDecrementingAndRearranging(vector<int>& arr) {",
"container": "Solution",
"callable": "maximumElementAfterDecrementingAndRearranging",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leet... |
1,847 | closest-room | Hard | There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomId_i, size_i] denotes that there is a room with room number roomId_i and size equal to size_i. Each roomId_i is guaranteed to be unique.
You are also given k queries in a 2D array queries where queries[j] = [pref... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(rooms = [[10, 5], [20, 3], [30, 8]],queries = [[15, 4], [25, 7], [35, 2]]) == [10, 30, 30]\n assert candidate(rooms = [[5, 5], [10, 5], [15, 5], [20, 5]],queries = [[7, 5], [12, 5], [17, 5], [22, 5]]) == [5, 10, 15, 20]\n assert ca... | [
"[[2,2],[1,2],[3,2]]\n[[3,1],[3,3],[5,2]]",
"[[1,4],[2,3],[3,5],[4,1],[5,2]]\n[[2,3],[2,4],[2,5]]"
] | [
"Is there a way to sort the queries so it's easier to search the closest room larger than the size?",
"Use binary search to speed up the search time."
] | {
"canonical_parameter_names": [
"rooms",
"queries"
],
"leetcode_dataset_entry_point": "Solution().closestRoom",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:34",
"tests_total": 2... | cpp | {
"raw_signature": "vector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "closestRoom",
"parameters": [
{
"name": "rooms",
"type": "vector<vector<int>>&"
},
{
"name": "queries",
"type": "vector<vector<int>>... |
1,848 | minimum-distance-to-the-target-element | Easy | Given an integer array nums (0-indexed) and two integers target and start, find an index i such that nums[i] == target and abs(i - start) is minimized. Note that abs(x) is the absolute value of x.
Return abs(i - start).
It is guaranteed that target exists in nums.
Example 1:
Input: nums = [1,2,3,4,5], target = 5, s... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 1, 4, 1],target = 1,start = 2) == 1\n assert candidate(nums = [1, 5, 3, 4, 5],target = 5,start = 2) == 1\n assert candidate(nums = [4, 1, 3, 5, 2],target = 2,start = 1) == 3\n assert candidate(nums = [4, 1, 3, 5, 6],t... | [
"[1,2,3,4,5]\n5\n3",
"[1]\n1\n0",
"[5,3,6]\n5\n2"
] | [
"Loop in both directions until you find the target element.",
"For each index i such that nums[i] == target calculate abs(i - start)."
] | {
"canonical_parameter_names": [
"nums",
"target",
"start"
],
"leetcode_dataset_entry_point": "Solution().getMinDistance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:36",
"t... | cpp | {
"raw_signature": "int getMinDistance(vector<int>& nums, int target, int start) {",
"container": "Solution",
"callable": "getMinDistance",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
},
{
"name": "start",
... |
1,849 | splitting-a-string-into-descending-consecutive-values | Medium | You are given a string s that consists of only digits.
Check if we can split s into two or more non-empty substrings such that the numerical values of the substrings are in descending order and the difference between numerical values of every two adjacent substrings is equal to 1.
- For example, the string s = "00900... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"21\") == True\n assert candidate(s = \"9876543210\") == True\n assert candidate(s = \"050043\") == True\n assert candidate(s = \"989796959493929190\") == True\n assert candidate(s = \"1009998\") == True\n assert cand... | [
"\"1234\"",
"\"050043\"",
"\"9080701\""
] | [
"One solution is to try all possible splits using backtrack",
"Look out for trailing zeros in string"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().splitString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:38",
"tests_total": 135,
"tests_droppe... | cpp | {
"raw_signature": "bool splitString(string s) {",
"container": "Solution",
"callable": "splitString",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,850 | minimum-adjacent-swaps-to-reach-the-kth-smallest-number | Medium | You are given a string num, representing a large integer, and an integer k.
We call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many wonderful integers. However, we only care about the smallest-valued ones.
- For example, when num = "5489355142":
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = \"111222333\",k = 10) == 3\n assert candidate(num = \"1234567890\",k = 5) == 2\n assert candidate(num = \"1111111111\",k = 5) == 0\n assert candidate(num = \"9876543210\",k = 3) == 0\n assert candidate(num = \"548935514... | [
"\"5489355142\"\n4",
"\"11112\"\n4",
"\"00123\"\n1"
] | [
"Find the next permutation of the given string k times.",
"Try to move each element to its correct position and calculate the number of steps."
] | {
"canonical_parameter_names": [
"num",
"k"
],
"leetcode_dataset_entry_point": "Solution().getMinSwaps",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:40",
"tests_total": 105,
"t... | cpp | {
"raw_signature": "int getMinSwaps(string num, int k) {",
"container": "Solution",
"callable": "getMinSwaps",
"parameters": [
{
"name": "num",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
... |
1,851 | minimum-interval-to-include-each-query | Hard | You are given a 2D integer array intervals, where intervals[i] = [left_i, right_i] describes the i^th interval starting at left_i and ending at right_i (inclusive). The size of an interval is defined as the number of integers it contains, or more formally right_i - left_i + 1.
You are also given an integer array queri... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(intervals = [[1, 1], [2, 2]],queries = [1, 2, 3]) == [1, 1, -1]\n assert candidate(intervals = [[1, 10], [10, 20], [15, 25]],queries = [5, 10, 15, 20, 25]) == [10, 10, 11, 11, 11]\n assert candidate(intervals = [[1, 1]],queries = [... | [
"[[1,4],[2,4],[3,6],[4,4]]\n[2,3,4,5]",
"[[2,3],[2,5],[1,8],[20,25]]\n[2,19,5,22]"
] | [
"Is there a way to order the intervals and queries such that it takes less time to query?",
"Is there a way to add and remove intervals by going from the smallest query to the largest query to find the minimum size?"
] | {
"canonical_parameter_names": [
"intervals",
"queries"
],
"leetcode_dataset_entry_point": "Solution().minInterval",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:43",
"tests_total... | cpp | {
"raw_signature": "vector<int> minInterval(vector<vector<int>>& intervals, vector<int>& queries) {",
"container": "Solution",
"callable": "minInterval",
"parameters": [
{
"name": "intervals",
"type": "vector<vector<int>>&"
},
{
"name": "queries",
"type": "vector<int>&"
}... |
1,854 | maximum-population-year | Easy | You are given a 2D integer array logs where each logs[i] = [birth_i, death_i] indicates the birth and death years of the i^th person.
The population of some year x is the number of people alive during that year. The i^th person is counted in year x's population if x is in the inclusive range [birth_i, death_i - 1]. No... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(logs = [[2000, 2005], [2005, 2010], [2010, 2015]]) == 2000\n assert candidate(logs = [[1980, 1985], [1985, 1990], [1990, 1995], [1995, 2000]]) == 1980\n assert candidate(logs = [[2000, 2010], [1990, 2000], [2000, 2020]]) == 2000\n ... | [
"[[1993,1999],[2000,2010]]",
"[[1950,1961],[1960,1971],[1970,1981]]"
] | [
"For each year find the number of people whose birth_i ≤ year and death_i > year.",
"Find the maximum value between all years."
] | {
"canonical_parameter_names": [
"logs"
],
"leetcode_dataset_entry_point": "Solution().maximumPopulation",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:48",
"tests_total": 91,
"test... | cpp | {
"raw_signature": "int maximumPopulation(vector<vector<int>>& logs) {",
"container": "Solution",
"callable": "maximumPopulation",
"parameters": [
{
"name": "logs",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
1,855 | maximum-distance-between-a-pair-of-values | Medium | You are given two non-increasing 0-indexed integer arrays nums1 and nums2.
A pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.length, is valid if both i <= j and nums1[i] <= nums2[j]. The distance of the pair is j - i.
Return the maximum distance of any valid pair (i, j). If there are no valid p... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [100],nums2 = [101]) == 0\n assert candidate(nums1 = [30, 29, 19, 5],nums2 = [25, 25, 25, 25, 25]) == 2\n assert candidate(nums1 = [5, 4, 3, 2, 1],nums2 = [5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [10, 9, 8, 7, 6]... | [
"[55,30,5,4,2]\n[100,20,10,10,5]",
"[2,2,2]\n[10,10,1]",
"[30,29,19,5]\n[25,25,25,25,25]"
] | [
"Since both arrays are sorted in a non-increasing way, this means that for each value in the first array, we can find the farthest value larger than or equal to it using binary search.",
"There is another solution using a two pointers approach. Since the first array is non-increasing, the farthest j such that num... | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().maxDistance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:50",
"tests_total": 75,... | cpp | {
"raw_signature": "int maxDistance(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "maxDistance",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type": "int",
"sig... |
1,856 | maximum-subarray-min-product | Medium | The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.
- For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20.
Given an array of integers nums, return the maximum min-product of any non-empty subarray of nums. Since the answe... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 9, 6, 8, 7]) == 180\n assert candidate(nums = [2, 1]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 240\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 180\n assert candidate(nums = [... | [
"[1,2,3,2]",
"[2,3,3,1,2]",
"[3,1,5,6,4,2]"
] | [
"Is there a way we can sort the elements to simplify the problem?",
"Can we find the maximum min-product for every value in the array?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxSumMinProduct",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:53",
"tests_total": 101,
"test... | cpp | {
"raw_signature": "int maxSumMinProduct(vector<int>& nums) {",
"container": "Solution",
"callable": "maxSumMinProduct",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,857 | largest-color-value-in-a-directed-graph | Hard | There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1.
You are given a string colors where colors[i] is a lowercase English letter representing the color of the i^th node in this graph (0-indexed). You are also given a 2D array edges where edges[j] = [a_j, b_j] indicates that... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(colors = \"abcde\",edges = []) == 1\n assert candidate(colors = \"abcdefghijklmnopqrstuvwxyz\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15],... | [
"\"abaca\"\n[[0,1],[0,2],[2,3],[3,4]]",
"\"a\"\n[[0,0]]"
] | [
"Use topological sort.",
"let dp[u][c] := the maximum count of vertices with color c of any path starting from vertex u. (by JerryJin2905)"
] | {
"canonical_parameter_names": [
"colors",
"edges"
],
"leetcode_dataset_entry_point": "Solution().largestPathValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:32:56",
"tests_total... | cpp | {
"raw_signature": "int largestPathValue(string colors, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "largestPathValue",
"parameters": [
{
"name": "colors",
"type": "string"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type... |
1,859 | sorting-the-sentence | Easy | A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.
A sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence.
- For example, the sentence... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"eight8 seven7 six6 five5 four4 three3 two2 one1\") == \"one two three four five six seven eight\"\n assert candidate(s = \"seven7 six6 five5 four4 three3 two2 one1\") == \"one two three four five six seven\"\n assert candidat... | [
"\"is2 sentence4 This1 a3\"",
"\"Myself2 Me1 I4 and3\""
] | [
"Divide the string into the words as an array of strings",
"Sort the words by removing the last character from each word and sorting according to it"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().sortSentence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:00",
"tests_total": 70,
"tests_droppe... | cpp | {
"raw_signature": "string sortSentence(string s) {",
"container": "Solution",
"callable": "sortSentence",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,860 | incremental-memory-leak | Medium | You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
At the i^th second (starting from 1), i bits of memory are allocated to the stick with more available mem... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(memory1 = 0,memory2 = 0) == [1, 0, 0]\n assert candidate(memory1 = 2147483647,memory2 = 2147483647) == [92681, 88047, 41707]\n assert candidate(memory1 = 1000000000,memory2 = 1000000000) == [63245, 49116, 17494]\n assert candida... | [
"2\n2",
"8\n11"
] | [
"What is the upper bound for the number of seconds?",
"Simulate the process of allocating memory."
] | {
"canonical_parameter_names": [
"memory1",
"memory2"
],
"leetcode_dataset_entry_point": "Solution().memLeak",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:02",
"tests_total": 81,... | cpp | {
"raw_signature": "vector<int> memLeak(int memory1, int memory2) {",
"container": "Solution",
"callable": "memLeak",
"parameters": [
{
"name": "memory1",
"type": "int"
},
{
"name": "memory2",
"type": "int"
}
],
"return_type": "vector<int>",
"signature_source": "lee... |
1,861 | rotating-the-box | Medium | You are given an m x n matrix of characters boxGrid representing a side-view of a box. Each cell of the box is one of the following:
- A stone '#'
- A stationary obstacle '*'
- Empty '.'
The box is rotated 90 degrees clockwise, causing some of the stones to fall due to gravity. Each stone falls down until it lands on... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(boxGrid = [['#', '.', '*', '.'], ['#', '#', '*', '.']]) == [['#', '.'], ['#', '#'], ['*', '*'], ['.', '.']]\n assert candidate(boxGrid = [['#', '.', '#']]) == [['.'], ['#'], ['#']]\n assert candidate(boxGrid = [['#', '#', '*', '.',... | [
"[[\"#\",\".\",\"#\"]]",
"[[\"#\",\".\",\"*\",\".\"],[\"#\",\"#\",\"*\",\".\"]]",
"[[\"#\",\"#\",\"*\",\".\",\"*\",\".\"],[\"#\",\"#\",\"#\",\"*\",\".\",\".\"],[\"#\",\"#\",\"#\",\".\",\"#\",\".\"]]"
] | [
"Rotate the box using the relation rotatedBox[i][j] = box[m - 1 - j][i].",
"Start iterating from the bottom of the box and for each empty cell check if there is any stone above it with no obstacles between them."
] | {
"canonical_parameter_names": [
"boxGrid"
],
"leetcode_dataset_entry_point": "Solution().rotateTheBox",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:05",
"tests_total": 114,
"tests... | cpp | {
"raw_signature": "vector<vector<char>> rotateTheBox(vector<vector<char>>& boxGrid) {",
"container": "Solution",
"callable": "rotateTheBox",
"parameters": [
{
"name": "boxGrid",
"type": "vector<vector<char>>&"
}
],
"return_type": "vector<vector<char>>",
"signature_source": "leetcode/c... |
1,862 | sum-of-floored-pairs | Hard | Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 10^9 + 7.
The floor() function returns the integer part of the division.
Example 1:
Input: nums = [2,5,9]
Output: 10
Explanation:
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == 49\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 100\n assert candidate(nums = [2, 5, 9]) == 10\n assert candidate(nums = [100000, 1, 100000]) == 200005\n assert candidate(nums ... | [
"[2,5,9]",
"[7,7,7,7,7,7,7]"
] | [
"Find the frequency (number of occurrences) of all elements in the array.",
"For each element, iterate through its multiples and multiply frequencies to find the answer."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().sumOfFlooredPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:09",
"tests_total": 60,
"test... | cpp | {
"raw_signature": "int sumOfFlooredPairs(vector<int>& nums) {",
"container": "Solution",
"callable": "sumOfFlooredPairs",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
1,863 | sum-of-all-subset-xor-totals | Easy | The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty.
- For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1.
Given an array nums, return the sum of all XOR totals for every subset of nums.
Note: Subsets with the same elements should be counted multi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 1, 6]) == 28\n assert candidate(nums = [1, 1, 1, 1]) == 8\n assert candidate(nums = [1, 2, 4, 8, 16]) == 496\n assert candidate(nums = [10, 11, 12]) == 60\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14]) == 896\... | [
"[1,3]",
"[5,1,6]",
"[3,4,5,6,7,8]"
] | [
"Is there a way to iterate through all the subsets of the array?",
"Can we use recursion to efficiently iterate through all the subsets?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().subsetXORSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:11",
"tests_total": 99,
"tests_dro... | cpp | {
"raw_signature": "int subsetXORSum(vector<int>& nums) {",
"container": "Solution",
"callable": "subsetXORSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,864 | minimum-number-of-swaps-to-make-the-binary-string-alternating | Medium | Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible.
The string is called alternating if no two adjacent characters are equal. For example, the strings "010" and "1010" are alternating, while the string "0100" is not.
Any two characters may be swappe... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1111\") == -1\n assert candidate(s = \"1100110\") == 2\n assert candidate(s = \"110011\") == -1\n assert candidate(s = \"00110011\") == 2\n assert candidate(s = \"0101010\") == 0\n assert candidate(s = \"111\") == -1... | [
"\"111000\"",
"\"010\"",
"\"1110\""
] | [
"Think about all valid strings of length n.",
"Try to count the mismatched positions with each valid string of length n."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().minSwaps",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:13",
"tests_total": 243,
"tests_dropped":... | cpp | {
"raw_signature": "int minSwaps(string s) {",
"container": "Solution",
"callable": "minSwaps",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,866 | number-of-ways-to-rearrange-sticks-with-k-sticks-visible | Hard | There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from the left. A stick is visible from the left if there are no longer sticks to the left of it.
- For example, if the sticks are arranged [1,3,2,5,4], then the sticks with le... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 10,k = 1) == 362880\n assert candidate(n = 1000,k = 500) == 761367694\n assert candidate(n = 7,k = 4) == 735\n assert candidate(n = 1,k = 1) == 1\n assert candidate(n = 3,k = 2) == 3\n assert candidate(n = 100,k = 50) ... | [
"3\n2",
"5\n5",
"20\n11"
] | [
"Is there a way to build the solution from a base case?",
"How many ways are there if we fix the position of one stick?"
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().rearrangeSticks",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:16",
"tests_total": 57,
"... | cpp | {
"raw_signature": "int rearrangeSticks(int n, int k) {",
"container": "Solution",
"callable": "rearrangeSticks",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"... |
1,869 | longer-contiguous-segments-of-ones-than-zeros | Easy | Given a binary string s, return true if the longest contiguous segment of 1's is strictly longer than the longest contiguous segment of 0's in s, or return false otherwise.
- For example, in s = "110100010" the longest continuous segment of 1s has length 2, and the longest continuous segment of 0s has length 3.
Note ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1111\") == True\n assert candidate(s = \"111000\") == False\n assert candidate(s = \"101010\") == False\n assert candidate(s = \"11100111\") == True\n assert candidate(s = \"11001100\") == False\n assert candidate(s ... | [
"\"1101\"",
"\"111000\"",
"\"110100010\""
] | [
"Check every possible segment of 0s and 1s.",
"Is there a way to iterate through the string to keep track of the current character and its count?"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().checkZeroOnes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:21",
"tests_total": 161,
"tests_drop... | cpp | {
"raw_signature": "bool checkZeroOnes(string s) {",
"container": "Solution",
"callable": "checkZeroOnes",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,870 | minimum-speed-to-arrive-on-time | Medium | You are given a floating-point number hour, representing the amount of time you have to reach the office. To commute to the office, you must take n trains in sequential order. You are also given an integer array dist of length n, where dist[i] describes the distance (in kilometers) of the i^th train ride.
Each train c... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(dist = [5, 4, 3, 2, 1],hour = 5.5) == 4\n assert candidate(dist = [5, 4, 1, 2],hour = 3.5) == 5\n assert candidate(dist = [1, 2, 3, 4, 5],hour = 9.0) == 2\n assert candidate(dist = [1, 3, 2],hour = 1.9) == -1\n assert candida... | [
"[1,3,2]\n6",
"[1,3,2]\n2.7",
"[1,3,2]\n1.9"
] | [
"Given the speed the trains are traveling at, can you find the total time it takes for you to arrive?",
"Is there a cutoff where any speeds larger will always allow you to arrive on time?"
] | {
"canonical_parameter_names": [
"dist",
"hour"
],
"leetcode_dataset_entry_point": "Solution().minSpeedOnTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:23",
"tests_total": 98... | cpp | {
"raw_signature": "int minSpeedOnTime(vector<int>& dist, double hour) {",
"container": "Solution",
"callable": "minSpeedOnTime",
"parameters": [
{
"name": "dist",
"type": "vector<int>&"
},
{
"name": "hour",
"type": "double"
}
],
"return_type": "int",
"signature_sou... |
1,871 | jump-game-vii | Medium | You are given a 0-indexed binary string s and two integers minJump and maxJump. In the beginning, you are standing at index 0, which is equal to '0'. You can move from index i to index j if the following conditions are fulfilled:
- i + minJump <= j <= min(i + maxJump, s.length - 1), and
- s[j] == '0'.
Return true if ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"0100100010001000\",minJump = 2,maxJump = 5) == True\n assert candidate(s = \"00001000\",minJump = 2,maxJump = 4) == True\n assert candidate(s = \"0010010010010010010010010010010010010010\",minJump = 2,maxJump = 4) == True\n ... | [
"\"011010\"\n2\n3",
"\"01101110\"\n2\n3"
] | [
"Consider for each reachable index i the interval [i + a, i + b].",
"Use partial sums to mark the intervals as reachable."
] | {
"canonical_parameter_names": [
"s",
"minJump",
"maxJump"
],
"leetcode_dataset_entry_point": "Solution().canReach",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:25",
"tests_t... | cpp | {
"raw_signature": "bool canReach(string s, int minJump, int maxJump) {",
"container": "Solution",
"callable": "canReach",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "minJump",
"type": "int"
},
{
"name": "maxJump",
"type": "int"
}
]... |
1,872 | stone-game-viii | Hard | Alice and Bob take turns playing a game, with Alice starting first.
There are n stones arranged in a row. On each player's turn, while the number of stones is more than one, they will do the following:
1. Choose an integer x > 1, and remove the leftmost x stones from the row.
2. Add the sum of the removed stones' val... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(stones = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(stones = [10, -10, 20, -20, 30, -30]) == 30\n assert candidate(stones = [100, 200, -300, 400, -500, 600, -700, 800]) == 600\n assert candidate(stones = [5, 5,... | [
"[-1,2,-3,4,-5]",
"[7,-6,5,10,5,-2,-6]",
"[-10,-12]"
] | [
"Let's note that the only thing that matters is how many stones were removed so we can maintain dp[numberOfRemovedStones]",
"dp[x] = max(sum of all elements up to y - dp[y]) for all y > x"
] | {
"canonical_parameter_names": [
"stones"
],
"leetcode_dataset_entry_point": "Solution().stoneGameVIII",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:28",
"tests_total": 79,
"tests_... | cpp | {
"raw_signature": "int stoneGameVIII(vector<int>& stones) {",
"container": "Solution",
"callable": "stoneGameVIII",
"parameters": [
{
"name": "stones",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
1,876 | substrings-of-size-three-with-distinct-characters | Easy | A string is good if there are no repeated characters.
Given a string s, return the number of good substrings of length three in s.
Note that if there are multiple occurrences of the same substring, every occurrence should be counted.
A substring is a contiguous sequence of characters in a string.
Example 1:
Input:... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"xyzxyzxyz\") == 7\n assert candidate(s = \"abcabcabc\") == 7\n assert candidate(s = \"xyzzaz\") == 1\n assert candidate(s = \"aabbcc\") == 0\n assert candidate(s = \"abacab\") == 2\n assert candidate(s = \"qqqppprrr\... | [
"\"xyzzaz\"",
"\"aababcabc\""
] | [
"Try using a set to find out the number of distinct characters in a substring."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().countGoodSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:33",
"tests_total": 96,
"tests... | cpp | {
"raw_signature": "int countGoodSubstrings(string s) {",
"container": "Solution",
"callable": "countGoodSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,877 | minimize-maximum-pair-sum-in-array | Medium | The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs.
- For example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8.
Given an array nums of even length n, pair up the elements of nums into n / 2 p... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 6, 2, 5, 3, 4]) == 7\n assert candidate(nums = [10, 10, 10, 10]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [1... | [
"[3,5,2,3]",
"[3,5,4,2,4,6]"
] | [
"Would sorting help find the optimal order?",
"Given a specific element, how would you minimize its specific pairwise sum?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minPairSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:35",
"tests_total": 97,
"tests_dropp... | cpp | {
"raw_signature": "int minPairSum(vector<int>& nums) {",
"container": "Solution",
"callable": "minPairSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,878 | get-biggest-three-rhombus-sums-in-a-grid | Medium | You are given an m x n integer matrix grid.
A rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the correspo... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25]]) == [104, 76, 72]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) ... | [
"[[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]",
"[[1,2,3],[4,5,6],[7,8,9]]",
"[[7,7,7]]"
] | [
"You need to maintain only the biggest 3 distinct sums",
"The limits are small enough for you to iterate over all rhombus sizes then iterate over all possible borders to get the sums"
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().getBiggestThree",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:38",
"tests_total": 118,
"tests... | cpp | {
"raw_signature": "vector<int> getBiggestThree(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "getBiggestThree",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"typ... |
1,879 | minimum-xor-sum-of-two-arrays | Hard | You are given two integer arrays nums1 and nums2 of length n.
The XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1]) (0-indexed).
- For example, the XOR sum of [1,2,3] and [3,2,1] is equal to (1 XOR 3) + (2 XOR 2) + (3 XOR 1) = 2 + 0 + 2 = 4.... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [3, 4, 2],nums2 = [4, 2, 2]) == 1\n assert candidate(nums1 = [1, 2],nums2 = [2, 3]) == 2\n assert candidate(nums1 = [2, 3, 4, 5],nums2 = [5, 4, 3, 2]) == 0\n assert candidate(nums1 = [4, 6, 2],nums2 = [9, 3, 5]) == 17\n ... | [
"[1,2]\n[2,3]",
"[1,0,3]\n[5,3,4]"
] | [
"Since n <= 14, we can consider every subset of nums2.",
"We can represent every subset of nums2 using bitmasks."
] | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().minimumXORSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:40",
"tests_total": 9... | cpp | {
"raw_signature": "int minimumXORSum(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "minimumXORSum",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type": "int",
... |
1,880 | check-if-word-equals-summation-of-two-words | Easy | The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.).
The numerical value of some string of lowercase English letters s is the concatenation of the letter values of each letter in s, which is then converted into an integer.
- For example, if s = "acb",... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(firstWord = \"ij\",secondWord = \"ji\",targetWord = \"ii\") == False\n assert candidate(firstWord = \"fgh\",secondWord = \"ghf\",targetWord = \"ggg\") == False\n assert candidate(firstWord = \"ij\",secondWord = \"ji\",targetWord = ... | [
"\"acb\"\n\"cba\"\n\"cdb\"",
"\"aaa\"\n\"a\"\n\"aab\"",
"\"aaa\"\n\"a\"\n\"aaaa\""
] | [
"Convert each character of each word to its numerical value.",
"Check if the numerical values satisfies the condition."
] | {
"canonical_parameter_names": [
"firstWord",
"secondWord",
"targetWord"
],
"leetcode_dataset_entry_point": "Solution().isSumEqual",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33... | cpp | {
"raw_signature": "bool isSumEqual(string firstWord, string secondWord, string targetWord) {",
"container": "Solution",
"callable": "isSumEqual",
"parameters": [
{
"name": "firstWord",
"type": "string"
},
{
"name": "secondWord",
"type": "string"
},
{
"name": "t... |
1,881 | maximum-value-after-insertion | Medium | You are given a very large integer n, represented as a string, and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number.
You want to maximize n's numerical value by inserting x anywhere in the decimal representation of n. You cannot insert x to th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = \"5486\",x = 7) == \"75486\"\n assert candidate(n = \"-11111\",x = 1) == \"-111111\"\n assert candidate(n = \"-123456789\",x = 5) == \"-1234556789\"\n assert candidate(n = \"987654321\",x = 5) == \"9876554321\"\n assert c... | [
"\"99\"\n9",
"\"-13\"\n2"
] | [
"Note that if the number is negative it's the same as positive but you look for the minimum instead.",
"In the case of maximum, if s[i] < x it's optimal that x is put before s[i].",
"In the case of minimum, if s[i] > x it's optimal that x is put before s[i]."
] | {
"canonical_parameter_names": [
"n",
"x"
],
"leetcode_dataset_entry_point": "Solution().maxValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:44",
"tests_total": 133,
"tests_... | cpp | {
"raw_signature": "string maxValue(string n, int x) {",
"container": "Solution",
"callable": "maxValue",
"parameters": [
{
"name": "n",
"type": "string"
},
{
"name": "x",
"type": "int"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"ty... |
1,882 | process-tasks-using-servers | Medium | You are given two 0-indexed integer arrays servers and tasks of lengths n and m respectively. servers[i] is the weight of the i^th server, and tasks[j] is the time needed to process the j^th task in seconds.
Tasks are assigned to the servers using a task queue. Initially, all servers are free, and the queue is empty.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(servers = [3, 3, 2],tasks = [1, 2, 3, 2, 1, 2]) == [2, 2, 0, 2, 1, 2]\n assert candidate(servers = [1, 1, 1],tasks = [10, 20, 30, 40, 50]) == [0, 1, 2, 0, 1]\n assert candidate(servers = [5, 1, 4, 3, 2],tasks = [2, 1, 2, 4, 5, 2, 1... | [
"[3,3,2]\n[1,2,3,2,1,2]",
"[5,1,4,3,2]\n[2,1,2,4,5,2,1]"
] | [
"You can maintain a Heap of available Servers and a Heap of unavailable servers",
"Note that the tasks will be processed in the input order so you just need to find the x-th server that will be available according to the rules"
] | {
"canonical_parameter_names": [
"servers",
"tasks"
],
"leetcode_dataset_entry_point": "Solution().assignTasks",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:47",
"tests_total": 1... | cpp | {
"raw_signature": "vector<int> assignTasks(vector<int>& servers, vector<int>& tasks) {",
"container": "Solution",
"callable": "assignTasks",
"parameters": [
{
"name": "servers",
"type": "vector<int>&"
},
{
"name": "tasks",
"type": "vector<int>&"
}
],
"return_type": "... |
1,883 | minimum-skips-to-arrive-at-meeting-on-time | Hard | You are given an integer hoursBefore, the number of hours you have to travel to your meeting. To arrive at your meeting, you have to travel through n roads. The road lengths are given as an integer array dist of length n, where dist[i] describes the length of the i^th road in kilometers. In addition, you are given an i... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(dist = [10, 10, 10],speed = 5,hoursBefore = 6) == 0\n assert candidate(dist = [1, 1, 1, 1, 1],speed = 1,hoursBefore = 3) == -1\n assert candidate(dist = [5, 5, 5, 5, 5],speed = 10,hoursBefore = 2) == -1\n assert candidate(dist =... | [
"[1,3,2]\n4\n2",
"[7,3,5,5]\n2\n10",
"[7,3,5,5]\n1\n10"
] | [
"Is there something you can keep track of from one road to another?",
"How would knowing the start time for each state help us solve the problem?"
] | {
"canonical_parameter_names": [
"dist",
"speed",
"hoursBefore"
],
"leetcode_dataset_entry_point": "Solution().minSkips",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:49",
"te... | cpp | {
"raw_signature": "int minSkips(vector<int>& dist, int speed, int hoursBefore) {",
"container": "Solution",
"callable": "minSkips",
"parameters": [
{
"name": "dist",
"type": "vector<int>&"
},
{
"name": "speed",
"type": "int"
},
{
"name": "hoursBefore",
"t... |
1,884 | egg-drop-with-2-eggs-and-n-floors | Medium | You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.
You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.
In each move, you may take an unbroken egg... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 8) == 4\n assert candidate(n = 1000) == 45\n assert candidate(n = 5) == 3\n assert candidate(n = 81) == 13\n assert candidate(n = 999) == 45\n assert candidate(n = 15) == 5\n assert candidate(n = 64) == 11\n asse... | [
"2",
"100"
] | [
"Is it really optimal to always drop the egg on the middle floor for each move?",
"Can we create states based on the number of unbroken eggs and floors to build our solution?"
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().twoEggDrop",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:51",
"tests_total": 46,
"tests_dropped"... | cpp | {
"raw_signature": "int twoEggDrop(int n) {",
"container": "Solution",
"callable": "twoEggDrop",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,886 | determine-whether-matrix-can-be-obtained-by-rotation | Easy | Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise.
Example 1:
Input: mat = [[0,1],[1,0]], target = [[1,0],[0,1]]
Output: true
Explanation: We can rotate mat 90 degrees clockwise to make mat equal target... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mat = [[1, 0, 0], [0, 1, 0], [0, 0, 1]],target = [[0, 0, 1], [0, 1, 0], [1, 0, 0]]) == True\n assert candidate(mat = [[0, 1], [1, 0]],target = [[1, 0], [0, 1]]) == True\n assert candidate(mat = [[1, 1], [0, 0]],target = [[0, 1], [0... | [
"[[0,1],[1,0]]\n[[1,0],[0,1]]",
"[[0,1],[1,1]]\n[[1,0],[0,1]]",
"[[0,0,0],[0,1,0],[1,1,1]]\n[[1,1,1],[0,1,0],[0,0,0]]"
] | [
"What is the maximum number of rotations you have to check?",
"Is there a formula you can use to rotate a matrix 90 degrees?"
] | {
"canonical_parameter_names": [
"mat",
"target"
],
"leetcode_dataset_entry_point": "Solution().findRotation",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:56",
"tests_total": 79,... | cpp | {
"raw_signature": "bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target) {",
"container": "Solution",
"callable": "findRotation",
"parameters": [
{
"name": "mat",
"type": "vector<vector<int>>&"
},
{
"name": "target",
"type": "vector<vector<int>>&"
}
... |
1,887 | reduction-operations-to-make-the-array-elements-equal | Medium | Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps:
1. Find the largest value in nums. Let its index be i (0-indexed) and its value be largest. If there are multiple elements with the largest value, pick the smallest i.
2. Find the next largest v... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 20\n assert candidate(nums = [4, 3, 2, 1]) == 6\n assert candidate(nums = [1, 5, 2, 4, 3]) == 10\n assert candidate(nums = [1, 1, 1]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3]) =... | [
"[5,1,3]",
"[1,1,1]",
"[1,1,2,2,3]"
] | [
"Sort the array.",
"Try to reduce all elements with maximum value to the next maximum value in one operation."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().reductionOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:33:58",
"tests_total": 99,
"te... | cpp | {
"raw_signature": "int reductionOperations(vector<int>& nums) {",
"container": "Solution",
"callable": "reductionOperations",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,888 | minimum-number-of-flips-to-make-the-binary-string-alternating | Medium | You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence:
- Type-1: Remove the character at the start of the string s and append it to the end of the string.
- Type-2: Pick any character in s and flip its value, i.e., if its value is '0' it becomes '1' and vice-... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"100100100\") == 3\n assert candidate(s = \"1111\") == 2\n assert candidate(s = \"110011\") == 3\n assert candidate(s = \"111000111000\") == 4\n assert candidate(s = \"11110000\") == 4\n assert candidate(s = \"1110\")... | [
"\"111000\"",
"\"010\"",
"\"1110\""
] | [
"Note what actually matters is how many 0s and 1s are in odd and even positions",
"For every cyclic shift we need to count how many 0s and 1s are at each parity and convert the minimum between them for each parity"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().minFlips",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:00",
"tests_total": 153,
"tests_dropped":... | cpp | {
"raw_signature": "int minFlips(string s) {",
"container": "Solution",
"callable": "minFlips",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,889 | minimum-space-wasted-from-packaging | Hard | You have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (with infinite supply). A package can be placed in a box if the size of the package is less than or equal to the size of the box.
The package sizes are given as an intege... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(packages = [10, 20, 30],boxes = [[10], [20], [30], [40]]) == 30\n assert candidate(packages = [100000],boxes = [[100000]]) == 0\n assert candidate(packages = [10, 20, 30],boxes = [[10, 20, 30], [15, 25, 35]]) == 0\n assert candi... | [
"[2,3,5]\n[[4,8],[2,8]]",
"[2,3,5]\n[[1,4],[2,3],[3,4]]",
"[3,5,8,10,11,12]\n[[12],[11,9],[10,5,14]]"
] | [
"Given a fixed size box, is there a way to quickly query which packages (i.e., count and sizes) should end up in that box size?",
"Do we have to order the boxes a certain way to allow us to answer the query quickly?"
] | {
"canonical_parameter_names": [
"packages",
"boxes"
],
"leetcode_dataset_entry_point": "Solution().minWastedSpace",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:03",
"tests_total... | cpp | {
"raw_signature": "int minWastedSpace(vector<int>& packages, vector<vector<int>>& boxes) {",
"container": "Solution",
"callable": "minWastedSpace",
"parameters": [
{
"name": "packages",
"type": "vector<int>&"
},
{
"name": "boxes",
"type": "vector<vector<int>>&"
}
],
... |
1,893 | check-if-all-the-integers-in-a-range-are-covered | Easy | You are given a 2D integer array ranges and two integers left and right. Each ranges[i] = [start_i, end_i] represents an inclusive interval between start_i and end_i.
Return true if each integer in the inclusive range [left, right] is covered by at least one interval in ranges. Return false otherwise.
An integer x is... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(ranges = [[5, 7], [1, 3]],left = 1,right = 7) == False\n assert candidate(ranges = [[5, 10], [15, 20]],left = 10,right = 15) == False\n assert candidate(ranges = [[1, 1], [2, 2], [3, 3]],left = 1,right = 3) == True\n assert cand... | [
"[[1,2],[3,4],[5,6]]\n2\n5",
"[[1,10],[10,20]]\n21\n21"
] | [
"Iterate over every integer point in the range [left, right].",
"For each of these points check if it is included in one of the ranges."
] | {
"canonical_parameter_names": [
"ranges",
"left",
"right"
],
"leetcode_dataset_entry_point": "Solution().isCovered",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:08",
"tests_... | cpp | {
"raw_signature": "bool isCovered(vector<vector<int>>& ranges, int left, int right) {",
"container": "Solution",
"callable": "isCovered",
"parameters": [
{
"name": "ranges",
"type": "vector<vector<int>>&"
},
{
"name": "left",
"type": "int"
},
{
"name": "right",... |
1,894 | find-the-student-that-will-replace-the-chalk | Medium | There are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the student number 1, and so on until the teacher reaches the student number n - 1. After that, the teacher will restart the process, starting with the student number 0 again.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(chalk = [1, 2, 3, 4, 5],k = 15) == 0\n assert candidate(chalk = [1],k = 1000000000) == 0\n assert candidate(chalk = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 999999999) == 9\n assert candidate(chalk = [10, 10, 10],k = 100) == 1\n as... | [
"[5,1,5]\n22",
"[3,4,1,2]\n25"
] | [
"Subtract the sum of chalk from k until k is less than the sum of chalk.",
"Now iterate over the array. If chalk[i] is less than k, this is the answer. Otherwise, subtract chalk[i] from k and continue."
] | {
"canonical_parameter_names": [
"chalk",
"k"
],
"leetcode_dataset_entry_point": "Solution().chalkReplacer",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:10",
"tests_total": 92,
... | cpp | {
"raw_signature": "int chalkReplacer(vector<int>& chalk, int k) {",
"container": "Solution",
"callable": "chalkReplacer",
"parameters": [
{
"name": "chalk",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetc... |
1,895 | largest-magic-square | Medium | A k x k magic square is a k x k grid filled with integers such that every row sum, every column sum, and both diagonal sums are all equal. The integers in the magic square do not have to be distinct. Every 1 x 1 grid is trivially a magic square.
Given an m x n integer grid, return the size (i.e., the side length k) of... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[10, 20], [15, 25]]) == 1\n assert candidate(grid = [[7, 1, 4, 5, 6], [2, 5, 1, 6, 4], [1, 5, 4, 3, 2], [1, 2, 7, 3, 4]]) == 3\n assert candidate(grid = [[6, 3, 2, 8, 1, 9, 3, 2], [4, 7, 5, 4, 5, 3, 4, 7], [8, 4, 6, 8, 7, 2... | [
"[[7,1,4,5,6],[2,5,1,6,4],[1,5,4,3,2],[1,2,7,3,4]]",
"[[5,1,3,1],[9,3,3,1],[1,3,3,8]]"
] | [
"Check all squares in the matrix and find the largest one."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().largestMagicSquare",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:13",
"tests_total": 80,
"tes... | cpp | {
"raw_signature": "int largestMagicSquare(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "largestMagicSquare",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source":... |
1,896 | minimum-cost-to-change-the-final-value-of-expression | Hard | You are given a valid boolean expression as a string expression consisting of the characters '1','0','&' (bitwise AND operator),'|' (bitwise OR operator),'(', and ')'.
- For example, "()1|1" and "(1)&()" are not valid while "1", "(((1))|(0))", and "1|(0&(1))" are valid expressions.
Return the minimum cost to change t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(expression = \"(1&(0|1&(0|1)))\") == 1\n assert candidate(expression = \"(0&1&1)|(0|1)\") == 1\n assert candidate(expression = \"(1&1)|(0&0)\") == 1\n assert candidate(expression = \"(1&((0&0)|(1|1)))\") == 1\n assert candida... | [
"\"1&(0|1)\"",
"\"(0&0)&(0&0&0)\"",
"\"(0|(1|0&1))\""
] | [
"How many possible states are there for a given expression?",
"Is there a data structure that we can use to solve the problem optimally?"
] | {
"canonical_parameter_names": [
"expression"
],
"leetcode_dataset_entry_point": "Solution().minOperationsToFlip",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:15",
"tests_total": 173... | cpp | {
"raw_signature": "int minOperationsToFlip(string expression) {",
"container": "Solution",
"callable": "minOperationsToFlip",
"parameters": [
{
"name": "expression",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,897 | redistribute-characters-to-make-all-strings-equal | Easy | You are given an array of strings words (0-indexed).
In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j].
Return true if you can make every string in words equal using any number of operations, and false otherwise.... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl']) == False\n assert candidate(words = ['aabbcc', 'abc', 'abc', 'abc']) == False\n assert candidate(words = ['abcd', 'dcba', 'abcd', 'dcba']) == True\n assert candidate(words = ['abcd', 'bcad',... | [
"[\"abc\",\"aabc\",\"bc\"]",
"[\"ab\",\"a\"]"
] | [
"Characters are independent—only the frequency of characters matters.",
"It is possible to distribute characters if all characters can be divided equally among all strings."
] | {
"canonical_parameter_names": [
"words"
],
"leetcode_dataset_entry_point": "Solution().makeEqual",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:17",
"tests_total": 89,
"tests_dropp... | cpp | {
"raw_signature": "bool makeEqual(vector<string>& words) {",
"container": "Solution",
"callable": "makeEqual",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"... |
1,898 | maximum-number-of-removable-characters | Medium | You are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed).
You want to choose an integer k (0 <= k <= removable.length) such that, after removing k characters from s using the first k indice... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"pqrstu\",p = \"psu\",removable = [5, 4, 3, 2, 1, 0]) == 0\n assert candidate(s = \"abcdefghij\",p = \"acegi\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(s = \"deeddeede\",p = \"dee\",removable = [5, 3... | [
"\"abcacb\"\n\"ab\"\n[3,1,0]",
"\"abcbddddd\"\n\"abcd\"\n[3,2,1,4,5,6]",
"\"abcab\"\n\"abc\"\n[0,1,2,3,4]"
] | [
"First, we need to think about solving an easier problem, If we remove a set of indices from the string does P exist in S as a subsequence",
"We can binary search the K and check by solving the above problem."
] | {
"canonical_parameter_names": [
"s",
"p",
"removable"
],
"leetcode_dataset_entry_point": "Solution().maximumRemovals",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:20",
"test... | cpp | {
"raw_signature": "int maximumRemovals(string s, string p, vector<int>& removable) {",
"container": "Solution",
"callable": "maximumRemovals",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "p",
"type": "string"
},
{
"name": "removable",
"ty... |
1,899 | merge-triplets-to-form-target-triplet | Medium | A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [a_i, b_i, c_i] describes the i^th triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain.
To obtain target, you may apply the following operation on triplets a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6]],target = [1, 2, 3]) == True\n assert candidate(triplets = [[3, 4, 5], [4, 5, 6]],target = [3, 2, 5]) == False\n assert candidate(triplets = [[2, 5, 3], [1, 8, 4], [1, 7, 5]],target = [2, 7, 5]) == ... | [
"[[2,5,3],[1,8,4],[1,7,5]]\n[2,7,5]",
"[[3,4,5],[4,5,6]]\n[3,2,5]",
"[[2,5,3],[2,3,4],[1,2,5],[5,2,3]]\n[5,5,5]"
] | [
"Which triplets do you actually care about?",
"What property of max can you use to solve the problem?"
] | {
"canonical_parameter_names": [
"triplets",
"target"
],
"leetcode_dataset_entry_point": "Solution().mergeTriplets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:23",
"tests_total... | cpp | {
"raw_signature": "bool mergeTriplets(vector<vector<int>>& triplets, vector<int>& target) {",
"container": "Solution",
"callable": "mergeTriplets",
"parameters": [
{
"name": "triplets",
"type": "vector<vector<int>>&"
},
{
"name": "target",
"type": "vector<int>&"
}
],
... |
1,900 | the-earliest-and-latest-rounds-where-players-compete | Hard | There is a tournament where n players are participating. The players are standing in a single row and are numbered from 1 to n based on their initial standing position (player 1 is the first player in the row, player 2 is the second player in the row, etc.).
The tournament consists of multiple rounds (starting from ro... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 10,firstPlayer = 4,secondPlayer = 9) == [2, 4]\n assert candidate(n = 28,firstPlayer = 5,secondPlayer = 24) == [1, 1]\n assert candidate(n = 16,firstPlayer = 5,secondPlayer = 12) == [1, 1]\n assert candidate(n = 5,firstPlaye... | [
"11\n2\n4",
"5\n1\n5"
] | [
"Brute force using bitmasks and simulate the rounds.",
"Calculate each state one time and save its solution."
] | {
"canonical_parameter_names": [
"n",
"firstPlayer",
"secondPlayer"
],
"leetcode_dataset_entry_point": "Solution().earliestAndLatest",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:... | cpp | {
"raw_signature": "vector<int> earliestAndLatest(int n, int firstPlayer, int secondPlayer) {",
"container": "Solution",
"callable": "earliestAndLatest",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "firstPlayer",
"type": "int"
},
{
"name": "secondP... |
1,901 | find-a-peak-element-ii | Medium | A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom.
Given a 0-indexed m x n matrix mat where no two adjacent cells are equal, find any peak element mat[i][j] and return the length 2 array [i,j].
You may assume that the entire matri... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mat = [[1]]) == [0, 0]\n assert candidate(mat = [[1, 2, 3, 4, 5], [16, 17, 18, 19, 6], [15, 24, 25, 20, 7], [14, 23, 22, 21, 8], [13, 12, 11, 10, 9]]) == [2, 2]\n assert candidate(mat = [[1, 2, 3, 4, 5], [16, 17, 24, 25, 6], [7, 8,... | [
"[[1,4],[3,2]]",
"[[10,20,15],[21,30,14],[7,16,32]]"
] | [
"Let's assume that the width of the array is bigger than the height, otherwise, we will split in another direction.",
"Split the array into three parts: central column left side and right side.",
"Go through the central column and two neighbor columns and look for maximum.",
"If it's in the central column - t... | {
"canonical_parameter_names": [
"mat"
],
"leetcode_dataset_entry_point": "Solution().findPeakGrid",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:27",
"tests_total": 85,
"tests_drop... | cpp | {
"raw_signature": "vector<int> findPeakGrid(vector<vector<int>>& mat) {",
"container": "Solution",
"callable": "findPeakGrid",
"parameters": [
{
"name": "mat",
"type": "vector<vector<int>>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source... |
1,903 | largest-odd-number-in-string | Easy | You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string "" if no odd integer exists.
A substring is a contiguous sequence of characters within a string.
Example 1:
Input: num = "52"
Output: "5"
Explanation:... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = \"52\") == \"5\"\n assert candidate(num = \"9\") == \"9\"\n assert candidate(num = \"86420\") == \"\"\n assert candidate(num = \"1111111111\") == \"1111111111\"\n assert candidate(num = \"2468\") == \"\"\n assert can... | [
"\"52\"",
"\"4206\"",
"\"35427\""
] | [
"In what order should you iterate through the digits?",
"If an odd number exists, where must the number start from?"
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().largestOddNumber",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:32",
"tests_total": 140,
"tests... | cpp | {
"raw_signature": "string largestOddNumber(string num) {",
"container": "Solution",
"callable": "largestOddNumber",
"parameters": [
{
"name": "num",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,904 | the-number-of-full-rounds-you-have-played | Medium | You are participating in an online chess tournament. There is a chess round that starts every 15 minutes. The first round of the day starts at 00:00, and after every 15 minutes, a new round starts.
- For example, the second round starts at 00:15, the fourth round starts at 00:45, and the seventh round starts at 01:30.... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(loginTime = \"11:59\",logoutTime = \"12:01\") == 0\n assert candidate(loginTime = \"14:30\",logoutTime = \"15:30\") == 4\n assert candidate(loginTime = \"00:01\",logoutTime = \"00:14\") == 0\n assert candidate(loginTime = \"14:2... | [
"\"09:31\"\n\"10:14\"",
"\"21:30\"\n\"03:00\""
] | [
"Consider the day as 48 hours instead of 24.",
"For each round check if you were playing."
] | {
"canonical_parameter_names": [
"loginTime",
"logoutTime"
],
"leetcode_dataset_entry_point": "Solution().numberOfRounds",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:34",
"tests... | cpp | {
"raw_signature": "int numberOfRounds(string loginTime, string logoutTime) {",
"container": "Solution",
"callable": "numberOfRounds",
"parameters": [
{
"name": "loginTime",
"type": "string"
},
{
"name": "logoutTime",
"type": "string"
}
],
"return_type": "int",
"sig... |
1,905 | count-sub-islands | Medium | You are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land). An island is a group of 1's connected 4-directionally (horizontal or vertical). Any cells outside of the grid are considered water cells.
An island in grid2 is considered a sub-island if there ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid1 = [[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 1, 1], [0, 0, 0, 0, 0]],grid2 = [[1, 1, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 1, 0], [0, 0, 0, 0, 1]]) == 2\n assert candidate(grid1 = [[1, 1, 1, 1,... | [
"[[1,1,1,0,0],[0,1,1,1,1],[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,1]]\n[[1,1,1,0,0],[0,0,1,1,1],[0,1,0,0,0],[1,0,1,1,0],[0,1,0,1,0]]",
"[[1,0,1,0,1],[1,1,1,1,1],[0,0,0,0,0],[1,1,1,1,1],[1,0,1,0,1]]\n[[0,0,0,0,0],[1,1,1,1,1],[0,1,0,1,0],[0,1,0,1,0],[1,0,0,0,1]]"
] | [
"Let's use floodfill to iterate over the islands of the second grid",
"Let's note that if all the cells in an island in the second grid if they are represented by land in the first grid then they are connected hence making that island a sub-island"
] | {
"canonical_parameter_names": [
"grid1",
"grid2"
],
"leetcode_dataset_entry_point": "Solution().countSubIslands",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:37",
"tests_total":... | cpp | {
"raw_signature": "int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {",
"container": "Solution",
"callable": "countSubIslands",
"parameters": [
{
"name": "grid1",
"type": "vector<vector<int>>&"
},
{
"name": "grid2",
"type": "vector<vector<int>>&"
... |
1,906 | minimum-absolute-difference-queries | Medium | The minimum absolute difference of an array a is defined as the minimum value of |a[i] - a[j]|, where 0 <= i < j < a.length and a[i] != a[j]. If all elements of a are the same, the minimum absolute difference is -1.
- For example, the minimum absolute difference of the array [5,2,3,7,2] is |2 - 3| = 1. Note that it is... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1],queries = [[0, 4], [1, 3]]) == [-1, -1]\n assert candidate(nums = [5, 5, 5, 5],queries = [[0, 3], [1, 2], [2, 3], [0, 1]]) == [-1, -1, -1, -1]\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9],querie... | [
"[1,3,4,8]\n[[0,1],[1,2],[2,3],[0,3]]",
"[4,5,2,2,7,10]\n[[2,3],[0,2],[0,5],[3,5]]"
] | [
"How does the maximum value being 100 help us?",
"How can we tell if a number exists in a given range?"
] | {
"canonical_parameter_names": [
"nums",
"queries"
],
"leetcode_dataset_entry_point": "Solution().minDifference",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:39",
"tests_total": ... | cpp | {
"raw_signature": "vector<int> minDifference(vector<int>& nums, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "minDifference",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "queries",
"type": "vector<vector<int>>&"
}
],
... |
1,909 | remove-one-element-to-make-the-array-strictly-increasing | Easy | Given a 0-indexed integer array nums, return true if it can be made strictly increasing after removing exactly one element, or false otherwise. If the array is already strictly increasing, return true.
The array nums is strictly increasing if nums[i - 1] < nums[i] for each index (1 <= i < nums.length).
Example 1:
In... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == True\n assert candidate(nums = [1, 2, 2, 3, 4, 5]) == True\n assert candidate(nums = [1, 2, 2, 3]) == True\n assert candidate(nums = [1, 1, 1]) == False\n assert candidate(nums = [10, 9, 2, 5, 3, 7,... | [
"[1,2,10,5,7]",
"[2,3,1,2]",
"[1,1,1]"
] | [
"For each index i in nums remove this index.",
"If the array becomes sorted return true, otherwise revert to the original array and try different index."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().canBeIncreasing",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:44",
"tests_total": 179,
"tests... | cpp | {
"raw_signature": "bool canBeIncreasing(vector<int>& nums) {",
"container": "Solution",
"callable": "canBeIncreasing",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,910 | remove-all-occurrences-of-a-substring | Medium | Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed:
- Find the leftmost occurrence of the substring part and remove it from s.
Return s after removing all occurrences of part.
A substring is a contiguous sequence of characters in a string.
Exam... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcd\",part = \"efg\") == \"abcd\"\n assert candidate(s = \"zzzz\",part = \"zz\") == \"\"\n assert candidate(s = \"abcdabcdabcd\",part = \"abcd\") == \"\"\n assert candidate(s = \"abcdefg\",part = \"xyz\") == \"abcdefg\"\n... | [
"\"daabcbaabcbc\"\n\"abc\"",
"\"axxxxyyyyb\"\n\"xy\""
] | [
"Note that a new occurrence of pattern can appear if you remove an old one, For example, s = \"ababcc\" and pattern = \"abc\".",
"You can maintain a stack of characters and if the last character of the pattern size in the stack match the pattern remove them"
] | {
"canonical_parameter_names": [
"s",
"part"
],
"leetcode_dataset_entry_point": "Solution().removeOccurrences",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:46",
"tests_total": 13... | cpp | {
"raw_signature": "string removeOccurrences(string s, string part) {",
"container": "Solution",
"callable": "removeOccurrences",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "part",
"type": "string"
}
],
"return_type": "string",
"signature_source": ... |
1,911 | maximum-alternating-subsequence-sum | Medium | The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices.
- For example, the alternating sum of [4,2,5,3] is (4 + 5) - (2 + 3) = 4.
Given an array nums, return the maximum alternating sum of any subsequence of nums (after reindexing th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996]) == 100000\n assert candidate(nums = [4, 2, 5, 3]) == 7\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [6, 2, 1, 2, 4, 5]) == 10\n assert... | [
"[4,2,5,3]",
"[5,6,7,8]",
"[6,2,1,2,4,5]"
] | [
"Is only tracking a single sum enough to solve the problem?",
"How does tracking an odd sum and an even sum reduce the number of states?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxAlternatingSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:49",
"tests_total": 96,
"test... | cpp | {
"raw_signature": "long long maxAlternatingSum(vector<int>& nums) {",
"container": "Solution",
"callable": "maxAlternatingSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leet... |
1,913 | maximum-product-difference-between-two-pairs | Easy | The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d).
- For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16.
Given an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nums[... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 6, 2, 7, 4]) == 34\n assert candidate(nums = [9, 5, 8, 6, 7, 3, 2, 1, 4]) == 70\n assert candidate(nums = [1, 2, 3, 4]) == 10\n assert candidate(nums = [4, 2, 5, 9, 7, 4, 8]) == 64\n assert candidate(nums = [10000,... | [
"[5,6,2,7,4]",
"[4,2,5,9,7,4,8]"
] | [
"If you only had to find the maximum product of 2 numbers in an array, which 2 numbers should you choose?",
"We only need to worry about 4 numbers in the array."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxProductDifference",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:51",
"tests_total": 98,
"t... | cpp | {
"raw_signature": "int maxProductDifference(vector<int>& nums) {",
"container": "Solution",
"callable": "maxProductDifference",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
1,914 | cyclically-rotating-a-grid | Medium | You are given an m x n integer matrix grid, where m and n are both even integers, and an integer k.
The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:
A cyclic rotation of the matrix is done by cyclically rotating each layer in the matrix. To cyclically rot... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 2], [3, 4], [5, 6], [7, 8]],k = 1) == [[2, 4], [1, 6], [3, 8], [5, 7]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8], [9, 10, 11, 12, 13, 14, 15, 16], [17, 18, 19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30, 31, 32... | [
"[[40,10],[30,20]]\n1",
"[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]\n2"
] | [
"First, you need to consider each layer separately as an array.",
"Just cycle this array and then re-assign it."
] | {
"canonical_parameter_names": [
"grid",
"k"
],
"leetcode_dataset_entry_point": "Solution().rotateGrid",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:53",
"tests_total": 57,
"te... | cpp | {
"raw_signature": "vector<vector<int>> rotateGrid(vector<vector<int>>& grid, int k) {",
"container": "Solution",
"callable": "rotateGrid",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "vector<vec... |
1,915 | number-of-wonderful-substrings | Medium | A wonderful string is a string where at most one letter appears an odd number of times.
- For example, "ccjjc" and "abab" are wonderful, but "ab" is not.
Given a string word that consists of the first ten lowercase English letters ('a' through 'j'), return the number of wonderful non-empty substrings in word. If the ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word = \"aaaaaaaaaa\") == 55\n assert candidate(word = \"aabbccddeeffgghhiijj\") == 165\n assert candidate(word = \"aba\") == 4\n assert candidate(word = \"aaaabbbbcccc\") == 66\n assert candidate(word = \"babcbabcbab\") == 3... | [
"\"aba\"",
"\"aabb\"",
"\"he\""
] | [
"For each prefix of the string, check which characters are of even frequency and which are not and represent it by a bitmask.",
"Find the other prefixes whose masks differs from the current prefix mask by at most one bit."
] | {
"canonical_parameter_names": [
"word"
],
"leetcode_dataset_entry_point": "Solution().wonderfulSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:55",
"tests_total": 77,
"te... | cpp | {
"raw_signature": "long long wonderfulSubstrings(string word) {",
"container": "Solution",
"callable": "wonderfulSubstrings",
"parameters": [
{
"name": "word",
"type": "string"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
1,916 | count-ways-to-build-rooms-in-an-ant-colony | Hard | You are an ant tasked with adding n new rooms numbered 0 to n-1 to your colony. You are given the expansion plan as a 0-indexed integer array of length n, prevRoom, where prevRoom[i] indicates that you must build room prevRoom[i] before building room i, and these two rooms must be connected directly. Room 0 is already ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9]) == 258365767\n assert candidate(prevRoom = [-1, 0, 1, 1, 2, 2]) == 8\n assert candidate(prevRoom = [-1, 0, 0, 1, 2]) == 6\n assert candidate(prevRoom = [-... | [
"[-1,0,1]",
"[-1,0,0,1,2]"
] | [
"Use dynamic programming.",
"Let dp[i] be the number of ways to solve the problem for the subtree of node i.",
"Imagine you are trying to fill an array with the order of traversal, dp[i] equals the multiplications of the number of ways to distribute the subtrees of the children of i on the array using combinato... | {
"canonical_parameter_names": [
"prevRoom"
],
"leetcode_dataset_entry_point": "Solution().waysToBuildRooms",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:34:58",
"tests_total": 89,
"t... | cpp | {
"raw_signature": "int waysToBuildRooms(vector<int>& prevRoom) {",
"container": "Solution",
"callable": "waysToBuildRooms",
"parameters": [
{
"name": "prevRoom",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
1,920 | build-array-from-permutation | Easy | Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.
A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).
Example 1:
Input: nums = [0,2,1,5,3,4]
Output: [0,1,2,... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 0, 2, 1, 3]) == [3, 4, 2, 0, 1]\n assert candidate(nums = [3, 2, 1, 0]) == [0, 1, 2, 3]\n assert candidate(nums = [5, 0, 1, 2, 3, 4]) == [4, 5, 0, 1, 2, 3]\n assert candidate(nums = [1, 0, 3, 2]) == [0, 1, 2, 3]\n ... | [
"[0,2,1,5,3,4]",
"[5,0,1,2,3,4]"
] | [
"Just apply what's said in the statement.",
"Notice that you can't apply it on the same array directly since some elements will change after application"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().buildArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:35:02",
"tests_total": 81,
"tests_dropp... | cpp | {
"raw_signature": "vector<int> buildArray(vector<int>& nums) {",
"container": "Solution",
"callable": "buildArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeS... |
1,921 | eliminate-maximum-number-of-monsters | Medium | You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, where dist[i] is the initial distance in kilometers of the i^th monster from the city.
The monsters walk toward the city at a constant speed. The speed of each monster is g... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(dist = [6, 7, 8],speed = [2, 2, 2]) == 3\n assert candidate(dist = [1, 2, 3],speed = [3, 2, 1]) == 1\n assert candidate(dist = [100, 200, 300],speed = [1, 1, 1]) == 3\n assert candidate(dist = [7, 14, 21],speed = [1, 2, 3]) == 3... | [
"[1,3,4]\n[1,1,1]",
"[1,1,2,3]\n[1,1,1,1]",
"[3,2,4]\n[5,3,2]"
] | [
"Find the amount of time it takes each monster to arrive.",
"Find the order in which the monsters will arrive."
] | {
"canonical_parameter_names": [
"dist",
"speed"
],
"leetcode_dataset_entry_point": "Solution().eliminateMaximum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:35:05",
"tests_total":... | cpp | {
"raw_signature": "int eliminateMaximum(vector<int>& dist, vector<int>& speed) {",
"container": "Solution",
"callable": "eliminateMaximum",
"parameters": [
{
"name": "dist",
"type": "vector<int>&"
},
{
"name": "speed",
"type": "vector<int>&"
}
],
"return_type": "int"... |
1,923 | longest-common-subpath | Hard | There is a country of n cities numbered from 0 to n - 1. In this country, there is a road connecting every pair of cities.
There are m friends numbered from 0 to m - 1 who are traveling through the country. Each one of them will take a path consisting of some cities. Each path is represented by an integer array that c... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 1,paths = [[0], [0], [0]]) == 1\n assert candidate(n = 5,paths = [[0, 1, 2, 3, 4], [4, 3, 2, 1, 0]]) == 1\n assert candidate(n = 3,paths = [[0], [1], [2]]) == 0\n assert candidate(n = 10,paths = [[0, 1, 2], [1, 2, 3], [2, 3,... | [
"5\n[[0,1,2,3,4],[2,3,4],[4,0,1,2,3]]",
"3\n[[0],[1],[2]]",
"5\n[[0,1,2,3,4],[4,3,2,1,0]]"
] | [
"If there is a common path with length x, there is for sure a common path of length y where y < x.",
"We can use binary search over the answer with the range [0, min(path[i].length)].",
"Using binary search, we want to verify if we have a common path of length m. We can achieve this using hashing."
] | {
"canonical_parameter_names": [
"n",
"paths"
],
"leetcode_dataset_entry_point": "Solution().longestCommonSubpath",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:35:10",
"tests_total"... | cpp | {
"raw_signature": "int longestCommonSubpath(int n, vector<vector<int>>& paths) {",
"container": "Solution",
"callable": "longestCommonSubpath",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "paths",
"type": "vector<vector<int>>&"
}
],
"return_type": "int"... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.