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,497 | check-if-array-pairs-are-divisible-by-k | Medium | Given an array of integers arr of even length n and an integer k.
We want to divide the array into exactly n / 2 pairs such that the sum of each pair is divisible by k.
Return true If you can find a way to do that or false otherwise.
Example 1:
Input: arr = [1,2,3,4,5,10,6,7,8,9], k = 5
Output: true
Explanation: Pa... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8],k = 4) == True\n assert candidate(arr = [0, 0, 0, 0],k = 1) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6],k = 10) == False\n assert candidate(arr = [-1, 1, -2, 2, -3, 3],k = 2) == True\n a... | [
"[1,2,3,4,5,10,6,7,8,9]\n5",
"[1,2,3,4,5,6]\n7",
"[1,2,3,4,5,6]\n10"
] | [
"Keep an array of the frequencies of ((x % k) + k) % k for each x in arr.",
"for each i in [0, k - 1] we need to check if freq[i] == freq[k - i]",
"Take care of the case when i == k - i and when i == 0"
] | {
"canonical_parameter_names": [
"arr",
"k"
],
"leetcode_dataset_entry_point": "Solution().canArrange",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:54",
"tests_total": 93,
"tes... | cpp | {
"raw_signature": "bool canArrange(vector<int>& arr, int k) {",
"container": "Solution",
"callable": "canArrange",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcode/code... |
1,498 | number-of-subsequences-that-satisfy-the-given-sum-condition | Medium | You are given an array of integers nums and an integer target.
Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:
Input: nums = [3,5,6,7], target = 9
Output... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],target = 10) == 31\n assert candidate(nums = [10, 10, 10, 10],target = 20) == 15\n assert candidate(nums = [1, 3, 5, 7],target = 8) == 10\n assert candidate(nums = [1, 2, 3, 4, 5],target = 5) == 10\n as... | [
"[3,5,6,7]\n9",
"[3,3,6,8]\n10",
"[2,3,3,4,6,7]\n12"
] | [
"Sort the array nums.",
"Use two pointers approach: Given an index i (choose it as the minimum in a subsequence) find the maximum j where j ≥ i and nums[i] +nums[j] ≤ target.",
"Count the number of subsequences."
] | {
"canonical_parameter_names": [
"nums",
"target"
],
"leetcode_dataset_entry_point": "Solution().numSubseq",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:56",
"tests_total": 81,
... | cpp | {
"raw_signature": "int numSubseq(vector<int>& nums, int target) {",
"container": "Solution",
"callable": "numSubseq",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetc... |
1,499 | max-value-of-equation | Hard | You are given an array points containing the coordinates of points on a 2D plane, sorted by the x-values, where points[i] = [x_i, y_i] such that x_i < x_j for all 1 <= i < j <= points.length. You are also given an integer k.
Return the maximum value of the equation y_i + y_j + |x_i - x_j| where |x_i - x_j| <= k and 1 ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(points = [[1, 3], [2, 0], [5, 10], [6, -10]],k = 1) == 4\n assert candidate(points = [[1, 5], [2, 3], [4, 7], [8, 10]],k = 6) == 21\n assert candidate(points = [[1, 3], [2, 0], [5, 10], [6, -10], [7, 5]],k = 4) == 17\n assert ca... | [
"[[1,3],[2,0],[5,10],[6,-10]]\n1",
"[[0,0],[3,0],[9,2]]\n3"
] | [
"Use a priority queue to store for each point i, the tuple [yi-xi, xi]",
"Loop through the array and pop elements from the heap if the condition xj - xi > k, where j is the current index and i is the point on top the queue.",
"After popping elements from the queue. If the queue is not empty, calculate the equat... | {
"canonical_parameter_names": [
"points",
"k"
],
"leetcode_dataset_entry_point": "Solution().findMaxValueOfEquation",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:21:59",
"tests_tot... | cpp | {
"raw_signature": "int findMaxValueOfEquation(vector<vector<int>>& points, int k) {",
"container": "Solution",
"callable": "findMaxValueOfEquation",
"parameters": [
{
"name": "points",
"type": "vector<vector<int>>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type":... |
1,502 | can-make-arithmetic-progression-from-sequence | Easy | A sequence of numbers is called an arithmetic progression if the difference between any two consecutive elements is the same.
Given an array of numbers arr, return true if the array can be rearranged to form an arithmetic progression. Otherwise, return false.
Example 1:
Input: arr = [3,5,1]
Output: true
Explanation:... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [2, 4, 6, 8, 10]) == True\n assert candidate(arr = [-1, 1, 0]) == True\n assert candidate(arr = [5, 3, 1, 4, 2]) == True\n assert candidate(arr = [10, 20, 30, 40, 50]) == True\n assert candidate(arr = [10, 5, 15]) == Tr... | [
"[3,5,1]",
"[1,2,4]"
] | [
"Consider that any valid arithmetic progression will be in sorted order.",
"Sort the array, then check if the differences of all consecutive elements are equal."
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().canMakeArithmeticProgression",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:01",
"tests_total": 1... | cpp | {
"raw_signature": "bool canMakeArithmeticProgression(vector<int>& arr) {",
"container": "Solution",
"callable": "canMakeArithmeticProgression",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_sour... |
1,503 | last-moment-before-all-ants-fall-out-of-a-plank | Medium | We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with a speed of 1 unit per second. Some of the ants move to the left, the other move to the right.
When two ants moving in two different directions meet at some point, they change their directions and continue moving again... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 15,left = [10, 11, 12],right = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 15\n assert candidate(n = 1,left = [],right = [0]) == 1\n assert candidate(n = 5,left = [5],right = [0]) == 5\n assert candidate(n = 1,left = [1],right = []) ... | [
"4\n[4,3]\n[0,1]",
"7\n[]\n[0,1,2,3,4,5,6,7]",
"7\n[0,1,2,3,4,5,6,7]\n[]"
] | [
"The ants change their way when they meet is equivalent to continue moving without changing their direction.",
"Answer is the max distance for one ant to reach the end of the plank in the facing direction."
] | {
"canonical_parameter_names": [
"n",
"left",
"right"
],
"leetcode_dataset_entry_point": "Solution().getLastMoment",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:03",
"tests_t... | cpp | {
"raw_signature": "int getLastMoment(int n, vector<int>& left, vector<int>& right) {",
"container": "Solution",
"callable": "getLastMoment",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "left",
"type": "vector<int>&"
},
{
"name": "right",
"ty... |
1,504 | count-submatrices-with-all-ones | Medium | Given an m x n binary matrix mat, return the number of submatrices that have all ones.
Example 1:
Input: mat = [[1,0,1],[1,1,0],[1,1,0]]
Output: 13
Explanation:
There are 6 rectangles of side 1x1.
There are 2 rectangles of side 1x2.
There are 3 rectangles of side 2x1.
There is 1 rectangle of side 2x2.
There is 1 rect... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mat = [[0, 0], [0, 0]]) == 0\n assert candidate(mat = [[1, 0, 1], [1, 1, 0], [1, 1, 0]]) == 13\n assert candidate(mat = [[1, 0], [0, 1]]) == 2\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 60\n asser... | [
"[[1,0,1],[1,1,0],[1,1,0]]",
"[[0,1,1,0],[0,1,1,1],[1,1,1,0]]"
] | [
"For each row i, create an array nums where: if mat[i][j] == 0 then nums[j] = 0 else nums[j] = nums[j-1] +1.",
"In the row i, number of rectangles between column j and k(inclusive) and ends in row i, is equal to SUM(min(nums[j, .. idx])) where idx go from j to k. Expected solution is O(n^3)."
] | {
"canonical_parameter_names": [
"mat"
],
"leetcode_dataset_entry_point": "Solution().numSubmat",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:05",
"tests_total": 90,
"tests_dropped... | cpp | {
"raw_signature": "int numSubmat(vector<vector<int>>& mat) {",
"container": "Solution",
"callable": "numSubmat",
"parameters": [
{
"name": "mat",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,505 | minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits | Hard | You are given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times.
Return the minimum integer you can obtain also as a string.
Example 1:
Input: num = "4321", k = 4
Output: "1342"
Explanation: The steps to obtai... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = \"36789\",k = 1000) == \"36789\"\n assert candidate(num = \"100\",k = 1) == \"010\"\n assert candidate(num = \"9876543210\",k = 9) == \"0987654321\"\n assert candidate(num = \"9876543210\",k = 100) == \"0123456789\"\n a... | [
"\"4321\"\n4",
"\"100\"\n1",
"\"36789\"\n1000"
] | [
"We want to make the smaller digits the most significant digits in the number.",
"For each index i, check the smallest digit in a window of size k and append it to the answer. Update the indices of all digits in this range accordingly."
] | {
"canonical_parameter_names": [
"num",
"k"
],
"leetcode_dataset_entry_point": "Solution().minInteger",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:07",
"tests_total": 106,
"te... | cpp | {
"raw_signature": "string minInteger(string num, int k) {",
"container": "Solution",
"callable": "minInteger",
"parameters": [
{
"name": "num",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets... |
1,507 | reformat-date | Easy | Given a date string in the form Day Month Year, where:
- Day is in the set {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}.
- Month is in the set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}.
- Year is in the range [1900, 2100].
Convert the date string to the format YYYY-MM-D... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(date = \"15th Aug 2022\") == \"2022-08-15\"\n assert candidate(date = \"22nd Aug 1999\") == \"1999-08-22\"\n assert candidate(date = \"3rd Mar 1987\") == \"1987-03-03\"\n assert candidate(date = \"3rd Nov 2022\") == \"2022-11-03... | [
"\"20th Oct 2052\"",
"\"6th Jun 1933\"",
"\"26th May 1960\""
] | [
"Handle the conversions of day, month and year separately.",
"Notice that days always have a two-word ending, so if you erase the last two characters of this days you'll get the number."
] | {
"canonical_parameter_names": [
"date"
],
"leetcode_dataset_entry_point": "Solution().reformatDate",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:10",
"tests_total": 111,
"tests_dr... | cpp | {
"raw_signature": "string reformatDate(string date) {",
"container": "Solution",
"callable": "reformatDate",
"parameters": [
{
"name": "date",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,508 | range-sum-of-sorted-subarray-sums | Medium | You are given the array nums consisting of n positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers.
Return the sum of the numbers from index left to index right (indexed from 1), inclusi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4],n = 4,left = 3,right = 4) == 6\n assert candidate(nums = [10, 20, 30],n = 3,left = 1,right = 3) == 60\n assert candidate(nums = [5, 1, 2],n = 3,left = 1,right = 4) == 11\n assert candidate(nums = [1, 2, 3, 4]... | [
"[1,2,3,4]\n4\n1\n5",
"[1,2,3,4]\n4\n3\n4",
"[1,2,3,4]\n4\n1\n10"
] | [
"Compute all sums and save it in array.",
"Then just go from LEFT to RIGHT index and calculate answer modulo 1e9 + 7."
] | {
"canonical_parameter_names": [
"nums",
"n",
"left",
"right"
],
"leetcode_dataset_entry_point": "Solution().rangeSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:13",
"... | cpp | {
"raw_signature": "int rangeSum(vector<int>& nums, int n, int left, int right) {",
"container": "Solution",
"callable": "rangeSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "n",
"type": "int"
},
{
"name": "left",
"type": "int"... |
1,509 | minimum-difference-between-largest-and-smallest-value-in-three-moves | Medium | You are given an integer array nums.
In one move, you can choose one element of nums and change it to any value.
Return the minimum difference between the largest and smallest value of nums after performing at most three moves.
Example 1:
Input: nums = [5,3,2,4]
Output: 0
Explanation: We can make at most 3 moves.
I... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [3, 100, 20]) == 0\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 6\n assert candidate(nums = ... | [
"[5,3,2,4]",
"[1,5,0,10,14]",
"[3,100,20]"
] | [
"The minimum difference possible is obtained by removing three elements between the three smallest and three largest values in the array."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minDifference",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:15",
"tests_total": 109,
"tests_d... | cpp | {
"raw_signature": "int minDifference(vector<int>& nums) {",
"container": "Solution",
"callable": "minDifference",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,510 | stone-game-iv | Hard | Alice and Bob take turns playing a game, with Alice starting first.
Initially, there are n stones in a pile. On each player's turn, that player makes a move consisting of removing any non-zero square number of stones in the pile.
Also, if a player cannot make a move, he/she loses the game.
Given a positive integer n... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 101) == True\n assert candidate(n = 3) == True\n assert candidate(n = 100) == True\n assert candidate(n = 30) == True\n assert candidate(n = 5) == False\n assert candidate(n = 4) == True\n assert candidate(n = 200) ... | [
"1",
"2",
"4"
] | [
"Use dynamic programming to keep track of winning and losing states. Given some number of stones, Alice can win if she can force Bob onto a losing state."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().winnerSquareGame",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:18",
"tests_total": 24,
"tests_dr... | cpp | {
"raw_signature": "bool winnerSquareGame(int n) {",
"container": "Solution",
"callable": "winnerSquareGame",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,512 | number-of-good-pairs | Easy | Given an array of integers nums, return the number of good pairs.
A pair (i, j) is called good if nums[i] == nums[j] and i < j.
Example 1:
Input: nums = [1,2,3,1,1,3]
Output: 4
Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.
Example 2:
Input: nums = [1,1,1,1]
Output: 6
Explanation: Each p... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 6, 7, 8, 9, 5]) == 1\n assert candidate(nums = [1, 1, 1, 1]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7])... | [
"[1,2,3,1,1,3]",
"[1,1,1,1]",
"[1,2,3]"
] | [
"Count how many times each number appears. If a number appears n times, then n * (n – 1) // 2 good pairs can be made with this number."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().numIdenticalPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:20",
"tests_total": 102,
"tes... | cpp | {
"raw_signature": "int numIdenticalPairs(vector<int>& nums) {",
"container": "Solution",
"callable": "numIdenticalPairs",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
1,513 | number-of-substrings-with-only-1s | Medium | Given a binary string s, return the number of substrings with all characters 1's. Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:
Input: s = "0110111"
Output: 9
Explanation: There are 9 substring in total with only 1's characters.
"1" -> 5 times.
"11" -> 3 times.
"111" -> 1 time.
Example 2:
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1100110011\") == 9\n assert candidate(s = \"101\") == 2\n assert candidate(s = \"1001001001\") == 4\n assert candidate(s = \"1111101111\") == 25\n assert candidate(s = \"110110110110110\") == 15\n assert candidate(s ... | [
"\"0110111\"",
"\"101\"",
"\"111111\""
] | [
"Count number of 1s in each consecutive-1 group. For a group with n consecutive 1s, the total contribution of it to the final answer is (n + 1) * n // 2."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().numSub",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:22",
"tests_total": 28,
"tests_dropped": 0,... | cpp | {
"raw_signature": "int numSub(string s) {",
"container": "Solution",
"callable": "numSub",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,514 | path-with-maximum-probability | Medium | You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with a probability of success of traversing that edge succProb[i].
Given two nodes start and end, find the path with the maximum probability of succe... | {
"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... | [
"3\n[[0,1],[1,2],[0,2]]\n[0.5,0.5,0.2]\n0\n2",
"3\n[[0,1],[1,2],[0,2]]\n[0.5,0.5,0.3]\n0\n2",
"3\n[[0,1]]\n[0.5]\n0\n2"
] | [
"Multiplying probabilities will result in precision errors.",
"Take log probabilities to sum up numbers instead of multiplying them.",
"Use Dijkstra's algorithm to find the minimum path between the two nodes after negating all costs."
] | {
"canonical_parameter_names": [
"n",
"edges",
"succProb",
"start_node",
"end_node"
],
"leetcode_dataset_entry_point": "Solution().maxProbability",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched... | cpp | {
"raw_signature": "double maxProbability(int n, vector<vector<int>>& edges, vector<double>& succProb, int start_node, int end_node) {",
"container": "Solution",
"callable": "maxProbability",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<v... |
1,515 | best-position-for-a-service-centre | Hard | A delivery company wants to build a new service center in a new city. The company knows the positions of all the customers in this city on a 2D-Map and wants to build the new center in a position such that the sum of the euclidean distances to all customers is minimum.
Given an array positions where positions[i] = [x_... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat... | [
"[[0,1],[1,0],[1,2],[2,1]]",
"[[1,1],[3,3]]"
] | [
"The problem can be reworded as, giving a set of points on a 2d-plane, return the geometric median.",
"Loop over each triplet of points (positions[i], positions[j], positions[k]) where i < j < k, get the centre of the circle which goes throw the 3 points, check if all other points lie in this circle."
] | {
"canonical_parameter_names": [
"positions"
],
"leetcode_dataset_entry_point": "Solution().getMinDistSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:27",
"tests_total": 104,
"te... | cpp | {
"raw_signature": "double getMinDistSum(vector<vector<int>>& positions) {",
"container": "Solution",
"callable": "getMinDistSum",
"parameters": [
{
"name": "positions",
"type": "vector<vector<int>>&"
}
],
"return_type": "double",
"signature_source": "leetcode/codeSnippets",
"type_so... |
1,518 | water-bottles | Easy | There are numBottles water bottles that are initially full of water. You can exchange numExchange empty water bottles from the market with one full water bottle.
The operation of drinking a full water bottle turns it into an empty bottle.
Given the two integers numBottles and numExchange, return the maximum number of... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(numBottles = 10,numExchange = 2) == 19\n assert candidate(numBottles = 20,numExchange = 6) == 23\n assert candidate(numBottles = 100,numExchange = 10) == 111\n assert candidate(numBottles = 5,numExchange = 5) == 6\n assert ca... | [
"9\n3",
"15\n4"
] | [
"Simulate the process until there are not enough empty bottles for even one full bottle of water."
] | {
"canonical_parameter_names": [
"numBottles",
"numExchange"
],
"leetcode_dataset_entry_point": "Solution().numWaterBottles",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:29",
"te... | cpp | {
"raw_signature": "int numWaterBottles(int numBottles, int numExchange) {",
"container": "Solution",
"callable": "numWaterBottles",
"parameters": [
{
"name": "numBottles",
"type": "int"
},
{
"name": "numExchange",
"type": "int"
}
],
"return_type": "int",
"signature... |
1,519 | number-of-nodes-in-the-sub-tree-with-the-same-label | Medium | You are given a tree (i.e. a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of the tree is the node 0, and each node of the tree has a label which is a lower-case character given in the string labels (i.e. The node with the number i has t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [0, 3]],labels = \"bbbb\") == [4, 2, 1, 1]\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],labels = \"cbabaa\") == [1, 2, 2, 1, 1, 1]\n assert candidate(n = 6,edges = [[0, 1]... | [
"7\n[[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]]\n\"abaedcd\"",
"4\n[[0,1],[1,2],[0,3]]\n\"bbbb\"",
"5\n[[0,1],[0,2],[1,3],[0,4]]\n\"aabab\""
] | [
"Start traversing the tree and each node should return a vector to its parent node.",
"The vector should be of length 26 and have the count of all the labels in the sub-tree of this node."
] | {
"canonical_parameter_names": [
"n",
"edges",
"labels"
],
"leetcode_dataset_entry_point": "Solution().countSubTrees",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:32",
"tests... | cpp | {
"raw_signature": "vector<int> countSubTrees(int n, vector<vector<int>>& edges, string labels) {",
"container": "Solution",
"callable": "countSubTrees",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
},
{
"name... |
1,520 | maximum-number-of-non-overlapping-substrings | Hard | Given a string s of lowercase letters, you need to find the maximum number of non-empty substrings of s that meet the following conditions:
1. The substrings do not overlap, that is for any two substrings s[i..j] and s[x..y], either j < x or i > y is true.
2. A substring that contains a certain character c must also c... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ... | [
"\"adefaddaccc\"",
"\"abbaccd\""
] | [
"Notice that it's impossible for any two valid substrings to overlap unless one is inside another.",
"We can start by finding the starting and ending index for each character.",
"From these indices, we can form the substrings by expanding each character's range if necessary (if another character exists in the r... | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().maxNumOfSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:34",
"tests_total": 59,
"tests_... | cpp | {
"raw_signature": "vector<string> maxNumOfSubstrings(string s) {",
"container": "Solution",
"callable": "maxNumOfSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "vector<string>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
1,521 | find-a-value-of-a-mysterious-function-closest-to-target | Hard | Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible.
Return the minimum possible value of |func(arr, l, r) - target|.
Notice that func should be called with the v... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [7, 7, 7, 7, 7, 7],target = 8) == 1\n assert candidate(arr = [1000000],target = 1000000) == 0\n assert candidate(arr = [2, 4, 6, 8, 10],target = 7) == 1\n assert candidate(arr = [5, 5, 5, 5, 5],target = 5) == 0\n assert... | [
"[9,12,3,7,15]\n5",
"[1000000,1000000,1000000]\n1",
"[1,2,4,8,16]\n0"
] | [
"If the and value of sub-array arr[i...j] is ≥ the and value of the sub-array arr[i...j+1].",
"For each index i using binary search or ternary search find the index j where |target - AND(arr[i...j])| is minimum, minimize this value with the global answer."
] | {
"canonical_parameter_names": [
"arr",
"target"
],
"leetcode_dataset_entry_point": "Solution().closestToTarget",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:36",
"tests_total": ... | cpp | {
"raw_signature": "int closestToTarget(vector<int>& arr, int target) {",
"container": "Solution",
"callable": "closestToTarget",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "int",
"signature_sourc... |
1,523 | count-odd-numbers-in-an-interval-range | Easy | Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive).
Example 1:
Input: low = 3, high = 7
Output: 3
Explanation: The odd numbers between 3 and 7 are [3,5,7].
Example 2:
Input: low = 8, high = 10
Output: 1
Explanation: The odd numbers between 8 and 10 are [9]... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(low = 3,high = 7) == 3\n assert candidate(low = 0,high = 1000000000) == 500000000\n assert candidate(low = 0,high = 1) == 1\n assert candidate(low = 500000000,high = 500000000) == 0\n assert candidate(low = 1,high = 100000000... | [
"3\n7",
"8\n10"
] | [
"If the range (high - low + 1) is even, the number of even and odd numbers in this range will be the same.",
"If the range (high - low + 1) is odd, the solution will depend on the parity of high and low."
] | {
"canonical_parameter_names": [
"low",
"high"
],
"leetcode_dataset_entry_point": "Solution().countOdds",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:38",
"tests_total": 93,
"t... | cpp | {
"raw_signature": "int countOdds(int low, int high) {",
"container": "Solution",
"callable": "countOdds",
"parameters": [
{
"name": "low",
"type": "int"
},
{
"name": "high",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"ty... |
1,524 | number-of-sub-arrays-with-odd-sum | Medium | Given an array of integers arr, return the number of subarrays with an odd sum.
Since the answer can be very large, return it modulo 10^9 + 7.
Example 1:
Input: arr = [1,3,5]
Output: 4
Explanation: All subarrays are [[1],[1,3],[1,3,5],[3],[3,5],[5]]
All sub-arrays sum are [1,4,9,3,8,5].
Odd sums are [1,9,3,5] so the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [2, 4, 6, 8, 10]) == 0\n assert candidate(arr = [100, 100, 100, 100, 100]) == 0\n assert candidate(arr = [50, 50, 50, 50, 50]) == 0\n assert candidate(arr = [1, 2, 3]) == 4\n assert candidate(arr = [2, 2, 2, 2, 2]) == 0... | [
"[1,3,5]",
"[2,4,6]",
"[1,2,3,4,5,6,7]"
] | [
"Can we use the accumulative sum to keep track of all the odd-sum sub-arrays ?",
"if the current accu sum is odd, we care only about previous even accu sums and vice versa."
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().numOfSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:41",
"tests_total": 87,
"tests_dr... | cpp | {
"raw_signature": "int numOfSubarrays(vector<int>& arr) {",
"container": "Solution",
"callable": "numOfSubarrays",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,525 | number-of-good-ways-to-split-a-string | Medium | You are given a string s.
A split is called good if you can split s into two non-empty strings s_left and s_right where their concatenation is equal to s (i.e., s_left + s_right = s) and the number of distinct letters in s_left and s_right is the same.
Return the number of good splits you can make in s.
Example 1:
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"xyzxyzxyz\") == 4\n assert candidate(s = \"aabbcc\") == 1\n assert candidate(s = \"abcde\") == 0\n assert candidate(s = \"abcdefghij\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 1\n assert candid... | [
"\"aacaba\"",
"\"abcd\""
] | [
"Use two HashMap to store the counts of distinct letters in the left and right substring divided by the current index."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().numSplits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:43",
"tests_total": 81,
"tests_dropped":... | cpp | {
"raw_signature": "int numSplits(string s) {",
"container": "Solution",
"callable": "numSplits",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,526 | minimum-number-of-increments-on-subarrays-to-form-a-target-array | Hard | You are given an integer array target. You have an integer array initial of the same size as target with all elements initially zeros.
In one operation you can choose any subarray from initial and increment each value by one.
Return the minimum number of operations to form a target array from initial.
The test cases... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(target = [1, 2, 3, 4, 5]) == 5\n assert candidate(target = [5, 4, 3, 2, 1]) == 5\n assert candidate(target = [100000]) == 100000\n assert candidate(target = [... | [
"[1,2,3,2,1]",
"[3,1,1,2]",
"[3,1,5,4,2]"
] | [
"For a given range of values in target, an optimal strategy is to increment the entire range by the minimum value. The minimum in a range could be obtained with Range minimum query or Segment trees algorithm."
] | {
"canonical_parameter_names": [
"target"
],
"leetcode_dataset_entry_point": "Solution().minNumberOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:46",
"tests_total": 105,
... | cpp | {
"raw_signature": "int minNumberOperations(vector<int>& target) {",
"container": "Solution",
"callable": "minNumberOperations",
"parameters": [
{
"name": "target",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
1,528 | shuffle-string | Easy | You are given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the i^th position moves to indices[i] in the shuffled string.
Return the shuffled string.
Example 1:
Input: s = "codeleet", indices = [4,5,6,7,0,2,1,3]
Output: "leetcode"
Explanation: As... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"codeleet\",indices = [4, 5, 6, 7, 0, 2, 1, 3]) == \"leetcode\"\n assert candidate(s = \"aaiougrt\",indices = [4, 0, 2, 6, 7, 3, 1, 5]) == \"arigatou\"\n assert candidate(s = \"aiohn\",indices = [3, 1, 4, 2, 0]) == \"nihao\"\n... | [
"\"codeleet\"\n[4,5,6,7,0,2,1,3]",
"\"abc\"\n[0,1,2]"
] | [
"You can create an auxiliary string t of length n.",
"Assign t[indexes[i]] to s[i] for each i from 0 to n-1."
] | {
"canonical_parameter_names": [
"s",
"indices"
],
"leetcode_dataset_entry_point": "Solution().restoreString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:48",
"tests_total": 61,... | cpp | {
"raw_signature": "string restoreString(string s, vector<int>& indices) {",
"container": "Solution",
"callable": "restoreString",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "indices",
"type": "vector<int>&"
}
],
"return_type": "string",
"signature... |
1,529 | minimum-suffix-flips | Medium | You are given a 0-indexed binary string target of length n. You have another binary string s of length n that is initially set to all zeros. You want to make s equal to target.
In one operation, you can pick an index i where 0 <= i < n and flip all bits in the inclusive range [i, n - 1]. Flip means changing '0' to '1'... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(target = \"00000\") == 0\n assert candidate(target = \"00110\") == 2\n assert candidate(target = \"1100110011\") == 5\n assert candidate(target = \"000111000111\") == 3\n assert candidate(target = \"001100\") == 2\n assert... | [
"\"10111\"",
"\"101\"",
"\"00000\""
] | [
"Consider a strategy where the choice of bulb with number i is increasing. In such a strategy, you no longer need to worry about bulbs that have been set to the left."
] | {
"canonical_parameter_names": [
"target"
],
"leetcode_dataset_entry_point": "Solution().minFlips",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:50",
"tests_total": 117,
"tests_drop... | cpp | {
"raw_signature": "int minFlips(string target) {",
"container": "Solution",
"callable": "minFlips",
"parameters": [
{
"name": "target",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,531 | string-compression-ii | Hard | Run-length encoding is a string compression method that works by replacing consecutive identical characters (repeated 2 or more times) with the concatenation of the character and the number marking the count of the characters (length of the run). For example, to compress the string "aabccc" we replace "aa" by "a2" and ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcabcabc\",k = 5) == 3\n assert candidate(s = \"aaabcccd\",k = 2) == 4\n assert candidate(s = \"aabcc\",k = 1) == 4\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 20) == 32\n assert... | [
"\"aaabcccd\"\n2",
"\"aabbaa\"\n2",
"\"aaaaaaaaaaa\"\n0"
] | [
"Use dynamic programming.",
"The state of the DP can be the current index and the remaining characters to delete.",
"Having a prefix sum for each character can help you determine for a certain character c in some specific range, how many characters you need to delete to merge all occurrences of c in that range.... | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().getLengthOfOptimalCompression",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:55",
"tests_t... | cpp | {
"raw_signature": "int getLengthOfOptimalCompression(string s, int k) {",
"container": "Solution",
"callable": "getLengthOfOptimalCompression",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_sou... |
1,534 | count-good-triplets | Easy | Given an array of integers arr, and three integers a, b and c. You need to find the number of good triplets.
A triplet (arr[i], arr[j], arr[k]) is good if the following conditions are true:
- 0 <= i < j < k < arr.length
- |arr[i] - arr[j]| <= a
- |arr[j] - arr[k]| <= b
- |arr[i] - arr[k]| <= c
Where |x| denotes the ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [3, 0, 1, 1, 9, 7],a = 7,b = 2,c = 3) == 4\n assert candidate(arr = [1, 3, 5, 7, 9],a = 2,b = 3,c = 4) == 3\n assert candidate(arr = [1, 1, 2, 2, 3],a = 0,b = 0,c = 1) == 0\n assert candidate(arr = [10, 20, 30, 40, 50],a =... | [
"[3,0,1,1,9,7]\n7\n2\n3",
"[1,1,2,2,3]\n0\n0\n1"
] | [
"Notice that the constraints are small enough for a brute force solution to pass.",
"Loop through all triplets, and count the ones that are good."
] | {
"canonical_parameter_names": [
"arr",
"a",
"b",
"c"
],
"leetcode_dataset_entry_point": "Solution().countGoodTriplets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:22:57",
... | cpp | {
"raw_signature": "int countGoodTriplets(vector<int>& arr, int a, int b, int c) {",
"container": "Solution",
"callable": "countGoodTriplets",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "a",
"type": "int"
},
{
"name": "b",
"type":... |
1,535 | find-the-winner-of-an-array-game | Medium | Given an integer array arr of distinct integers and an integer k.
A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of the game, we compare arr[0] with arr[1], the larger integer wins and remains at position 0, and the smaller integer moves to the end of the arra... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [2, 1, 3, 5, 4, 6, 7],k = 2) == 5\n assert candidate(arr = [7, 10, 5, 3, 8],k = 3) == 10\n assert candidate(arr = [5, 4, 3, 2, 1],k = 1) == 5\n assert candidate(arr = [3, 2, 1],k = 10) == 3\n assert candidate(arr = [100... | [
"[2,1,3,5,4,6,7]\n2",
"[3,2,1]\n10"
] | [
"If k ≥ arr.length return the max element of the array.",
"If k < arr.length simulate the game until a number wins k consecutive games."
] | {
"canonical_parameter_names": [
"arr",
"k"
],
"leetcode_dataset_entry_point": "Solution().getWinner",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:00",
"tests_total": 105,
"tes... | cpp | {
"raw_signature": "int getWinner(vector<int>& arr, int k) {",
"container": "Solution",
"callable": "getWinner",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnip... |
1,536 | minimum-swaps-to-arrange-a-binary-grid | Medium | Given an n x n binary grid, in one step you can choose two adjacent rows of the grid and swap them.
A grid is said to be valid if all the cells above the main diagonal are zeros.
Return the minimum number of steps needed to make the grid valid, or -1 if the grid cannot be valid.
The main diagonal of a grid is the di... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 0, 1], [1, 1, 0], [1, 0, 0]]) == 3\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == -1\n assert candidate(grid = [[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1]]) == -1\n assert candidate(grid ... | [
"[[0,0,1],[1,1,0],[1,0,0]]",
"[[0,1,1,0],[0,1,1,0],[0,1,1,0],[0,1,1,0]]",
"[[1,0,0],[1,1,0],[1,1,1]]"
] | [
"For each row of the grid calculate the most right 1 in the grid in the array maxRight.",
"To check if there exist answer, sort maxRight and check if maxRight[i] ≤ i for all possible i's.",
"If there exist an answer, simulate the swaps."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().minSwaps",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:02",
"tests_total": 71,
"tests_dropped... | cpp | {
"raw_signature": "int minSwaps(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "minSwaps",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,537 | get-the-maximum-score | Hard | You are given two sorted arrays of distinct integers nums1 and nums2.
A valid path is defined as follows:
- Choose array nums1 or nums2 to traverse (from index-0).
- Traverse the current array from left to right.
- If you are reading any value that is present in nums1 and nums2 you are allowed to change your path to ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [10000000],nums2 = [10000000]) == 10000000\n assert candidate(nums1 = [2, 4, 5, 8, 10],nums2 = [4, 6, 8, 9]) == 30\n assert candidate(nums1 = [1, 2, 3],nums2 = [4, 5, 6, 7, 8, 9, 10]) == 49\n assert candidate(nums1 = [1,... | [
"[2,4,5,8,10]\n[4,6,8,9]",
"[1,3,5,7,9]\n[3,5,100]",
"[1,2,3,4,5]\n[6,7,8,9,10]"
] | [
"Partition the array by common integers, and choose the path with larger sum with a DP technique."
] | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().maxSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:05",
"tests_total": 110,
"... | cpp | {
"raw_signature": "int maxSum(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "maxSum",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_sou... |
1,539 | kth-missing-positive-number | Easy | Given an array arr of positive integers sorted in a strictly increasing order, and an integer k.
Return the k^th positive integer that is missing from this array.
Example 1:
Input: arr = [2,3,4,7,11], k = 5
Output: 9
Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5^th missing positive i... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 20\n assert candidate(arr = [10, 20, 30],k = 15) == 16\n assert candidate(arr = [2, 3, 4, 7, 11],k = 5) == 9\n assert candidate(arr = [5, 6, 7, 8, 9],k = 1) == 1\n assert candi... | [
"[2,3,4,7,11]\n5",
"[1,2,3,4]\n2"
] | [
"Keep track of how many positive numbers are missing as you scan the array."
] | {
"canonical_parameter_names": [
"arr",
"k"
],
"leetcode_dataset_entry_point": "Solution().findKthPositive",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:07",
"tests_total": 109,
... | cpp | {
"raw_signature": "int findKthPositive(vector<int>& arr, int k) {",
"container": "Solution",
"callable": "findKthPositive",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetc... |
1,540 | can-convert-string-in-k-moves | Medium | Given two strings s and t, your goal is to convert s into t in k moves or less.
During the i^th (1 <= i <= k) move you can:
- Choose any index j (1-indexed) from s, such that 1 <= j <= s.length and j has not been chosen in any previous move, and shift the character at that index i times.
- Do nothing.
Shifting a cha... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abc\",t = \"abc\",k = 0) == True\n assert candidate(s = \"aaa\",t = \"zzz\",k = 702) == True\n assert candidate(s = \"abc\",t = \"bcd\",k = 10) == False\n assert candidate(s = \"abc\",t = \"xyz\",k = 702) == True\n asse... | [
"\"input\"\n\"ouput\"\n9",
"\"abc\"\n\"bcd\"\n10",
"\"aab\"\n\"bbb\"\n27"
] | [
"Observe that shifting a letter x times has the same effect of shifting the letter x + 26 times.",
"You need to check whether k is large enough to cover all shifts with the same remainder after modulo 26."
] | {
"canonical_parameter_names": [
"s",
"t",
"k"
],
"leetcode_dataset_entry_point": "Solution().canConvertString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:10",
"tests_total... | cpp | {
"raw_signature": "bool canConvertString(string s, string t, int k) {",
"container": "Solution",
"callable": "canConvertString",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "t",
"type": "string"
},
{
"name": "k",
"type": "int"
}
],
... |
1,541 | minimum-insertions-to-balance-a-parentheses-string | Medium | Given a parentheses string s containing only the characters '(' and ')'. A parentheses string is balanced if:
- Any left parenthesis '(' must have a corresponding two consecutive right parenthesis '))'.
- Left parenthesis '(' must go before the corresponding two consecutive right parenthesis '))'.
In other words, we ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"(()))\") == 1\n assert candidate(s = \"))())(\") == 3\n assert candidate(s = \"())\") == 0\n assert candidate(s = \"(()(())))))))))))()()\") == 6\n assert candidate(s = \"(()))(()))(()))(()))(())))()\") == 5\n assert... | [
"\"(()))\"",
"\"())\"",
"\"))())(\""
] | [
"Use a stack to keep opening brackets. If you face single closing ')' add 1 to the answer and consider it as '))'.",
"If you have '))' with empty stack, add 1 to the answer, If after finishing you have x opening remaining in the stack, add 2x to the answer."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().minInsertions",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:12",
"tests_total": 115,
"tests_drop... | cpp | {
"raw_signature": "int minInsertions(string s) {",
"container": "Solution",
"callable": "minInsertions",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,542 | find-longest-awesome-substring | Hard | You are given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it a palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1111\") == 4\n assert candidate(s = \"1000000001\") == 10\n assert candidate(s = \"9876543210\") == 1\n assert candidate(s = \"213123\") == 6\n assert candidate(s = \"9437493749\") == 9\n assert candidate(s = \"1221\... | [
"\"3242415\"",
"\"12345678\"",
"\"213123\""
] | [
"Given the character counts, under what conditions can a palindrome be formed ?",
"From left to right, use bitwise xor-operation to compute for any prefix the number of times modulo 2 of each digit. (mask ^= (1<<(s[i]-'0')).",
"Expected complexity is O(n*A) where A is the alphabet (10)."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().longestAwesome",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:14",
"tests_total": 133,
"tests_dro... | cpp | {
"raw_signature": "int longestAwesome(string s) {",
"container": "Solution",
"callable": "longestAwesome",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,544 | make-the-string-great | Easy | Given a string s of lower and upper case English letters.
A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:
- 0 <= i <= s.length - 2
- s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa.
To make the string good, you can choose two a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcdefg\") == \"abcdefg\"\n assert candidate(s = \"ABCDEFG\") == \"ABCDEFG\"\n assert candidate(s = \"vVtTkKsSiIdDgGhHjJfFcCrRlLpPoOeEaAqQzZxXcCvVbBnNmM\") == \"\"\n assert candidate(s = \"aAbBcCdDeEfFgG\") == \"\"\n as... | [
"\"leEeetcode\"",
"\"abBAcC\"",
"\"s\""
] | [
"The order you choose 2 characters to remove doesn't matter.",
"Keep applying the mentioned step to s till the length of the string is not changed."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().makeGood",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:16",
"tests_total": 107,
"tests_dropped":... | cpp | {
"raw_signature": "string makeGood(string s) {",
"container": "Solution",
"callable": "makeGood",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,545 | find-kth-bit-in-nth-binary-string | Medium | Given two positive integers n and k, the binary string S_n is formed as follows:
- S_1 = "0"
- S_i = S_{i - 1} + "1" + reverse(invert(S_{i - 1})) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0)... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,k = 31) == \"1\"\n assert candidate(n = 4,k = 11) == \"1\"\n assert candidate(n = 14,k = 511) == \"1\"\n assert candidate(n = 15,k = 545) == \"0\"\n assert candidate(n = 17,k = 65536) == \"1\"\n assert candidate(n = ... | [
"3\n1",
"4\n11"
] | [
"Since n is small, we can simply simulate the process of constructing S1 to Sn."
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().findKthBit",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:18",
"tests_total": 85,
"tests... | cpp | {
"raw_signature": "char findKthBit(int n, int k) {",
"container": "Solution",
"callable": "findKthBit",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "char",
"signature_source": "leetcode/codeSnippets",
"type_sou... |
1,546 | maximum-number-of-non-overlapping-subarrays-with-sum-equals-target | Medium | Given an array nums and an integer target, return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.
Example 1:
Input: nums = [1,1,1,1,1], target = 2
Output: 2
Explanation: There are 2 non-overlapping subarrays [1,1,1,1,1] with sum equals to targ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],target = 10) == 2\n assert candidate(nums = [1, 2, 3, 4, 5],target = 9) == 1\n assert candidate(nums = [-1, 3, 5, 1, 4, 2, -9],target = 6) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5],target = 15) == ... | [
"[1,1,1,1,1]\n2",
"[-1,3,5,1,4,2,-9]\n6"
] | [
"Keep track of prefix sums to quickly look up what subarray that sums \"target\" can be formed at each step of scanning the input array.",
"It can be proved that greedily forming valid subarrays as soon as one is found is optimal."
] | {
"canonical_parameter_names": [
"nums",
"target"
],
"leetcode_dataset_entry_point": "Solution().maxNonOverlapping",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:21",
"tests_total... | cpp | {
"raw_signature": "int maxNonOverlapping(vector<int>& nums, int target) {",
"container": "Solution",
"callable": "maxNonOverlapping",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "int",
"signature... |
1,547 | minimum-cost-to-cut-a-stick | Hard | Given a wooden stick of length n units. The stick is labelled from 0 to n. For example, a stick of length 6 is labelled as follows:
Given an integer array cuts where cuts[i] denotes a position you should perform a cut at.
You should perform the cuts in order, you can change the order of the cuts as you wish.
The cos... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 15,cuts = [3, 5, 10]) == 30\n assert candidate(n = 100,cuts = [50, 25, 75, 10, 90, 60, 30, 40, 80]) == 330\n assert candidate(n = 15,cuts = [1, 5, 9, 13]) == 35\n assert candidate(n = 7,cuts = [1, 3, 4, 5]) == 16\n assert... | [
"7\n[1,3,4,5]",
"9\n[5,6,1,4,2]"
] | [
"Build a dp array where dp[i][j] is the minimum cost to achieve all the cuts between i and j.",
"When you try to get the minimum cost between i and j, try all possible cuts k between them, dp[i][j] = min(dp[i][k] + dp[k][j]) + (j - i) for all possible cuts k between them."
] | {
"canonical_parameter_names": [
"n",
"cuts"
],
"leetcode_dataset_entry_point": "Solution().minCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:23",
"tests_total": 97,
"tests... | cpp | {
"raw_signature": "int minCost(int n, vector<int>& cuts) {",
"container": "Solution",
"callable": "minCost",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "cuts",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippe... |
1,550 | three-consecutive-odds | Easy | Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false.
Example 1:
Input: arr = [2,6,4,1]
Output: false
Explanation: There are no three consecutive odds.
Example 2:
Input: arr = [1,2,34,3,4,5,7,23,12]
Output: true
Explanation: [5,7,23] are three cons... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [1, 3, 2, 5, 7, 9]) == True\n assert candidate(arr = [2, 4, 6, 8, 10]) == False\n assert candidate(arr = [1, 1, 1, 1, 1, 1]) == True\n assert candidate(arr = [1000, 999, 998, 997]) == False\n assert candidate(arr = [2, ... | [
"[2,6,4,1]",
"[1,2,34,3,4,5,7,23,12]"
] | [
"Check every three consecutive numbers in the array for parity."
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().threeConsecutiveOdds",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:28",
"tests_total": 131,
"t... | cpp | {
"raw_signature": "bool threeConsecutiveOdds(vector<int>& arr) {",
"container": "Solution",
"callable": "threeConsecutiveOdds",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
1,551 | minimum-operations-to-make-array-equal | Medium | You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e., 0 <= i < n).
In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 to arr[y] (i.e., perform arr[x] -=1 and arr[y] += 1). The goal is to make all the elements of the arra... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 100) == 2500\n assert candidate(n = 10000) == 25000000\n assert candidate(n = 6) == 9\n assert candidate(n = 1) == 0\n assert candidate(n = 1000) == 250000\n assert candidate(n = 10) =... | [
"3",
"6"
] | [
"Build the array arr using the given formula, define target = sum(arr) / n",
"What is the number of operations needed to convert arr so that all elements equal target ?"
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:30",
"tests_total": 53,
"tests_dropp... | cpp | {
"raw_signature": "int minOperations(int n) {",
"container": "Solution",
"callable": "minOperations",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,552 | magnetic-force-between-two-balls | Medium | In the universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the i^th basket is at position[i], Morty has m balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(position = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 5) == 2\n assert candidate(position = [5, 4, 3, 2, 1, 1000000000],m = 2) == 999999999\n assert candidate(position = [1, 3, 5, 7, 9],m = 4) == 2\n assert candidate(position = [1, 3, ... | [
"[1,2,3,4,7]\n3",
"[5,4,3,2,1,1000000000]\n2"
] | [
"If you can place balls such that the answer is x then you can do it for y where y < x.",
"Similarly if you cannot place balls such that the answer is x then you can do it for y where y > x.",
"Binary search on the answer and greedily see if it is possible."
] | {
"canonical_parameter_names": [
"position",
"m"
],
"leetcode_dataset_entry_point": "Solution().maxDistance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:32",
"tests_total": 87,
... | cpp | {
"raw_signature": "int maxDistance(vector<int>& position, int m) {",
"container": "Solution",
"callable": "maxDistance",
"parameters": [
{
"name": "position",
"type": "vector<int>&"
},
{
"name": "m",
"type": "int"
}
],
"return_type": "int",
"signature_source": "lee... |
1,553 | minimum-number-of-days-to-eat-n-oranges | Hard | There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows:
- Eat one orange.
- If the number of remaining oranges n is divisible by 2 then you can eat n / 2 oranges.
- If the number of remaining oranges n is divisible by 3 then you can eat 2 * (n / 3) oranges.
You can only c... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 2000000000) == 32\n assert candidate(n = 100) == 8\n assert candidate(n = 1000) == 10\n assert candidate(n = 5) == 4\n assert candidate(n = 4) == 3\n assert candidate(n = 2) == 2\n ... | [
"10",
"6"
] | [
"In each step, choose between 2 options: minOranges = 1 + min( (n%2) + f(n/2), (n%3) + f(n/3) ) where f(n) is the minimum number of days to eat n oranges."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().minDays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:35",
"tests_total": 234,
"tests_dropped": ... | cpp | {
"raw_signature": "int minDays(int n) {",
"container": "Solution",
"callable": "minDays",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,556 | thousand-separator | Easy | Given an integer n, add a dot (".") as the thousands separator and return it in string format.
Example 1:
Input: n = 987
Output: "987"
Example 2:
Input: n = 1234
Output: "1.234"
Constraints:
- 0 <= n <= 2^31 - 1
| {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 0) == \"0\"\n assert candidate(n = 1234) == \"1.234\"\n assert candidate(n = 1000000) == \"1.000.000\"\n assert candidate(n = 2147483647) == \"2.147.483.647\"\n assert candidate(n = 123456789) == \"123.456.789\"\n asse... | [
"987",
"1234"
] | [
"Scan from the back of the integer and use dots to connect blocks with length 3 except the last block."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().thousandSeparator",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:39",
"tests_total": 50,
"tests_d... | cpp | {
"raw_signature": "string thousandSeparator(int n) {",
"container": "Solution",
"callable": "thousandSeparator",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,557 | minimum-number-of-vertices-to-reach-all-nodes | Medium | Given a directed acyclic graph, with n vertices numbered from 0 to n-1, and an array edges where edges[i] = [from_i, to_i] represents a directed edge from node from_i to node to_i.
Find the smallest set of vertices from which all nodes in the graph are reachable. It's guaranteed that a unique solution exists.
Notice ... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ... | [
"6\n[[0,1],[0,2],[2,5],[3,4],[4,2]]",
"5\n[[0,1],[2,1],[3,1],[1,4],[2,4]]"
] | [
"A node that does not have any incoming edge can only be reached by itself.",
"Any other node with incoming edges can be reached from some other node.",
"We only have to count the number of nodes with zero incoming edges."
] | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().findSmallestSetOfVertices",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:41",
"tests_t... | cpp | {
"raw_signature": "vector<int> findSmallestSetOfVertices(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "findSmallestSetOfVertices",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"r... |
1,558 | minimum-numbers-of-function-calls-to-make-target-array | Medium | You are given an integer array nums. You have an integer array arr of the same length with all values set to 0 initially. You also have the following modify function:
You want to use the modify function to convert arr to nums using the minimum number of calls.
Return the minimum number of function calls to make nums ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1000000000]) == 43\n assert candidate(nums = [10, 20, 30]) == 12\n assert candidate(nums = [10, 15, 20]) == 12\n assert candidate(nums = [1, 1, 1, 1]) == 4\n assert candidate(nums = [3, 3, 3, 3]) == 9\n assert c... | [
"[1,5]",
"[2,2]",
"[4,2,5]"
] | [
"Work backwards: try to go from nums to arr.",
"You should try to divide by 2 as much as possible, but you can only divide by 2 if everything is even."
] | {
"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:23:44",
"tests_total": 98,
"tests_dr... | 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,559 | detect-cycles-in-2d-grid | Medium | Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid.
A cycle is a path of length 4 or more in the grid that starts and ends at the same cell. From a given cell, you can move to one of the cells adjacent to it - in one of the four directions... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [['a', 'b', 'c'], ['b', 'c', 'a'], ['c', 'a', 'b']]) == False\n assert candidate(grid = [['a', 'a', 'a', 'a'], ['a', 'b', 'b', 'a'], ['a', 'b', 'b', 'a'], ['a', 'a', 'a', 'a']]) == True\n assert candidate(grid = [['a', 'b'],... | [
"[[\"a\",\"a\",\"a\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"a\",\"a\",\"a\"]]",
"[[\"c\",\"c\",\"c\",\"a\"],[\"c\",\"d\",\"c\",\"c\"],[\"c\",\"c\",\"e\",\"c\"],[\"f\",\"c\",\"c\",\"c\"]]",
"[[\"a\",\"b\",\"b\"],[\"b\",\"z\",\"b\"],[\"b\",\"b\",\"a\"]]"
] | [
"Keep track of the parent (previous position) to avoid considering an invalid path.",
"Use DFS or BFS and keep track of visited cells to see if there is a cycle."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().containsCycle",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:46",
"tests_total": 74,
"tests_dr... | cpp | {
"raw_signature": "bool containsCycle(vector<vector<char>>& grid) {",
"container": "Solution",
"callable": "containsCycle",
"parameters": [
{
"name": "grid",
"type": "vector<vector<char>>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leet... |
1,560 | most-visited-sector-in-a-circular-track | Easy | Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The i^th round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, round 1 starts at sector rounds[0] ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,rounds = [1, 3, 1, 2]) == [1, 2]\n assert candidate(n = 7,rounds = [1, 3, 5, 7]) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(n = 6,rounds = [3, 6, 2, 4, 1]) == [1, 3, 4, 5, 6]\n assert candidate(n = 6,rounds = [3, 6, 2, 5]... | [
"4\n[1,3,1,2]",
"2\n[2,1,2,1,2,1,2,1,2]",
"7\n[1,3,5,7]"
] | [
"For each round increment the visits of the sectors visited during the marathon with 1.",
"Determine the max number of visits, and return any sector visited the max number of visits."
] | {
"canonical_parameter_names": [
"n",
"rounds"
],
"leetcode_dataset_entry_point": "Solution().mostVisited",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:48",
"tests_total": 98,
... | cpp | {
"raw_signature": "vector<int> mostVisited(int n, vector<int>& rounds) {",
"container": "Solution",
"callable": "mostVisited",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "rounds",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_s... |
1,561 | maximum-number-of-coins-you-can-get | Medium | There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:
- In each step, you will choose any 3 piles of coins (not necessarily consecutive).
- Of your choice, Alice will pick the pile with the maximum number of coins.
- You will pick the next pile with the maximum number o... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(piles = [1, 12, 2, 11, 3, 10, 4, 9, 5, 8, 6, 7]) == 32\n assert candidate(piles = [2, 4, 1, 2, 7, 8]) == 9\n assert candidate(piles = [9, 8, 7, 6, 5, 1, 2, 3, 4]) == 18\n assert candidate(piles = [10000, 10000, 10000, 1, 1, 1, 2... | [
"[2,4,1,2,7,8]",
"[2,4,5]",
"[9,8,7,6,5,1,2,3,4]"
] | [
"Which pile of coins will you never be able to pick up?",
"Bob is forced to take the last pile of coins, no matter what it is. Which pile should you give to him?"
] | {
"canonical_parameter_names": [
"piles"
],
"leetcode_dataset_entry_point": "Solution().maxCoins",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:50",
"tests_total": 99,
"tests_droppe... | cpp | {
"raw_signature": "int maxCoins(vector<int>& piles) {",
"container": "Solution",
"callable": "maxCoins",
"parameters": [
{
"name": "piles",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,562 | find-latest-group-of-size-m | Medium | Given an array arr that represents a permutation of numbers from 1 to n.
You have a binary string of size n that initially has all its bits set to zero. At each step i (assuming both the binary string and arr are 1-indexed) from 1 to n, the bit at position arr[i] is set to 1.
You are also given an integer m. Find the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5],m = 3) == 3\n assert candidate(arr = [1, 3, 5, 2, 4],m = 1) == 4\n assert candidate(arr = [2, 1, 3, 5, 4],m = 1) == 4\n assert candidate(arr = [3, 5, 1, 2, 4],m = 1) == 4\n assert candidate(arr = [5, 4, ... | [
"[3,5,1,2,4]\n1",
"[3,1,5,4,2]\n2"
] | [
"Since the problem asks for the latest step, can you start the searching from the end of arr?",
"Use a map to store the current “1” groups.",
"At each step (going backwards) you need to split one group and update the map."
] | {
"canonical_parameter_names": [
"arr",
"m"
],
"leetcode_dataset_entry_point": "Solution().findLatestStep",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:53",
"tests_total": 106,
... | cpp | {
"raw_signature": "int findLatestStep(vector<int>& arr, int m) {",
"container": "Solution",
"callable": "findLatestStep",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "m",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcod... |
1,563 | stone-game-v | Hard | There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.
In each round of the game, Alice divides the row into two non-empty rows (i.e. left row and right row), then Bob calculates the value of each row which is the sum of the values of all t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(stoneValue = [1, 2, 3, 4, 5]) == 10\n assert candidate(stoneValue = [5, 3, 1, 4, 2]) == 9\n assert candidate(stoneValue = [1, 3, 5, 7, 9, 11, 13]) == 35\n assert candidate(stoneValue = [3, 6, 2, 8, 7, 4, 5]) == 23\n assert ca... | [
"[6,2,3,4,5,5]",
"[7,7,7,7,7,7,7]",
"[4]"
] | [
"We need to try all possible divisions for the current row to get the max score.",
"As calculating all possible divisions will lead us to calculate some sub-problems more than once, we need to think of dynamic programming."
] | {
"canonical_parameter_names": [
"stoneValue"
],
"leetcode_dataset_entry_point": "Solution().stoneGameV",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:23:55",
"tests_total": 93,
"tests... | cpp | {
"raw_signature": "int stoneGameV(vector<int>& stoneValue) {",
"container": "Solution",
"callable": "stoneGameV",
"parameters": [
{
"name": "stoneValue",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,566 | detect-pattern-of-length-m-repeated-k-or-more-times | Easy | Given an array of positive integers arr, find a pattern of length m that is repeated k or more times.
A pattern is a subarray (consecutive sub-sequence) that consists of one or more values, repeated multiple times consecutively without overlapping. A pattern is defined by its length and the number of repetitions.
Ret... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [1, 2, 4, 4, 4, 4],m = 1,k = 3) == True\n assert candidate(arr = [2, 2, 2, 2, 2, 2],m = 2,k = 2) == True\n assert candidate(arr = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3],m = 2,k = 5) == True\n assert candidate(arr = [2, 2, 2, 2, 2,... | [
"[1,2,4,4,4,4]\n1\n3",
"[1,2,1,2,1,1,1,3]\n2\n2",
"[1,2,1,2,1,3]\n2\n3"
] | [
"Use a three-layer loop to check all possible patterns by iterating through all possible starting positions, all indexes less than m, and if the character at the index is repeated k times."
] | {
"canonical_parameter_names": [
"arr",
"m",
"k"
],
"leetcode_dataset_entry_point": "Solution().containsPattern",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:00",
"tests_tota... | cpp | {
"raw_signature": "bool containsPattern(vector<int>& arr, int m, int k) {",
"container": "Solution",
"callable": "containsPattern",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "m",
"type": "int"
},
{
"name": "k",
"type": "int"
... |
1,567 | maximum-length-of-subarray-with-positive-product | Medium | Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive.
A subarray of an array is a consecutive sequence of zero or more values taken out of that array.
Return the maximum length of a subarray with positive product.
Example 1:
Input: nums = [1,-2,-3,... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [-1, 2, -3, 4, -5]) == 4\n assert candidate(nums = [-1, -2, -3, 0, 1]) == 2\n assert candidate(nums = [-1]) == 0\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 2, 3, 0, -1, -2, -3]) == 3\n assert ... | [
"[1,-2,-3,4]",
"[0,1,-2,-3,-4]",
"[-1,-2,-3,0,1]"
] | [
"Split the whole array into subarrays by zeroes since a subarray with positive product cannot contain any zero.",
"If the subarray has even number of negative numbers, the whole subarray has positive product.",
"Otherwise, we have two choices, either - remove the prefix till the first negative element in this s... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().getMaxLen",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:02",
"tests_total": 122,
"tests_dropp... | cpp | {
"raw_signature": "int getMaxLen(vector<int>& nums) {",
"container": "Solution",
"callable": "getMaxLen",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,568 | minimum-number-of-days-to-disconnect-island | Hard | You are given an m x n binary grid grid where 1 represents land and 0 represents water. An island is a maximal 4-directionally (horizontal or vertical) connected group of 1's.
The grid is said to be connected if we have exactly one island, otherwise is said disconnected.
In one day, we are allowed to change any singl... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 2\n assert candidate(grid = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == 0\n assert candidate(grid = [[1, 1]]) == 2\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0... | [
"[[0,1,1,0],[0,1,1,0],[0,0,0,0]]",
"[[1,1]]"
] | [
"Return 0 if the grid is already disconnected.",
"Return 1 if changing a single land to water disconnect the island.",
"Otherwise return 2.",
"We can disconnect the grid within at most 2 days."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().minDays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:04",
"tests_total": 73,
"tests_dropped"... | cpp | {
"raw_signature": "int minDays(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "minDays",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
1,569 | number-of-ways-to-reorder-array-to-get-same-bst | Hard | Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number of different ways to reorder nums so that the constructed BST is identical to that formed from the origi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 2]) == 0\n assert candidate(nums = [9, 4, 10, 2, 5, 8, 11, 1, 3, 6, 7]) == 3149\n assert candidate(nums = [6, 2, 9, 1, 3, 8, 10, 4, 5, 7]) == 1511\n assert candidate(nums = [1, 2, 3]) == 0\n assert candidate(num... | [
"[2,1,3]",
"[3,4,5,1,2]",
"[1,2,3]"
] | [
"Use a divide and conquer strategy.",
"The first number will always be the root. Consider the numbers smaller and larger than the root separately. When merging the results together, how many ways can you order x elements in x+y positions?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().numOfWays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:07",
"tests_total": 74,
"tests_droppe... | cpp | {
"raw_signature": "int numOfWays(vector<int>& nums) {",
"container": "Solution",
"callable": "numOfWays",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,572 | matrix-diagonal-sum | Easy | Given a square matrix mat, return the sum of the matrix diagonals.
Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal.
Example 1:
Input: mat = [[1,2,3],
[4,5,6],
[7,8,9]]
Output: 25
Expl... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mat = [[7, 3, 1, 9], [3, 4, 6, 9], [6, 9, 6, 6], [9, 5, 8, 5]]) == 55\n assert candidate(mat = [[5]]) == 5\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 25\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [... | [
"[[1,2,3],[4,5,6],[7,8,9]]",
"[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]]",
"[[5]]"
] | [
"There will be overlap of elements in the primary and secondary diagonals if and only if the length of the matrix is odd, which is at the center."
] | {
"canonical_parameter_names": [
"mat"
],
"leetcode_dataset_entry_point": "Solution().diagonalSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:09",
"tests_total": 54,
"tests_dropp... | cpp | {
"raw_signature": "int diagonalSum(vector<vector<int>>& mat) {",
"container": "Solution",
"callable": "diagonalSum",
"parameters": [
{
"name": "mat",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeS... |
1,573 | number-of-ways-to-split-a-string | Medium | Given a binary string s, you can split s into 3 non-empty strings s1, s2, and s3 where s1 + s2 + s3 = s.
Return the number of ways s can be split such that the number of ones is the same in s1, s2, and s3. Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:
Input: s = "10101"
Output: 4
Explanati... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"101010101\") == 0\n assert candidate(s = \"10101010101\") == 4\n assert candidate(s = \"0000\") == 3\n assert candidate(s = \"0000000\") == 15\n assert candidate(s = \"010101010\") == 0\n assert candidate(s = \"11100... | [
"\"10101\"",
"\"1001\"",
"\"0000\""
] | [
"There is no way if the sum (number of '1's) is not divisible by the number of splits. So sum%3 should be 0.",
"Preffix s1 , and suffix s3 should have sum/3 characters '1'.",
"Follow up: Can you generalize the problem with numbers between [-10^9, 10^9] such the sum between subarrays s1, s2, s3 are the same?"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().numWays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:11",
"tests_total": 84,
"tests_dropped": 0... | cpp | {
"raw_signature": "int numWays(string s) {",
"container": "Solution",
"callable": "numWays",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,574 | shortest-subarray-to-be-removed-to-make-array-sorted | Medium | Given an integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing.
Return the length of the shortest subarray to remove.
A subarray is a contiguous subsequence of the array.
Example 1:
Input: arr = [1,2,3,10,4,2,3,5]
Output: 3
Explanation: The shortest ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [5, 4, 3, 2, 1]) == 4\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1]) == 9\n assert candidate(arr = [1, 2, 3]) == 0\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 10\n assert candidate(arr ... | [
"[11,10,18,14,12,11,16,20,13,11]",
"[17,32,32,29,4,29,19,5,26,35,35,6,10,27,11,35,0,31]",
"[1,8,34,2,3,22,18,27,3,1,0,12,21,23,8,7,17]"
] | [
"The key is to find the longest non-decreasing subarray starting with the first element or ending with the last element, respectively.",
"After removing some subarray, the result is the concatenation of a sorted prefix and a sorted suffix, where the last element of the prefix is smaller than the first element of ... | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().findLengthOfShortestSubarray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:14",
"tests_total": 1... | cpp | {
"raw_signature": "int findLengthOfShortestSubarray(vector<int>& arr) {",
"container": "Solution",
"callable": "findLengthOfShortestSubarray",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source... |
1,575 | count-all-possible-routes | Hard | You are given an array of distinct positive integers locations where locations[i] represents the position of city i. You are also given integers start, finish and fuel representing the starting city, ending city, and the initial amount of fuel you have, respectively.
At each step, if you are at city i, you can pick an... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(locations = [4, 3, 1],start = 1,finish = 0,fuel = 6) == 5\n assert candidate(locations = [1, 2, 3, 4, 5],start = 0,finish = 4,fuel = 10) == 1208\n assert candidate(locations = [5, 2, 1],start = 0,finish = 2,fuel = 3) == 0\n asse... | [
"[2,3,6,8,4]\n1\n3\n5",
"[4,3,1]\n1\n0\n6",
"[5,2,1]\n0\n2\n3"
] | [
"Use dynamic programming to solve this problem with each state defined by the city index and fuel left.",
"Since the array contains distinct integers fuel will always be spent in each move and so there can be no cycles."
] | {
"canonical_parameter_names": [
"locations",
"start",
"finish",
"fuel"
],
"leetcode_dataset_entry_point": "Solution().countRoutes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T2... | cpp | {
"raw_signature": "int countRoutes(vector<int>& locations, int start, int finish, int fuel) {",
"container": "Solution",
"callable": "countRoutes",
"parameters": [
{
"name": "locations",
"type": "vector<int>&"
},
{
"name": "start",
"type": "int"
},
{
"name": "f... |
1,576 | replace-all-s-to-avoid-consecutive-repeating-characters | Easy | Given a string s containing only lowercase English letters and the '?' character, convert all the '?' characters into lowercase letters such that the final string does not contain any consecutive repeating characters. You cannot modify the non '?' characters.
It is guaranteed that there are no consecutive repeating ch... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"?zs\") == \"azs\"\n assert candidate(s = \"b?a\") == \"bca\"\n assert candidate(s = \"a?b?\") == \"acba\"\n assert candidate(s = \"zz?z?zz\") == \"zzazazz\"\n assert candidate(s = \"z?z\") == \"zaz\"\n assert candida... | [
"\"?zs\"",
"\"ubv?w\""
] | [
"Processing string from left to right, whenever you get a ‘?’, check left character and right character, and select a character not equal to either of them",
"Do take care to compare with replaced occurrence of ‘?’ when checking the left character."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().modifyString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:18",
"tests_total": 122,
"tests_dropp... | cpp | {
"raw_signature": "string modifyString(string s) {",
"container": "Solution",
"callable": "modifyString",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,577 | number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers | Medium | Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
- Type 1: Triplet (i, j, k) if nums1[i]^2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
- Type 2: Triplet (i, j, k) if nums2[i]^2 == nums1[j] * nums1[k] ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [3, 5, 7],nums2 = [9, 25, 49]) == 0\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [25, 25, 25, 25]) == 0\n assert candidate(nums1 = [10, 5, 2],nums2 = [100, 25, 4]) == 1\n assert candidate(nums1 = [2, 3, 5],nums2 = [2,... | [
"[7,4]\n[5,2,8,9]",
"[1,1]\n[1,1,1]",
"[7,7,8,3]\n[1,2,9,7]"
] | [
"Precalculate the frequencies of all nums1[i]^2 and nums2[i]^2"
] | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().numTriplets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:20",
"tests_total": 121... | cpp | {
"raw_signature": "int numTriplets(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "numTriplets",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type": "int",
"sig... |
1,578 | minimum-time-to-make-rope-colorful | Medium | Alice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the i^th balloon.
Alice wants the rope to be colorful. She does not want two consecutive balloons to be of the same color, so she asks Bob for help. Bob can remove some balloons from the rope to make it col... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(colors = \"abcabc\",neededTime = [1, 2, 3, 1, 2, 3]) == 0\n assert candidate(colors = \"aaaaa\",neededTime = [5, 4, 3, 2, 1]) == 10\n assert candidate(colors = \"abacabadabacaba\",neededTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12... | [
"\"abaac\"\n[1,2,3,4,5]",
"\"abc\"\n[1,2,3]",
"\"aabaa\"\n[1,2,3,4,1]"
] | [
"Maintain the running sum and max value for repeated letters."
] | {
"canonical_parameter_names": [
"colors",
"neededTime"
],
"leetcode_dataset_entry_point": "Solution().minCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:23",
"tests_total": 9... | cpp | {
"raw_signature": "int minCost(string colors, vector<int>& neededTime) {",
"container": "Solution",
"callable": "minCost",
"parameters": [
{
"name": "colors",
"type": "string"
},
{
"name": "neededTime",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_s... |
1,579 | remove-max-number-of-edges-to-keep-graph-fully-traversable | Hard | Alice and Bob have an undirected graph of n nodes and three types of edges:
- Type 1: Can be traversed by Alice only.
- Type 2: Can be traversed by Bob only.
- Type 3: Can be traversed by both Alice and Bob.
Given an array edges where edges[i] = [type_i, u_i, v_i] represents a bidirectional edge of type type_i betwee... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,edges = [[1, 1, 2], [2, 2, 3], [3, 3, 4], [3, 4, 5], [1, 2, 3], [2, 3, 4]]) == -1\n assert candidate(n = 4,edges = [[3, 1, 2], [3, 2, 3], [1, 1, 3], [1, 2, 4], [1, 1, 2], [2, 3, 4]]) == 2\n assert candidate(n = 4,edges = [[3,... | [
"4\n[[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]",
"4\n[[3,1,2],[3,2,3],[1,1,4],[2,1,4]]",
"4\n[[3,2,3],[1,1,2],[2,3,4]]"
] | [
"Build the network instead of removing extra edges.",
"Suppose you have the final graph (after removing extra edges). Consider the subgraph with only the edges that Alice can traverse. What structure does this subgraph have? How many edges are there?",
"Use disjoint set union data structure for both Alice and B... | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().maxNumEdgesToRemove",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:25",
"tests_total":... | cpp | {
"raw_signature": "int maxNumEdgesToRemove(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "maxNumEdgesToRemove",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
... |
1,582 | special-positions-in-a-binary-matrix | Easy | Given an m x n binary matrix mat, return the number of special positions in mat.
A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed).
Example 1:
Input: mat = [[1,0,0],[0,0,1],[1,0,0]]
Output: 1
Explanation: (1, 2) is a special posi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mat = [[1, 0], [0, 1]]) == 2\n assert candidate(mat = [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 0]]) == 2\n assert candidate(mat = [[1, 0, 0], [0, 0, 1], [1, 0, 0]]) == 1\n assert candidate(mat = [[0, 0, 0, 0], [0, 1,... | [
"[[1,0,0],[0,0,1],[1,0,0]]",
"[[1,0,0],[0,1,0],[0,0,1]]"
] | [
"Keep track of 1s in each row and in each column. Then while iterating over matrix, if the current position is 1 and current row as well as current column contains exactly one occurrence of 1."
] | {
"canonical_parameter_names": [
"mat"
],
"leetcode_dataset_entry_point": "Solution().numSpecial",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:30",
"tests_total": 70,
"tests_droppe... | cpp | {
"raw_signature": "int numSpecial(vector<vector<int>>& mat) {",
"container": "Solution",
"callable": "numSpecial",
"parameters": [
{
"name": "mat",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
1,584 | min-cost-to-connect-all-points | Medium | You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [x_i, y_i].
The cost of connecting two points [x_i, y_i] and [x_j, y_j] is the manhattan distance between them: |x_i - x_j| + |y_i - y_j|, where |val| denotes the absolute value of val.
Return the minimum co... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(points = [[0, 0], [2, 2], [4, 4], [6, 6], [8, 8]]) == 16\n assert candidate(points = [[1, 1], [0, 0], [2, 2], [3, 3], [4, 4]]) == 8\n assert candidate(points = [[-1000000, 1000000], [1000000, -1000000], [0, 0]]) == 4000000\n ass... | [
"[[0,0],[2,2],[3,10],[5,2],[7,0]]",
"[[3,12],[-2,5],[-4,1]]"
] | [
"Connect each pair of points with a weighted edge, the weight being the manhattan distance between those points.",
"The problem is now the cost of minimum spanning tree in graph with above edges."
] | {
"canonical_parameter_names": [
"points"
],
"leetcode_dataset_entry_point": "Solution().minCostConnectPoints",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:34",
"tests_total": 104,
... | cpp | {
"raw_signature": "int minCostConnectPoints(vector<vector<int>>& points) {",
"container": "Solution",
"callable": "minCostConnectPoints",
"parameters": [
{
"name": "points",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_... |
1,585 | check-if-string-is-transformable-with-substring-sort-operations | Hard | Given two strings s and t, transform string s into string t using the following operation any number of times:
- Choose a non-empty substring in s and sort it in place so the characters are in ascending order.
- For example, applying the operation on the underlined substring in "14234" results in "12344".
Return tr... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"9876543210\",t = \"0123456789\") == True\n assert candidate(s = \"1221\",t = \"1122\") == True\n assert candidate(s = \"987654321\",t = \"123456789\") == True\n assert candidate(s = \"123\",t = \"321\") == False\n asser... | [
"\"84532\"\n\"34852\"",
"\"34521\"\n\"23415\"",
"\"12345\"\n\"12435\""
] | [
"Suppose the first digit you need is 'd'. How can you determine if it's possible to get that digit there?",
"Consider swapping adjacent characters to maintain relative ordering."
] | {
"canonical_parameter_names": [
"s",
"t"
],
"leetcode_dataset_entry_point": "Solution().isTransformable",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:37",
"tests_total": 147,
... | cpp | {
"raw_signature": "bool isTransformable(string s, string t) {",
"container": "Solution",
"callable": "isTransformable",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "t",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/code... |
1,588 | sum-of-all-odd-length-subarrays | Easy | Given an array of positive integers arr, return the sum of all possible odd-length subarrays of arr.
A subarray is a contiguous subsequence of the array.
Example 1:
Input: arr = [1,4,2,5,3]
Output: 58
Explanation: The odd-length subarrays of arr and their sums are:
[1] = 1
[4] = 4
[2] = 2
[5] = 5
[3] = 3
[1,4,2] = 7... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == 8760\n assert candidate(arr = [2, 4, 6, 8, 10]) == 114\n assert candidate(arr = [1, 2]) == 3\n assert candidate(arr = [5]) == 5\n assert candidate(arr = [3, 1, 4, 1, 5,... | [
"[1,4,2,5,3]",
"[1,2]",
"[10,11,12]"
] | [
"You can brute force – try every (i,j) pair, and if the length is odd, go through and add the sum to the answer."
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().sumOddLengthSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:39",
"tests_total": 104,
"... | cpp | {
"raw_signature": "int sumOddLengthSubarrays(vector<int>& arr) {",
"container": "Solution",
"callable": "sumOddLengthSubarrays",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
1,589 | maximum-sum-obtained-of-any-permutation | Medium | We have an array of integers, nums, and an array of requests where requests[i] = [start_i, end_i]. The i^th request asks for the sum of nums[start_i] + nums[start_i + 1] + ... + nums[end_i - 1] + nums[end_i]. Both start_i and end_i are 0-indexed.
Return the maximum total sum of all requests among all permutations of n... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 10],requests = [[0, 2], [1, 3], [1, 1]]) == 47\n assert candidate(nums = [10, 20, 30, 40, 50],requests = [[0, 0], [1, 2], [2, 3], [3, 4]]) == 240\n assert candidate(nums = [0, 0, 0, 0, 0],requests = [[0, 0], ... | [
"[1,2,3,4,5]\n[[1,3],[0,1]]",
"[1,2,3,4,5,6]\n[[0,1]]",
"[1,2,3,4,5,10]\n[[0,2],[1,3],[1,1]]"
] | [
"Indexes with higher frequencies should be bound with larger values"
] | {
"canonical_parameter_names": [
"nums",
"requests"
],
"leetcode_dataset_entry_point": "Solution().maxSumRangeQuery",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:41",
"tests_tota... | cpp | {
"raw_signature": "int maxSumRangeQuery(vector<int>& nums, vector<vector<int>>& requests) {",
"container": "Solution",
"callable": "maxSumRangeQuery",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "requests",
"type": "vector<vector<int>>&"
}
],
... |
1,590 | make-sum-divisible-by-p | Medium | Given an array of positive integers nums, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by p. It is not allowed to remove the whole array.
Return the length of the smallest subarray that you need to remove, or -1 if it's impossible.
A subarray is defined as a c... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5, 5],p = 3) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],p = 2) == 1\n assert candidate(nums = [7, 8, 9, 10, 11],p = 11) == 4\n assert candidate(nums = [1, 2, 3, 4, 5],p = 10) == 1\n assert candidate(nu... | [
"[3,1,4,2]\n6",
"[6,3,5,2]\n9",
"[1,2,3]\n3"
] | [
"Use prefix sums to calculate the subarray sums.",
"Suppose you know the remainder for the sum of the entire array. How does removing a subarray affect that remainder? What remainder does the subarray need to have in order to make the rest of the array sum up to be divisible by k?",
"Use a map to keep track of ... | {
"canonical_parameter_names": [
"nums",
"p"
],
"leetcode_dataset_entry_point": "Solution().minSubarray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:44",
"tests_total": 76,
"t... | cpp | {
"raw_signature": "int minSubarray(vector<int>& nums, int p) {",
"container": "Solution",
"callable": "minSubarray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "p",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/co... |
1,591 | strange-printer-ii | Hard | There is a strange printer with the following two special requirements:
- On each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up the existing colors in the rectangle.
- Once the printer has used a color for the above operation, the same color cannot be used a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(targetGrid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == True\n assert candidate(targetGrid = [[1, 1, 1, 1], [1, 2, 2, 1], [1, 2, 2, 1], [1, 1, 1, 1]]) == True\n assert candidate(targetGrid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == True\n ... | [
"[[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]]",
"[[1,1,1,1],[1,1,3,3],[1,1,3,4],[5,5,1,4]]",
"[[1,2,1],[2,1,2],[1,2,1]]"
] | [
"Try thinking in reverse. Given the grid, how can you tell if a colour was painted last?"
] | {
"canonical_parameter_names": [
"targetGrid"
],
"leetcode_dataset_entry_point": "Solution().isPrintable",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:46",
"tests_total": 65,
"test... | cpp | {
"raw_signature": "bool isPrintable(vector<vector<int>>& targetGrid) {",
"container": "Solution",
"callable": "isPrintable",
"parameters": [
{
"name": "targetGrid",
"type": "vector<vector<int>>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source":... |
1,592 | rearrange-spaces-between-words | Easy | You are given a string text of words that are placed among some number of spaces. Each word consists of one or more lowercase English letters and are separated by at least one space. It's guaranteed that text contains at least one word.
Rearrange the spaces so that there is an equal number of spaces between every pair... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(text = \" leading and trailing spaces \") == \"leading and trailing spaces \"\n assert candidate(text = \"one\") == \"one\"\n assert candidate(text = \" a \") == \"a \"\n assert candidate(text = \"hello world\") == \... | [
"\" this is a sentence \"",
"\" practice makes perfect\""
] | [
"Count the total number of spaces and words. Then use the integer division to determine the numbers of spaces to add between each word and at the end."
] | {
"canonical_parameter_names": [
"text"
],
"leetcode_dataset_entry_point": "Solution().reorderSpaces",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:48",
"tests_total": 135,
"tests_d... | cpp | {
"raw_signature": "string reorderSpaces(string text) {",
"container": "Solution",
"callable": "reorderSpaces",
"parameters": [
{
"name": "text",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,593 | split-a-string-into-the-max-number-of-unique-substrings | Medium | Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substr... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aaaabbbb\") == 5\n assert candidate(s = \"abac\") == 3\n assert candidate(s = \"abcdef\") == 6\n assert candidate(s = \"aaaaaaaab\") == 4\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"zzzzzzz\") == 3\n ... | [
"\"ababccc\"",
"\"aba\"",
"\"aa\""
] | [
"Use a set to keep track of which substrings have been used already",
"Try each possible substring at every position and backtrack if a complete split is not possible"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().maxUniqueSplit",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:51",
"tests_total": 102,
"tests_dro... | cpp | {
"raw_signature": "int maxUniqueSplit(string s) {",
"container": "Solution",
"callable": "maxUniqueSplit",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,594 | maximum-non-negative-product-in-a-matrix | Medium | You are given a m x n matrix grid. Initially, you are located at the top-left corner (0, 0), and in each step, you can only move right or down in the matrix.
Among all possible paths starting from the top-left corner (0, 0) and ending in the bottom-right corner (m - 1, n - 1), find the path with the maximum non-negati... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[-1, -2, -3], [-2, -3, -3], [-3, -3, -2]]) == -1\n assert candidate(grid = [[-1, 0], [-2, -1]]) == 0\n assert candidate(grid = [[-4, 3], [-3, -4]]) == 48\n assert candidate(grid = [[0, 0], [0, 0]]) == 0\n assert candi... | [
"[[-1,-2,-3],[-2,-3,-3],[-3,-3,-2]]",
"[[1,-2,1],[1,-2,1],[3,-4,1]]",
"[[1,3],[0,-4]]"
] | [
"Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().maxProductPath",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:53",
"tests_total": 111,
"tests_... | cpp | {
"raw_signature": "int maxProductPath(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "maxProductPath",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
1,598 | crawler-log-folder | Easy | The Leetcode file system keeps a log each time some user performs a change folder operation.
The operations are described below:
- "../" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder).
- "./" : Remain in the same folder.
- "x/" : Move to the child... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(logs = ['d1/', '../', '../', '../']) == 0\n assert candidate(logs = ['d1/', 'd2/', '../', 'd21/', './']) == 2\n assert candidate(logs = ['d1/', '../', 'd2/', '../', 'd3/', '../', 'd4/', '../', 'd5/', '../']) == 0\n assert candid... | [
"[\"d1/\",\"d2/\",\"../\",\"d21/\",\"./\"]",
"[\"d1/\",\"d2/\",\"./\",\"d3/\",\"../\",\"d31/\"]",
"[\"d1/\",\"../\",\"../\",\"../\"]"
] | [
"Simulate the process but don’t move the pointer beyond the main folder."
] | {
"canonical_parameter_names": [
"logs"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:24:57",
"tests_total": 87,
"tests_dr... | cpp | {
"raw_signature": "int minOperations(vector<string>& logs) {",
"container": "Solution",
"callable": "minOperations",
"parameters": [
{
"name": "logs",
"type": "vector<string>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
1,599 | maximum-profit-of-operating-a-centennial-wheel | Medium | You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas counterclockwise, which costs you runningCost dollars.
You are given an array customers of length n where customers[i] is the number of new customers arriving ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(customers = [50, 50, 50, 50, 50],boardingCost = 100,runningCost = 1) == 63\n assert candidate(customers = [5, 5, 0, 8, 2],boardingCost = 6,runningCost = 3) == 6\n assert candidate(customers = [0, 0, 0, 0, 0],boardingCost = 1,runnin... | [
"[8,3]\n5\n6",
"[10,9,6]\n6\n4",
"[3,4,0,5,1]\n1\n92"
] | [
"Think simulation",
"Note that the number of turns will never be more than 50 / 4 * n"
] | {
"canonical_parameter_names": [
"customers",
"boardingCost",
"runningCost"
],
"leetcode_dataset_entry_point": "Solution().minOperationsMaxProfit",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2... | cpp | {
"raw_signature": "int minOperationsMaxProfit(vector<int>& customers, int boardingCost, int runningCost) {",
"container": "Solution",
"callable": "minOperationsMaxProfit",
"parameters": [
{
"name": "customers",
"type": "vector<int>&"
},
{
"name": "boardingCost",
"type": "int... |
1,601 | maximum-number-of-achievable-transfer-requests | Hard | We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array requests where requests[i] = [from_i, to_i] represents an employee's request to transfer from building from_i to building to... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]]) == 6\n assert candidate(n = 4,requests = [[0, 1], [1, 0], [0, 2], [2, 0], [0, 3], [3, 0]]) == 6\n assert candidate(n = 4,requests = [[0, 3], [3, 1], [1, 2], [2, 0]]... | [
"5\n[[0,1],[1,0],[0,1],[1,2],[2,0],[3,4]]",
"3\n[[0,0],[1,2],[2,1]]",
"4\n[[0,3],[3,1],[1,2],[2,0]]"
] | [
"Think brute force",
"When is a subset of requests okay?"
] | {
"canonical_parameter_names": [
"n",
"requests"
],
"leetcode_dataset_entry_point": "Solution().maximumRequests",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:02",
"tests_total": ... | cpp | {
"raw_signature": "int maximumRequests(int n, vector<vector<int>>& requests) {",
"container": "Solution",
"callable": "maximumRequests",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "requests",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
... |
1,604 | alert-using-same-key-card-three-or-more-times-in-a-one-hour-period | Medium | LeetCode company workers use key-cards to unlock office doors. Each time a worker uses their key-card, the security system saves the worker's name and the time when it was used. The system emits an alert if any worker uses the key-card three or more times in a one-hour period.
You are given a list of strings keyName a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(keyName = ['daniel', 'daniel', 'daniel', 'luis', 'luis', 'luis', 'luis'],keyTime = ['10:00', '10:40', '11:00', '09:00', '11:00', '13:00', '15:00']) == ['daniel']\n assert candidate(keyName = ['amy', 'amy', 'amy', 'adam', 'adam', 'adam... | [
"[\"daniel\",\"daniel\",\"daniel\",\"luis\",\"luis\",\"luis\",\"luis\"]\n[\"10:00\",\"10:40\",\"11:00\",\"09:00\",\"11:00\",\"13:00\",\"15:00\"]",
"[\"alice\",\"alice\",\"alice\",\"bob\",\"bob\",\"bob\",\"bob\"]\n[\"12:01\",\"12:00\",\"18:00\",\"21:00\",\"21:20\",\"21:30\",\"23:00\"]"
] | [
"Group the times by the name of the card user, then sort each group"
] | {
"canonical_parameter_names": [
"keyName",
"keyTime"
],
"leetcode_dataset_entry_point": "Solution().alertNames",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:07",
"tests_total": ... | cpp | {
"raw_signature": "vector<string> alertNames(vector<string>& keyName, vector<string>& keyTime) {",
"container": "Solution",
"callable": "alertNames",
"parameters": [
{
"name": "keyName",
"type": "vector<string>&"
},
{
"name": "keyTime",
"type": "vector<string>&"
}
],
... |
1,605 | find-valid-matrix-given-row-and-column-sums | Medium | You are given two arrays rowSum and colSum of non-negative integers where rowSum[i] is the sum of the elements in the i^th row and colSum[j] is the sum of the elements of the j^th column of a 2D matrix. In other words, you do not know the elements of the matrix, but you do know the sums of each row and column.
Find an... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(rowSum = [10, 15],colSum = [12, 13]) == [[10, 0], [2, 13]]\n assert candidate(rowSum = [5, 5, 5],colSum = [5, 5, 5]) == [[5, 0, 0], [0, 5, 0], [0, 0, 5]]\n assert candidate(rowSum = [10, 20],colSum = [15, 15]) == [[10, 0], [5, 15]]... | [
"[3,8]\n[4,7]",
"[5,7,10]\n[8,6,8]"
] | [
"Find the smallest rowSum or colSum, and let it be x. Place that number in the grid, and subtract x from rowSum and colSum. Continue until all the sums are satisfied."
] | {
"canonical_parameter_names": [
"rowSum",
"colSum"
],
"leetcode_dataset_entry_point": "Solution().restoreMatrix",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:10",
"tests_total":... | cpp | {
"raw_signature": "vector<vector<int>> restoreMatrix(vector<int>& rowSum, vector<int>& colSum) {",
"container": "Solution",
"callable": "restoreMatrix",
"parameters": [
{
"name": "rowSum",
"type": "vector<int>&"
},
{
"name": "colSum",
"type": "vector<int>&"
}
],
"ret... |
1,606 | find-servers-that-handled-most-number-of-requests | Hard | You have k servers numbered from 0 to k-1 that are being used to handle multiple requests simultaneously. Each server has infinite computational capacity but cannot handle more than one request at a time. The requests are assigned to servers according to a specific algorithm:
- The i^th (0-indexed) request arrives.
- ... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ... | [
"3\n[1,2,3,4,5]\n[5,2,3,3,3]",
"3\n[1,2,3,4]\n[1,2,1,2]",
"3\n[1,2,3]\n[10,12,11]"
] | [
"To speed up the next available server search, keep track of the available servers in a sorted structure such as an ordered set.",
"To determine if a server is available, keep track of the end times for each task in a heap and add the server to the available set once the soonest task ending time is less than or e... | {
"canonical_parameter_names": [
"k",
"arrival",
"load"
],
"leetcode_dataset_entry_point": "Solution().busiestServers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:13",
"test... | cpp | {
"raw_signature": "vector<int> busiestServers(int k, vector<int>& arrival, vector<int>& load) {",
"container": "Solution",
"callable": "busiestServers",
"parameters": [
{
"name": "k",
"type": "int"
},
{
"name": "arrival",
"type": "vector<int>&"
},
{
"name": "lo... |
1,608 | special-array-with-x-elements-greater-than-or-equal-x | Easy | You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x.
Notice that x does not have to be an element in nums.
Return x if the array is special, otherwise, return -1. It can be proven ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 10\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == 3\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]... | [
"[3,5]",
"[0,0]",
"[0,4,3,0,4]"
] | [
"Count the number of elements greater than or equal to x for each x in the range [0, nums.length].",
"If for any x, the condition satisfies, return that x. Otherwise, there is no answer."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().specialArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:15",
"tests_total": 75,
"tests_dro... | cpp | {
"raw_signature": "int specialArray(vector<int>& nums) {",
"container": "Solution",
"callable": "specialArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,610 | maximum-number-of-visible-points | Hard | You are given an array points, an integer angle, and your location, where location = [pos_x, pos_y] and points[i] = [x_i, y_i] both denote integral coordinates on the X-Y plane.
Initially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, pos_x and... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(points = [[1, 0], [0, 1], [-1, 0], [0, -1]],angle = 90,location = [0, 0]) == 2\n assert candidate(points = [[100, 100], [100, 99], [99, 100], [99, 99]],angle = 45,location = [100, 100]) == 3\n assert candidate(points = [[0, 0], [5,... | [
"[[2,1],[2,2],[3,3]]\n90\n[1,1]",
"[[2,1],[2,2],[3,4],[1,1]]\n90\n[1,1]",
"[[1,0],[2,1]]\n13\n[1,1]"
] | [
"Sort the points by polar angle with the original position. Now only a consecutive collection of points would be visible from any coordinate.",
"We can use two pointers to keep track of visible points for each start point",
"For handling the cyclic condition, it’d be helpful to append the point list to itself a... | {
"canonical_parameter_names": [
"points",
"angle",
"location"
],
"leetcode_dataset_entry_point": "Solution().visiblePoints",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:20",
... | cpp | {
"raw_signature": "int visiblePoints(vector<vector<int>>& points, int angle, vector<int>& location) {",
"container": "Solution",
"callable": "visiblePoints",
"parameters": [
{
"name": "points",
"type": "vector<vector<int>>&"
},
{
"name": "angle",
"type": "int"
},
{
... |
1,611 | minimum-one-bit-operations-to-make-integers-zero | Hard | Given an integer n, you must transform it into 0 using the following operations any number of times:
- Change the rightmost (0^th) bit in the binary representation of n.
- Change the i^th bit in the binary representation of n if the (i-1)^th bit is set to 1 and the (i-2)^th through 0^th bits are set to 0.
Return the ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 0) == 0\n assert candidate(n = 8) == 15\n assert candidate(n = 3) == 2\n assert candidate(n = 100) == 71\n assert candidate(n = 15) == 10\n assert candidate(n = 16) == 31\n assert candidate(n = 31) == 21\n assert... | [
"3",
"6"
] | [
"The fastest way to convert n to zero is to remove all set bits starting from the leftmost one. Try some simple examples to learn the rule of how many steps are needed to remove one set bit.",
"consider n=2^k case first, then solve for all n."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().minimumOneBitOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:22",
"tests_total": 71,
"t... | cpp | {
"raw_signature": "int minimumOneBitOperations(int n) {",
"container": "Solution",
"callable": "minimumOneBitOperations",
"parameters": [
{
"name": "n",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,614 | maximum-nesting-depth-of-the-parentheses | Easy | Given a valid parentheses string s, return the nesting depth of s. The nesting depth is the maximum number of nested parentheses.
Example 1:
Input: s = "(1+(2*3)+((8)/4))+1"
Output: 3
Explanation:
Digit 8 is inside of 3 nested parentheses in the string.
Example 2:
Input: s = "(1)+((2))+(((3)))"
Output: 3
Explanatio... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"(1+(2*3)+((8)/4))+1\") == 3\n assert candidate(s = \"()()()\") == 1\n assert candidate(s = \"(1+2)\") == 1\n assert candidate(s = \"1+(2*3)\") == 1\n assert candidate(s = \"(())\") == 2\n assert candidate(s = \"((1+3... | [
"\"(1+(2*3)+((8)/4))+1\"",
"\"(1)+((2))+(((3)))\"",
"\"()(())((()()))\""
] | [
"The depth of any character in the VPS is the ( number of left brackets before it ) - ( number of right brackets before it )"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().maxDepth",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:24",
"tests_total": 101,
"tests_dropped":... | cpp | {
"raw_signature": "int maxDepth(string s) {",
"container": "Solution",
"callable": "maxDepth",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,615 | maximal-network-rank | Medium | There is an infrastructure of n cities with some number of roads connecting these cities. Each roads[i] = [a_i, b_i] indicates that there is a bidirectional road between cities a_i and b_i.
The network rank of two different cities is defined as the total number of directly connected roads to either city. If a road is ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,roads = [[0, 1], [0, 3], [1, 2], [1, 3]]) == 4\n assert candidate(n = 100,roads = []) == 0\n assert candidate(n = 6,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5]]) == 5\n assert candidate(n = 10,roads = [[0, 1], [0, 2], ... | [
"4\n[[0,1],[0,3],[1,2],[1,3]]",
"5\n[[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]]",
"8\n[[0,1],[1,2],[2,3],[2,4],[5,6],[5,7]]"
] | [
"Try every pair of different cities and calculate its network rank.",
"The network rank of two vertices is almost the sum of their degrees.",
"How can you efficiently check if there is a road connecting two different cities?"
] | {
"canonical_parameter_names": [
"n",
"roads"
],
"leetcode_dataset_entry_point": "Solution().maximalNetworkRank",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:26",
"tests_total": ... | cpp | {
"raw_signature": "int maximalNetworkRank(int n, vector<vector<int>>& roads) {",
"container": "Solution",
"callable": "maximalNetworkRank",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "roads",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
... |
1,616 | split-two-strings-to-make-palindrome | Medium | You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: a_prefix and a_suffix where a = a_prefix + a_suffix, and splitting b into two strings: b_prefix and b_suffix where b = b_prefix + b_suffix. Check if a_prefix + b_suffix or b_pref... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(a = \"abcdefg\",b = \"gfedcba\") == True\n assert candidate(a = \"aabbcc\",b = \"ccbbdd\") == True\n assert candidate(a = \"ulacfd\",b = \"jizalu\") == True\n assert candidate(a = \"aabbaa\",b = \"aabbaa\") == True\n assert c... | [
"\"x\"\n\"y\"",
"\"xbdef\"\n\"xecab\"",
"\"ulacfd\"\n\"jizalu\""
] | [
"Try finding the largest prefix from a that matches a suffix in b",
"Try string matching"
] | {
"canonical_parameter_names": [
"a",
"b"
],
"leetcode_dataset_entry_point": "Solution().checkPalindromeFormation",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:29",
"tests_total"... | cpp | {
"raw_signature": "bool checkPalindromeFormation(string a, string b) {",
"container": "Solution",
"callable": "checkPalindromeFormation",
"parameters": [
{
"name": "a",
"type": "string"
},
{
"name": "b",
"type": "string"
}
],
"return_type": "bool",
"signature_sourc... |
1,617 | count-subtrees-with-max-distance-between-cities | Hard | There are n cities numbered from 1 to n. You are given an array edges of size n-1, where edges[i] = [u_i, v_i] represents a bidirectional edge between cities u_i and v_i. There exists a unique path between each pair of cities. In other words, the cities form a tree.
A subtree is a subset of cities where every city is ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == [5, 8, 9, 0, 0]\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 4], [4, 5]]) == [4, 3, 2, 1]\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6]... | [
"4\n[[1,2],[2,3],[2,4]]",
"2\n[[1,2]]",
"3\n[[1,2],[2,3]]"
] | [
"Iterate through every possible subtree by doing a bitmask on which vertices to include. How can you determine if a subtree is valid (all vertices are connected)?",
"To determine connectivity, count the number of reachable vertices starting from any included vertex and only traveling on edges connecting 2 vertice... | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().countSubgraphsForEachDiameter",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:31",
"tes... | cpp | {
"raw_signature": "vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "countSubgraphsForEachDiameter",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
... |
1,619 | mean-of-array-after-removing-some-elements | Easy | Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements.
Answers within 10^-5 of the actual answer will be considered accepted.
Example 1:
Input: arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]
Output: 2.00000
Explanation: After erasing ... | {
"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,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]",
"[6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]",
"[6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]"
] | [
"Sort the given array.",
"Remove the first and last 5% of the sorted array."
] | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().trimMean",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:33",
"tests_total": 50,
"tests_dropped"... | cpp | {
"raw_signature": "double trimMean(vector<int>& arr) {",
"container": "Solution",
"callable": "trimMean",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "double",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
1,620 | coordinate-with-maximum-network-quality | Medium | You are given an array of network towers towers, where towers[i] = [x_i, y_i, q_i] denotes the i^th network tower with location (x_i, y_i) and quality factor q_i. All the coordinates are integral coordinates on the X-Y plane, and the distance between the two coordinates is the Euclidean distance.
You are also given an... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(towers = [[23, 11, 21]],radius = 9) == [23, 11]\n assert candidate(towers = [[5, 5, 15], [6, 6, 20], [7, 7, 25]],radius = 3) == [6, 6]\n assert candidate(towers = [[1, 2, 5], [2, 1, 7], [3, 1, 9]],radius = 2) == [2, 1]\n assert ... | [
"[[1,2,5],[2,1,7],[3,1,9]]\n2",
"[[23,11,21]]\n9",
"[[1,2,13],[2,1,7],[0,1,9]]\n2"
] | [
"The constraints are small enough to consider every possible coordinate and calculate its quality."
] | {
"canonical_parameter_names": [
"towers",
"radius"
],
"leetcode_dataset_entry_point": "Solution().bestCoordinate",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:36",
"tests_total"... | cpp | {
"raw_signature": "vector<int> bestCoordinate(vector<vector<int>>& towers, int radius) {",
"container": "Solution",
"callable": "bestCoordinate",
"parameters": [
{
"name": "towers",
"type": "vector<vector<int>>&"
},
{
"name": "radius",
"type": "int"
}
],
"return_type... |
1,621 | number-of-sets-of-k-non-overlapping-line-segments | Medium | Given n points on a 1-D plane, where the i^th point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments such that each segment covers two or more points. The endpoints of each segment must have integral coordinates. The k line segments do not have to cover all n poin... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3,k = 1) == 3\n assert candidate(n = 1000,k = 500) == 70047606\n assert candidate(n = 30,k = 7) == 796297179\n assert candidate(n = 6,k = 3) == 28\n assert candidate(n = 8,k = 4) == 165\n assert candidate(n = 5,k = 2) ... | [
"4\n2",
"3\n1",
"30\n7"
] | [
"Try to use dynamic programming where the current index and remaining number of line segments to form can describe any intermediate state.",
"To make the computation of each state in constant time, we could add another flag to the state that indicates whether or not we are in the middle of placing a line (placed ... | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().numberOfSets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:38",
"tests_total": 58,
"tes... | cpp | {
"raw_signature": "int numberOfSets(int n, int k) {",
"container": "Solution",
"callable": "numberOfSets",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_s... |
1,624 | largest-substring-between-two-equal-characters | Easy | Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1.
A substring is a contiguous sequence of characters within a string.
Example 1:
Input: s = "aa"
Output: 0
Explanation: The optimal substring here is an empt... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aabbaa\") == 4\n assert candidate(s = \"xyzx\") == 2\n assert candidate(s = \"a\") == -1\n assert candidate(s = \"aa\") == 0\n assert candidate(s = \"abcda\") == 3\n assert candidate(s = \"abcabc\") == 2\n assert ... | [
"\"aa\"",
"\"abca\"",
"\"cbzxy\""
] | [
"Try saving the first and last position of each character",
"Try finding every pair of indexes with equal characters"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().maxLengthBetweenEqualCharacters",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:40",
"tests_total": ... | cpp | {
"raw_signature": "int maxLengthBetweenEqualCharacters(string s) {",
"container": "Solution",
"callable": "maxLengthBetweenEqualCharacters",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
1,625 | lexicographically-smallest-string-after-applying-operations | Medium | You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b.
You can apply either of the following two operations any number of times and in any order on s:
- Add a to all odd indices of s (0-indexed). Digits post 9 are cycled back to 0. For example, if s = "3456" and a = 5, s b... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"5525\",a = 9,b = 2) == \"2050\"\n assert candidate(s = \"9876543210\",a = 7,b = 4) == \"1098765432\"\n assert candidate(s = \"74\",a = 5,b = 1) == \"24\"\n assert candidate(s = \"8900\",a = 3,b = 3) == \"0018\"\n assert... | [
"\"5525\"\n9\n2",
"\"74\"\n5\n1",
"\"0011\"\n4\n2"
] | [
"Since the length of s is even, the total number of possible sequences is at most 10 * 10 * s.length.",
"You can generate all possible sequences and take their minimum.",
"Keep track of already generated sequences so they are not processed again."
] | {
"canonical_parameter_names": [
"s",
"a",
"b"
],
"leetcode_dataset_entry_point": "Solution().findLexSmallestString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:42",
"tests_... | cpp | {
"raw_signature": "string findLexSmallestString(string s, int a, int b) {",
"container": "Solution",
"callable": "findLexSmallestString",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "a",
"type": "int"
},
{
"name": "b",
"type": "int"
}... |
1,626 | best-team-with-no-conflicts | Medium | You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team.
However, the basketball team is not allowed to have conflicts. A conflict exists if a younger player has a strict... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(scores = [1000000, 999999, 999998],ages = [1, 2, 3]) == 1000000\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],ages = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(scores = [50, 50, 50, 50],ages = [1, 2, 3,... | [
"[1,3,5,10,15]\n[1,2,3,4,5]",
"[4,5,6,5]\n[2,1,2,1]",
"[1,2,3,5]\n[8,9,10,1]"
] | [
"First, sort players by age and break ties by their score. You can now consider the players from left to right.",
"If you choose to include a player, you must only choose players with at least that score later on."
] | {
"canonical_parameter_names": [
"scores",
"ages"
],
"leetcode_dataset_entry_point": "Solution().bestTeamScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:44",
"tests_total": 1... | cpp | {
"raw_signature": "int bestTeamScore(vector<int>& scores, vector<int>& ages) {",
"container": "Solution",
"callable": "bestTeamScore",
"parameters": [
{
"name": "scores",
"type": "vector<int>&"
},
{
"name": "ages",
"type": "vector<int>&"
}
],
"return_type": "int",
... |
1,627 | graph-connectivity-with-threshold | Hard | We have n cities labeled from 1 to n. Two different cities with labels x and y are directly connected by a bidirectional road if and only if x and y share a common divisor strictly greater than some threshold. More formally, cities with labels x and y have a road between them if there exists an integer z such that all ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,threshold = 0,queries = [[4, 5], [3, 4], [3, 2], [2, 6], [1, 3]]) == [True, True, True, True, True]\n assert candidate(n = 10,threshold = 3,queries = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == [False, False, False, False, Fal... | [
"6\n2\n[[1,4],[2,5],[3,6]]",
"6\n0\n[[4,5],[3,4],[3,2],[2,6],[1,3]]",
"5\n1\n[[4,5],[4,5],[3,2],[2,3],[3,4]]"
] | [
"How to build the graph of the cities?",
"Connect city i with all its multiples 2*i, 3*i, ...",
"Answer the queries using union-find data structure."
] | {
"canonical_parameter_names": [
"n",
"threshold",
"queries"
],
"leetcode_dataset_entry_point": "Solution().areConnected",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:47",
"t... | cpp | {
"raw_signature": "vector<bool> areConnected(int n, int threshold, vector<vector<int>>& queries) {",
"container": "Solution",
"callable": "areConnected",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "threshold",
"type": "int"
},
{
"name": "queries"... |
1,629 | slowest-key | Easy | A newly designed keypad was tested, where a tester pressed a sequence of n keys, one at a time.
You are given a string keysPressed of length n, where keysPressed[i] was the i^th key pressed in the testing sequence, and a sorted list releaseTimes, where releaseTimes[i] was the time the i^th key was released. Both array... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(releaseTimes = [2, 3, 7, 10, 15],keysPressed = \"zzzaa\") == \"a\"\n assert candidate(releaseTimes = [5, 10, 15, 20, 25],keysPressed = \"zabzc\") == \"z\"\n assert candidate(releaseTimes = [5, 15, 25, 35, 45, 55],keysPressed = \"ab... | [
"[9,29,49,50]\n\"cbcd\"",
"[12,23,36,46,62]\n\"spuda\""
] | [
"Get for each press its key and amount of time taken.",
"Iterate on the presses, maintaining the answer so far.",
"The current press will change the answer if and only if its amount of time taken is longer than that of the previous answer, or they are equal but the key is larger than that of the previous answer... | {
"canonical_parameter_names": [
"releaseTimes",
"keysPressed"
],
"leetcode_dataset_entry_point": "Solution().slowestKey",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:49",
"tests... | cpp | {
"raw_signature": "char slowestKey(vector<int>& releaseTimes, string keysPressed) {",
"container": "Solution",
"callable": "slowestKey",
"parameters": [
{
"name": "releaseTimes",
"type": "vector<int>&"
},
{
"name": "keysPressed",
"type": "string"
}
],
"return_type": ... |
1,630 | arithmetic-subarrays | Medium | A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1] - s[i] == s[1] - s[0] for all valid i.
For example, these are arithmetic sequences:
1, 3, 5, 7, 9
7... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1],l = [0, 0, 2, 3],r = [1, 2, 4, 4]) == [True, True, True, True]\n assert candidate(nums = [5, 5, 5, 5, 5],l = [0, 1, 2],r = [1, 2, 3]) == [True, True, True]\n assert candidate(nums = [0, 3, 5, 7, 9],l = [0, 1,... | [
"[4,6,5,9,3,7]\n[0,0,2]\n[2,3,5]",
"[-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10]\n[0,1,6,4,8,7]\n[4,4,9,7,9,10]"
] | [
"To check if a given sequence is arithmetic, just check that the difference between every two consecutive elements is the same.",
"If and only if a set of numbers can make an arithmetic sequence, then its sorted version makes an arithmetic sequence. So to check a set of numbers, sort it, and check if that sequenc... | {
"canonical_parameter_names": [
"nums",
"l",
"r"
],
"leetcode_dataset_entry_point": "Solution().checkArithmeticSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:51",
"... | cpp | {
"raw_signature": "vector<bool> checkArithmeticSubarrays(vector<int>& nums, vector<int>& l, vector<int>& r) {",
"container": "Solution",
"callable": "checkArithmeticSubarrays",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "l",
"type": "vector<int>&"
... |
1,631 | path-with-minimum-effort | Medium | You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0), and you hope to travel to the bottom-right cell, (rows-1, columns-1) (i.e., 0-indexed). You can move ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(heights = [[4, 3, 4, 10, 5, 5, 9, 2], [10, 8, 2, 10, 9, 7, 5, 6], [5, 8, 1, 10, 10, 7, 7, 2], [5, 10, 2, 8, 3, 9, 7, 9], [7, 6, 6, 8, 6, 6, 4, 4], [4, 9, 6, 10, 2, 1, 2, 7], [5, 10, 3, 7, 7, 5, 10, 10]]) == 4\n assert candidate(height... | [
"[[1,2,2],[3,8,2],[5,3,5]]",
"[[1,2,3],[3,8,4],[5,3,5]]",
"[[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]"
] | [
"Consider the grid as a graph, where adjacent cells have an edge with cost of the difference between the cells.",
"If you are given threshold k, check if it is possible to go from (0, 0) to (n-1, m-1) using only edges of ≤ k cost.",
"Binary search the k value."
] | {
"canonical_parameter_names": [
"heights"
],
"leetcode_dataset_entry_point": "Solution().minimumEffortPath",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:53",
"tests_total": 69,
"t... | cpp | {
"raw_signature": "int minimumEffortPath(vector<vector<int>>& heights) {",
"container": "Solution",
"callable": "minimumEffortPath",
"parameters": [
{
"name": "heights",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_sour... |
1,632 | rank-transform-of-a-matrix | Hard | Given an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col].
The rank is an integer that represents how large an element is compared to other elements. It is calculated using the following rules:
- The rank is an integer starting from 1.
- If two elements p and q are in th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(matrix = [[-1, -2], [-3, -4]]) == [[3, 2], [2, 1]]\n assert candidate(matrix = [[20, -21, 14], [-19, 4, 19], [22, -47, 24], [-19, 4, 19]]) == [[4, 2, 3], [1, 3, 4], [5, 1, 6], [1, 3, 4]]\n assert candidate(matrix = [[1, 2], [3, 4]]... | [
"[[1,2],[3,4]]",
"[[7,7],[7,7]]",
"[[20,-21,14],[-19,4,19],[22,-47,24],[-19,4,19]]"
] | [
"Sort the cells by value and process them in increasing order.",
"The rank of a cell is the maximum rank in its row and column plus one.",
"Handle the equal cells by treating them as components using a union-find data structure."
] | {
"canonical_parameter_names": [
"matrix"
],
"leetcode_dataset_entry_point": "Solution().matrixRankTransform",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:56",
"tests_total": 96,
"... | cpp | {
"raw_signature": "vector<vector<int>> matrixRankTransform(vector<vector<int>>& matrix) {",
"container": "Solution",
"callable": "matrixRankTransform",
"parameters": [
{
"name": "matrix",
"type": "vector<vector<int>>&"
}
],
"return_type": "vector<vector<int>>",
"signature_source": "le... |
1,636 | sort-array-by-increasing-frequency | Easy | Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.
Return the sorted array.
Example 1:
Input: nums = [1,1,2,2,2,3]
Output: [3,1,1,2,2,2]
Explanation: '3' has a frequency of 1, '1' has a f... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 2, 2, 2, 3]) == [3, 1, 1, 2, 2, 2]\n assert candidate(nums = [10, 10, 20, 20, 30]) == [30, 20, 20, 10, 10]\n assert candidate(nums = [7, 7, 7, 6, 6, 5, 5, 5, 5]) == [6, 6, 7, 7, 7, 5, 5, 5, 5]\n assert candidate(nu... | [
"[1,1,2,2,2,3]",
"[2,3,1,3,2]",
"[-1,1,-6,4,5,-6,1,4,1]"
] | [
"Count the frequency of each value.",
"Use a custom comparator to compare values by their frequency. If two values have the same frequency, compare their values."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().frequencySort",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:25:58",
"tests_total": 117,
"tests_d... | cpp | {
"raw_signature": "vector<int> frequencySort(vector<int>& nums) {",
"container": "Solution",
"callable": "frequencySort",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
1,637 | widest-vertical-area-between-two-points-containing-no-points | Easy | Given n points on a 2D plane where points[i] = [x_i, y_i], Return the widest vertical area between two points such that no points are inside the area.
A vertical area is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The widest vertical area is the one with the maximum width.
No... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 1\n assert candidate(points = [[1, 10], [3, 3], [5, 5], [7, 7], [9, 9]]) == 2\n assert candidate(points = [[5, 1], [4, 1], [3, 1], [2, 1], [1, 1]]) == 1\n assert candidate(po... | [
"[[8,7],[9,9],[7,4],[9,7]]",
"[[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]"
] | [
"Try sorting the points",
"Think whether the y-axis of a point is relevant"
] | {
"canonical_parameter_names": [
"points"
],
"leetcode_dataset_entry_point": "Solution().maxWidthOfVerticalArea",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:26:00",
"tests_total": 104,... | cpp | {
"raw_signature": "int maxWidthOfVerticalArea(vector<vector<int>>& points) {",
"container": "Solution",
"callable": "maxWidthOfVerticalArea",
"parameters": [
{
"name": "points",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"t... |
1,638 | count-substrings-that-differ-by-one-character | Medium | Given two strings s and t, find the number of ways you can choose a non-empty substring of s and replace a single character by a different character such that the resulting substring is a substring of t. In other words, find the number of substrings in s that differ from some substring in t by exactly one character.
F... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abc\",t = \"abcd\") == 9\n assert candidate(s = \"abcde\",t = \"bcdef\") == 21\n assert candidate(s = \"aaaa\",t = \"bbbb\") == 16\n assert candidate(s = \"xyz\",t = \"xya\") == 9\n assert candidate(s = \"python\",t = \... | [
"\"aba\"\n\"baba\"",
"\"ab\"\n\"bb\""
] | [
"Take every substring of s, change a character, and see how many substrings of t match that substring.",
"Use a Trie to store all substrings of t as a dictionary."
] | {
"canonical_parameter_names": [
"s",
"t"
],
"leetcode_dataset_entry_point": "Solution().countSubstrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:26:02",
"tests_total": 156,
... | cpp | {
"raw_signature": "int countSubstrings(string s, string t) {",
"container": "Solution",
"callable": "countSubstrings",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "t",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSn... |
1,639 | number-of-ways-to-form-a-target-string-given-a-dictionary | Hard | You are given a list of strings of the same length words and a string target.
Your task is to form target using the given words under the following rules:
- target should be formed from left to right.
- To form the i^th character (0-indexed) of target, you can choose the k^th character of the j^th string in words if ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['a', 'b', 'c'],target = \"abc\") == 0\n assert candidate(words = ['abc', 'def'],target = \"ad\") == 0\n assert candidate(words = ['mississippi'],target = \"issi\") == 15\n assert candidate(words = ['aaa', 'aaa', 'aaa'],... | [
"[\"acca\",\"bbbb\",\"caca\"]\n\"aba\"",
"[\"abba\",\"baab\"]\n\"bab\""
] | [
"For each index i, store the frequency of each character in the ith row.",
"Use dynamic programing to calculate the number of ways to get the target string using the frequency array."
] | {
"canonical_parameter_names": [
"words",
"target"
],
"leetcode_dataset_entry_point": "Solution().numWays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:26:05",
"tests_total": 148,
... | cpp | {
"raw_signature": "int numWays(vector<string>& words, string target) {",
"container": "Solution",
"callable": "numWays",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
},
{
"name": "target",
"type": "string"
}
],
"return_type": "int",
"signature_sourc... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.