question_id
int64
1
3.24k
task_id
stringlengths
3
77
difficulty
stringclasses
3 values
problem_description
stringlengths
193
3.69k
canonical_tests
dict
public_tests
listlengths
1
5
hints
listlengths
0
8
metadata
dict
language
stringclasses
9 values
interface
dict
2,609
find-the-longest-balanced-substring-of-a-binary-string
Easy
You are given a binary string s consisting only of zeroes and ones. A substring of s is considered balanced if all zeroes are before ones and the number of zeroes is equal to the number of ones inside the substring. Notice that the empty substring is considered a balanced substring. Return the length of the longest b...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"000000111111\") == 12\n assert candidate(s = \"000111000111\") == 6\n assert candidate(s = \"000110\") == 4\n assert candidate(s = \"01\") == 2\n assert candidate(s = \"00111\") == 4\n assert candidate(s = \"00011001...
[ "\"01000111\"", "\"00111\"", "\"111\"" ]
[ "Consider iterating over each subarray and checking if it’s balanced or not.", "Among all balanced subarrays, the answer is the longest one of them." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().findTheLongestBalancedSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:02", "tests_total": ...
cpp
{ "raw_signature": "int findTheLongestBalancedSubstring(string s) {", "container": "Solution", "callable": "findTheLongestBalancedSubstring", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
2,610
convert-an-array-into-a-2d-array-with-conditions
Medium
You are given an integer array nums. You need to create a 2D array from nums satisfying the following conditions: - The 2D array should contain only the elements of the array nums. - Each row in the 2D array contains distinct integers. - The number of rows in the 2D array should be minimal. Return the resulting array...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == [[1, 2, 3, 4], [2, 3, 4], [3, 4], [4]]\n assert candidate(nums = [1, 2, 3, 4]) == [[1, 2, 3, 4]]\n assert candidate(nums = [10, 1, 2, 9, 3, 8, 4, 7, 5, 6]) == [[10, 1, 2, 9, 3, 8, 4, 7, 5, ...
[ "[1,3,4,1,2,3,1]", "[2,1,1]" ]
[ "Process the elements in the array one by one in any order and only create a new row in the matrix when we cannot put it into the existing rows", "We can simply iterate over the existing rows of the matrix to see if we can place each element." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:04", "tests_total": 79, "tests_dropp...
cpp
{ "raw_signature": "vector<vector<int>> findMatrix(vector<int>& nums) {", "container": "Solution", "callable": "findMatrix", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "vector<vector<int>>", "signature_source": "leetcode/codeSnippets", "type_source":...
2,611
mice-and-cheese
Medium
There are two mice and n different types of cheese, each type of cheese should be eaten by exactly one mouse. A point of the cheese with index i (0-indexed) is: - reward1[i] if the first mouse eats it. - reward2[i] if the second mouse eats it. You are given a positive integer array reward1, a positive integer array ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(reward1 = [10, 20, 30, 40],reward2 = [40, 30, 20, 10],k = 3) == 130\n assert candidate(reward1 = [5, 4, 3, 2, 1],reward2 = [1, 2, 3, 4, 5],k = 3) == 21\n assert candidate(reward1 = [10, 20, 30],reward2 = [40, 50, 60],k = 0) == 150\...
[ "[1,1,3,4]\n[4,4,1,1]\n2", "[1,1]\n[1,1]\n2" ]
[ "The intended solution uses greedy approach.", "Imagine at first that the second mouse eats all the cheese, then we should choose k types of cheese with the maximum sum of - reward2[i] + reward1[i]." ]
{ "canonical_parameter_names": [ "reward1", "reward2", "k" ], "leetcode_dataset_entry_point": "Solution().miceAndCheese", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:07", "te...
cpp
{ "raw_signature": "int miceAndCheese(vector<int>& reward1, vector<int>& reward2, int k) {", "container": "Solution", "callable": "miceAndCheese", "parameters": [ { "name": "reward1", "type": "vector<int>&" }, { "name": "reward2", "type": "vector<int>&" }, { "na...
2,614
prime-in-diagonal
Easy
You are given a 0-indexed two-dimensional integer array nums. Return the largest prime number that lies on at least one of the diagonals of nums. In case, no prime is present on any of the diagonals, return 0. Note that: - An integer is prime if it is greater than 1 and has no positive integer divisors other than 1 ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [[4, 6, 8], [10, 12, 14], [16, 18, 20]]) == 0\n assert candidate(nums = [[3, 1, 4], [1, 5, 9], [2, 6, 5]]) == 5\n assert candidate(nums = [[1, 4, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12], [13, 14, 15, 16]]) == 13\n assert can...
[ "[[1,2,3],[5,6,7],[9,10,11]]", "[[1,2,3],[5,17,7],[9,11,10]]" ]
[ "Iterate over the diagonals of the matrix and check for each element.", "Check if the element is prime or not in O(sqrt(n)) time." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().diagonalPrime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:11", "tests_total": 73, "tests_dr...
cpp
{ "raw_signature": "int diagonalPrime(vector<vector<int>>& nums) {", "container": "Solution", "callable": "diagonalPrime", "parameters": [ { "name": "nums", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode...
2,615
sum-of-distances
Medium
You are given a 0-indexed integer array nums. There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] to be 0. Return the array arr. Example 1: Input: nums = [1,3,1,1,2] Output: [5,0,3,4,0] Explanation:...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 5, 3]) == [0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [1]) == [0]\n assert candidate(nums = [10, 10, 10, 10]) == [6, 4, 4, 6]\n as...
[ "[1,3,1,1,2]", "[0,5,3]" ]
[ "Can we use the prefix sum here?", "For each number x, collect all the indices where x occurs, and calculate the prefix sum of the array.", "For each occurrence of x, the indices to the right will be regular subtraction while the indices to the left will be reversed subtraction." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().distance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:14", "tests_total": 105, "tests_droppe...
cpp
{ "raw_signature": "vector<long long> distance(vector<int>& nums) {", "container": "Solution", "callable": "distance", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "vector<long long>", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
2,616
minimize-the-maximum-difference-of-pairs
Medium
You are given a 0-indexed integer array nums and an integer p. Find p pairs of indices of nums such that the maximum difference amongst all the pairs is minimized. Also, ensure no index appears more than once amongst the p pairs. Note that for a pair of elements at the index i and j, the difference of this pair is |nu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 6, 8, 10],p = 2) == 2\n assert candidate(nums = [5, 3, 8, 4, 9, 1],p = 3) == 2\n assert candidate(nums = [5, 5, 5, 5, 5],p = 2) == 0\n assert candidate(nums = [7, 1, 3, 4, 2, 5],p = 0) == 0\n assert candidate(nu...
[ "[10,1,2,7,1,3]\n2", "[4,2,1,2]\n1" ]
[ "To minimize the answer, the array should be sorted first.", "Can we use binary search here?" ]
{ "canonical_parameter_names": [ "nums", "p" ], "leetcode_dataset_entry_point": "Solution().minimizeMax", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:16", "tests_total": 106, "...
cpp
{ "raw_signature": "int minimizeMax(vector<int>& nums, int p) {", "container": "Solution", "callable": "minimizeMax", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "p", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/co...
2,617
minimum-number-of-visited-cells-in-a-grid
Hard
You are given a 0-indexed m x n integer matrix grid. Your initial position is at the top-left cell (0, 0). Starting from the cell (i, j), you can move to one of the following cells: - Cells (i, k) with j < k <= grid[i][j] + j (rightward movement), or - Cells (k, j) with i < k <= grid[i][j] + i (downward movement). R...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[2, 0, 0], [1, 3, 1], [0, 1, 0]]) == 5\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == -1\n assert candidate(grid = [[3, 4, 2, 1], [4, 2, 3, 1], [2, 1, 0, 0], [2, 4, 0, 0]]) == 4\n ...
[ "[[3,4,2,1],[4,2,3,1],[2,1,0,0],[2,4,0,0]]", "[[3,4,2,1],[4,2,1,1],[2,1,1,0],[3,4,1,0]]", "[[2,1,0],[1,0,0]]" ]
[ "For each cell (i,j), it is critical to find out the minimum number of steps to reach (i,j), denoted dis[i][j], quickly, given the tight constraint.", "Calculate dis[i][j] going left to right, top to bottom.", "Suppose we want to calculate dis[i][j], keep track of a priority queue that stores (dis[i][k], i, k) ...
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minimumVisitedCells", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:19", "tests_total": 103, "t...
cpp
{ "raw_signature": "int minimumVisitedCells(vector<vector<int>>& grid) {", "container": "Solution", "callable": "minimumVisitedCells", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source...
2,639
find-the-width-of-columns-of-a-grid
Easy
You are given a 0-indexed m x n integer matrix grid. The width of a column is the maximum length of its integers. - For example, if grid = [[-10], [3], [12]], the width of the only column is 3 since -10 is of length 3. Return an integer array ans of size n where ans[i] is the width of the i^th column. The length of ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[12345], [67890]]) == [5]\n assert candidate(grid = [[1], [22], [333]]) == [3]\n assert candidate(grid = [[1000], [-1000], [100], [-100], [10], [-10], [1], [-1]]) == [5]\n assert candidate(grid = [[-15, 1, 3], [15, 7, 12...
[ "[[1],[22],[333]]", "[[-15,1,3],[15,7,12],[5,6,-2]]" ]
[ "You can find the length of a number by dividing it by 10 and then rounding it down again and again until this number becomes equal to 0. Add 1 if this number is negative.", "Traverse the matrix column-wise to find the maximum length in each column." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().findColumnWidth", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:23", "tests_total": 96, "tests_...
cpp
{ "raw_signature": "vector<int> findColumnWidth(vector<vector<int>>& grid) {", "container": "Solution", "callable": "findColumnWidth", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "typ...
2,640
find-the-score-of-all-prefixes-of-an-array
Medium
We define the conversion array conver of an array arr as follows: - conver[i] = arr[i] + max(arr[0..i]) where max(arr[0..i]) is the maximum value of arr[j] over 0 <= j <= i. We also define the score of an array arr as the sum of the values of the conversion array of arr. Given a 0-indexed integer array nums of lengt...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == [10, 19, 27, 34, 40]\n assert candidate(nums = [1]) == [2]\n assert candidate(nums = [1000000000]) == [2000000000]\n assert candidate(nums = [1, 1, 2, 4, 8, 16]) == [2, 4, 8, 16, 32, 64]\n assert ca...
[ "[2,3,7,5,10]", "[1,1,2,4,8,16]" ]
[ "Keep track of the prefix maximum of the array", "Establish a relationship between ans[i] and ans[i-1]", "for 0 < i < n, ans[i] = ans[i-1]+conver[i]. In other words, array ans is the prefix sum array of the conversion array" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findPrefixScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:26", "tests_total": 94, "tests_...
cpp
{ "raw_signature": "vector<long long> findPrefixScore(vector<int>& nums) {", "container": "Solution", "callable": "findPrefixScore", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "vector<long long>", "signature_source": "leetcode/codeSnippets", "type_so...
2,643
row-with-maximum-ones
Easy
Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row. In case there are multiple rows that have the maximum count of ones, the row with the smallest row number should be selected. Return an array containing the index of the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[0, 1], [1, 0]]) == [0, 1]\n assert candidate(mat = [[1, 1, 1], [0, 1, 1], [1, 0, 0]]) == [0, 3]\n assert candidate(mat = [[1, 1, 1, 0], [0, 1, 1, 1], [1, 1, 1, 1], [0, 0, 1, 1]]) == [2, 4]\n assert candidate(mat = [[0, 0...
[ "[[0,1],[1,0]]", "[[0,0,0],[0,1,1]]", "[[0,0],[1,1],[0,0]]" ]
[ "Iterate through each row and keep the count of ones." ]
{ "canonical_parameter_names": [ "mat" ], "leetcode_dataset_entry_point": "Solution().rowAndMaximumOnes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:30", "tests_total": 71, "tests...
cpp
{ "raw_signature": "vector<int> rowAndMaximumOnes(vector<vector<int>>& mat) {", "container": "Solution", "callable": "rowAndMaximumOnes", "parameters": [ { "name": "mat", "type": "vector<vector<int>>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "t...
2,644
find-the-maximum-divisibility-score
Easy
You are given two integer arrays nums and divisors. The divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i]. Return the integer divisors[i] with the maximum divisibility score. If multiple integers have the maximum score, return the smallest one. Example 1: Inp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [20, 14, 21, 10],divisors = [10, 16, 20]) == 10\n assert candidate(nums = [7, 14, 28, 35],divisors = [7, 14, 28, 35]) == 7\n assert candidate(nums = [12, 24, 36, 48],divisors = [3, 6, 12, 24]) == 3\n assert candidate(nums...
[ "[2,9,15,50]\n[5,3,7,2]", "[4,7,9,3,9]\n[5,2,3]", "[20,14,21,10]\n[10,16,20]" ]
[ "Consider counting for each element in divisors the count of elements in nums divisible by it using bruteforce.", "After counting for each divisor, take the one with the maximum count. In case of a tie, take the minimum one of them." ]
{ "canonical_parameter_names": [ "nums", "divisors" ], "leetcode_dataset_entry_point": "Solution().maxDivScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:33", "tests_total": 1...
cpp
{ "raw_signature": "int maxDivScore(vector<int>& nums, vector<int>& divisors) {", "container": "Solution", "callable": "maxDivScore", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "divisors", "type": "vector<int>&" } ], "return_type": "int", ...
2,645
minimum-additions-to-make-valid-string
Medium
Given a string word to which you can insert letters "a", "b" or "c" anywhere and any number of times, return the minimum number of letters that must be inserted so that word becomes valid. A string is called valid if it can be formed by concatenating the string "abc" several times. Example 1: Input: word = "b" Outpu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"aab\") == 3\n assert candidate(word = \"abc\") == 0\n assert candidate(word = \"bacbac\") == 6\n assert candidate(word = \"aabbcc\") == 6\n assert candidate(word = \"acbac\") == 4\n assert candidate(word = \"aabab...
[ "\"b\"", "\"aaa\"", "\"abc\"" ]
[ "Maintain a pointer on word and another pointer on string “abc”.", "If the two characters that are being pointed to differ, Increment the answer and the pointer to the string “abc” by one." ]
{ "canonical_parameter_names": [ "word" ], "leetcode_dataset_entry_point": "Solution().addMinimum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:35", "tests_total": 108, "tests_drop...
cpp
{ "raw_signature": "int addMinimum(string word) {", "container": "Solution", "callable": "addMinimum", "parameters": [ { "name": "word", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,646
minimize-the-total-price-of-the-trips
Hard
There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree. Each node has an associated price. You are given an integer arr...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3,edges = [[0, 1], [1, 2]],price = [10, 10, 10],trips = [[0, 2], [0, 1], [1, 2]]) == 50\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [1, 3], [3, 4]],price = [2, 4, 6, 8, 10],trips = [[0, 4], [1, 2]]) == 25\n assert candida...
[ "4\n[[0,1],[1,2],[1,3]]\n[2,2,10,6]\n[[0,3],[2,1],[2,3]]", "2\n[[0,1]]\n[2,2]\n[[0,0]]" ]
[ "The final answer is the price[i] * freq[i], where freq[i] is the number of times node i was visited during the trip, and price[i] is the final price.", "To find freq[i] we will use dfs or bfs for each trip and update every node on the path start and end.", "Finally, to find the final price[i] we will use dynam...
{ "canonical_parameter_names": [ "n", "edges", "price", "trips" ], "leetcode_dataset_entry_point": "Solution().minimumTotalPrice", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:...
cpp
{ "raw_signature": "int minimumTotalPrice(int n, vector<vector<int>>& edges, vector<int>& price, vector<vector<int>>& trips) {", "container": "Solution", "callable": "minimumTotalPrice", "parameters": [ { "name": "n", "type": "int" }, { "name": "edges", "type": "vector<vector...
2,651
calculate-delayed-arrival-time
Easy
You are given a positive integer arrivalTime denoting the arrival time of a train in hours, and another positive integer delayedTime denoting the amount of delay in hours. Return the time when the train will arrive at the station. Note that the time in this problem is in 24-hours format. Example 1: Input: arrivalTi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arrivalTime = 5,delayedTime = 19) == 0\n assert candidate(arrivalTime = 8,delayedTime = 16) == 0\n assert candidate(arrivalTime = 13,delayedTime = 11) == 0\n assert candidate(arrivalTime = 15,delayedTime = 5) == 20\n assert c...
[ "15\n5", "13\n11" ]
[ "Use the modulo operator to handle the case when the arrival time plus the delayed time goes beyond 24 hours.", "If the arrival time plus the delayed time is greater than or equal to 24, you can also subtract 24 to get the time in the 24-hour format." ]
{ "canonical_parameter_names": [ "arrivalTime", "delayedTime" ], "leetcode_dataset_entry_point": "Solution().findDelayedArrivalTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:42...
cpp
{ "raw_signature": "int findDelayedArrivalTime(int arrivalTime, int delayedTime) {", "container": "Solution", "callable": "findDelayedArrivalTime", "parameters": [ { "name": "arrivalTime", "type": "int" }, { "name": "delayedTime", "type": "int" } ], "return_type": "in...
2,652
sum-multiples
Easy
Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7. Return an integer denoting the sum of all numbers in the given range satisfying the constraint. Example 1: Input: n = 7 Output: 21 Explanation: Numbers in the range [1, 7] that are divisible by 3,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 9) == 30\n assert candidate(n = 1) == 0\n assert candidate(n = 1000) == 272066\n assert candidate(n = 7) == 21\n assert candidate(n = 10) == 40\n assert candidate(n = 210) == 12075\n assert candidate(n = 666) == 121...
[ "7", "10", "9" ]
[ "Iterate through the range 1 to n and count numbers divisible by either 3, 5, or 7." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().sumOfMultiples", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:44", "tests_total": 38, "tests_drop...
cpp
{ "raw_signature": "int sumOfMultiples(int n) {", "container": "Solution", "callable": "sumOfMultiples", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,653
sliding-subarray-beauty
Medium
Given an integer array nums containing n integers, find the beauty of each subarray of size k. The beauty of a subarray is the x^th smallest integer in the subarray if it is negative, or 0 if there are fewer than x negative integers. Return an integer array containing n - k + 1 integers, which denote the beauty of th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 6, 7, 8, 9],k = 3,x = 2) == [0, 0, 0]\n assert candidate(nums = [-1, -2, -3, -4, -5],k = 2,x = 2) == [-1, -2, -3, -4]\n assert candidate(nums = [1, -1, -3, -2, 3],k = 3,x = 2) == [-1, -2, -2]\n assert candidate(nums =...
[ "[1,-1,-3,-2,3]\n3\n2", "[-1,-2,-3,-4,-5]\n2\n2", "[-3,1,2,-3,0,-3]\n2\n1" ]
[ "Try to maintain the frequency of negative numbers in the current window of size k.", "The x^th smallest negative integer can be gotten by iterating through the frequencies of the numbers in order." ]
{ "canonical_parameter_names": [ "nums", "k", "x" ], "leetcode_dataset_entry_point": "Solution().getSubarrayBeauty", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:46", "tests_t...
cpp
{ "raw_signature": "vector<int> getSubarrayBeauty(vector<int>& nums, int k, int x) {", "container": "Solution", "callable": "getSubarrayBeauty", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" }, { "name": "x", "typ...
2,654
minimum-number-of-operations-to-make-all-array-elements-equal-to-1
Medium
You are given a 0-indexed array nums consisting of positive integers. You can do the following operation on the array any number of times: - Select an index i such that 0 <= i < n - 1 and replace either of nums[i] or nums[i+1] with their gcd value. Return the minimum number of operations to make all elements of nums ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 1]) == 3\n assert candidate(nums = [100, 200, 300, 400]) == -1\n assert candidate(nums = [1, 2, 2, 3]) == 3\n assert candidate(nums = [7, 21, 35, 49, 63]) == -1\n assert candidate(nums = [2, 4, 6, 8, 10, 12])...
[ "[2,6,3,4]", "[2,10,6,14]" ]
[ "Note that if you have at least one occurrence of 1 in the array, then you can make all the other elements equal to 1 with one operation each.", "Try finding the shortest subarray with a gcd equal to 1." ]
{ "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:59:49", "tests_total": 157, "tests_d...
cpp
{ "raw_signature": "int minOperations(vector<int>& nums) {", "container": "Solution", "callable": "minOperations", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,656
maximum-sum-with-exactly-k-elements
Easy
You are given a 0-indexed integer array nums and an integer k. Your task is to perform the following operation exactly k times in order to maximize your score: 1. Select an element m from nums. 2. Remove the selected element m from the array. 3. Add a new element with a value of m + 1 to the array. 4. Increase your sc...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 18\n assert candidate(nums = [5, 5, 5],k = 2) == 11\n assert candidate(nums = [1, 1, 1, 1],k = 4) == 10\n assert candidate(nums = [10, 20, 30],k = 1) == 30\n assert candidate(nums = [100],k = ...
[ "[1,2,3,4,5]\n3", "[5,5,5]\n2" ]
[]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximizeSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:53", "tests_total": 97, "t...
cpp
{ "raw_signature": "int maximizeSum(vector<int>& nums, int k) {", "container": "Solution", "callable": "maximizeSum", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/co...
2,657
find-the-prefix-common-array-of-two-arrays
Medium
You are given two 0-indexed integer permutations A and B of length n. A prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A and B. Return the prefix common array of A and B. A sequence of n integers is called a permutation i...
{ "language": "python", "source": "def check(candidate):\n assert candidate(A = [1, 3, 2, 4],B = [3, 1, 2, 4]) == [0, 2, 3, 4]\n assert candidate(A = [1, 2, 3],B = [3, 2, 1]) == [0, 1, 3]\n assert candidate(A = [2, 3, 1],B = [3, 1, 2]) == [0, 1, 3]\n assert candidate(A = [5, 4, 3, 2, 1],B = [1, 2, 3, 4,...
[ "[1,3,2,4]\n[3,1,2,4]", "[2,3,1]\n[3,1,2]" ]
[ "Consider keeping a frequency array that stores the count of occurrences of each number till index i.", "If a number occurred two times, it means it occurred in both A and B since they’re both permutations so add one to the answer." ]
{ "canonical_parameter_names": [ "A", "B" ], "leetcode_dataset_entry_point": "Solution().findThePrefixCommonArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:56", "tests_total"...
cpp
{ "raw_signature": "vector<int> findThePrefixCommonArray(vector<int>& A, vector<int>& B) {", "container": "Solution", "callable": "findThePrefixCommonArray", "parameters": [ { "name": "A", "type": "vector<int>&" }, { "name": "B", "type": "vector<int>&" } ], "return_ty...
2,658
maximum-number-of-fish-in-a-grid
Medium
You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents: - A land cell if grid[r][c] = 0, or - A water cell containing grid[r][c] fish, if grid[r][c] > 0. A fisher can start at any water cell (r, c) and can do the following operations any number of times: - Catch all the fish at cell (r, c), ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 1\n assert candidate(grid = [[1, 2, 3], [0, 0, 0], [4, 5, 6]]) == 15\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 45\n assert candidate(grid = [[10, 0, 0], [0, 0, 0...
[ "[[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]]", "[[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]]" ]
[ "Run DFS from each non-zero cell.", "Each time you pick a cell to start from, add up the number of fish contained in the cells you visit." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().findMaxFish", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:58", "tests_total": 105, "tests_dro...
cpp
{ "raw_signature": "int findMaxFish(vector<vector<int>>& grid) {", "container": "Solution", "callable": "findMaxFish", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...
2,659
make-array-empty
Hard
You are given an integer array nums containing distinct numbers, and you can perform the following operations until the array is empty: - If the first element has the smallest value, remove it - Otherwise, put the first element at the end of the array. Return an integer denoting the number of operations it takes to m...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 55\n assert candidate(nums = [-3, -1, -2, -4]) == 8\n assert candidate(nums = [10, 20, -10, 0]) == 6\n assert candidate(nums = [0, 10, -10, 5, -5]) == 9\n assert candidate(...
[ "[3,4,-1]", "[1,2,4,3]", "[1,2,3]" ]
[ "Understand the order in which the indices are removed from the array.", "We don’t really need to delete or move the elements, only the array length matters.", "Upon removing an index, decide how many steps it takes to move to the next one.", "Use a data structure to speed up the calculation." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countOperationsToEmptyArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:00", "tests_total": 2...
cpp
{ "raw_signature": "long long countOperationsToEmptyArray(vector<int>& nums) {", "container": "Solution", "callable": "countOperationsToEmptyArray", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", ...
2,660
determine-the-winner-of-a-bowling-game
Easy
You are given two 0-indexed integer arrays player1 and player2, representing the number of pins that player 1 and player 2 hit in a bowling game, respectively. The bowling game consists of n turns, and the number of pins in each turn is exactly 10. Assume a player hits x_i pins in the i^th turn. The value of the i^th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(player1 = [5, 5, 5, 5, 5],player2 = [5, 5, 5, 5, 5]) == 0\n assert candidate(player1 = [2, 3],player2 = [4, 1]) == 0\n assert candidate(player1 = [5, 10, 3, 2],player2 = [6, 5, 7, 3]) == 1\n assert candidate(player1 = [5, 5, 5, ...
[ "[5,10,3,2]\n[6,5,7,3]", "[3,5,7,6]\n[8,10,10,2]", "[2,3]\n[4,1]", "[1,1,1,10,10,10,10]\n[10,10,10,10,1,1,1]" ]
[ "Think about simulating the process to calculate the answer.", "Iterate over each element and check the previous two elements. See if one of them is 10 and can affect the score." ]
{ "canonical_parameter_names": [ "player1", "player2" ], "leetcode_dataset_entry_point": "Solution().isWinner", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:03", "tests_total": 93...
cpp
{ "raw_signature": "int isWinner(vector<int>& player1, vector<int>& player2) {", "container": "Solution", "callable": "isWinner", "parameters": [ { "name": "player1", "type": "vector<int>&" }, { "name": "player2", "type": "vector<int>&" } ], "return_type": "int", "s...
2,661
first-completely-painted-row-or-column
Medium
You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n]. Go through each index i in arr starting from index 0 and paint the cell in mat containing the integer arr[i]. Return the smallest index i at which either a row or a column w...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [15, 13, 14, 12, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 1],mat = [[13, 14, 15], [10, 11, 12], [7, 8, 9], [4, 5, 6], [1, 2, 3]]) == 2\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9...
[ "[1,3,4,2]\n[[1,4],[2,3]]", "[2,8,7,4,1,3,5,6,9]\n[[3,2,5],[1,4,6],[8,7,9]]" ]
[ "Can we use a frequency array?", "Pre-process the positions of the values in the matrix.", "Traverse the array and increment the corresponding row and column frequency using the pre-processed positions.", "If the row frequency becomes equal to the number of columns, or vice-versa return the current index." ]
{ "canonical_parameter_names": [ "arr", "mat" ], "leetcode_dataset_entry_point": "Solution().firstCompleteIndex", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:05", "tests_total": ...
cpp
{ "raw_signature": "int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) {", "container": "Solution", "callable": "firstCompleteIndex", "parameters": [ { "name": "arr", "type": "vector<int>&" }, { "name": "mat", "type": "vector<vector<int>>&" } ], "retur...
2,662
minimum-cost-of-a-path-with-special-roads
Medium
You are given an array start where start = [startX, startY] represents your initial position (startX, startY) in a 2D space. You are also given the array target where target = [targetX, targetY] represents your target position (targetX, targetY). The cost of going from a position (x1, y1) to any other position in the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(start = [3, 2],target = [5, 7],specialRoads = [[5, 7, 3, 2, 1], [3, 2, 3, 4, 4], [3, 3, 5, 5, 5], [3, 4, 5, 6, 6]]) == 7\n assert candidate(start = [1, 1],target = [4, 5],specialRoads = [[1, 2, 3, 3, 2], [3, 4, 4, 5, 1]]) == 5\n as...
[ "[1,1]\n[4,5]\n[[1,2,3,3,2],[3,4,4,5,1]]", "[3,2]\n[5,7]\n[[5,7,3,2,1],[3,2,3,4,4],[3,3,5,5,5],[3,4,5,6,6]]", "[1,1]\n[10,4]\n[[4,2,1,1,3],[1,2,7,4,4],[10,3,6,1,2],[6,1,1,2,3]]" ]
[ "It can be proven that it is optimal to go only to the positions that are either the start or the end of a special road or the target position.", "Consider all positions given to you as nodes in a graph, and the edges of the graph are the special roads.", "Now the problem is equivalent to finding the shortest p...
{ "canonical_parameter_names": [ "start", "target", "specialRoads" ], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:08",...
cpp
{ "raw_signature": "int minimumCost(vector<int>& start, vector<int>& target, vector<vector<int>>& specialRoads) {", "container": "Solution", "callable": "minimumCost", "parameters": [ { "name": "start", "type": "vector<int>&" }, { "name": "target", "type": "vector<int>&" ...
2,663
lexicographically-smallest-beautiful-string
Hard
A string is beautiful if: - It consists of the first k letters of the English lowercase alphabet. - It does not contain any substring of length 2 or more which is a palindrome. You are given a beautiful string s of length n and a positive integer k. Return the lexicographically smallest string of length n, which is ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcd\",k = 5) == \"abce\"\n assert candidate(s = \"aabbcc\",k = 6) == \"aabbcd\"\n assert candidate(s = \"zyx\",k = 26) == \"\"\n assert candidate(s = \"abcz\",k = 26) == \"abda\"\n assert candidate(s = \"aaa\",k = 4) =...
[ "\"abcz\"\n26", "\"dc\"\n4" ]
[ "If the string does not contain any palindromic substrings of lengths 2 and 3, then the string does not contain any palindromic substrings at all.", "Iterate from right to left and if it is possible to increase character at index i without creating any palindromic substrings of lengths 2 and 3, then increase it."...
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().smallestBeautifulString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:10", "tests_total":...
cpp
{ "raw_signature": "string smallestBeautifulString(string s, int k) {", "container": "Solution", "callable": "smallestBeautifulString", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "int" } ], "return_type": "string", "signature_source": ...
2,670
find-the-distinct-difference-array
Easy
You are given a 0-indexed array nums of length n. The distinct difference array of nums is an array diff of length n such that diff[i] is equal to the number of distinct elements in the suffix nums[i + 1, ..., n - 1] subtracted from the number of distinct elements in the prefix nums[0, ..., i]. Return the distinct di...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == [-3, -1, 1, 3, 5]\n assert candidate(nums = [10, 20, 10, 20, 10]) == [-1, 0, 0, 1, 2]\n assert candidate(nums = [1, 1, 2, 2, 3]) == [-2, -1, 0, 1, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, ...
[ "[1,2,3,4,5]", "[3,2,3,4,2]" ]
[ "Which data structure will help you maintain distinct elements?", "Iterate over all possible prefix sizes. Then, use a nested loop to add the elements of the prefix to a set, and another nested loop to add the elements of the suffix to another set." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().distinctDifferenceArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:15", "tests_total": 107, ...
cpp
{ "raw_signature": "vector<int> distinctDifferenceArray(vector<int>& nums) {", "container": "Solution", "callable": "distinctDifferenceArray", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "typ...
2,672
number-of-adjacent-elements-with-the-same-color
Medium
You are given an integer n representing an array colors of length n where all elements are set to 0's meaning uncolored. You are also given a 2D integer array queries where queries[i] = [index_i, color_i]. For the i^th query: - Set colors[index_i] to color_i. - Count the number of adjacent pairs in colors which have t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3,queries = [[0, 2], [1, 2], [2, 2]]) == [0, 1, 2]\n assert candidate(n = 1,queries = [[0, 100000]]) == [0]\n assert candidate(n = 10,queries = [[5, 3], [6, 3], [5, 3], [4, 3], [3, 3], [2, 3], [1, 3], [0, 3], [8, 3], [9, 3]]) =...
[ "4\n[[0,2],[1,2],[3,1],[1,1],[2,1]]", "1\n[[0,100000]]" ]
[ "Since at each query, only one element is being recolored, we just need to focus on its neighbors.", "If an element that is changed on the i-th query had the same color as its right element answer decreases by 1. Similarly contributes its left element too.", "After changing the color, if the element has the sam...
{ "canonical_parameter_names": [ "n", "queries" ], "leetcode_dataset_entry_point": "Solution().colorTheArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:18", "tests_total": 74,...
cpp
{ "raw_signature": "vector<int> colorTheArray(int n, vector<vector<int>>& queries) {", "container": "Solution", "callable": "colorTheArray", "parameters": [ { "name": "n", "type": "int" }, { "name": "queries", "type": "vector<vector<int>>&" } ], "return_type": "vector...
2,673
make-costs-of-paths-equal-in-a-binary-tree
Medium
You are given an integer n representing the number of nodes in a perfect binary tree consisting of nodes numbered from 1 to n. The root of the tree is node 1 and each node i in the tree has two children where the left child is the node 2 * i and the right child is 2 * i + 1. Each node in the tree also has a cost repre...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 31,cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(n = 7,cost = [1, 5, 2, 2, 3, 3, 1]) == 6\n assert candidate(n = 31,cost = [1, 2, 3, 4, 5, 6, 7, 8,...
[ "7\n[1,5,2,2,3,3,1]", "3\n[5,3,3]" ]
[ "The path from the root to a leaf that has the maximum cost should not be modified.", "The optimal way is to increase all other paths to make their costs equal to the path with maximum cost." ]
{ "canonical_parameter_names": [ "n", "cost" ], "leetcode_dataset_entry_point": "Solution().minIncrements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:21", "tests_total": 50, ...
cpp
{ "raw_signature": "int minIncrements(int n, vector<int>& cost) {", "container": "Solution", "callable": "minIncrements", "parameters": [ { "name": "n", "type": "int" }, { "name": "cost", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcod...
2,678
number-of-senior-citizens
Easy
You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that: - The first ten characters consist of the phone number of passengers. - The next character denotes the gender of the person. - The fol...
{ "language": "python", "source": "def check(candidate):\n assert candidate(details = ['0000000000M5500', '1111111111F5999', '2222222222O6100']) == 1\n assert candidate(details = ['1234567890M5999', '0987654321F6000']) == 0\n assert candidate(details = ['1111111111M5999', '2222222222F6000', '3333333333M600...
[ "[\"7868190130M7522\",\"5303914400F9211\",\"9273338290F4010\"]", "[\"1313579440F2036\",\"2921522980M5644\"]" ]
[ "Convert the value at index 11 and 12 to a numerical value.", "The age of the person at index i is equal to details[i][11]*10+details[i][12]." ]
{ "canonical_parameter_names": [ "details" ], "leetcode_dataset_entry_point": "Solution().countSeniors", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:23", "tests_total": 78, "tests_...
cpp
{ "raw_signature": "int countSeniors(vector<string>& details) {", "container": "Solution", "callable": "countSeniors", "parameters": [ { "name": "details", "type": "vector<string>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeS...
2,679
sum-in-a-matrix
Medium
You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty: 1. From each row in the matrix, select the largest number and remove it. In the case of a tie, it does not matter which number is chosen. 2. Identify the highest number amongst ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [[1]]) == 1\n assert candidate(nums = [[5, 4, 3], [1, 2, 3], [3, 2, 1]]) == 12\n assert candidate(nums = [[5, 3, 1], [4, 2, 1], [3, 2, 1]]) == 9\n assert candidate(nums = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0\n asser...
[ "[[7,2,1],[6,4,2],[6,5,3],[3,2,1]]", "[[1]]" ]
[ "Sort the numbers in each row in decreasing order.", "The answer is the summation of the max number in every column after sorting the rows." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().matrixSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:25", "tests_total": 103, "tests_dropp...
cpp
{ "raw_signature": "int matrixSum(vector<vector<int>>& nums) {", "container": "Solution", "callable": "matrixSum", "parameters": [ { "name": "nums", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
2,680
maximum-or
Medium
You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2. Return the maximum possible value of nums[0] | nums[1] | ... | nums[n - 1] that can be obtained after applying the operation on nums at most k times. Note that a | b denotes the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 31\n assert candidate(nums = [1, 2, 4, 8, 16],k = 3) == 143\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 8) == 256554748416\n assert candidate(nums = [3, 5, ...
[ "[12,9]\n1", "[8,1,2]\n2" ]
[ "The optimal solution should apply all the k operations on a single number.", "Calculate the prefix or and the suffix or and perform k operations over each element, and maximize the answer." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumOr", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:28", "tests_total": 114, "te...
cpp
{ "raw_signature": "long long maximumOr(vector<int>& nums, int k) {", "container": "Solution", "callable": "maximumOr", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "long long", "signature_source": "lee...
2,681
power-of-heroes
Hard
You are given a 0-indexed integer array nums representing the strength of some heroes. The power of a group of heroes is defined as follows: - Let i_0, i_1, ... ,i_k be the indices of the heroes in a group. Then, the power of this group is max(nums[i_0], nums[i_1], ... ,nums[i_k])^2 * min(nums[i_0], nums[i_1], ... ,nu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 5, 7, 2]) == 1627\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1000000000]) == 999999664\n assert candidate(nums = [3, 2, 5, 6]) == 1253\n assert candidate(nums = [3, 5, 2, 8]) == 2081\n assert...
[ "[2,1,4]", "[1,1,1]" ]
[ "Try something with sorting the array.", "For a pair of array elements nums[i] and nums[j] (i < j), the power would be nums[i]*nums[j]^2 regardless of how many elements in between are included.", "The number of subsets with the above as power will correspond to 2^(j-i-1).", "Try collecting the terms for nums[...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().sumOfPower", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:30", "tests_total": 93, "tests_dropp...
cpp
{ "raw_signature": "int sumOfPower(vector<int>& nums) {", "container": "Solution", "callable": "sumOfPower", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,682
find-the-losers-of-the-circular-game
Easy
There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the i^th friend brings you to the (i+1)^th friend for 1 <= i < n, and moving clockwise from the n^th friend brings you to the 1^st friend. The rules of ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 10,k = 5) == [2, 3, 4, 5, 7, 8, 9, 10]\n assert candidate(n = 4,k = 4) == [2, 3, 4]\n assert candidate(n = 5,k = 2) == [4, 5]\n assert candidate(n = 7,k = 3) == [2, 6, 7]\n assert candidate(n = 6,k = 1) == [3, 5, 6]\n ...
[ "5\n2", "4\n4" ]
[ "Simulate the whole game until a player receives the ball for the second time." ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().circularGameLosers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:32", "tests_total": 73, ...
cpp
{ "raw_signature": "vector<int> circularGameLosers(int n, int k) {", "container": "Solution", "callable": "circularGameLosers", "parameters": [ { "name": "n", "type": "int" }, { "name": "k", "type": "int" } ], "return_type": "vector<int>", "signature_source": "leetc...
2,683
neighboring-bitwise-xor
Medium
A 0-indexed array derived with length n is derived by computing the bitwise XOR (⊕) of adjacent values in a binary array original of length n. Specifically, for each index i in the range [0, n - 1]: - If i = n - 1, then derived[i] = original[i] ⊕ original[0]. - Otherwise, derived[i] = original[i] ⊕ original[i + 1]. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(derived = [0, 0, 0]) == True\n assert candidate(derived = [0, 0, 1, 1]) == True\n assert candidate(derived = [0, 1, 1, 0, 1]) == False\n assert candidate(derived = [1, 0, 1, 0]) == True\n assert candidate(derived = [0, 1, 0, ...
[ "[1,1,0]", "[1,1]", "[1,0]" ]
[ "Understand that from the original element, we are using each element twice to construct the derived array", "The xor-sum of the derived array should be 0 since there is always a duplicate occurrence of each element." ]
{ "canonical_parameter_names": [ "derived" ], "leetcode_dataset_entry_point": "Solution().doesValidArrayExist", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:35", "tests_total": 91, ...
cpp
{ "raw_signature": "bool doesValidArrayExist(vector<int>& derived) {", "container": "Solution", "callable": "doesValidArrayExist", "parameters": [ { "name": "derived", "type": "vector<int>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leet...
2,684
maximum-number-of-moves-in-a-grid
Medium
You are given a 0-indexed m x n matrix grid consisting of positive integers. You can start at any cell in the first column of the matrix, and traverse the grid in the following way: - From a cell (row, col), you can move to any of the cells: (row - 1, col + 1), (row, col + 1) and (row + 1, col + 1) such that the valu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 3, 5, 7], [2, 4, 6, 8], [1, 3, 5, 7]]) == 3\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == 2\n assert candidate(grid = [[10, 15, 20], [5, 9, 12], [7, 8, 10]]) == 2\n assert candidate(grid = [[5, 3, 2...
[ "[[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]]", "[[3,2,4],[2,1,9],[1,1,7]]" ]
[ "Consider using dynamic programming to find the maximum number of moves that can be made from each cell.", "The final answer will be the maximum value in cells of the first column." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().maxMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:38", "tests_total": 81, "tests_dropped...
cpp
{ "raw_signature": "int maxMoves(vector<vector<int>>& grid) {", "container": "Solution", "callable": "maxMoves", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnipp...
2,685
count-the-number-of-complete-components
Medium
You are given an integer n. There is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [a_i, b_i] denotes that there exists an undirected edge connecting vertices a_i and b_i. Return the number of complete connected components of the graph. A connec...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 2,edges = [[0, 1]]) == 1\n assert candidate(n = 1,edges = []) == 1\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [0, 2], [2, 4], [1, 3]]) == 0\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1,...
[ "6\n[[0,1],[0,2],[1,2],[3,4]]", "6\n[[0,1],[0,2],[1,2],[3,4],[3,5]]" ]
[ "Find the connected components of an undirected graph using depth-first search (DFS) or breadth-first search (BFS).", "For each connected component, count the number of nodes and edges in the component.", "A connected component is complete if and only if the number of edges in the component is equal to m*(m-1)/...
{ "canonical_parameter_names": [ "n", "edges" ], "leetcode_dataset_entry_point": "Solution().countCompleteComponents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:40", "tests_tot...
cpp
{ "raw_signature": "int countCompleteComponents(int n, vector<vector<int>>& edges) {", "container": "Solution", "callable": "countCompleteComponents", "parameters": [ { "name": "n", "type": "int" }, { "name": "edges", "type": "vector<vector<int>>&" } ], "return_type":...
2,696
minimum-string-length-after-removing-substrings
Easy
You are given a string s consisting only of uppercase English letters. You can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings "AB" or "CD" from s. Return the minimum possible length of the resulting string that you can obtain. Note that the string...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"ABCDBA\") == 2\n assert candidate(s = \"CDCDCD\") == 0\n assert candidate(s = \"ABABAB\") == 0\n assert candidate(s = \"ACBBD\") == 5\n assert candidate(s = \"ABFCACDB\") == 2\n assert candidate(s = \"AAAA\") == 4\n ...
[ "\"ABFCACDB\"", "\"ACBBD\"" ]
[ "Can we use brute force to solve the problem?", "Repeatedly traverse the string to find and remove the substrings “AB” and “CD” until no more occurrences exist.", "Can the solution be optimized using a stack?" ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:42", "tests_total": 153, "tests_dropped"...
cpp
{ "raw_signature": "int minLength(string s) {", "container": "Solution", "callable": "minLength", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,697
lexicographically-smallest-palindrome
Easy
You are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a character in s with another lowercase English letter. Your task is to make s a palindrome with the minimum number of operations possible. If there are multiple palindro...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcba\") == \"abcba\"\n assert candidate(s = \"madam\") == \"madam\"\n assert candidate(s = \"abac\") == \"aaaa\"\n assert candidate(s = \"aabbaa\") == \"aabbaa\"\n assert candidate(s = \"abcdcba\") == \"abcdcba\"\n ...
[ "\"egcfe\"", "\"abcd\"", "\"seven\"" ]
[ "We can make any string a palindrome, by simply making any character at index i equal to the character at index length - i - 1 (using 0-based indexing).", "To make it lexicographically smallest we can change the character with maximum ASCII value to the one with minimum ASCII value." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().makeSmallestPalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:44", "tests_total": 216, "t...
cpp
{ "raw_signature": "string makeSmallestPalindrome(string s) {", "container": "Solution", "callable": "makeSmallestPalindrome", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnipp...
2,698
find-the-punishment-number-of-an-integer
Medium
Given a positive integer n, return the punishment number of n. The punishment number of n is defined as the sum of the squares of all integers i such that: - 1 <= i <= n - The decimal representation of i * i can be partitioned into contiguous substrings such that the sum of the integer values of these substrings equa...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 700) == 1660140\n assert candidate(n = 800) == 3353149\n assert candidate(n = 100) == 41334\n assert candidate(n = 600) == 772866\n assert candidate(n = 37) == 1478\n assert candidate(n = 200) == 41334\n assert cand...
[ "10", "37" ]
[ "Can we generate all possible partitions of a number?", "Use a recursive algorithm that splits the number into two parts, generates all possible partitions of each part recursively, and then combines them in all possible ways." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().punishmentNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:47", "tests_total": 21, "tests_dr...
cpp
{ "raw_signature": "int punishmentNumber(int n) {", "container": "Solution", "callable": "punishmentNumber", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,699
modify-graph-edge-weights
Hard
You are given an undirected weighted connected graph containing n nodes labeled from 0 to n - 1, and an integer array edges where edges[i] = [a_i, b_i, w_i] indicates that there is an edge between nodes a_i and b_i with weight w_i. Some edges have a weight of -1 (w_i = -1), while others have a positive weight (w_i > 0...
{ "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 ...
[ "5\n[[4,1,-1],[2,0,-1],[0,3,-1],[4,3,-1]]\n0\n1\n5", "3\n[[0,1,-1],[0,2,5]]\n0\n2\n6", "4\n[[1,0,4],[1,2,3],[2,3,5],[0,3,-1]]\n0\n2\n6" ]
[ "Firstly, check that it’s actually possible to make the shortest path from source to destination equal to the target.", "If the shortest path from source to destination without the edges to be modified, is less than the target, then it is not possible.", "If the shortest path from source to destination includin...
{ "canonical_parameter_names": [ "n", "edges", "source", "destination", "target" ], "leetcode_dataset_entry_point": "Solution().modifiedGraphEdges", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetche...
cpp
{ "raw_signature": "vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {", "container": "Solution", "callable": "modifiedGraphEdges", "parameters": [ { "name": "n", "type": "int" }, { "name": "edges", "type": "ve...
2,706
buy-two-chocolates
Easy
You are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which represents your initial amount of money. You must buy exactly two chocolates in such a way that you still have some non-negative leftover money. You would like to minimize th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(prices = [99, 1],money = 100) == 0\n assert candidate(prices = [5, 4, 3, 2, 1],money = 10) == 7\n assert candidate(prices = [1, 1, 1, 1],money = 2) == 0\n assert candidate(prices = [1, 1],money = 3) == 1\n assert candidate(pr...
[ "[1,2,2]\n3", "[3,2,3]\n3" ]
[ "Sort the array and check if the money is more than or equal to the sum of the two cheapest elements." ]
{ "canonical_parameter_names": [ "prices", "money" ], "leetcode_dataset_entry_point": "Solution().buyChoco", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:54", "tests_total": 111, ...
cpp
{ "raw_signature": "int buyChoco(vector<int>& prices, int money) {", "container": "Solution", "callable": "buyChoco", "parameters": [ { "name": "prices", "type": "vector<int>&" }, { "name": "money", "type": "int" } ], "return_type": "int", "signature_source": "leetc...
2,707
extra-characters-in-a-string
Medium
You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra characters in s which are not present in any of the substrings. Return the minimum number of extra characte...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc\",dictionary = ['a', 'b', 'c']) == 0\n assert candidate(s = \"sayhelloworld\",dictionary = ['hello', 'world']) == 3\n assert candidate(s = \"abc\",dictionary = ['d', 'e']) == 3\n assert candidate(s = \"abcabcabc\",dict...
[ "\"leetscode\"\n[\"leet\",\"code\",\"leetcode\"]", "\"sayhelloworld\"\n[\"hello\",\"world\"]" ]
[ "Can we use Dynamic Programming here?", "Define DP[i] as the min extra character if breaking up s[0:i] optimally." ]
{ "canonical_parameter_names": [ "s", "dictionary" ], "leetcode_dataset_entry_point": "Solution().minExtraChar", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:56", "tests_total": 9...
cpp
{ "raw_signature": "int minExtraChar(string s, vector<string>& dictionary) {", "container": "Solution", "callable": "minExtraChar", "parameters": [ { "name": "s", "type": "string" }, { "name": "dictionary", "type": "vector<string>&" } ], "return_type": "int", "signa...
2,708
maximum-strength-of-a-group
Medium
You are given a 0-indexed integer array nums representing the score of students in an exam. The teacher would like to form one non-empty group of students with maximal strength, where the strength of a group of students of indices i_0, i_1, i_2, ... , i_k is defined as nums[i_0] * nums[i_1] * nums[i_2] * ... * nums[i_k...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == 36\n assert candidate(nums = [-9]) == -9\n assert candidate(nums = [0, 0, 0, 1, -1]) == 1\n assert candidate(nums = [-4, -5, -4]) == 20\n assert candidate(nums = [0, 2, 3, 4]) == 24\n asser...
[ "[3,-1,-5,2,5,-9]", "[-4,-5,-4]" ]
[ "Try to generate all pairs of subsets and check which group provides maximal strength.", "It can also be solved in O(NlogN) by sorting the array and using all positive integers.", "Use negative integers only in pairs such that their product becomes positive." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxStrength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:59", "tests_total": 123, "tests_dro...
cpp
{ "raw_signature": "long long maxStrength(vector<int>& nums) {", "container": "Solution", "callable": "maxStrength", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
2,709
greatest-common-divisor-traversal
Hard
You are given a 0-indexed integer array nums, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != j, if and only if gcd(nums[i], nums[j]) > 1, where gcd is the greatest common divisor. Your task is to determine if for every pair of indices i and j in nums, where i < ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 3, 6]) == True\n assert candidate(nums = [100, 200, 300, 400]) == True\n assert candidate(nums = [1, 1, 1]) == False\n assert candidate(nums = [1, 1, 1, 1]) == False\n assert candidate(nums = [7, 14, 21, 35]) == Tr...
[ "[2,3,6]", "[3,9,5]", "[4,3,12,8]" ]
[ "Create a (prime) factor-numbers list for all the indices.", "Add an edge between the neighbors of the (prime) factor-numbers list. The order of the numbers doesn’t matter. We only need edges between 2 neighbors instead of edges for all pairs.", "The problem is now similar to checking if all the numbers (nodes ...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().canTraverseAllPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:01", "tests_total": 134, "t...
cpp
{ "raw_signature": "bool canTraverseAllPairs(vector<int>& nums) {", "container": "Solution", "callable": "canTraverseAllPairs", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/c...
2,710
remove-trailing-zeros-from-a-string
Easy
Given a positive integer num represented as a string, return the integer num without trailing zeros as a string. Example 1: Input: num = "51230100" Output: "512301" Explanation: Integer "51230100" has 2 trailing zeros, we remove them and return integer "512301". Example 2: Input: num = "123" Output: "123" Explanati...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = \"10\") == \"1\"\n assert candidate(num = \"100100\") == \"1001\"\n assert candidate(num = \"1111111111\") == \"1111111111\"\n assert candidate(num = \"1000\") == \"1\"\n assert candidate(num = \"1\") == \"1\"\n asse...
[ "\"51230100\"", "\"123\"" ]
[ "Find the last non-zero digit in num." ]
{ "canonical_parameter_names": [ "num" ], "leetcode_dataset_entry_point": "Solution().removeTrailingZeros", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:03", "tests_total": 24, "tes...
cpp
{ "raw_signature": "string removeTrailingZeros(string num) {", "container": "Solution", "callable": "removeTrailingZeros", "parameters": [ { "name": "num", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
2,711
difference-of-number-of-distinct-values-on-diagonals
Medium
Given a 2D grid of size m x n, you should find the matrix answer of size m x n. The cell answer[r][c] is calculated by looking at the diagonal values of the cell grid[r][c]: - Let leftAbove[r][c] be the number of distinct values on the diagonal to the left and above the cell grid[r][c] not including the cell grid[r][...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == [[1, 1, 0], [1, 0, 1], [0, 1, 1]]\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert...
[ "[[1,2,3],[3,1,5],[3,2,1]]", "[[1]]" ]
[ "Use the set to count the number of distinct elements on diagonals." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().differenceOfDistinctValues", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:06", "tests_total": 91...
cpp
{ "raw_signature": "vector<vector<int>> differenceOfDistinctValues(vector<vector<int>>& grid) {", "container": "Solution", "callable": "differenceOfDistinctValues", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "vector<vector<int>>", "signature_so...
2,712
minimum-cost-to-make-all-characters-equal
Medium
You are given a 0-indexed binary string s of length n on which you can apply two types of operations: - Choose an index i and invert all characters from index 0 to index i (both inclusive), with a cost of i + 1 - Choose an index i and invert all characters from index i to index n - 1 (both inclusive), with a cost of n...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"100100100\") == 13\n assert candidate(s = \"00000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"110011\") == 4\n assert candidate(s = \"11110000\") == 4\n assert candidate(s = \"100010001...
[ "\"0011\"", "\"010101\"" ]
[ "For every index i, calculate the number of operations required to make the prefix [0, i - 1] equal to the character at index i, denoted prefix[i].", "For every index i, calculate the number of operations required to make the suffix [i + 1, n - 1] equal to the character at index i, denoted suffix[i].", "The fin...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:08", "tests_total": 162, "tests_droppe...
cpp
{ "raw_signature": "long long minimumCost(string s) {", "container": "Solution", "callable": "minimumCost", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,713
maximum-strictly-increasing-cells-in-a-matrix
Hard
Given a 1-indexed m x n integer matrix mat, you can select any cell in the matrix as your starting cell. From the starting cell, you can move to any other cell in the same row or column, but only if the value of the destination cell is strictly greater than the value of the current cell. You can repeat this process as...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[10, 20, 30], [15, 25, 35], [20, 30, 40]]) == 5\n assert candidate(mat = [[1]]) == 1\n assert candidate(mat = [[-100000, 100000], [-100000, 100000]]) == 2\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]...
[ "[[3,1],[3,4]]", "[[1,1],[1,1]]", "[[3,1,6],[-9,5,7]]" ]
[ "We can try to build the answer in a bottom-up fashion, starting from the smallest values and increasing to the larger values.", "Going through the values in sorted order, we can store the maximum path we have seen so far for a row/column.", "When we are at a cell, we check its row and column to find out the be...
{ "canonical_parameter_names": [ "mat" ], "leetcode_dataset_entry_point": "Solution().maxIncreasingCells", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:11", "tests_total": 106, "tes...
cpp
{ "raw_signature": "int maxIncreasingCells(vector<vector<int>>& mat) {", "container": "Solution", "callable": "maxIncreasingCells", "parameters": [ { "name": "mat", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "...
2,716
minimize-string-length
Easy
Given a string s, you have two types of operation: 1. Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the left of i (if exists). 2. Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the right...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aaabc\") == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"abacabadabacaba\") == 4\n assert candidate(s = \"abcabcabc\") == 3\n assert candi...
[ "\"aaabc\"", "\"cbbd\"", "\"baadccab\"" ]
[ "The minimized string will not contain duplicate characters.", "The minimized string will contain all distinct characters of the original string." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minimizedStringLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:15", "tests_total": 112, "te...
cpp
{ "raw_signature": "int minimizedStringLength(string s) {", "container": "Solution", "callable": "minimizedStringLength", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,717
semi-ordered-permutation
Easy
You are given a 0-indexed permutation of n integers nums. A permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want until you make nums a semi-ordered permutation: - Pick two adjacent elements in nums, then swap them. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 7\n assert candidate(nums = [2, 4, 1, 3]) == 3\n assert candidate(nums = [3, 5, 4, 1, 2]) == 5\n assert candidate(nums = [3, 1, 2, 5, 4]) == 2\n assert candidate(nums = [1, 5, 4, 3, 2]) == 3\n as...
[ "[2,1,4,3]", "[2,4,1,3]", "[1,3,4,2,5]" ]
[ "Find the index of elements 1 and n.", "Let x be the position of 1 and y be the position of n. the answer is x + (n-y-1) if x < y and x + (n-y-1) - 1 if x > y." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().semiOrderedPermutation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:17", "tests_total": 99, ...
cpp
{ "raw_signature": "int semiOrderedPermutation(vector<int>& nums) {", "container": "Solution", "callable": "semiOrderedPermutation", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
2,718
sum-of-matrix-after-queries
Medium
You are given an integer n and a 0-indexed 2D array queries where queries[i] = [type_i, index_i, val_i]. Initially, there is a 0-indexed n x n matrix filled with 0's. For each query, you must apply one of the following changes: - if type_i == 0, set the values in the row with index_i to val_i, overwriting any previou...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 2,queries = [[0, 0, 1], [1, 0, 2], [0, 1, 3], [1, 1, 4]]) == 13\n assert candidate(n = 5,queries = [[0, 1, 10], [1, 2, 5], [0, 4, 7], [1, 0, 3]]) == 93\n assert candidate(n = 4,queries = [[1, 3, 2], [0, 1, 5], [1, 0, 3], [0, 2,...
[ "3\n[[0,0,1],[1,2,2],[0,2,3],[1,0,4]]", "3\n[[0,0,4],[0,1,2],[1,0,1],[0,2,3],[1,2,1]]" ]
[ "Process queries in reversed order, as the latest queries represent the most recent changes in the matrix.", "Once you encounter an operation on some row/column, no further operations will affect the values in this row/column. Keep track of seen rows and columns with a set.", "When operating on an unseen row/co...
{ "canonical_parameter_names": [ "n", "queries" ], "leetcode_dataset_entry_point": "Solution().matrixSumQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:20", "tests_total": ...
cpp
{ "raw_signature": "long long matrixSumQueries(int n, vector<vector<int>>& queries) {", "container": "Solution", "callable": "matrixSumQueries", "parameters": [ { "name": "n", "type": "int" }, { "name": "queries", "type": "vector<vector<int>>&" } ], "return_type": "lo...
2,719
count-of-integers
Hard
You are given two numeric strings num1 and num2 and two integers max_sum and min_sum. We denote an integer x to be good if: - num1 <= x <= num2 - min_sum <= digit_sum(x) <= max_sum. Return the number of good integers. Since the answer may be large, return it modulo 10^9 + 7. Note that digit_sum(x) denotes the sum of...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num1 = \"1\",num2 = \"5\",min_sum = 1,max_sum = 5) == 5\n assert candidate(num1 = \"1\",num2 = \"1000000000000000000000000000000\",min_sum = 300,max_sum = 400) == 0\n assert candidate(num1 = \"999999999999999999999999999999\",num2 ...
[ "\"1\"\n\"12\"\n1\n8", "\"1\"\n\"5\"\n1\n5" ]
[ "Let f(n, l, r) denotes the number of integers from 1 to n with the sum of digits between l and r.", "The answer is f(num2, min_sum, max_sum) - f(num1-1, min_sum, max_sum).", "You can calculate f(n, l, r) using digit dp." ]
{ "canonical_parameter_names": [ "num1", "num2", "min_sum", "max_sum" ], "leetcode_dataset_entry_point": "Solution().count", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:22"...
cpp
{ "raw_signature": "int count(string num1, string num2, int min_sum, int max_sum) {", "container": "Solution", "callable": "count", "parameters": [ { "name": "num1", "type": "string" }, { "name": "num2", "type": "string" }, { "name": "min_sum", "type": "in...
2,729
check-if-the-number-is-fascinating
Easy
You are given an integer n that consists of exactly 3 digits. We call the number n fascinating if, after the following modification, the resulting number contains all the digits from 1 to 9 exactly once and does not contain any 0's: - Concatenate n with the numbers 2 * n and 3 * n. Return true if n is fascinating, o...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 933) == False\n assert candidate(n = 147) == False\n assert candidate(n = 576) == False\n assert candidate(n = 789) == False\n assert candidate(n = 579) == False\n assert candidate(n = 273) == True\n assert candidat...
[ "192", "100" ]
[ "Consider changing the number to the way it is described in the statement.", "Check if the resulting number contains all the digits from 1 to 9 exactly once." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().isFascinating", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:25", "tests_total": 60, "tests_dropp...
cpp
{ "raw_signature": "bool isFascinating(int n) {", "container": "Solution", "callable": "isFascinating", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,730
find-the-longest-semi-repetitive-substring
Medium
You are given a digit string s that consists of digits from 0 to 9. A string is called semi-repetitive if there is at most one adjacent pair of the same digit. For example, "0010", "002020", "0123", "2002", and "54944" are semi-repetitive while the following are not: "00101022" (adjacent same digit pairs are 00 and 22...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == 2\n assert candidate(s = \"9876543210\") == 10\n assert candidate(s = \"111222333\") == 3\n assert candidate(s = \"88888888888\") == 2\n assert candidate(s = \"87878787878787878\") == 17\n assert candidate...
[ "\"52233\"", "\"5494\"", "\"1111111\"" ]
[ "Since n is small, we can just check every substring, and if the substring is semi-repetitive, maximize the answer with its length." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().longestSemiRepetitiveSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:27", "tests_total": 1...
cpp
{ "raw_signature": "int longestSemiRepetitiveSubstring(string s) {", "container": "Solution", "callable": "longestSemiRepetitiveSubstring", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode...
2,731
movement-of-robots
Medium
Some robots are standing on an infinite number line with their initial coordinates given by a 0-indexed integer array nums and will start moving once given the command to move. The robots will move a unit distance each second. You are given a string s denoting the direction in which robots will move on command. 'L' me...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, 2, -3, 4],s = \"RLRL\",d = 5) == 24\n assert candidate(nums = [-5, 1, 4],s = \"RLR\",d = 4) == 22\n assert candidate(nums = [-5, -1, 0, 3, 7],s = \"RLLLR\",d = 5) == 82\n assert candidate(nums = [-10, -20, -30],s = \...
[ "[-2,0,2]\n\"RLL\"\n3", "[1,0]\n\"RL\"\n2" ]
[ "Observe that if you ignore collisions, the resultant positions of robots after d seconds would be the same.", "After d seconds, sort the ending positions and use prefix sum to calculate the distance sum." ]
{ "canonical_parameter_names": [ "nums", "s", "d" ], "leetcode_dataset_entry_point": "Solution().sumDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:29", "tests_total":...
cpp
{ "raw_signature": "int sumDistance(vector<int>& nums, string s, int d) {", "container": "Solution", "callable": "sumDistance", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "s", "type": "string" }, { "name": "d", "type": "int" ...
2,732
find-a-good-subset-of-the-matrix
Hard
You are given a 0-indexed m x n binary matrix grid. Let us call a non-empty subset of rows good if the sum of each column of the subset is at most half of the length of the subset. More formally, if the length of the chosen subset of rows is k, then the sum of each column should be at most floor(k / 2). Return an in...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 1, 0]]) == [2, 3]\n assert candidate(grid = [[0, 0, 0, 0], [1, 0, 0, 1], [0, 1, 1, 0]]) == [0]\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [1, 0, 0]]) == [0]\n assert candidate(g...
[ "[[0,1,1,0],[0,0,0,1],[1,1,1,1]]", "[[0]]", "[[1,1,1],[1,1,1]]" ]
[ "It can be proven, that if there exists a good subset of rows then there exists a good subset of rows with the size of either 1 or 2.", "To check if there exists a good subset of rows of size 1, we check if there exists a row containing only zeros, if it does, we return its index as a good subset.", "To check i...
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().goodSubsetofBinaryMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:32", "tests_total": 86, ...
cpp
{ "raw_signature": "vector<int> goodSubsetofBinaryMatrix(vector<vector<int>>& grid) {", "container": "Solution", "callable": "goodSubsetofBinaryMatrix", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/cod...
2,733
neither-minimum-nor-maximum
Easy
Given an integer array nums containing distinct positive integers, find and return any number from the array that is neither the minimum nor the maximum value in the array, or -1 if there is no such number. Return the selected integer. Example 1: Input: nums = [3,2,1,4] Output: 2 Explanation: In this example, the mi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1]) == -1\n assert candidate(nums = [1, 3, 2]) == 2\n assert candidate(nums = [9, 5, 6]) == 6\n assert candidate(nums = [9, 11, 10]) == 10\n assert candidate(nums = [1, 2]) == -1\n assert candidate(nums = [7, 8, 9]...
[ "[3,2,1,4]", "[1,2]", "[2,1,3]" ]
[ "Find any value in the array that is not the minimum or the maximum value." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findNonMinOrMax", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:34", "tests_total": 94, "tests_...
cpp
{ "raw_signature": "int findNonMinOrMax(vector<int>& nums) {", "container": "Solution", "callable": "findNonMinOrMax", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
2,734
lexicographically-smallest-string-after-substring-operation
Medium
Given a string s consisting of lowercase English letters. Perform the following operation: - Select any non-empty substring then replace every letter of the substring with the preceding letter of the English alphabet. For example, 'b' is converted to 'a', and 'a' is converted to 'z'. Return the lexicographically smal...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abz\") == \"aay\"\n assert candidate(s = \"azazaz\") == \"ayazaz\"\n assert candidate(s = \"zzzz\") == \"yyyy\"\n assert candidate(s = \"azaza\") == \"ayaza\"\n assert candidate(s = \"acbbc\") == \"abaab\"\n assert c...
[ "\"cbabc\"", "\"aa\"", "\"acbbc\"", "\"leetcode\"" ]
[ "When a character is replaced by the one that comes before it on the alphabet, it makes the string lexicographically smaller, except for ‘a'.", "Find the leftmost substring that doesn’t contain the character 'a' and change all characters in it." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().smallestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:36", "tests_total": 102, "tests_dro...
cpp
{ "raw_signature": "string smallestString(string s) {", "container": "Solution", "callable": "smallestString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,735
collecting-chocolates
Medium
You are given a 0-indexed integer array nums of size n representing the cost of collecting different chocolates. The cost of collecting the chocolate at the index i is nums[i]. Each chocolate is of a different type, and initially, the chocolate at the index i is of i^th type. In one operation, you can do the following...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],x = 10) == 90\n assert candidate(nums = [10, 20, 30, 40],x = 10) == 70\n assert candidate(nums = [1, 1, 1, 1, 1],x = 1) == 5\n assert candidate(nums = [7, 7, 7, 7, 7, 7],x = 2) == 42\n assert candi...
[ "[20,1,15]\n5", "[1,2,3]\n4" ]
[ "How many maximum rotations will be needed?", "The array will be rotated for a max of N times, so try all possibilities as N = 1000." ]
{ "canonical_parameter_names": [ "nums", "x" ], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:39", "tests_total": 100, "test...
cpp
{ "raw_signature": "long long minCost(vector<int>& nums, int x) {", "container": "Solution", "callable": "minCost", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "x", "type": "int" } ], "return_type": "long long", "signature_source": "leetcod...
2,736
maximum-sum-queries
Hard
You are given two 0-indexed integer arrays nums1 and nums2, each of length n, and a 1-indexed 2D array queries where queries[i] = [x_i, y_i]. For the i^th query, find the maximum value of nums1[j] + nums2[j] among all indices j (0 <= j < n), where nums1[j] >= x_i and nums2[j] >= y_i, or -1 if there is no j satisfying ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [4, 3, 1, 2],nums2 = [2, 4, 9, 5],queries = [[4, 1], [1, 3], [2, 5]]) == [6, 10, 7]\n assert candidate(nums1 = [2, 1],nums2 = [2, 3],queries = [[3, 3]]) == [-1]\n assert candidate(nums1 = [3, 2, 5],nums2 = [2, 3, 4],queries...
[ "[4,3,1,2]\n[2,4,9,5]\n[[4,1],[1,3],[2,5]]", "[3,2,5]\n[2,3,4]\n[[4,4],[3,2],[1,1]]", "[2,1]\n[2,3]\n[[3,3]]" ]
[ "Sort (x, y) tuples and queries by x-coordinate descending. Don’t forget to index queries before sorting so that you can answer them in the correct order.", "Before answering a query (min_x, min_y), add all (x, y) pairs with x >= min_x to some data structure.", "Use a monotone descending map to store (y, x + y)...
{ "canonical_parameter_names": [ "nums1", "nums2", "queries" ], "leetcode_dataset_entry_point": "Solution().maximumSumQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:41",...
cpp
{ "raw_signature": "vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& queries) {", "container": "Solution", "callable": "maximumSumQueries", "parameters": [ { "name": "nums1", "type": "vector<int>&" }, { "name": "nums2", "type": "vecto...
2,739
total-distance-traveled
Easy
A truck has two fuel tanks. You are given two integers, mainTank representing the fuel present in the main tank in liters and additionalTank representing the fuel present in the additional tank in liters. The truck has a mileage of 10 km per liter. Whenever 5 liters of fuel get used up in the main tank, if the additio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mainTank = 100,additionalTank = 100) == 1240\n assert candidate(mainTank = 5,additionalTank = 10) == 60\n assert candidate(mainTank = 7,additionalTank = 3) == 80\n assert candidate(mainTank = 1,additionalTank = 2) == 10\n ass...
[ "5\n10", "1\n2" ]
[ "Avoid calculations in decimal to prevent precision errors." ]
{ "canonical_parameter_names": [ "mainTank", "additionalTank" ], "leetcode_dataset_entry_point": "Solution().distanceTraveled", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:46", "...
cpp
{ "raw_signature": "int distanceTraveled(int mainTank, int additionalTank) {", "container": "Solution", "callable": "distanceTraveled", "parameters": [ { "name": "mainTank", "type": "int" }, { "name": "additionalTank", "type": "int" } ], "return_type": "int", "signa...
2,740
find-the-value-of-the-partition
Medium
You are given a positive integer array nums. Partition nums into two arrays, nums1 and nums2, such that: - Each element of the array nums belongs to either the array nums1 or the array nums2. - Both arrays are non-empty. - The value of the partition is minimized. The value of the partition is |max(nums1) - min(nums2...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1000000000]) == 999999999\n assert candidate(nums = [5, 1, 3, 2, 4]) == 1\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [2, 2, 2, 2, 2]) == 0\n assert candidate(nums = [5, 1, 3, 19...
[ "[1,3,2,4]", "[100,1,10]" ]
[ "Sort the array.", "The answer is min(nums[i+1] - nums[i]) for all i in the range [0, n-2]." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findValueOfPartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:48", "tests_total": 106, "...
cpp
{ "raw_signature": "int findValueOfPartition(vector<int>& nums) {", "container": "Solution", "callable": "findValueOfPartition", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/c...
2,741
special-permutations
Medium
You are given a 0-indexed integer array nums containing n distinct positive integers. A permutation of nums is called special if: - For all indexes 0 <= i < n - 1, either nums[i] % nums[i+1] == 0 or nums[i+1] % nums[i] == 0. Return the total number of special permutations. As the answer could be large, return it modu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [31, 62, 93, 124, 155]) == 0\n assert candidate(nums = [2, 3, 6]) == 2\n assert candidate(nums = [17, 34, 51, 68, 85]) == 0\n assert candidate(nums = [7, 14, 28, 56, 112]) == 120\n assert candidate(nums = [1, 2, 3, 4, ...
[ "[2,3,6]", "[1,4,3]" ]
[ "Can we solve this problem using DP with bit masking?", "You just need two states in DP which are last_ind in the permutation and the mask of numbers already used." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().specialPerm", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:51", "tests_total": 99, "tests_drop...
cpp
{ "raw_signature": "int specialPerm(vector<int>& nums) {", "container": "Solution", "callable": "specialPerm", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,742
painting-the-walls
Hard
You are given two 0-indexed integer arrays, cost and time, of size n representing the costs and the time taken to paint n different walls respectively. There are two painters available: - A paid painter that paints the i^th wall in time[i] units of time and takes cost[i] units of money. - A free painter that paints an...
{ "language": "python", "source": "def check(candidate):\n assert candidate(cost = [4, 4, 4, 4],time = [4, 4, 4, 4]) == 4\n assert candidate(cost = [5, 8, 4, 3],time = [2, 3, 1, 2]) == 7\n assert candidate(cost = [10, 20, 30, 40],time = [5, 4, 3, 2]) == 10\n assert candidate(cost = [10, 20, 30, 40, 50],...
[ "[1,2,3,2]\n[1,2,3,2]", "[2,3,4,2]\n[1,1,1,1]" ]
[ "Can we break the problem down into smaller subproblems and use DP?", "If you pay for wall i, it contributes cost[i] and effectively covers time[i] + 1 walls: the paid wall itself plus up to time[i] walls that the free painter can paint while the paid painter works.", "Use DP over the number of walls covered, c...
{ "canonical_parameter_names": [ "cost", "time" ], "leetcode_dataset_entry_point": "Solution().paintWalls", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:53", "tests_total": 93, ...
cpp
{ "raw_signature": "int paintWalls(vector<int>& cost, vector<int>& time) {", "container": "Solution", "callable": "paintWalls", "parameters": [ { "name": "cost", "type": "vector<int>&" }, { "name": "time", "type": "vector<int>&" } ], "return_type": "int", "signature...
2,744
find-maximum-number-of-string-pairs
Easy
You are given a 0-indexed array words consisting of distinct strings. The string words[i] can be paired with the string words[j] if: - The string words[i] is equal to the reversed string of words[j]. - 0 <= i < j < words.length. Return the maximum number of pairs that can be formed from the array words. Note that e...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji']) == 5\n assert candidate(words = ['mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts']) == 4\n assert candidate(words = ['uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'ab', 'ba'...
[ "[\"cd\",\"ac\",\"dc\",\"ca\",\"zz\"]", "[\"ab\",\"ba\",\"cc\"]", "[\"aa\",\"ab\"]" ]
[ "Notice that array words consist of distinct strings.", "Iterate over all indices (i, j) and check if they can be paired." ]
{ "canonical_parameter_names": [ "words" ], "leetcode_dataset_entry_point": "Solution().maximumNumberOfStringPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:57", "tests_total": 6...
cpp
{ "raw_signature": "int maximumNumberOfStringPairs(vector<string>& words) {", "container": "Solution", "callable": "maximumNumberOfStringPairs", "parameters": [ { "name": "words", "type": "vector<string>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_...
2,745
construct-the-longest-new-string
Medium
You are given three integers x, y, and z. You have x strings equal to "AA", y strings equal to "BB", and z strings equal to "AB". You want to choose some (possibly all or none) of these strings and concatenate them in some order to form a new string. This new string must not contain "AAA" or "BBB" as a substring. Ret...
{ "language": "python", "source": "def check(candidate):\n assert candidate(x = 1,y = 10,z = 10) == 26\n assert candidate(x = 50,y = 50,z = 50) == 300\n assert candidate(x = 10,y = 1,z = 10) == 26\n assert candidate(x = 20,y = 10,z = 5) == 52\n assert candidate(x = 10,y = 10,z = 1) == 42\n assert ...
[ "2\n5\n1", "3\n2\n2" ]
[ "It can be proved that ALL “AB”s can be used in the optimal solution. (1) If the final string starts with 'A', we can put all unused “AB”s at the very beginning. (2) If the final string starts with 'B' (meaning) it starts with “BB”, we can put all unused “AB”s after the 2nd 'B'.", "Using “AB” doesn’t increase the...
{ "canonical_parameter_names": [ "x", "y", "z" ], "leetcode_dataset_entry_point": "Solution().longestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:00", "tests_total": ...
cpp
{ "raw_signature": "int longestString(int x, int y, int z) {", "container": "Solution", "callable": "longestString", "parameters": [ { "name": "x", "type": "int" }, { "name": "y", "type": "int" }, { "name": "z", "type": "int" } ], "return_type": "i...
2,746
decremental-string-concatenation
Medium
You are given a 0-indexed array words containing n strings. Let's define a join operation join(x, y) between two strings x and y as concatenating them into xy. However, if the last character of x is equal to the first character of y, one of them is deleted. For example join("ab", "ba") = "aba" and join("ab", "cde") =...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['abcd', 'de', 'efg', 'gh']) == 8\n assert candidate(words = ['abcd', 'dcba', 'abdc', 'cdab']) == 13\n assert candidate(words = ['x', 'y', 'z', 'x', 'y', 'z']) == 4\n assert candidate(words = ['ab', 'bc', 'cd', 'da']) ==...
[ "[\"aa\",\"ab\",\"bc\"]", "[\"ab\",\"b\"]", "[\"aaa\",\"c\",\"aba\"]" ]
[ "Use dynamic programming with memoization.", "Notice that the first and last characters of a string are sufficient to determine the length of its concatenation with any other string.", "Define dp[i][first][last] as the shortest concatenation length of the first i words starting with a character first and ending...
{ "canonical_parameter_names": [ "words" ], "leetcode_dataset_entry_point": "Solution().minimizeConcatenatedLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:02", "tests_total": 8...
cpp
{ "raw_signature": "int minimizeConcatenatedLength(vector<string>& words) {", "container": "Solution", "callable": "minimizeConcatenatedLength", "parameters": [ { "name": "words", "type": "vector<string>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_...
2,747
count-zero-request-servers
Medium
You are given an integer n denoting the total number of servers and a 2D 0-indexed integer array logs, where logs[i] = [server_id, time] denotes that the server with id server_id received a request at time time. You are also given an integer x and a 0-indexed integer array queries. Return a 0-indexed integer array ar...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 1,logs = [[1, 1]],x = 1,queries = [2]) == [0]\n assert candidate(n = 10,logs = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],x = 10,queries = [20, 50, 80, 110]) == [8, 8, 8, 9]\n a...
[ "3\n[[1,3],[2,6],[1,5]]\n5\n[10,11]", "3\n[[2,4],[2,1],[1,2],[3,1]]\n2\n[3,4]" ]
[ "Can we use sorting and two-pointer approach here?", "Sort the queries array and logs array based on time in increasing order.", "For every window of size x, use sliding window and two-pointer approach to find the answer to the queries." ]
{ "canonical_parameter_names": [ "n", "logs", "x", "queries" ], "leetcode_dataset_entry_point": "Solution().countServers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:05", ...
cpp
{ "raw_signature": "vector<int> countServers(int n, vector<vector<int>>& logs, int x, vector<int>& queries) {", "container": "Solution", "callable": "countServers", "parameters": [ { "name": "n", "type": "int" }, { "name": "logs", "type": "vector<vector<int>>&" }, { ...
2,748
number-of-beautiful-pairs
Easy
You are given a 0-indexed integer array nums. A pair of indices i, j where 0 <= i < j < nums.length is called beautiful if the first digit of nums[i] and the last digit of nums[j] are coprime. Return the total number of beautiful pairs in nums. Two integers x and y are coprime if there is no integer greater than 1 th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [34, 23, 12, 45, 56]) == 5\n assert candidate(nums = [33, 14, 25, 78]) == 5\n assert candidate(nums = [123, 456, 789, 101, 202]) == 9\n assert candidate(nums = [13, 31, 17, 71]) == 6\n assert candidate(nums = [111, 222...
[ "[2,5,1,4]", "[11,21,12]" ]
[ "Since nums.length is small, you can find all pairs of indices and check if each pair is beautiful.", "Use integer to string conversion to get the first and last digit of each number." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countBeautifulPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:07", "tests_total": 102, "t...
cpp
{ "raw_signature": "int countBeautifulPairs(vector<int>& nums) {", "container": "Solution", "callable": "countBeautifulPairs", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...
2,749
minimum-operations-to-make-the-integer-zero
Medium
You are given two integers num1 and num2. In one operation, you can choose integer i in the range [0, 60] and subtract 2^i + num2 from num1. Return the integer denoting the minimum number of operations needed to make num1 equal to 0. If it is impossible to make num1 equal to 0, return -1. Example 1: Input: num1 = ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num1 = 8,num2 = 2) == 2\n assert candidate(num1 = 8,num2 = -1) == 2\n assert candidate(num1 = 7,num2 = -3) == 3\n assert candidate(num1 = 1,num2 = 0) == 1\n assert candidate(num1 = 15,num2 = -3) == 3\n assert candidate(num...
[ "3\n-2", "5\n7" ]
[ "If we want to make integer n equal to 0 by only subtracting powers of 2 from n, in how many operations can we achieve it?", "We need at least - the number of bits in the binary representation of n, and at most - n.", "Notice that, if it is possible to make num1 equal to 0, then we need at most 60 operations.",...
{ "canonical_parameter_names": [ "num1", "num2" ], "leetcode_dataset_entry_point": "Solution().makeTheIntegerZero", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:09", "tests_total"...
cpp
{ "raw_signature": "int makeTheIntegerZero(int num1, int num2) {", "container": "Solution", "callable": "makeTheIntegerZero", "parameters": [ { "name": "num1", "type": "int" }, { "name": "num2", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/...
2,750
ways-to-split-array-into-good-subarrays
Medium
You are given a binary array nums. A subarray of an array is good if it contains exactly one element with the value 1. Return an integer denoting the number of ways to split the array nums into good subarrays. As the number may be too large, return it modulo 10^9 + 7. A subarray is a contiguous non-empty sequence of...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 0, 0, 1]) == 3\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 1]) == 8\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1]) == 9\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 1, 0, 0...
[ "[0,1,0,0,1]", "[0,1,0]" ]
[ "If the array consists of only 0s answer is 0.", "In the final split, exactly one separation point exists between two consecutive 1s.", "In how many ways can separation points be put?" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().numberOfGoodSubarraySplits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:12", "tests_total": 87...
cpp
{ "raw_signature": "int numberOfGoodSubarraySplits(vector<int>& nums) {", "container": "Solution", "callable": "numberOfGoodSubarraySplits", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source":...
2,751
robot-collisions
Hard
There are n 1-indexed robots, each having a position on a line, health, and movement direction. You are given 0-indexed integer arrays positions, healths, and a string directions (directions[i] is either 'L' for left or 'R' for right). All integers in positions are unique. All robots start moving on the line simultan...
{ "language": "python", "source": "def check(candidate):\n assert candidate(positions = [2, 4, 6, 8, 10],healths = [30, 25, 20, 15, 10],directions = \"LLRRR\") == [30, 25, 20, 15, 10]\n assert candidate(positions = [2, 4, 6, 8],healths = [1, 2, 3, 4],directions = \"LLLL\") == [1, 2, 3, 4]\n assert candidat...
[ "[5,4,3,2,1]\n[2,17,9,15,10]\n\"RRRRR\"", "[3,5,2,6]\n[10,10,15,12]\n\"RLRL\"", "[1,2,5,6]\n[10,10,11,11]\n\"RLRL\"" ]
[ "Process the robots in the order of their positions to ensure that we process the collisions correctly.", "To optimize the solution, use a stack to keep track of the surviving robots as we iterate through the positions.", "Instead of simulating each collision, check the current robot against the top of the stac...
{ "canonical_parameter_names": [ "positions", "healths", "directions" ], "leetcode_dataset_entry_point": "Solution().survivedRobotsHealths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-...
cpp
{ "raw_signature": "vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {", "container": "Solution", "callable": "survivedRobotsHealths", "parameters": [ { "name": "positions", "type": "vector<int>&" }, { "name": "healths", "type...
2,760
longest-even-odd-subarray-with-threshold
Easy
You are given a 0-indexed integer array nums and an integer threshold. Find the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following conditions: - nums[l] % 2 == 0 - For all indices i in the range [l, r - 1], nums[i] % 2 != nums[i + ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 10) == 9\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1],threshold = 2) == 10\n assert candidate(nums = [2, 3, 4, 5],threshold = 4) == 3\n assert candidate(nums = [6, 1...
[ "[3,2,5,4]\n5", "[1,2]\n2", "[2,3,4,5]\n4" ]
[ "Brute force all the possible subarrays and find the longest that satisfies the conditions." ]
{ "canonical_parameter_names": [ "nums", "threshold" ], "leetcode_dataset_entry_point": "Solution().longestAlternatingSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:17", ...
cpp
{ "raw_signature": "int longestAlternatingSubarray(vector<int>& nums, int threshold) {", "container": "Solution", "callable": "longestAlternatingSubarray", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "threshold", "type": "int" } ], "return_ty...
2,761
prime-pairs-with-target-sum
Medium
You are given an integer n. We say that two integers x and y form a prime number pair if: - 1 <= x <= y <= n - x + y == n - x and y are prime numbers Return the 2D sorted list of prime number pairs [x_i, y_i]. The list should be sorted in increasing order of x_i. If there are no prime number pairs at all, return an e...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 11) == []\n assert candidate(n = 20) == [[3, 17], [7, 13]]\n assert candidate(n = 2) == []\n assert candidate(n = 10) == [[3, 7], [5, 5]]\n assert candidate(n = 3) == []\n assert candidate(n = 29) == []\n assert can...
[ "10", "2" ]
[ "Pre-compute all the prime numbers in the range [1, n] using a sieve, and store them in a data structure where they can be accessed in O(1) time.", "For x in the range [2, n/2], we can use the pre-computed list of prime numbers to check if both x and n - x are primes. If they are, we add them to the result." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().findPrimePairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:19", "tests_total": 52, "tests_drop...
cpp
{ "raw_signature": "vector<vector<int>> findPrimePairs(int n) {", "container": "Solution", "callable": "findPrimePairs", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "vector<vector<int>>", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeS...
2,762
continuous-subarrays
Medium
You are given a 0-indexed integer array nums. A subarray of nums is called continuous if: - Let i, i + 1, ..., jbe the indices in the subarray. Then, for each pair of indices i <= i_1, i_2 <= j, 0 <= |nums[i_1] - nums[i_2]| <= 2. Return the total number of continuous subarrays. A subarray is a contiguous non-empty s...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 2, 4]) == 8\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 4]) == 27\n assert candidate(nums = [9, 7, 5, 3, 1]) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 27\n assert candidate(nums = [9, 8...
[ "[5,4,2,4]", "[1,2,3]" ]
[ "Try using the sliding window technique.", "Use a set or map to keep track of the maximum and minimum of subarrays." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().continuousSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:22", "tests_total": 234, "t...
cpp
{ "raw_signature": "long long continuousSubarrays(vector<int>& nums) {", "container": "Solution", "callable": "continuousSubarrays", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "...
2,763
sum-of-imbalance-numbers-of-all-subarrays
Hard
The imbalance number of a 0-indexed integer array arr of length n is defined as the number of indices in sarr = sorted(arr) such that: - 0 <= i < n - 1, and - sarr[i+1] - sarr[i] > 1 Here, sorted(arr) is the function that returns the sorted version of arr. Given a 0-indexed integer array nums, return the sum of imba...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [2, 3, 1, 4]) == 3\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 8\n assert candidate(nums = [1, 2, 2, 3, ...
[ "[2,3,1,4]", "[1,3,3,3,5]" ]
[ "Iterate over all subarrays in a nested fashion. Namely, for each left endpoint, start from nums[left] and add elements nums[left + 1], nums[left + 2], etc.", "To keep track of the imbalance value, maintain a set of added elements.", "Increment the imbalance value whenever a new number is not adjacent (+/- 1) t...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().sumImbalanceNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:24", "tests_total": 181, "t...
cpp
{ "raw_signature": "int sumImbalanceNumbers(vector<int>& nums) {", "container": "Solution", "callable": "sumImbalanceNumbers", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...
2,765
longest-alternating-subarray
Easy
You are given a 0-indexed integer array nums. A subarray s of length m is called alternating if: - m is greater than 1. - s_1 = s_0 + 1. - The 0-indexed subarray s looks like [s_0, s_1, s_0, s_1,...,s_{(m-1) % 2}]. In other words, s_1 - s_0 = 1, s_2 - s_1 = -1, s_3 - s_2 = 1, s_4 - s_3 = -1, and so on up to s[m - 1] -...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [10, 9, 8, 9, 8, 9, 10]) == 4\n assert candidate(nums = [3, 2, 1, 2, 1, 2, 3, 2, 1]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == -1\n assert candid...
[ "[2,3,4,3,4]", "[4,5,6]" ]
[ "As the constraints are low, you can check each subarray for the given condition." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().alternatingSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:29", "tests_total": 157, "t...
cpp
{ "raw_signature": "int alternatingSubarray(vector<int>& nums) {", "container": "Solution", "callable": "alternatingSubarray", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...
2,766
relocate-marbles
Medium
You are given a 0-indexed integer array nums representing the initial positions of some marbles. You are also given two 0-indexed integer arrays moveFrom and moveTo of equal length. Throughout moveFrom.length steps, you will change the positions of the marbles. On the i^th step, you will move all marbles at position m...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],moveFrom = [1, 2, 3],moveTo = [5, 5, 5]) == [4, 5]\n assert candidate(nums = [1, 6, 7, 8],moveFrom = [1, 7, 2],moveTo = [2, 9, 5]) == [5, 6, 8, 9]\n assert candidate(nums = [5, 5, 5, 5],moveFrom = [5],moveTo ...
[ "[1,6,7,8]\n[1,7,2]\n[2,9,5]", "[1,1,3,3]\n[1,3]\n[2,2]" ]
[ "Can we solve this problem using a set or map?", "Sequentially process pairs from moveFrom[i] and moveTo[i]. In each step, remove the occurrence of moveFrom[i] and add moveTo[i] into the set." ]
{ "canonical_parameter_names": [ "nums", "moveFrom", "moveTo" ], "leetcode_dataset_entry_point": "Solution().relocateMarbles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:31", ...
cpp
{ "raw_signature": "vector<int> relocateMarbles(vector<int>& nums, vector<int>& moveFrom, vector<int>& moveTo) {", "container": "Solution", "callable": "relocateMarbles", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "moveFrom", "type": "vector<int>&" ...
2,767
partition-string-into-minimum-beautiful-substrings
Medium
Given a binary string s, partition the string into one or more substrings such that each substring is beautiful. A string is beautiful if: - It doesn't contain leading zeros. - It's the binary representation of a number that is a power of 5. Return the minimum number of substrings in such partition. If it is impossi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"1100101\") == -1\n assert candidate(s = \"100000000000000\") == -1\n assert candidate(s = \"101010101010101\") == -1\n assert candidate(s = \"101010101\") == -1\n assert candidate(s = \"111\") == 3\n assert candidate...
[ "\"1011\"", "\"111\"", "\"0\"" ]
[ "To check if number x is a power of 5 or not, we will divide x by 5 while x > 1 and x mod 5 == 0. After iteration if x == 1, then it was a power of 5.", "Since the constraint of s.length is small, we can use recursion to find all the partitions." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minimumBeautifulSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:33", "tests_total": 148, ...
cpp
{ "raw_signature": "int minimumBeautifulSubstrings(string s) {", "container": "Solution", "callable": "minimumBeautifulSubstrings", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
2,768
number-of-black-blocks
Medium
You are given two integers m and n representing the dimensions of a 0-indexed m x n grid. You are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordinates [x, y] is colored black. All cells in the grid that do not appear in coordinates are white. A b...
{ "language": "python", "source": "def check(candidate):\n assert candidate(m = 5,n = 5,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2]]) == [9, 3, 3, 0, 1]\n assert candidate(m = 5,n = 5,coordinates = [[2, 2], [3, 3], [1, 1]]) == [6, 8, 2, 0, 0]\n assert candidate(m = 3,n = 3,coordinates = [[0, 0], ...
[ "3\n3\n[[0,0]]", "3\n3\n[[0,0],[1,1],[0,2]]" ]
[ "The number of blocks is too much but the number of black cells is less than that.", "It means the number of blocks with at least one black cell is O(|coordinates|). let’s just hold them.", "Iterate through the coordinates and update the block counts accordingly. For each coordinate, determine which block(s) it...
{ "canonical_parameter_names": [ "m", "n", "coordinates" ], "leetcode_dataset_entry_point": "Solution().countBlackBlocks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:36", "t...
cpp
{ "raw_signature": "vector<long long> countBlackBlocks(int m, int n, vector<vector<int>>& coordinates) {", "container": "Solution", "callable": "countBlackBlocks", "parameters": [ { "name": "m", "type": "int" }, { "name": "n", "type": "int" }, { "name": "coordin...
2,769
find-the-maximum-achievable-number
Easy
Given two integers, num and t. A number x is achievable if it can become equal to num after applying the following operation at most t times: - Increase or decrease x by 1, and simultaneously increase or decrease num by 1. Return the maximum possible value of x. Example 1: Input: num = 4, t = 1 Output: 6 Explanatio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = 1,t = 50) == 101\n assert candidate(num = 10,t = 5) == 20\n assert candidate(num = 50,t = 50) == 150\n assert candidate(num = 1,t = 1) == 3\n assert candidate(num = 25,t = 25) == 75\n assert candidate(num = 3,t = 2) ...
[ "4\n1", "3\n2" ]
[ "Let x be the answer, it’s always optimal to decrease x in each operation and increase nums." ]
{ "canonical_parameter_names": [ "num", "t" ], "leetcode_dataset_entry_point": "Solution().theMaximumAchievableX", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:38", "tests_total":...
cpp
{ "raw_signature": "int theMaximumAchievableX(int num, int t) {", "container": "Solution", "callable": "theMaximumAchievableX", "parameters": [ { "name": "num", "type": "int" }, { "name": "t", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/co...
2,770
maximum-number-of-jumps-to-reach-the-last-index
Medium
You are given a 0-indexed array nums of n integers and an integer target. You are initially positioned at index 0. In one step, you can jump from index i to any index j such that: - 0 <= i < j < n - -target <= nums[j] - nums[i] <= target Return the maximum number of jumps you can make to reach index n - 1. If there...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 6, 4, 1, 2],target = 3) == 5\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],target = 9) == 9\n assert candidate(nums = [1, 5, 10, 15, 20],target = 4) == -1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, ...
[ "[1,3,6,4,1,2]\n2", "[1,3,6,4,1,2]\n3", "[1,3,6,4,1,2]\n0" ]
[ "Use a dynamic programming approach.", "Define a dynamic programming array dp of size n, where dp[i] represents the maximum number of jumps from index 0 to index i.", "For each j iterate over all i < j. Set dp[j] = max(dp[j], dp[i] + 1) if -target <= nums[j] - nums[i] <= target." ]
{ "canonical_parameter_names": [ "nums", "target" ], "leetcode_dataset_entry_point": "Solution().maximumJumps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:40", "tests_total": 14...
cpp
{ "raw_signature": "int maximumJumps(vector<int>& nums, int target) {", "container": "Solution", "callable": "maximumJumps", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "target", "type": "int" } ], "return_type": "int", "signature_source": ...
2,771
longest-non-decreasing-subarray-from-two-arrays
Medium
You are given two 0-indexed integer arrays nums1 and nums2 of length n. Let's define another 0-indexed integer array, nums3, of length n. For each index i in the range [0, n - 1], you can assign either nums1[i] or nums2[i] to nums3[i]. Your task is to maximize the length of the longest non-decreasing subarray in nums...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [2, 3, 1],nums2 = [1, 2, 1]) == 2\n assert candidate(nums1 = [8, 6, 4, 2],nums2 = [7, 5, 3, 1]) == 1\n assert candidate(nums1 = [1, 2, 2, 2, 3],nums2 = [2, 2, 3, 3, 4]) == 5\n assert candidate(nums1 = [1000000000, 1, 100...
[ "[2,3,1]\n[1,2,1]", "[1,3,2,1]\n[2,2,3,4]", "[1,1]\n[2,2]" ]
[ "Consider using dynamic programming.", "Let dp[i][0] (dp[i][1]) be the length of the longest non-decreasing ending with nums1[i] (nums2[i]).", "Initialize dp[i][0] to 1. If nums1[i] >= nums1[i - 1] then dp[i][0] may be dp[i - 1][0] + 1. If nums1[i] >= nums2[i - 1] then dp[i][0] may be dp[i - 1][1] + 1. Perform ...
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().maxNonDecreasingLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:43", "tests_...
cpp
{ "raw_signature": "int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {", "container": "Solution", "callable": "maxNonDecreasingLength", "parameters": [ { "name": "nums1", "type": "vector<int>&" }, { "name": "nums2", "type": "vector<int>&" } ], "retur...
2,772
apply-operations-to-make-all-array-elements-equal-to-zero
Medium
You are given a 0-indexed integer array nums and a positive integer k. You can apply the following operation on the array any number of times: - Choose any subarray of size k from the array and decrease all its elements by 1. Return true if you can make all the array elements equal to 0, or false otherwise. A subar...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 3, 1, 1, 0],k = 3) == True\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == True\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == False\n assert candidate(nums = [1000000, 1000000, 1000000],k = 3) == True\n ...
[ "[2,2,3,1,1,0]\n3", "[1,3,1,1]\n2" ]
[ "In case it is possible, then how can you do the operations? which subarrays do you choose and in what order?", "The order of the chosen subarrays should be from the left to the right of the array" ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().checkArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:46", "tests_total": 101, "t...
cpp
{ "raw_signature": "bool checkArray(vector<int>& nums, int k) {", "container": "Solution", "callable": "checkArray", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "bool", "signature_source": "leetcode/co...
2,778
sum-of-squares-of-special-elements
Easy
You are given a 1-indexed integer array nums of length n. An element nums[i] of nums is called special if i divides n, i.e. n % i == 0. Return the sum of the squares of all special elements of nums. Example 1: Input: nums = [1,2,3,4] Output: 21 Explanation: There are exactly 3 special elements in nums: nums[1] sinc...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25]) == 650\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4]) == 21\n assert candidate(nums = [49, 49, 49, 49, 49...
[ "[1,2,3,4]", "[2,7,1,19,18,3]" ]
[ "Iterate over all the elements of the array. For each index i, check if it is special using the modulo operator.", "if n%i == 0, index i is special and you should add nums[i] to the answer." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().sumOfSquares", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:50", "tests_total": 105, "tests_dr...
cpp
{ "raw_signature": "int sumOfSquares(vector<int>& nums) {", "container": "Solution", "callable": "sumOfSquares", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,779
maximum-beauty-of-an-array-after-applying-operation
Medium
You are given a 0-indexed array nums and a non-negative integer k. In one operation, you can do the following: - Choose an index i that hasn't been chosen before from the range [0, nums.length - 1]. - Replace nums[i] with any integer from the range [nums[i] - k, nums[i] + k]. The beauty of the array is the length of...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 3) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 3\n assert candidate(nums = [10, 20, 30, 40, 50],k = 15) == 4\n assert candidate(nums = [5, 15, 25, 35],k = 5...
[ "[4,6,1,2]\n2", "[1,1,1,1]\n10" ]
[ "Sort the array.", "The problem becomes the following: find maximum subarray A[i … j] such that A[j] - A[i] ≤ 2 * k." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumBeauty", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:53", "tests_total": 119, ...
cpp
{ "raw_signature": "int maximumBeauty(vector<int>& nums, int k) {", "container": "Solution", "callable": "maximumBeauty", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcod...
2,780
minimum-index-of-a-valid-split
Medium
An element x of an integer array arr of length m is dominant if more than half the elements of arr have a value of x. You are given a 0-indexed integer array nums of length n with one dominant element. You can split nums at an index i into two arrays nums[0, ..., i] and nums[i + 1, ..., n - 1], but the split is only ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 1]) == 0\n assert candidate(nums = [3, 3, 3, 3, 7, 2, 2]) == -1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 1]) == 0\n assert candidate...
[ "[1,2,2,2]", "[2,1,3,1,1,1,7,1,2,1]", "[3,3,3,3,7,2,2]" ]
[ "Find the dominant element of nums by using a hashmap to maintain element frequency, we denote the dominant element as x and its frequency as f.", "For each index in [0, n - 2], calculate f1, x’s frequency in the subarray [0, i] when looping the index. And f2, x’s frequency in the subarray [i + 1, n - 1] which is...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumIndex", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:55", "tests_total": 12, "tests_dro...
cpp
{ "raw_signature": "int minimumIndex(vector<int>& nums) {", "container": "Solution", "callable": "minimumIndex", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,781
length-of-the-longest-valid-substring
Hard
You are given a string word and an array of strings forbidden. A string is called valid if none of its substrings are present in forbidden. Return the length of the longest valid substring of the string word. A substring is a contiguous sequence of characters in a string, possibly empty. Example 1: Input: word = "...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"zzzzzzzzzz\",forbidden = ['zz']) == 1\n assert candidate(word = \"abacab\",forbidden = ['ba', 'ca']) == 2\n assert candidate(word = \"leetcode\",forbidden = ['de', 'le', 'e']) == 4\n assert candidate(word = \"abcde\",fo...
[ "\"cbaaaabc\"\n[\"aaa\",\"cb\"]", "\"leetcode\"\n[\"de\",\"le\",\"e\"]" ]
[]
{ "canonical_parameter_names": [ "word", "forbidden" ], "leetcode_dataset_entry_point": "Solution().longestValidSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:59", "test...
cpp
{ "raw_signature": "int longestValidSubstring(string word, vector<string>& forbidden) {", "container": "Solution", "callable": "longestValidSubstring", "parameters": [ { "name": "word", "type": "string" }, { "name": "forbidden", "type": "vector<string>&" } ], "return_...
2,784
check-if-array-is-good
Easy
You are given an integer array nums. We consider an array good if it is a permutation of an array base[n]. base[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 exactly once, plus two occurrences of n). For example, base[1] = [1, 1] and base[3] = [1, 2, 3, 3]. Re...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 3, 2]) == True\n assert candidate(nums = [2, 1, 1]) == False\n assert candidate(nums = [2, 1, 2]) == True\n assert candidate(nums = [1, 2, 3, 3, 5, 4]) == False\n assert candidate(nums = [2, 2]) == False\n as...
[ "[2, 1, 3]", "[1, 3, 3, 2]", "[1, 1]", "[3, 4, 4, 1, 2, 1]" ]
[ "Find the maximum element of the array." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().isGood", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:03", "tests_total": 120, "tests_dropped"...
cpp
{ "raw_signature": "bool isGood(vector<int>& nums) {", "container": "Solution", "callable": "isGood", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,785
sort-vowels-in-a-string
Medium
Given a 0-indexed string s, permute s to get a new string t such that: - All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then t[i] = s[i]. - The vowels must be sorted in the nondecreasing order of their ASCII values. More forma...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"b\") == \"b\"\n assert candidate(s = \"bCdEfGhIjK\") == \"bCdEfGhIjK\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"AEIOUaeiou\") == \"AEIOUaeiou\"\n ...
[ "\"lEetcOde\"", "\"lYmpH\"" ]
[ "Add all the vowels in an array and sort the array.", "Replace characters in string s if it's a vowel from the new array." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().sortVowels", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:06", "tests_total": 150, "tests_dropped...
cpp
{ "raw_signature": "string sortVowels(string s) {", "container": "Solution", "callable": "sortVowels", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,786
visit-array-positions-to-maximize-score
Medium
You are given a 0-indexed integer array nums and a positive integer x. You are initially at position 0 in the array and you can visit other positions according to the following rules: - If you are currently in position i, then you can move to any position j such that i < j. - For each position i that you visit, you g...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],x = 1) == 11\n assert candidate(nums = [10, 13, 15, 17, 19],x = 10) == 64\n assert candidate(nums = [1, 2, 3, 4, 5, 6],x = 2) == 13\n assert candidate(nums = [10, 13, 14, 15, 19],x = 10) == 48\n assert ...
[ "[2,3,6,1,9,2]\n5", "[2,4,6,8]\n3" ]
[ "How can we use dynamic programming to solve the problem?", "Let dp[i] be the answer to the subarray nums[0…i]. What are the transitions of this dp?" ]
{ "canonical_parameter_names": [ "nums", "x" ], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:08", "tests_total": 109, "tes...
cpp
{ "raw_signature": "long long maxScore(vector<int>& nums, int x) {", "container": "Solution", "callable": "maxScore", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "x", "type": "int" } ], "return_type": "long long", "signature_source": "leetc...
2,787
ways-to-express-an-integer-as-sum-of-powers
Medium
Given two positive integers n and x. Return the number of ways n can be expressed as the sum of the x^th power of unique positive integers, in other words, the number of sets of unique integers [n_1, n_2, ..., n_k] where n = n_1^x + n_2^x + ... + n_k^x. Since the result can be very large, return it modulo 10^9 + 7. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 100,x = 4) == 0\n assert candidate(n = 50,x = 2) == 3\n assert candidate(n = 200,x = 2) == 9\n assert candidate(n = 300,x = 5) == 0\n assert candidate(n = 160,x = 3) == 1\n assert candidate(n = 4,x = 1) == 2\n asser...
[ "10\n2", "4\n1" ]
[ "You can use dynamic programming, where dp[k][j] represents the number of ways to express k as the sum of the x-th power of unique positive integers such that the biggest possible number we use is j.", "To calculate dp[k][j], you can iterate over the numbers smaller than j and try to use each one as a power of x ...
{ "canonical_parameter_names": [ "n", "x" ], "leetcode_dataset_entry_point": "Solution().numberOfWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:10", "tests_total": 96, "tes...
cpp
{ "raw_signature": "int numberOfWays(int n, int x) {", "container": "Solution", "callable": "numberOfWays", "parameters": [ { "name": "n", "type": "int" }, { "name": "x", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_s...
2,788
split-strings-by-separator
Easy
Given an array of strings words and a character separator, split each string in words by separator. Return an array of strings containing the new strings formed after the splits, excluding empty strings. Notes - separator is used to determine where the split should occur, but it is not included as part of the result...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['no-separator'],separator = \",\") == ['no-separator']\n assert candidate(words = ['hello.world', 'foo.bar.baz'],separator = \".\") == ['hello', 'world', 'foo', 'bar', 'baz']\n assert candidate(words = ['test|test|test'],s...
[ "[\"one.two.three\",\"four.five\",\"six\"]\n\".\"", "[\"$easy$\",\"$problem$\"]\n\"$\"", "[\"|||\"]\n\"|\"" ]
[ "Iterate over each string in the given array using a loop and perform string splitting based on the provided separator character.", "Be sure not to return empty strings." ]
{ "canonical_parameter_names": [ "words", "separator" ], "leetcode_dataset_entry_point": "Solution().splitWordsBySeparator", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:13", "tes...
cpp
{ "raw_signature": "vector<string> splitWordsBySeparator(vector<string>& words, char separator) {", "container": "Solution", "callable": "splitWordsBySeparator", "parameters": [ { "name": "words", "type": "vector<string>&" }, { "name": "separator", "type": "char" } ], ...
2,789
largest-element-in-an-array-after-merge-operations
Medium
You are given a 0-indexed array nums consisting of positive integers. You can do the following operation on the array any number of times: - Choose an index i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i + 1]. Replace the element nums[i + 1] with nums[i] + nums[i + 1] and delete the element nums[i] from t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 30\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000]) =...
[ "[2,3,7,9,3]", "[5,3,3]" ]
[ "Start from the end of the array and keep merging elements together until it is no longer possible.", "The answer will be the resulting element from the last merge operation." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxArrayValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:15", "tests_total": 124, "tests_d...
cpp
{ "raw_signature": "long long maxArrayValue(vector<int>& nums) {", "container": "Solution", "callable": "maxArrayValue", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...
2,790
maximum-number-of-groups-with-increasing-length
Hard
You are given a 0-indexed array usageLimits of length n. Your task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no more than usageLimits[i] times in total across all groups. You must also satisfy the following conditions: - Each group must consist of distinct numbers, meani...
{ "language": "python", "source": "def check(candidate):\n assert candidate(usageLimits = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(usageLimits = [1000000000, 1000000000, 1000000000]) == 3\n assert candidate(usageLimits = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 9\n assert candidate(usageLimit...
[ "[1,2,5]", "[2,1,2]", "[1,1]" ]
[ "Can we solve this problem using sorting and binary search?", "Sort the array in increasing order and run a binary search on the number of groups, x.", "To determine if a value x is feasible, greedily distribute the numbers such that each group receives 1, 2, 3, ..., x numbers." ]
{ "canonical_parameter_names": [ "usageLimits" ], "leetcode_dataset_entry_point": "Solution().maxIncreasingGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:18", "tests_total": 70...
cpp
{ "raw_signature": "int maxIncreasingGroups(vector<int>& usageLimits) {", "container": "Solution", "callable": "maxIncreasingGroups", "parameters": [ { "name": "usageLimits", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source":...
2,798
number-of-employees-who-met-the-target
Easy
There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company. The company requires each employee to work for at least target hours. You are given a 0-indexed array of non-negative integers hours of length n and a non-negative integer target. Return the in...
{ "language": "python", "source": "def check(candidate):\n assert candidate(hours = [5, 5, 5, 5, 5],target = 5) == 5\n assert candidate(hours = [3, 4, 5, 6, 7],target = 4) == 4\n assert candidate(hours = [1, 5, 7, 9],target = 8) == 1\n assert candidate(hours = [10, 10, 10],target = 10) == 3\n assert ...
[ "[0,1,2,3,4]\n2", "[5,1,4,2,2]\n6" ]
[ "Iterate over the elements of array hours and check if the value is greater than or equal to target." ]
{ "canonical_parameter_names": [ "hours", "target" ], "leetcode_dataset_entry_point": "Solution().numberOfEmployeesWhoMetTarget", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:26", ...
cpp
{ "raw_signature": "int numberOfEmployeesWhoMetTarget(vector<int>& hours, int target) {", "container": "Solution", "callable": "numberOfEmployeesWhoMetTarget", "parameters": [ { "name": "hours", "type": "vector<int>&" }, { "name": "target", "type": "int" } ], "return_...
2,799
count-complete-subarrays-in-an-array
Medium
You are given an array nums consisting of positive integers. We call a subarray of an array complete if the following condition is satisfied: - The number of distinct elements in the subarray is equal to the number of distinct elements in the whole array. Return the number of complete subarrays. A subarray is a con...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == 28\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 4\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996]) == 1\n assert candidate(nums = [1, 2, 3, 1, 2, 3]) == 10\n assert candidate(nums...
[ "[1,3,1,2,2]", "[5,5,5,5]" ]
[ "Let’s say k is the number of distinct elements in the array. Our goal is to find the number of subarrays with k distinct elements.", "Since the constraints are small, you can check every subarray." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countCompleteSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:28", "tests_total": 99, ...
cpp
{ "raw_signature": "int countCompleteSubarrays(vector<int>& nums) {", "container": "Solution", "callable": "countCompleteSubarrays", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
2,800
shortest-string-that-contains-three-strings
Medium
Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings. If there are multiple such strings, return the lexicographically smallest one. Return a string denoting the answer to the problem. Notes - A string a is lexicographically smaller ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(a = \"aaaa\",b = \"bbbb\",c = \"cccc\") == \"aaaabbbbcccc\"\n assert candidate(a = \"aaa\",b = \"aa\",c = \"a\") == \"aaa\"\n assert candidate(a = \"ab\",b = \"ba\",c = \"aba\") == \"aba\"\n assert candidate(a = \"hello\",b = \"...
[ "\"abc\"\n\"bca\"\n\"aaa\"", "\"ab\"\n\"ba\"\n\"aba\"" ]
[ "Think about how you can generate all possible strings that contain all three input strings as substrings. Can you come up with an efficient algorithm to do this?", "Check all permutations of the words a, b, and c. For each permutation, begin by appending some letters to the end of the first word to form the seco...
{ "canonical_parameter_names": [ "a", "b", "c" ], "leetcode_dataset_entry_point": "Solution().minimumString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:30", "tests_total": ...
cpp
{ "raw_signature": "string minimumString(string a, string b, string c) {", "container": "Solution", "callable": "minimumString", "parameters": [ { "name": "a", "type": "string" }, { "name": "b", "type": "string" }, { "name": "c", "type": "string" } ]...
2,801
count-stepping-numbers-in-range
Hard
Given two positive integers low and high represented as strings, find the count of stepping numbers in the inclusive range [low, high]. A stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1. Return an integer denoting the count of stepping numbers in the inclusi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(low = \"123\",high = \"456\") == 13\n assert candidate(low = \"5555555555\",high = \"6666666666\") == 436\n assert candidate(low = \"1111111111\",high = \"2222222222\") == 307\n assert candidate(low = \"1000000000\",high = \"100...
[ "\"1\"\n\"11\"", "\"90\"\n\"101\"" ]
[ "Calculate the number of stepping numbers in the range [1, high] and subtract the number of stepping numbers in the range [1, low - 1].", "The main problem is calculating the number of stepping numbers in the range [1, x].", "First, calculate the number of stepping numbers shorter than x in length, which can be...
{ "canonical_parameter_names": [ "low", "high" ], "leetcode_dataset_entry_point": "Solution().countSteppingNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:32", "tests_total...
cpp
{ "raw_signature": "int countSteppingNumbers(string low, string high) {", "container": "Solution", "callable": "countSteppingNumbers", "parameters": [ { "name": "low", "type": "string" }, { "name": "high", "type": "string" } ], "return_type": "int", "signature_sourc...
2,806
account-balance-after-rounded-purchase
Easy
Initially, you have a bank account balance of 100 dollars. You are given an integer purchaseAmount representing the amount you will spend on a purchase in dollars, in other words, its price. When making the purchase, first the purchaseAmount is rounded to the nearest multiple of 10. Let us call this value roundedAmou...
{ "language": "python", "source": "def check(candidate):\n assert candidate(purchaseAmount = 100) == 0\n assert candidate(purchaseAmount = 85) == 10\n assert candidate(purchaseAmount = 15) == 80\n assert candidate(purchaseAmount = 10) == 90\n assert candidate(purchaseAmount = 45) == 50\n assert ca...
[ "9", "15", "10" ]
[ "To determine the nearest multiple of 10, we can brute force the rounded amount since there are at most 100 options. In case of multiple nearest multiples, choose the largest.", "Another solution is observing that the rounded amount is floor((purchaseAmount + 5) / 10) * 10. Using this formula, we can calculate th...
{ "canonical_parameter_names": [ "purchaseAmount" ], "leetcode_dataset_entry_point": "Solution().accountBalanceAfterPurchase", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:37", "tests...
cpp
{ "raw_signature": "int accountBalanceAfterPurchase(int purchaseAmount) {", "container": "Solution", "callable": "accountBalanceAfterPurchase", "parameters": [ { "name": "purchaseAmount", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_sour...