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
3,101
count-alternating-subarrays
Medium
You are given a binary array nums. We call a subarray alternating if no two adjacent elements in the subarray have the same value. Return the number of alternating subarrays in nums. Example 1: Input: nums = [0,1,1,1] Output: 5 Explanation: The following subarrays are alternating: [0], [1], [1], [1], and [0,1]. Ex...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 1, 1, 0, 0]) == 8\n assert candidate(nums = [0, 1, 0, 1, 0, 1]) == 21\n assert candidate(nums = [1, 0, 1, 0, 1]) == 15\n assert candidate(nums = [1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 0, 0, 1, 0, 1, 1,...
[ "[0,1,1,1]", "[1,0,1,0]" ]
[ "Try using dynamic programming.", "Let dp[i] be the number of alternating subarrays ending at index i.", "The final answer is the sum of dp[i] over all indices i from 0 to n - 1." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countAlternatingSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:03", "tests_total": 110...
cpp
{ "raw_signature": "long long countAlternatingSubarrays(vector<int>& nums) {", "container": "Solution", "callable": "countAlternatingSubarrays", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "typ...
3,102
minimize-manhattan-distances
Hard
You are given an array points representing integer coordinates of some points on a 2D plane, where points[i] = [x_i, y_i]. The distance between two points is defined as their Manhattan distance. Return the minimum possible value for maximum distance between any two points by removing exactly one point. Example 1: I...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 4\n assert candidate(points = [[1, 9], [9, 1], [2, 8], [8, 2], [3, 7], [7, 3], [4, 6], [6, 4], [5, 5]]) == 14\n assert candidate(points = [[1, 2], [4, 6], [8, 10], [15, 18]]) == 15\n ...
[ "[[3,10],[5,15],[10,2],[4,4]]", "[[1,1],[1,1],[1,1]]" ]
[ "Notice that the Manhattan distance between two points [x_i, y_i] and [x_j, y_j] is max({x_i - x_j + y_i - y_j, x_i - x_j - y_i + y_j, - x_i + x_j + y_i - y_j, - x_i + x_j - y_i + y_j}).", "If you replace points as [x_i - y_i, x_i + y_i] then the Manhattan distance is max(max(x_i) - min(x_i), max(y_i) - min(y_i)...
{ "canonical_parameter_names": [ "points" ], "leetcode_dataset_entry_point": "Solution().minimumDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:06", "tests_total": 155, "tes...
cpp
{ "raw_signature": "int minimumDistance(vector<vector<int>>& points) {", "container": "Solution", "callable": "minimumDistance", "parameters": [ { "name": "points", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "...
3,105
longest-strictly-increasing-or-strictly-decreasing-subarray
Easy
You are given an array of integers nums. Return the length of the longest subarray of nums which is either strictly increasing or strictly decreasing. Example 1: Input: nums = [1,4,3,3,2] Output: 2 Explanation: The strictly increasing subarrays of nums are [1], [2], [3], [3], [4], and [1,4]. The strictly decreasing s...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 4, 7, 8, 6, 9]) == 3\n assert candidate(nums = [1, 2, 2, 3, 4, 5]) == 4\n assert candidate(nums = [10, 9, 4, 3, 3, 2, 1]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candida...
[ "[1,4,3,3,2]", "[3,3,3,3]", "[3,2,1]" ]
[]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().longestMonotonicSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:10", "tests_total": 139,...
cpp
{ "raw_signature": "int longestMonotonicSubarray(vector<int>& nums) {", "container": "Solution", "callable": "longestMonotonicSubarray", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "le...
3,106
lexicographically-smallest-string-after-operations-with-constraint
Medium
You are given a string s and an integer k. Define a function distance(s_1, s_2) between two strings s_1 and s_2 of the same length n as: - The sum of the minimum distance between s_1[i] and s_2[i] when the characters from 'a' to 'z' are placed in a cyclic order, for all i in the range [0, n - 1]. For example, distan...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zbbz\",k = 3) == \"aaaz\"\n assert candidate(s = \"abc\",k = 1) == \"aac\"\n assert candidate(s = \"abc\",k = 0) == \"abc\"\n assert candidate(s = \"zzz\",k = 9) == \"aaa\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgf...
[ "\"zbbz\"\n3", "\"xaxcd\"\n4", "\"lol\"\n0" ]
[ "The problem can be approached greedily.", "For each index in order from 0 to n - 1, we try all letters from 'a' to 'z', selecting the first one as long as the current total distance accumulated is not larger than k." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().getSmallestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:12", "tests_total": 110, ...
cpp
{ "raw_signature": "string getSmallestString(string s, int k) {", "container": "Solution", "callable": "getSmallestString", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "int" } ], "return_type": "string", "signature_source": "leetcode/co...
3,107
minimum-operations-to-make-median-of-array-equal-to-k
Medium
You are given an integer array nums and a non-negative integer k. In one operation, you can increase or decrease any element by 1. Return the minimum number of operations needed to make the median of nums equal to k. The median of an array is defined as the middle element of the array when it is sorted in non-decreas...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 3, 3, 7, 7, 9],k = 3) == 0\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3],k = 500000000) == 499999997\n assert candidate(nums = [2, 5, 6, 8, 5],k = ...
[ "[2,5,6,8,5]\n4", "[2,5,6,8,5]\n7", "[1,2,3,4,5,6]\n4" ]
[ "Sort nums in non-descending order.", "For all the smaller values on the left side of the median, change them to k if they are larger than k.", "For all the larger values on the right side of the median, change them to k if they are smaller than k." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().minOperationsToMakeMedianK", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:15", "tests_t...
cpp
{ "raw_signature": "long long minOperationsToMakeMedianK(vector<int>& nums, int k) {", "container": "Solution", "callable": "minOperationsToMakeMedianK", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "long...
3,108
minimum-cost-walk-in-weighted-graph
Hard
There is an undirected weighted graph with n vertices labeled from 0 to n - 1. You are given the integer n and an array edges, where edges[i] = [u_i, v_i, w_i] indicates that there is an edge between vertices u_i and v_i with a weight of w_i. A walk on a graph is a sequence of vertices and edges. The walk starts and ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 10,edges = [[0, 1, 1], [2, 3, 2], [4, 5, 3], [6, 7, 4], [8, 9, 5]],query = [[0, 9], [1, 8]]) == [-1, -1]\n assert candidate(n = 6,edges = [[0, 1, 5], [1, 2, 4], [2, 3, 3], [3, 4, 2], [4, 5, 1]],query = [[0, 5], [2, 4]]) == [0, 0]\...
[ "5\n[[0,1,7],[1,3,7],[1,2,1]]\n[[0,3],[3,4]]", "3\n[[0,2,7],[0,1,15],[1,2,6],[1,2,1]]\n[[1,2]]" ]
[ "The intended solution uses Disjoint Set Union.", "Notice that, if u and v are not connected then the answer is -1, otherwise we can use all the edges from the connected component where both belong to." ]
{ "canonical_parameter_names": [ "n", "edges", "query" ], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:18", "tests_to...
cpp
{ "raw_signature": "vector<int> minimumCost(int n, vector<vector<int>>& edges, vector<vector<int>>& query) {", "container": "Solution", "callable": "minimumCost", "parameters": [ { "name": "n", "type": "int" }, { "name": "edges", "type": "vector<vector<int>>&" }, { ...
3,110
score-of-a-string
Easy
You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters. Return the score of s. Example 1: Input: s = "hello" Output: 13 Explanation: The ASCII values of the characters in s are: 'h' = 104, 'e' = 101, 'l' = 108, 'o' = 111. So, t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 25\n assert candidate(s = \"abracadabra\") == 78\n assert candidate(s = \"zzzz\") == 0\n assert candidate(s = \"zyx\") == 2\n assert candidate(s = \"mnopqr\") == 5\n assert candidate(...
[ "\"hello\"", "\"zaz\"" ]
[ "Sum the difference between all the adjacent characters by just taking the absolute difference of their ASCII values." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().scoreOfString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:23", "tests_total": 87, "tests_dropp...
cpp
{ "raw_signature": "int scoreOfString(string s) {", "container": "Solution", "callable": "scoreOfString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,111
minimum-rectangles-to-cover-points
Medium
You are given a 2D integer array points, where points[i] = [x_i, y_i]. You are also given an integer w. Your task is to cover all the given points with rectangles. Each rectangle has its lower end at some point (x_1, 0) and its upper end at some point (x_2, y_2), where x_1 <= x_2, y_2 >= 0, and the condition x_2 - x_1...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],w = 1) == 3\n assert candidate(points = [[5, 5], [10, 10], [15, 15]],w = 5) == 2\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9...
[ "[[2,1],[1,0],[1,4],[1,8],[3,5],[4,6]]\n1", "[[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]]\n2", "[[2,3],[1,2]]\n0" ]
[ "The y values don't matter; only the x values matter.", "Sort all the points by x_i.", "Each time, select the smallest x value, x_0, from the unselected points, and then select all the points with x values not larger than x_0 + w." ]
{ "canonical_parameter_names": [ "points", "w" ], "leetcode_dataset_entry_point": "Solution().minRectanglesToCoverPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:25", "tests...
cpp
{ "raw_signature": "int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {", "container": "Solution", "callable": "minRectanglesToCoverPoints", "parameters": [ { "name": "points", "type": "vector<vector<int>>&" }, { "name": "w", "type": "int" } ], "retur...
3,112
minimum-time-to-visit-disappearing-nodes
Medium
There is an undirected graph of n nodes. You are given a 2D array edges, where edges[i] = [u_i, v_i, length_i] describes an edge between node u_i and node v_i with a traversal time of length_i units. Additionally, you are given an array disappear, where disappear[i] denotes the time when the node i disappears from the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 2,edges = [[0, 1, 1]],disappear = [1, 1]) == [0, -1]\n assert candidate(n = 6,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5]],disappear = [1, 2, 3, 4, 5, 6]) == [0, 1, -1, -1, -1, -1]\n assert candidate(n = 4,ed...
[ "3\n[[0,1,2],[1,2,1],[0,2,4]]\n[1,1,5]", "3\n[[0,1,2],[1,2,1],[0,2,4]]\n[1,3,5]", "2\n[[0,1,1]]\n[1,1]" ]
[ "Use Dijkstra’s algorithm, but only visit nodes if you can reach them before disappearance." ]
{ "canonical_parameter_names": [ "n", "edges", "disappear" ], "leetcode_dataset_entry_point": "Solution().minimumTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:28", "test...
cpp
{ "raw_signature": "vector<int> minimumTime(int n, vector<vector<int>>& edges, vector<int>& disappear) {", "container": "Solution", "callable": "minimumTime", "parameters": [ { "name": "n", "type": "int" }, { "name": "edges", "type": "vector<vector<int>>&" }, { ...
3,113
find-the-number-of-subarrays-where-boundary-elements-are-maximum
Hard
You are given an array of positive integers nums. Return the number of subarrays of nums, where the first and the last elements of the subarray are equal to the largest element in the subarray. Example 1: Input: nums = [1,4,3,3,2] Output: 6 Explanation: There are 6 subarrays which have the first and the last element...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 5, 4, 5]) == 8\n assert candidate(nums = [2, 1, 2, 1, 2]) == 8\n assert candidate(nums = [1, 3, 2, 3, 1, 3]) == 9\n assert candidate(nums = [1, 2, 2, 1]) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, ...
[ "[1,4,3,3,2]", "[3,3,3]", "[1]" ]
[ "For each element nums[i], we can count the number of valid subarrays ending with it.", "For each index i, find the nearest index j on its left (j < i) such that nums[j] < nums[i]. This can be done via a monotonic stack.", "For each index i, find the number of indices k in the window [j + 1, i] such that nums[k...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().numberOfSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:31", "tests_total": 110, "tes...
cpp
{ "raw_signature": "long long numberOfSubarrays(vector<int>& nums) {", "container": "Solution", "callable": "numberOfSubarrays", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "leet...
3,114
latest-time-you-can-obtain-after-replacing-characters
Easy
You are given a string s representing a 12-hour format time where some of the digits (possibly none) are replaced with a "?". 12-hour times are formatted as "HH:MM", where HH is between 00 and 11, and MM is between 00 and 59. The earliest 12-hour time is 00:00, and the latest is 11:59. You have to replace all the "?"...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"10:?5\") == \"10:55\"\n assert candidate(s = \"??:5?\") == \"11:59\"\n assert candidate(s = \"1?:4?\") == \"11:49\"\n assert candidate(s = \"1?:?4\") == \"11:54\"\n assert candidate(s = \"11:?9\") == \"11:59\"\n asse...
[ "\"1?:?4\"", "\"0?:5?\"" ]
[ "Try using a brute force approach.", "Iterate over all possible times that can be generated from the string and find the latest one." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().findLatestTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:33", "tests_total": 121, "tests_dro...
cpp
{ "raw_signature": "string findLatestTime(string s) {", "container": "Solution", "callable": "findLatestTime", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,115
maximum-prime-difference
Medium
You are given an integer array nums. Return an integer that is the maximum distance between the indices of two (not necessarily different) prime numbers in nums. Example 1: Input: nums = [4,2,9,5,3] Output: 3 Explanation: nums[1], nums[3], and nums[4] are prime. So the answer is |4 - 1| = 3. Example 2: Input: nums...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [97, 1, 97, 1, 97]) == 4\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 9\n assert candidate(nums = [100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 52, 49, 46, 43, 40, 37, 34, 31, 28, 25, 22, ...
[ "[4,2,9,5,3]", "[4,8,2,8]" ]
[ "Find all prime numbers in the nums.", "Find the first and the last prime number in the nums." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maximumPrimeDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:36", "tests_total": 53, ...
cpp
{ "raw_signature": "int maximumPrimeDifference(vector<int>& nums) {", "container": "Solution", "callable": "maximumPrimeDifference", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
3,116
kth-smallest-amount-with-single-denomination-combination
Hard
You are given an integer array coins representing coins of different denominations and an integer k. You have an infinite number of coins of each denomination. However, you are not allowed to combine coins of different denominations. Return the k^th smallest amount that can be made using these coins. Example 1: Inp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(coins = [15, 20, 25],k = 15) == 125\n assert candidate(coins = [4, 8, 12],k = 10) == 40\n assert candidate(coins = [2, 3, 5, 7],k = 12) == 15\n assert candidate(coins = [7, 11, 13],k = 15) == 52\n assert candidate(coins = [3,...
[ "[3,6,9]\n3", "[5,2]\n7" ]
[ "Binary search the answer x.", "Use the inclusion-exclusion principle to count the number of distinct amounts that can be made up to x." ]
{ "canonical_parameter_names": [ "coins", "k" ], "leetcode_dataset_entry_point": "Solution().findKthSmallest", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:38", "tests_total": 110...
cpp
{ "raw_signature": "long long findKthSmallest(vector<int>& coins, int k) {", "container": "Solution", "callable": "findKthSmallest", "parameters": [ { "name": "coins", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "long long", "signature...
3,117
minimum-sum-of-values-by-dividing-array
Hard
You are given two arrays nums and andValues of length n and m respectively. The value of an array is equal to the last element of that array. You have to divide nums into m disjoint contiguous subarrays such that for the i^th subarray [l_i, r_i], the bitwise AND of the subarray elements is equal to andValues[i], in o...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5],andValues = [5, 5]) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16],andValues = [0, 0, 0]) == 28\n assert candidate(nums = [8, 12, 10, 14],andValues = [8, 14]) == 24\n assert candidate(nums = [10...
[ "[1,4,3,3,2]\n[0,3,3,2]", "[2,3,5,7,7,7,5]\n[0,7,5]", "[1,2,3,4]\n[2]" ]
[ "Let dp[i][j] be the optimal answer to split nums[0..(i - 1)] into the first j andValues.", "dp[i][j] = min(dp[(i - z)][j - 1]) + nums[i - 1] over all x <= z <= y and dp[0][0] = 0, where x and y are the longest and shortest subarrays ending with nums[i - 1] and the bitwise-and of all the values in it is andValues...
{ "canonical_parameter_names": [ "nums", "andValues" ], "leetcode_dataset_entry_point": "Solution().minimumValueSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:40", "tests_tota...
cpp
{ "raw_signature": "int minimumValueSum(vector<int>& nums, vector<int>& andValues) {", "container": "Solution", "callable": "minimumValueSum", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "andValues", "type": "vector<int>&" } ], "return_type":...
3,120
count-the-number-of-special-characters-i
Easy
You are given a string word. A letter is called special if it appears both in lowercase and uppercase in word. Return the number of special letters in word. Example 1: Input: word = "aaAbcBC" Output: 3 Explanation: The special characters in word are 'a', 'b', and 'c'. Example 2: Input: word = "abc" Output: 0 Expla...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"abc\") == 0\n assert candidate(word = \"xyzXYZ\") == 3\n assert candidate(word = \"aabbcc\") == 0\n assert candidate(word = \"AABBCC\") == 0\n assert candidate(word = \"cCcCc\") == 1\n assert candidate(word = \"Aa...
[ "\"aaAbcBC\"", "\"abc\"", "\"abBCab\"" ]
[ "The constraints are small. For all 52 characters, check if they are present in word." ]
{ "canonical_parameter_names": [ "word" ], "leetcode_dataset_entry_point": "Solution().numberOfSpecialChars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:45", "tests_total": 159, "...
cpp
{ "raw_signature": "int numberOfSpecialChars(string word) {", "container": "Solution", "callable": "numberOfSpecialChars", "parameters": [ { "name": "word", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
3,121
count-the-number-of-special-characters-ii
Medium
You are given a string word. A letter c is called special if it appears both in lowercase and uppercase in word, and every lowercase occurrence of c appears before the first uppercase occurrence of c. Return the number of special letters in word. Example 1: Input: word = "aaAbcBC" Output: 3 Explanation: The special ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"aAbBcCdDeEfFgG\") == 7\n assert candidate(word = \"AaBbCc\") == 0\n assert candidate(word = \"aabbCC\") == 0\n assert candidate(word = \"Aabbcc\") == 0\n assert candidate(word = \"abABcdCD\") == 4\n assert candida...
[ "\"aaAbcBC\"", "\"abc\"", "\"AbBCab\"" ]
[ "For each character c, store the first occurrence of its uppercase and the last occurrence of its lowercase." ]
{ "canonical_parameter_names": [ "word" ], "leetcode_dataset_entry_point": "Solution().numberOfSpecialChars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:48", "tests_total": 100, "...
cpp
{ "raw_signature": "int numberOfSpecialChars(string word) {", "container": "Solution", "callable": "numberOfSpecialChars", "parameters": [ { "name": "word", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
3,122
minimum-number-of-operations-to-satisfy-conditions
Medium
You are given a 2D matrix grid of size m x n. In one operation, you can change the value of any cell to any non-negative number. You need to perform some operations such that each cell grid[i][j] is: - Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists). - Different from the cell to its right,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1], [2], [3]]) == 2\n assert candidate(grid = [[1, 1, 1], [0, 0, 0]]) == 3\n assert candidate(grid = [[0, 1, 2], [2, 1, 0], [0, 1, 2]]) == 2\n assert candidate(grid = [[9, 9], [9, 9], [9, 9]]) == 3\n assert candidate...
[ "[[1,0,2],[1,0,2]]", "[[1,1,1],[0,0,0]]", "[[1],[2],[3]]" ]
[]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:50", "tests_total": 108, "tes...
cpp
{ "raw_signature": "int minimumOperations(vector<vector<int>>& grid) {", "container": "Solution", "callable": "minimumOperations", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "...
3,123
find-edges-in-shortest-paths
Hard
You are given an undirected weighted graph of n nodes numbered from 0 to n - 1. The graph consists of m edges represented by a 2D 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. Consider all the shortest paths from node 0 to node n - 1 in the gra...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,edges = [[0, 1, 2], [0, 2, 2], [1, 2, 3], [1, 3, 2], [2, 3, 1], [2, 4, 4], [3, 4, 2]]) == [False, True, False, False, True, False, True]\n assert candidate(n = 7,edges = [[0, 1, 2], [0, 2, 5], [1, 2, 1], [1, 3, 4], [2, 3, 2], [3...
[ "6\n[[0,1,4],[0,2,1],[1,3,2],[1,4,3],[1,5,1],[2,3,1],[3,5,3],[4,5,2]]", "4\n[[2,0,1],[0,1,1],[0,3,4],[3,2,2]]" ]
[ "Find all the shortest paths starting from nodes 0 and n - 1 to all other nodes.", "How to use the above calculated shortest paths to check if an edge is part of at least one shortest path from 0 to n - 1?" ]
{ "canonical_parameter_names": [ "n", "edges" ], "leetcode_dataset_entry_point": "Solution().findAnswer", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:53", "tests_total": 67, "t...
cpp
{ "raw_signature": "vector<bool> findAnswer(int n, vector<vector<int>>& edges) {", "container": "Solution", "callable": "findAnswer", "parameters": [ { "name": "n", "type": "int" }, { "name": "edges", "type": "vector<vector<int>>&" } ], "return_type": "vector<bool>", ...
3,127
make-a-square-with-the-same-color
Easy
You are given a 2D matrix grid of size 3 x 3 consisting only of characters 'B' and 'W'. Character 'W' represents the white color, and character 'B' represents the black color. Your task is to change the color of at most one cell so that the matrix has a 2 x 2 square where all cells are of the same color. Return true ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [['B', 'W', 'B'], ['W', 'B', 'W'], ['B', 'W', 'B']]) == False\n assert candidate(grid = [['B', 'B', 'W'], ['B', 'B', 'W'], ['B', 'B', 'W']]) == True\n assert candidate(grid = [['B', 'W', 'B'], ['B', 'W', 'W'], ['B', 'W', 'B'...
[ "[[\"B\",\"W\",\"B\"],[\"B\",\"W\",\"W\"],[\"B\",\"W\",\"B\"]]", "[[\"B\",\"W\",\"B\"],[\"W\",\"B\",\"W\"],[\"B\",\"W\",\"B\"]]", "[[\"B\",\"W\",\"B\"],[\"B\",\"W\",\"W\"],[\"B\",\"W\",\"W\"]]" ]
[ "It is impossible to create 2 x 2 square with the same color by changing the color of at most one cell when the number of ‘W' or 'B’ in all squares is 2." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().canMakeSquare", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:57", "tests_total": 10, "tests_dr...
cpp
{ "raw_signature": "bool canMakeSquare(vector<vector<char>>& grid) {", "container": "Solution", "callable": "canMakeSquare", "parameters": [ { "name": "grid", "type": "vector<vector<char>>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leet...
3,128
right-triangles
Medium
You are given a 2D boolean matrix grid. A collection of 3 elements of grid is a right triangle if one of its elements is in the same row with another element and in the same column with the third element. The 3 elements may not be next to each other. Return an integer that is the number of right triangles that can be...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 36\n assert candidate(grid = [[0, 1, 0], [0, 1, 1], [0, 1, 0]]) == 2\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == 8\n assert candidate(grid =...
[ "[[0,1,0],[0,1,1],[0,1,0]]", "[[1,0,0,0],[0,1,0,1],[1,0,0,0]]", "[[1,0,1],[1,0,0],[1,0,0]]" ]
[ "If grid[x][y] is 1, it can form a right triangle with an element of grid with value 1 in the same row and an element of grid with value 1 in the same column.", "So we just need to count the number of 1s in each row and column.", "For each x, y with grid[x][y] = 1 if there are row[x] 1s in the row x and col[y] ...
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().numberOfRightTriangles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:00", "tests_total": 67, ...
cpp
{ "raw_signature": "long long numberOfRightTriangles(vector<vector<int>>& grid) {", "container": "Solution", "callable": "numberOfRightTriangles", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippet...
3,129
find-all-possible-stable-binary-arrays-i
Medium
You are given 3 positive integers num_zeros, num_ones, and limit. A binary array arr is called stable if: - The number of occurrences of 0 in arr is exactly num_zeros. - The number of occurrences of 1 in arr is exactly num_ones. - Each subarray of arr with a size greater than limit must contain at least one occurrenc...
{ "language": "python", "source": "def check(candidate):\n assert candidate(zero = 3,one = 5,limit = 3) == 40\n assert candidate(zero = 5,one = 5,limit = 4) == 242\n assert candidate(zero = 5,one = 5,limit = 2) == 84\n assert candidate(zero = 1,one = 1,limit = 1) == 2\n assert candidate(zero = 2,one ...
[ "1\n1\n2", "1\n2\n1", "3\n3\n2" ]
[ "Let dp[a][b][c = 0/1][d] be the number of stable arrays with exactly a 0s, b 1s and consecutive d value of c’s at the end.", "Try each case by appending a 0/1 at last to get the inductions." ]
{ "canonical_parameter_names": [ "zero", "one", "limit" ], "leetcode_dataset_entry_point": "Solution().numberOfStableArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:02", ...
cpp
{ "raw_signature": "int numberOfStableArrays(int zero, int one, int limit) {", "container": "Solution", "callable": "numberOfStableArrays", "parameters": [ { "name": "zero", "type": "int" }, { "name": "one", "type": "int" }, { "name": "limit", "type": "int...
3,130
find-all-possible-stable-binary-arrays-ii
Hard
You are given 3 positive integers num_zeros, num_ones, and limit. A binary array arr is called stable if: - The number of occurrences of 0 in arr is exactly num_zeros. - The number of occurrences of 1 in arr is exactly num_ones. - Each subarray of arr with a size greater than limit must contain at least one occurrenc...
{ "language": "python", "source": "def check(candidate):\n assert candidate(zero = 5,one = 5,limit = 4) == 242\n assert candidate(zero = 100,one = 100,limit = 50) == 375840050\n assert candidate(zero = 5,one = 5,limit = 2) == 84\n assert candidate(zero = 4,one = 4,limit = 3) == 62\n assert candidate(...
[ "1\n1\n2", "1\n2\n1", "3\n3\n2" ]
[ "Let dp[x][y][z = 0/1] be the number of stable arrays with exactly x zeros, y ones, and the last element is z. (0 or 1). dp[x][y][0] + dp[x][y][1] is the answer for given (x, y).", "If we have already placed x 1 and y 0, if we place a group of k 0, the number of ways is dp[x-k][y][1]. We can place a group with si...
{ "canonical_parameter_names": [ "zero", "one", "limit" ], "leetcode_dataset_entry_point": "Solution().numberOfStableArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:05", ...
cpp
{ "raw_signature": "int numberOfStableArrays(int zero, int one, int limit) {", "container": "Solution", "callable": "numberOfStableArrays", "parameters": [ { "name": "zero", "type": "int" }, { "name": "one", "type": "int" }, { "name": "limit", "type": "int...
3,131
find-the-integer-added-to-array-i
Easy
You are given two arrays of equal length, nums1 and nums2. Each element in nums1 has been increased (or decreased in the case of negative) by an integer, represented by the variable x. As a result, nums1 becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequenc...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [10],nums2 = [5]) == -5\n assert candidate(nums1 = [100, 200, 300],nums2 = [150, 250, 350]) == 50\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9, 10]) == 5\n assert candidate(nums1 = [7, 7, 7],nums2 = [10...
[ "[2,6,4]\n[9,7,5]", "[10]\n[5]", "[1,1,1,1]\n[1,1,1,1]" ]
[ "Notice that, after sorting both arrays, there should be a one-to-one correspondence between every element.", "Thus x = min(nums2) - min(nums1)." ]
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().addedInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:07", "tests_total": 10...
cpp
{ "raw_signature": "int addedInteger(vector<int>& nums1, vector<int>& nums2) {", "container": "Solution", "callable": "addedInteger", "parameters": [ { "name": "nums1", "type": "vector<int>&" }, { "name": "nums2", "type": "vector<int>&" } ], "return_type": "int", "s...
3,132
find-the-integer-added-to-array-ii
Medium
You are given two integer arrays nums1 and nums2. We say that nums2 is reachable from nums1 with an integer x if there exist two elements in nums1 that, when removed, and x is added to all the remaining elements of nums1 (or subtracted in the case of a negative x), the resulting array becomes equal to nums2. Two array...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [20, 30, 40]) == -10\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [12, 22, 32]) == -18\n assert candidate(nums1 = [4, 20, 16, 12, 8],nums2 = [14, 18, 10]) == -2\n assert candidate(...
[ "[4,20,16,12,8]\n[14,18,10]", "[3,5,5,3]\n[7,7]" ]
[ "Try all possibilities to remove 2 elements from nums1.", "x should be equal to min(nums2) - min(nums1), check it naively." ]
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().minimumAddedInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:09", "tests_tot...
cpp
{ "raw_signature": "int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2) {", "container": "Solution", "callable": "minimumAddedInteger", "parameters": [ { "name": "nums1", "type": "vector<int>&" }, { "name": "nums2", "type": "vector<int>&" } ], "return_type...
3,133
minimum-array-end
Medium
You are given two integers n and x. You have to construct an array of positive integers nums of size n where for every 0 <= i < n - 1, nums[i + 1] is greater than nums[i], and the result of the bitwise AND operation between all elements of nums is x. Return the minimum possible value of nums[n - 1]. Example 1: Input...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,x = 8) == 11\n assert candidate(n = 5,x = 1) == 9\n assert candidate(n = 10,x = 1) == 19\n assert candidate(n = 5,x = 3) == 19\n assert candidate(n = 2,x = 7) == 15\n assert candidate(n = 1,x = 10) == 10\n assert ...
[ "3\n4", "2\n7" ]
[ "Each element of the array should be obtained by “merging” x and v where v = 0, 1, 2, …(n - 1).", "To merge x with another number v, keep the set bits of x untouched, for all the other bits, fill the set bits of v from right to left in order one by one.", "So the final answer is the “merge” of x and n - 1." ]
{ "canonical_parameter_names": [ "n", "x" ], "leetcode_dataset_entry_point": "Solution().minEnd", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:11", "tests_total": 106, "tests_dr...
cpp
{ "raw_signature": "long long minEnd(int n, int x) {", "container": "Solution", "callable": "minEnd", "parameters": [ { "name": "n", "type": "int" }, { "name": "x", "type": "int" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_s...
3,134
find-the-median-of-the-uniqueness-array
Hard
You are given an integer array nums. The uniqueness array of nums is the sorted array that contains the number of distinct elements of all the subarrays of nums. In other words, it is a sorted array consisting of distinct(nums[i..j]), for all 0 <= i <= j < nums.length. Here, distinct(nums[i..j]) denotes the number of ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 2\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1...
[ "[1,2,3]", "[3,4,3,4,5]", "[4,3,5,4]" ]
[ "Binary search over the answer.", "For a given x, you need to check if x is the median, to the left of the median, or to the right of the median. You can do that by counting the number of sub-arrays nums[i…j] such that distinct(num[i…j]) <= x.", "Use the sliding window to solve the counting problem in the hint ...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().medianOfUniquenessArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:14", "tests_total": 101, ...
cpp
{ "raw_signature": "int medianOfUniquenessArray(vector<int>& nums) {", "container": "Solution", "callable": "medianOfUniquenessArray", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leet...
3,137
minimum-number-of-operations-to-make-word-k-periodic
Medium
You are given a string word of size n, and an integer k such that k divides n. In one operation, you can pick any two indices i and j, that are divisible by k, then replace the substring of length k starting at i with the substring of length k starting at j. That is, replace the substring word[i..i + k - 1] with the s...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"xyzxyzxyzxyzxyzxyz\",k = 3) == 0\n assert candidate(word = \"xyzxyzxyzxyz\",k = 3) == 0\n assert candidate(word = \"abcdefghijabcdefghij\",k = 5) == 2\n assert candidate(word = \"abcabcabc\",k = 3) == 0\n assert cand...
[ "\"leetcodeleet\"\n4", "\"leetcoleet\"\n2" ]
[ "Calculate the frequency of each substring of length k that starts at an index that is divisible by k.", "The period of the final string will be the substring with the highest frequency." ]
{ "canonical_parameter_names": [ "word", "k" ], "leetcode_dataset_entry_point": "Solution().minimumOperationsToMakeKPeriodic", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:22", "t...
cpp
{ "raw_signature": "int minimumOperationsToMakeKPeriodic(string word, int k) {", "container": "Solution", "callable": "minimumOperationsToMakeKPeriodic", "parameters": [ { "name": "word", "type": "string" }, { "name": "k", "type": "int" } ], "return_type": "int", "s...
3,138
minimum-length-of-anagram-concatenation
Medium
You are given a string s, which is known to be a concatenation of anagrams of some string t. Return the minimum possible length of the string t. An anagram is formed by rearranging the letters of a string. For example, "aab", "aba", and, "baa" are anagrams of "aab". Example 1: Input: s = "abba" Output: 2 Explanatio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"abababab\") == 2\n assert cand...
[ "\"abba\"", "\"cdef\"", "\"abcbcacabbaccba\"" ]
[ "The answer should be a divisor of s.length.", "Check each candidate naively." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minAnagramLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:26", "tests_total": 73, "tests_dr...
cpp
{ "raw_signature": "int minAnagramLength(string s) {", "container": "Solution", "callable": "minAnagramLength", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,139
minimum-cost-to-equalize-array
Hard
You are given an integer array nums and two integers cost1 and cost2. You are allowed to perform either of the following operations any number of times: - Choose an index i from nums and increase nums[i] by 1 for a cost of cost1. - Choose two different indices i, j, from nums and increase nums[i] and nums[j] by 1 for ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 1],cost1 = 5,cost2 = 2) == 15\n assert candidate(nums = [1, 3, 5, 7, 9],cost1 = 2,cost2 = 4) == 40\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost1 = 1,cost2 = 2) == 0\n assert candidate(nums = [10, 10, ...
[ "[4,1]\n5\n2", "[2,3,3,3,5]\n2\n1", "[3,5,3]\n1\n3" ]
[ "How can you determine the minimum cost if you know the maximum value in the array once all values are made equal?", "If cost2 > cost1 * 2, we should just use cost1 to change all the values to the maximum one.", "Otherwise, it's optimal to choose the smallest two values and use cost2 to increase both of them.",...
{ "canonical_parameter_names": [ "nums", "cost1", "cost2" ], "leetcode_dataset_entry_point": "Solution().minCostToEqualizeArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:29...
cpp
{ "raw_signature": "int minCostToEqualizeArray(vector<int>& nums, int cost1, int cost2) {", "container": "Solution", "callable": "minCostToEqualizeArray", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "cost1", "type": "int" }, { "name": "...
3,142
check-if-grid-satisfies-conditions
Easy
You are given a 2D matrix grid of size m x n. You need to check if each cell grid[i][j] is: - Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists). - Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists). Return true if all the cells satisfy these conditions, o...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1], [2], [3]]) == False\n assert candidate(grid = [[5, 4, 3], [5, 4, 3], [5, 4, 3]]) == True\n assert candidate(grid = [[5, 4, 3, 2, 1], [5, 4, 3, 2, 1]]) == True\n assert candidate(grid = [[5, 4], [5, 3]]) == False\n ...
[ "[[1,0,2],[1,0,2]]", "[[1,1,1],[0,0,0]]", "[[1],[2],[3]]" ]
[ "Check if each column has same value in each cell.", "If the previous condition is satisfied, we can simply check the first cells in adjacent columns." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().satisfiesConditions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:35", "tests_total": 116, "t...
cpp
{ "raw_signature": "bool satisfiesConditions(vector<vector<int>>& grid) {", "container": "Solution", "callable": "satisfiesConditions", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_sour...
3,143
maximum-points-inside-the-square
Medium
You are given a 2D array points and a string s where, points[i] represents the coordinates of point i, and s[i] represents the tag of point i. A valid square is a square centered at the origin (0, 0), has edges parallel to the axes, and does not contain two points with the same tag. Return the maximum number of point...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 1], [-1, -1], [2, -2]],s = \"ccd\") == 0\n assert candidate(points = [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]],s = \"abcde\") == 5\n assert candidate(points = [[0, 1], [1, 0], [1, 1]],s = \"abc\") == 3\n assert ca...
[ "[[2,2],[-1,-2],[-4,4],[-3,1],[3,-3]]\n\"abdca\"", "[[1,1],[-2,-2],[-2,2]]\n\"abb\"", "[[1,1],[-1,-1],[2,-2]]\n\"ccd\"" ]
[ "The smallest edge length of a square to include point (x, y) is max(abs(x), abs(y)) * 2.", "Sort the points by max(abs(x), abs(y)) and try each edge length, check the included point tags." ]
{ "canonical_parameter_names": [ "points", "s" ], "leetcode_dataset_entry_point": "Solution().maxPointsInsideSquare", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:39", "tests_tota...
cpp
{ "raw_signature": "int maxPointsInsideSquare(vector<vector<int>>& points, string s) {", "container": "Solution", "callable": "maxPointsInsideSquare", "parameters": [ { "name": "points", "type": "vector<vector<int>>&" }, { "name": "s", "type": "string" } ], "return_ty...
3,144
minimum-substring-partition-of-equal-character-frequency
Medium
Given a string s, you need to partition it into one or more balanced substrings. For example, if s == "ababcc" then ("abab", "c", "c"), ("ab", "abc", "c"), and ("ababcc") are all valid partitions, but ("a", "bab", "cc"), ("aba", "bc", "c"), and ("ab", "abcc") are not. The unbalanced substrings are bolded. Return the m...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 1\n assert candidate(s = \"aaabbbccc\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 1\n assert candidate(s = \"aabbaabbccddccdd\") == 1\n assert candidate(s = \"abcdef\") == 1\n ass...
[ "\"fabccddg\"", "\"abababaccddb\"" ]
[ "Let dp[i] be the minimum number of partitions for the prefix ending at index i + 1.", "dp[i] can be calculated as the min(dp[j]) over all j such that j < i and word[j+1…i] is valid." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minimumSubstringsInPartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:41", "tests_total": 72,...
cpp
{ "raw_signature": "int minimumSubstringsInPartition(string s) {", "container": "Solution", "callable": "minimumSubstringsInPartition", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...
3,146
permutation-difference-between-two-strings
Easy
You are given two strings s and t such that every character occurs at most once in s and t is a permutation of s. The permutation difference between s and t is defined as the sum of the absolute difference between the index of the occurrence of each character in s and the index of the occurrence of the same character ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 338\n assert candidate(s = \"mnopqr\",t = \"qrpmno\") == 18\n assert candidate(s = \"abcde\",t = \"edbac\") == 12\n assert candidate(s = \"abcxyz\",t = \"...
[ "\"abc\"\n\"bac\"", "\"abcde\"\n\"edbac\"" ]
[ "For each character, find the indices of its occurrences in string s then in string t." ]
{ "canonical_parameter_names": [ "s", "t" ], "leetcode_dataset_entry_point": "Solution().findPermutationDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:43", "tests_total...
cpp
{ "raw_signature": "int findPermutationDifference(string s, string t) {", "container": "Solution", "callable": "findPermutationDifference", "parameters": [ { "name": "s", "type": "string" }, { "name": "t", "type": "string" } ], "return_type": "int", "signature_sourc...
3,147
taking-maximum-energy-from-the-mystic-dungeon
Medium
In a mystic dungeon, n magicians are standing in a line. Each magician has an attribute that gives you energy. Some magicians can give you negative energy, which means taking energy from you. You have been cursed in such a way that after absorbing energy from magician i, you will be instantly transported to magician (...
{ "language": "python", "source": "def check(candidate):\n assert candidate(energy = [100, -100, 100, -100, 100, 100],k = 2) == 300\n assert candidate(energy = [-1, -2, -3, -4, -5],k = 3) == -3\n assert candidate(energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 30\n assert candidate(energy = [1, 2, 3,...
[ "[5,2,-10,-5,1]\n3", "[-2,-3,-1]\n2" ]
[ "Let dp[i] denote the energy we gain starting from index i.", "We can notice, that dp[i] = dp[i + k] + energy[i]." ]
{ "canonical_parameter_names": [ "energy", "k" ], "leetcode_dataset_entry_point": "Solution().maximumEnergy", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:46", "tests_total": 120,...
cpp
{ "raw_signature": "int maximumEnergy(vector<int>& energy, int k) {", "container": "Solution", "callable": "maximumEnergy", "parameters": [ { "name": "energy", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "lee...
3,148
maximum-difference-score-in-a-grid
Medium
You are given an m x n matrix grid consisting of positive integers. You can move from a cell in the matrix to any other cell that is either to the bottom or to the right (not necessarily adjacent). The score of a move from a cell with the value c1 to a cell with the value c2 is c2 - c1. You can start at any cell, and ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]) == 6\n assert candidate(grid = [[4, 3, 2], [3, 2, 1]]) == -1\n assert candidate(grid = [[100, 90, 80], [70, 60, 50], [40, 30, 20]]) == -10\n assert candidate(grid ...
[ "[[9,5,7,3],[8,9,6,1],[6,7,14,3],[2,5,3,1]]", "[[4,3,2],[3,2,1]]" ]
[ "Any path from a cell (x1, y1) to another cell (x2, y2) will always have a score of grid[x2][y2] - grid[x1][y1].", "Let’s say we fix the starting cell (x1, y1), how to the find a cell (x2, y2) such that the value grid[x2][y2] - grid[x1][y1] is the maximum possible?" ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:49", "tests_total": 83, "tests_dropped...
cpp
{ "raw_signature": "int maxScore(vector<vector<int>>& grid) {", "container": "Solution", "callable": "maxScore", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnipp...
3,149
find-the-minimum-cost-array-permutation
Hard
You are given an array nums which is a permutation of [0, 1, 2, ..., n - 1]. The score of any permutation of [0, 1, 2, ..., n - 1] named perm is defined as: score(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[perm[0]]| Return the permutation perm which has the minimum possi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [0, 7, 6, 8, 5, 9, 4, 10, 3, 11, 2, 12, 1, 13]\n assert candidate(nums = [2, 0, 1, 3]) == [0, 1, 2, 3]\n assert candidate(nums = [0, 2, 1]) == [0, 2, 1]\n assert candidat...
[ "[1,0,2]", "[0,2,1]" ]
[ "The score function is cyclic, so we can always set perm[0] = 0 for the smallest lexical order.", "It’s similar to the Traveling Salesman Problem. Use Dynamic Programming.", "Use a bitmask to track which elements have been assigned to perm." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findPermutation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:51", "tests_total": 113, "tests...
cpp
{ "raw_signature": "vector<int> findPermutation(vector<int>& nums) {", "container": "Solution", "callable": "findPermutation", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_source": "leet...
3,151
special-array-i
Easy
An array is considered special if the parity of every pair of adjacent elements is different. In other words, one element in each pair must be even, and the other must be odd. You are given an array of integers nums. Return true if nums is a special array, otherwise, return false. Example 1: Input: nums = [1] Output...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 99, 100]) == True\n assert candidate(nums = [5, 2, 7, 8]) == True\n assert candidate(nums = [20, 30, 40, 50, 60]) == False\n assert candidate(nums = [3, 8, 3, 8, 3, 8]) == True\n assert candidate(nums = [2, 3, 4,...
[ "[1]", "[2,1,4]", "[4,3,1,6]" ]
[ "Try to check the parity of each element and its previous element." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().isArraySpecial", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:53", "tests_total": 127, "tests_...
cpp
{ "raw_signature": "bool isArraySpecial(vector<int>& nums) {", "container": "Solution", "callable": "isArraySpecial", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
3,152
special-array-ii
Medium
An array is considered special if every pair of its adjacent elements contains two numbers with different parity. You are given an array of integer nums and a 2D integer matrix queries, where for queries[i] = [from_i, to_i] your task is to check that subarray nums[from_i..to_i] is special or not. Return an array of b...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2],queries = [[0, 4]]) == [False]\n assert candidate(nums = [2, 4, 6, 8, 10],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 4]]) == [True, True, True, True, True, False]\n assert candidate(nums = [1, 3, ...
[ "[3,4,1,2,6]\n[[0,4]]", "[4,3,1,6]\n[[0,2],[2,3]]" ]
[ "Try to split the array into some non-intersected continuous special subarrays.", "For each query check that the first and the last elements of that query are in the same subarray or not." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().isArraySpecial", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:56", "tests_total":...
cpp
{ "raw_signature": "vector<bool> isArraySpecial(vector<int>& nums, vector<vector<int>>& queries) {", "container": "Solution", "callable": "isArraySpecial", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "queries", "type": "vector<vector<int>>&" } ...
3,153
sum-of-digit-differences-of-all-pairs
Medium
You are given an array nums consisting of positive integers where all integers have the same number of digits. The digit difference between two integers is the count of different digits that are in the same position in the two integers. Return the sum of the digit differences between all pairs of integers in nums. E...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [12345, 54321, 13245]) == 11\n assert candidate(nums = [10, 10, 10, 10]) == 0\n assert candidate(nums = [123, 234, 345]) == 9\n assert candidate(nums = [123, 456, 789]) == 9\n assert candidate(nums = [987, 876, 765, 65...
[ "[13,23,12]", "[10,10,10,10]" ]
[ "You can solve the problem for digits that are on the same position separately, and then sum up all the answers.", "For each position, count the number of occurences of each digit from 0 to 9 that appear on that position.", "Let c be the number of occurences of a digit on a position, that will contribute with c...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().sumDigitDifferences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:59", "tests_total": 105, "t...
cpp
{ "raw_signature": "long long sumDigitDifferences(vector<int>& nums) {", "container": "Solution", "callable": "sumDigitDifferences", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "...
3,154
find-number-of-ways-to-reach-the-k-th-stair
Hard
You are given a non-negative integer k. There exists a staircase with an infinite number of stairs, with the lowest stair numbered 0. Alice has an integer jump, with an initial value of 0. She starts on stair 1 and wants to reach stair k using any number of operations. If she is on stair i, in one operation she can: ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(k = 1000) == 0\n assert candidate(k = 100) == 0\n assert candidate(k = 20) == 0\n assert candidate(k = 1000000000) == 0\n assert candidate(k = 1) == 4\n assert candidate(k = 10) == 0\n assert candidate(k = 10000) == 0\n...
[ "0", "1" ]
[ "On using x operations of the second type and y operations of the first type, the stair 2^x - y is reached.", "Since first operations cannot be consecutive, there are exactly x + 1 positions (before and after each power of 2) to perform the second operation.", "Using combinatorics, we have ^{x + 1}C_y number of...
{ "canonical_parameter_names": [ "k" ], "leetcode_dataset_entry_point": "Solution().waysToReachStair", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:01", "tests_total": 79, "tests_dr...
cpp
{ "raw_signature": "int waysToReachStair(int k) {", "container": "Solution", "callable": "waysToReachStair", "parameters": [ { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,158
find-the-xor-of-numbers-which-appear-twice
Easy
You are given an array nums, where each number in the array appears either once or twice. Return the bitwise XOR of all the numbers that appear twice in the array, or 0 if no number appears twice. Example 1: Input: nums = [1,2,1,3] Output: 1 Explanation: The only number that appears twice in nums is 1. Example 2: ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 20, 30, 30, 40, 50]) == 20\n assert candidate(nums = [8, 8, 9, 9, 10, 10, 11]) == 11\n assert candidate(nums = [10, 10, 20, 20, 30]) == 30\n assert candidate(nums = [5, 5, 6, 7, 7, 8, 8, 9]) == 10\n assert can...
[ "[1,2,1,3]", "[1,2,3]", "[1,2,2,1]" ]
[ "The constraints are small. Brute force checking each value in the array." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().duplicateNumbersXOR", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:09", "tests_total": 120, "t...
cpp
{ "raw_signature": "int duplicateNumbersXOR(vector<int>& nums) {", "container": "Solution", "callable": "duplicateNumbersXOR", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...
3,159
find-occurrences-of-an-element-in-an-array
Medium
You are given an integer array nums, an integer array queries, and an integer x. For each queries[i], you need to find the index of the queries[i]^th occurrence of x in the nums array. If there are fewer than queries[i] occurrences of x, the answer should be -1 for that query. Return an integer array answer containin...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],x = 1) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1]\n assert candidate(nums = [3, 2, 1],queries = [1, 1, 1],x = 3) == [0, 0, 0]\n assert candidate(nums = ...
[ "[1,3,1,7]\n[1,3,2,4]\n1", "[1,2,3]\n[10]\n5" ]
[ "Compress the array nums and save all the occurrences of each element in the separate arrays." ]
{ "canonical_parameter_names": [ "nums", "queries", "x" ], "leetcode_dataset_entry_point": "Solution().occurrencesOfElement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:11", ...
cpp
{ "raw_signature": "vector<int> occurrencesOfElement(vector<int>& nums, vector<int>& queries, int x) {", "container": "Solution", "callable": "occurrencesOfElement", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "queries", "type": "vector<int>&" },...
3,160
find-the-number-of-distinct-colors-among-the-balls
Medium
You are given an integer limit and a 2D array queries of size n x 2. There are limit + 1 balls with distinct labels in the range [0, limit]. Initially, all balls are uncolored. For every query in queries that is of the form [x, y], you mark ball x with the color y. After each query, you need to find the number of colo...
{ "language": "python", "source": "def check(candidate):\n assert candidate(limit = 3,queries = [[0, 1], [1, 2], [2, 3], [0, 1]]) == [1, 2, 3, 3]\n assert candidate(limit = 1,queries = [[0, 1], [1, 2]]) == [1, 2]\n assert candidate(limit = 4,queries = [[0, 1], [1, 2], [2, 2], [3, 4], [4, 5]]) == [1, 2, 2, ...
[ "4\n[[1,4],[2,5],[1,3],[3,4]]", "4\n[[0,1],[1,2],[2,2],[3,4],[4,5]]" ]
[ "Use two HashMaps to maintain the color of each ball and the set of balls with each color." ]
{ "canonical_parameter_names": [ "limit", "queries" ], "leetcode_dataset_entry_point": "Solution().queryResults", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:13", "tests_total": ...
cpp
{ "raw_signature": "vector<int> queryResults(int limit, vector<vector<int>>& queries) {", "container": "Solution", "callable": "queryResults", "parameters": [ { "name": "limit", "type": "int" }, { "name": "queries", "type": "vector<vector<int>>&" } ], "return_type": "...
3,161
block-placement-queries
Hard
There exists an infinite number line, with its origin at 0 and extending towards the positive x-axis. You are given a 2D array queries, which contains two types of queries: 1. For a query of type 1, queries[i] = [1, x]. Build an obstacle at distance x from the origin. It is guaranteed that there is no obstacle at dis...
{ "language": "python", "source": "def check(candidate):\n assert candidate(queries = [[2, 5, 2], [1, 3], [2, 5, 3], [1, 4], [2, 5, 1]]) == [True, True, True]\n assert candidate(queries = [[2, 10, 5], [1, 3], [2, 5, 2], [1, 10], [2, 10, 3]]) == [True, True, True]\n assert candidate(queries = [[1, 7], [2, 7...
[ "[[1,2],[2,3,3],[2,3,1],[2,2,2]]", "[[1,7],[2,7,6],[1,2],[2,7,5],[2,7,6]]" ]
[ "Let d[x] be the distance of the next obstacle after x.", "For each query of type 2, we just need to check if max(d[0], d[1], d[2], …d[x - sz]) > sz.", "Use segment tree to maintain d[x]." ]
{ "canonical_parameter_names": [ "queries" ], "leetcode_dataset_entry_point": "Solution().getResults", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:16", "tests_total": 131, "tests_d...
cpp
{ "raw_signature": "vector<bool> getResults(vector<vector<int>>& queries) {", "container": "Solution", "callable": "getResults", "parameters": [ { "name": "queries", "type": "vector<vector<int>>&" } ], "return_type": "vector<bool>", "signature_source": "leetcode/codeSnippets", "type_...
3,162
find-the-number-of-good-pairs-i
Easy
You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k. A pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1). Return the total number of good pairs. Example 1: Input: nums1 = [1,3,4], nums2 = [1,3,4]...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [7, 14, 21],nums2 = [1, 7],k = 3) == 2\n assert candidate(nums1 = [1, 3, 4],nums2 = [1, 3, 4],k = 1) == 5\n assert candidate(nums1 = [7, 14, 21],nums2 = [1, 7, 14],k = 1) == 7\n assert candidate(nums1 = [7, 14, 21],nums2...
[ "[1,3,4]\n[1,3,4]\n1", "[1,2,4,12]\n[2,4]\n3" ]
[ "The constraints are small. Check all pairs." ]
{ "canonical_parameter_names": [ "nums1", "nums2", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:19", "tests_...
cpp
{ "raw_signature": "int numberOfPairs(vector<int>& nums1, vector<int>& nums2, int k) {", "container": "Solution", "callable": "numberOfPairs", "parameters": [ { "name": "nums1", "type": "vector<int>&" }, { "name": "nums2", "type": "vector<int>&" }, { "name": "k"...
3,163
string-compression-iii
Medium
Given a string word, compress it using the following algorithm: - Begin with an empty string comp. While word is not empty, use the following operation: - Remove a maximum length prefix of word made of a single character c repeating at most 9 times. - Append the length of the prefix followed by c to comp. Return ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"pppppppppppppppppppppppppppppppppppppp\") == \"9p9p9p9p2p\"\n assert candidate(word = \"abcde\") == \"1a1b1c1d1e\"\n assert candidate(word = \"aabbcc\") == \"2a2b2c\"\n assert candidate(word = \"aaaaaaaaaaaaaabb\") == \...
[ "\"abcde\"", "\"aaaaaaaaaaaaaabb\"" ]
[ "Each time, just cut the same character in prefix up to at max 9 times. It’s always better to cut a bigger prefix." ]
{ "canonical_parameter_names": [ "word" ], "leetcode_dataset_entry_point": "Solution().compressedString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:21", "tests_total": 25, "tests...
cpp
{ "raw_signature": "string compressedString(string word) {", "container": "Solution", "callable": "compressedString", "parameters": [ { "name": "word", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,164
find-the-number-of-good-pairs-ii
Medium
You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k. A pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1). Return the total number of good pairs. Example 1: Input: nums1 = [1,3,4], nums2 = [1,3,4]...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [7, 14, 21],nums2 = [1, 7, 14],k = 7) == 3\n assert candidate(nums1 = [1, 3, 4],nums2 = [1, 3, 4],k = 1) == 5\n assert candidate(nums1 = [100, 200, 300],nums2 = [10, 20, 30],k = 10) == 5\n assert candidate(nums1 = [5, 10...
[ "[1,3,4]\n[1,3,4]\n1", "[1,2,4,12]\n[2,4]\n3" ]
[ "Let f[v] be the number of occurrences of v/k in nums2.", "For each value v in nums1, enumerating all its factors d (in sqrt(v) time) and sum up all the f[d] to get the final answer.", "It is also possible to improve the complexity from len(nums1) * sqrt(v) to len(nums1) * log(v) - How?" ]
{ "canonical_parameter_names": [ "nums1", "nums2", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:24", "tests_...
cpp
{ "raw_signature": "long long numberOfPairs(vector<int>& nums1, vector<int>& nums2, int k) {", "container": "Solution", "callable": "numberOfPairs", "parameters": [ { "name": "nums1", "type": "vector<int>&" }, { "name": "nums2", "type": "vector<int>&" }, { "name...
3,165
maximum-sum-of-subsequence-with-non-adjacent-elements
Hard
You are given an array nums consisting of integers. You are also given a 2D array queries, where queries[i] = [pos_i, x_i]. For query i, we first set nums[pos_i] equal to x_i, then we calculate the answer to query i which is the maximum sum of a subsequence of nums where no two adjacent elements are selected. Return ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 200, 300, 400, 500],queries = [[0, -100], [2, -200], [4, -300]]) == 2100\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [[0, 10], [4, -10], [2, 0]]) == 46\n assert candidate(nums = [-1, -2, -3, -4, -5],queries = [...
[ "[3,5,9]\n[[1,-2],[0,-3]]", "[0,-1]\n[[0,-5]]" ]
[ "Can you solve each query in O(nums.length) with dynamic programming?", "In order to optimize, we will use segment tree where each node contains the maximum value of (front element has been chosen or not, back element has been chosen or not)." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().maximumSumSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:26", "tests_...
cpp
{ "raw_signature": "int maximumSumSubsequence(vector<int>& nums, vector<vector<int>>& queries) {", "container": "Solution", "callable": "maximumSumSubsequence", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "queries", "type": "vector<vector<int>>&" ...
3,168
minimum-number-of-chairs-in-a-waiting-room
Easy
You are given a string s. Simulate events at each second i: - If s[i] == 'E', a person enters the waiting room and takes one of the chairs in it. - If s[i] == 'L', a person leaves the waiting room, freeing up a chair. Return the minimum number of chairs needed so that a chair is available for every person who enters ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"ELEELEELLL\") == 3\n assert candidate(s = \"EEEEEEE\") == 7\n assert candidate(s = \"EELLEELLL\") == 2\n assert candidate(s = \"E\") == 1\n assert candidate(s = \"EELLEL\") == 2\n assert candidate(s = \"ELE\") == 1\n...
[ "\"EEEEEEE\"", "\"ELELEEL\"", "\"ELEELEELLL\"" ]
[ "Iterate from left to right over the string and keep track of the number of people in the waiting room using a variable that you will increment on every occurrence of ‘E’ and decrement on every occurrence of ‘L’.", "The answer is the maximum number of people in the waiting room at any instance." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minimumChairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:31", "tests_total": 144, "tests_drop...
cpp
{ "raw_signature": "int minimumChairs(string s) {", "container": "Solution", "callable": "minimumChairs", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,169
count-days-without-meetings
Medium
You are given a positive integer days representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array meetings of size n where, meetings[i] = [start_i, end_i] represents the starting and ending days of meeting i (inclusive). Return the count of days when the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(days = 15,meetings = [[5, 6], [6, 7], [7, 8]]) == 11\n assert candidate(days = 10,meetings = [[5, 7], [1, 3], [9, 10]]) == 2\n assert candidate(days = 15,meetings = [[1, 2], [3, 5], [6, 8], [10, 12], [14, 15]]) == 2\n assert can...
[ "10\n[[5,7],[1,3],[9,10]]", "5\n[[2,4],[1,3]]", "6\n[[1,6]]" ]
[ "Merge the overlapping meetings and sort the new meetings timings.", "Return the sum of difference between the end time of a meeting and the start time of the next meeting for all adjacent pairs." ]
{ "canonical_parameter_names": [ "days", "meetings" ], "leetcode_dataset_entry_point": "Solution().countDays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:34", "tests_total": 90,...
cpp
{ "raw_signature": "int countDays(int days, vector<vector<int>>& meetings) {", "container": "Solution", "callable": "countDays", "parameters": [ { "name": "days", "type": "int" }, { "name": "meetings", "type": "vector<vector<int>>&" } ], "return_type": "int", "signa...
3,170
lexicographically-minimum-string-after-removing-stars
Medium
You are given a string s. It may contain any number of '*' characters. Your task is to remove all '*' characters. While there is a '*', do the following operation: - Delete the leftmost '*' and the smallest non-'*' character to its left. If there are several smallest characters, you can delete any of them. Return th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"*a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z\") == \"z\"\n assert candidate(s = \"*a*b*c\") == \"c\"\n assert candidate(s = \"aaba*\") == \"aab\"\n assert candidate(s = \"z*z*z*z\") == \"z\"\n assert candidate(s...
[ "\"aaba*\"", "\"abc\"" ]
[]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().clearStars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:36", "tests_total": 70, "tests_dropped"...
cpp
{ "raw_signature": "string clearStars(string s) {", "container": "Solution", "callable": "clearStars", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,171
find-subarray-with-bitwise-or-closest-to-k
Hard
You are given an array nums and an integer k. You need to find a subarray of nums such that the absolute difference between k and the bitwise OR of the subarray elements is as small as possible. In other words, select a subarray nums[l..r] such that |k - (nums[l] OR nums[l + 1] ... OR nums[r])| is minimum. Return the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000000],k = 500000000) == 500000000\n assert candidate(nums = [10, 20, 30, 40],k = 25) == 5\n assert candidate(nums = [1],k = 10) == 9\n assert candidate(nums = [5, 6, 7, 8, 9],k = 7) == 0\n assert candidate(nums ...
[ "[1,2,4,5]\n3", "[1,3,1,3]\n2", "[1]\n10" ]
[ "Let dp[i] be the set of all the bitwise OR of all the subarrays ending at index i.", "We start from nums[i], taking the bitwise OR result by including elements one by one from i towards left. Notice that only unset bits can become set on adding an element, and set bits never become unset again.", "Hence dp[i] ...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().minimumDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:39", "tests_total": 12...
cpp
{ "raw_signature": "int minimumDifference(vector<int>& nums, int k) {", "container": "Solution", "callable": "minimumDifference", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": ...
3,174
clear-digits
Easy
You are given a string s. Your task is to remove all digits by doing this operation repeatedly: - Delete the first digit and the closest non-digit character to its left. Return the resulting string after removing all digits. Note that the operation cannot be performed on a digit that does not have any non-digit cha...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdef\") == \"abcdef\"\n assert candidate(s = \"a1b2c3d4e5\") == \"\"\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0\") == \"\"\n assert candidate(s = \"a1b2c3d4e5f6\") == \"\"\n assert candidate(s = \"a1b2c3\") == \"\"...
[ "\"abc\"", "\"cb34\"" ]
[ "Process string s from left to right, if s[i] is a digit, mark the nearest unmarked non-digit index to its left.", "Delete all digits and all marked characters." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().clearDigits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:43", "tests_total": 72, "tests_dropped...
cpp
{ "raw_signature": "string clearDigits(string s) {", "container": "Solution", "callable": "clearDigits", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,175
find-the-first-player-to-win-k-games-in-a-row
Medium
A competition consists of n players numbered from 0 to n - 1. You are given an integer array skills of size n and a positive integer k, where skills[i] is the skill level of player i. All integers in skills are unique. All players are standing in a queue in order from player 0 to player n - 1. The competition proces...
{ "language": "python", "source": "def check(candidate):\n assert candidate(skills = [5, 1, 9, 2, 8, 3, 7, 4, 6],k = 3) == 2\n assert candidate(skills = [1000000, 999999, 999998, 999997],k = 4) == 0\n assert candidate(skills = [2, 5, 4],k = 3) == 1\n assert candidate(skills = [1, 3, 2, 5, 4],k = 1) == 1...
[ "[4,2,6,3,9]\n2", "[2,5,4]\n3" ]
[ "Suppose that k ≥ n, there is exactly one player who can win k games in a row. Who is it?", "In case k < n, you can simulate the competition process described." ]
{ "canonical_parameter_names": [ "skills", "k" ], "leetcode_dataset_entry_point": "Solution().findWinningPlayer", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:46", "tests_total": ...
cpp
{ "raw_signature": "int findWinningPlayer(vector<int>& skills, int k) {", "container": "Solution", "callable": "findWinningPlayer", "parameters": [ { "name": "skills", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_sourc...
3,176
find-the-maximum-length-of-a-good-subsequence-i
Medium
You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1]. Return the maximum possible length of a good subsequence of nums. Example 1: Input: nums = [1,2,1,1,3], k = 2 O...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 4) == 10\n assert candidate(nums = [1, 2, 3, 2, 1],k = 1) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 0) == 1\n ...
[ "[1,2,1,1,3]\n2", "[1,2,3,4,5,1]\n0" ]
[ "The absolute values in nums don’t really matter. So we can remap the set of values to the range [0, n - 1].", "Let dp[i][j] be the length of the longest subsequence till index j with at most i positions such that seq[i] != seq[i + 1].", "For each value x from left to right, update dp[i][x] = max(dp[i][x] + 1, ...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:48", "tests_total": 109, ...
cpp
{ "raw_signature": "int maximumLength(vector<int>& nums, int k) {", "container": "Solution", "callable": "maximumLength", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcod...
3,177
find-the-maximum-length-of-a-good-subsequence-ii
Hard
You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1]. Return the maximum possible length of a good subsequence of nums. Example 1: Input: nums = [1,2,1,1,3], k = 2 O...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 4) == 10\n assert candidate(nums = [1, 2, 3, 2, 1],k = 1) == 3\n assert can...
[ "[1,2,1,1,3]\n2", "[1,2,3,4,5,1]\n0" ]
[ "The absolute values in nums don’t really matter. So we can remap the set of values to the range [0, n - 1].", "Let dp[i][j] be the length of the longest subsequence till index j with at most i positions such that seq[i] != seq[i + 1].", "For each value x from left to right, update dp[i][x] = max(dp[i][x] + 1, ...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:51", "tests_total": 107, ...
cpp
{ "raw_signature": "int maximumLength(vector<int>& nums, int k) {", "container": "Solution", "callable": "maximumLength", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcod...
3,178
find-the-child-who-has-the-ball-after-k-seconds
Easy
You are given two positive integers n and k. There are n children numbered from 0 to n - 1 standing in a queue in order from left to right. Initially, child 0 holds a ball and the direction of passing the ball is towards the right direction. After each second, the child holding the ball passes it to the child next to ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 50,k = 50) == 48\n assert candidate(n = 3,k = 5) == 1\n assert candidate(n = 2,k = 1) == 1\n assert candidate(n = 40,k = 20) == 20\n assert candidate(n = 5,k = 6) == 2\n assert candidate(n = 10,k = 15) == 3\n assert...
[ "3\n5", "5\n6", "4\n2" ]
[ "The ball will go back to child 0 after 2 * (n - 1) seconds and everything is the same as time 0.", "So the answer for k is the same as the answer for k % (2 * (n - 1))." ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfChild", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:53", "tests_total": 82, "te...
cpp
{ "raw_signature": "int numberOfChild(int n, int k) {", "container": "Solution", "callable": "numberOfChild", "parameters": [ { "name": "n", "type": "int" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type...
3,179
find-the-n-th-value-after-k-seconds
Medium
You are given two integers n and k. Initially, you start with an array a of n integers where a[i] = 1 for all 0 <= i <= n - 1. After each second, you simultaneously update each element to be the sum of all its preceding elements plus the element itself. For example, after one second, a[0] remains the same, a[1] become...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 7,k = 4) == 210\n assert candidate(n = 2,k = 4) == 5\n assert candidate(n = 2,k = 5) == 6\n assert candidate(n = 8,k = 4) == 330\n assert candidate(n = 2,k = 1) == 2\n assert candidate(n = 1,k = 1) == 1\n assert can...
[ "4\n5", "5\n3" ]
[ "Calculate the prefix sum array of nums, k times." ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().valueAfterKSeconds", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:55", "tests_total": 63, ...
cpp
{ "raw_signature": "int valueAfterKSeconds(int n, int k) {", "container": "Solution", "callable": "valueAfterKSeconds", "parameters": [ { "name": "n", "type": "int" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets...
3,180
maximum-total-reward-using-operations-i
Medium
You are given an integer array rewardValues of length n, representing the values of rewards. Initially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times: - Choose an unmarked index i from the range [0, n - 1]. - If rewardValues[i] is greate...
{ "language": "python", "source": "def check(candidate):\n assert candidate(rewardValues = [1, 1, 3, 3]) == 4\n assert candidate(rewardValues = [2000, 1]) == 2001\n assert candidate(rewardValues = [1, 6, 4, 3, 2]) == 11\n assert candidate(rewardValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 37\n as...
[ "[1,1,3,3]", "[1,6,4,3,2]" ]
[ "Sort the rewards array first.", "If we decide to apply some rewards, it's always optimal to apply them in order.", "Let dp[i][j] (true/false) be the state after the first i rewards, indicating whether we can get exactly j points.", "The transition is given by: dp[i][j] = dp[i - 1][j - rewardValues[i]] if j -...
{ "canonical_parameter_names": [ "rewardValues" ], "leetcode_dataset_entry_point": "Solution().maxTotalReward", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:57", "tests_total": 104, ...
cpp
{ "raw_signature": "int maxTotalReward(vector<int>& rewardValues) {", "container": "Solution", "callable": "maxTotalReward", "parameters": [ { "name": "rewardValues", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
3,181
maximum-total-reward-using-operations-ii
Hard
You are given an integer array rewardValues of length n, representing the values of rewards. Initially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times: - Choose an unmarked index i from the range [0, n - 1]. - If rewardValues[i] is greate...
{ "language": "python", "source": "def check(candidate):\n assert candidate(rewardValues = [1, 2, 3, 4, 5]) == 9\n assert candidate(rewardValues = [1, 1, 3, 3]) == 4\n assert candidate(rewardValues = [50000, 40000, 30000, 20000, 10000]) == 90000\n assert candidate(rewardValues = [1, 2, 2, 1, 1, 2, 2, 1,...
[ "[1,1,3,3]", "[1,6,4,3,2]" ]
[ "Sort the rewards array first.", "If we decide to apply some rewards, it's always optimal to apply them in order.", "The transition is given by: dp[i][j] = dp[i - 1][j - rewardValues[i]] if j - rewardValues[i] < rewardValues[i].", "Note that the dp array is a boolean array. We just need 1 bit per element, so ...
{ "canonical_parameter_names": [ "rewardValues" ], "leetcode_dataset_entry_point": "Solution().maxTotalReward", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:00", "tests_total": 87, ...
cpp
{ "raw_signature": "int maxTotalReward(vector<int>& rewardValues) {", "container": "Solution", "callable": "maxTotalReward", "parameters": [ { "name": "rewardValues", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
3,184
count-pairs-that-form-a-complete-day-i
Easy
Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day. A complete day is defined as a time duration that is an exact multiple of 24 hours. For example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 h...
{ "language": "python", "source": "def check(candidate):\n assert candidate(hours = [23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11\n assert candidate(hours = [24, 48, 72, 96, 120]) == 10\n assert candidate(hours = [1000000000, 1000000000, 1000000000, 1000000000])...
[ "[12,12,30,24,24]", "[72,48,24,3]" ]
[ "Brute force all pairs (i, j) and check if they form a valid complete day. It is considered a complete day if (hours[i] + hours[j]) % 24 == 0." ]
{ "canonical_parameter_names": [ "hours" ], "leetcode_dataset_entry_point": "Solution().countCompleteDayPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:04", "tests_total": 83, ...
cpp
{ "raw_signature": "int countCompleteDayPairs(vector<int>& hours) {", "container": "Solution", "callable": "countCompleteDayPairs", "parameters": [ { "name": "hours", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
3,185
count-pairs-that-form-a-complete-day-ii
Medium
Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day. A complete day is defined as a time duration that is an exact multiple of 24 hours. For example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 h...
{ "language": "python", "source": "def check(candidate):\n assert candidate(hours = [5, 19, 15, 1, 23, 7, 17, 11, 3, 21, 9, 13, 20, 18, 4, 16, 8, 12, 6, 22, 14, 2, 10, 10, 10]) == 13\n assert candidate(hours = [24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384, 408, 432, 456, 480, 504...
[ "[12,12,30,24,24]", "[72,48,24,3]" ]
[ "A pair (i, j) forms a valid complete day if (hours[i] + hours[j]) % 24 == 0.", "Using an array or a map, for each index j moving from left to right, increase the answer by the count of (24 - hours[j]) % 24, and then increase the count of hours[j]." ]
{ "canonical_parameter_names": [ "hours" ], "leetcode_dataset_entry_point": "Solution().countCompleteDayPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:07", "tests_total": 73, ...
cpp
{ "raw_signature": "long long countCompleteDayPairs(vector<int>& hours) {", "container": "Solution", "callable": "countCompleteDayPairs", "parameters": [ { "name": "hours", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_sour...
3,186
maximum-total-damage-with-spell-casting
Medium
A magician has various spells. You are given an array power, where each element represents the damage of a spell. Multiple spells can have the same damage value. It is a known fact that if a magician decides to cast a spell with a damage of power[i], they cannot cast any spell with a damage of power[i] - 2, power[i] ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(power = [5, 5, 5, 5, 5]) == 25\n assert candidate(power = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91]) == 506\n assert candidate(power = [5, 3, 8, 9, 2]) == 16\n assert candidate(power = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59]) ...
[ "[1,1,3,4]", "[7,1,6,6]" ]
[ "If we ever decide to use some spell with power x, then we will use all spells with power x.", "Think of dynamic programming.", "dp[i][j] represents the maximum damage considering up to the i-th unique spell and j represents the number of spells skipped (up to 3 as per constraints)." ]
{ "canonical_parameter_names": [ "power" ], "leetcode_dataset_entry_point": "Solution().maximumTotalDamage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:10", "tests_total": 99, "te...
cpp
{ "raw_signature": "long long maximumTotalDamage(vector<int>& power) {", "container": "Solution", "callable": "maximumTotalDamage", "parameters": [ { "name": "power", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "...
3,187
peaks-in-array
Hard
A peak in an array arr is an element that is greater than its previous and next element in arr. You are given an integer array nums and a 2D integer array queries. You have to process queries of two types: - queries[i] = [1, l_i, r_i], determine the count of peak elements in the subarray nums[l_i..r_i]. - queries[i]...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 1, 4, 2, 5],queries = [[2, 3, 4], [1, 0, 4]]) == [0]\n assert candidate(nums = [4, 1, 4, 2, 1, 5],queries = [[2, 2, 4], [1, 0, 2], [1, 0, 4]]) == [0, 1]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5],queries = [[1...
[ "[3,1,4,2,5]\n[[2,3,4],[1,0,4]]", "[4,1,4,2,1,5]\n[[2,2,4],[1,0,2],[1,0,4]]" ]
[ "Let p[i] be whether nums[i] is a peak in the original array. Namely p[i] = nums[i] > nums[i - 1] && nums[i] > nums[i + 1].", "Updating nums[i], only affects p[i], p[i - 1] and p[i + 1]. We can recalculate the 3 values in constant time.", "The answer for [l_i, r_i] is p[l_i + 1] + p[l_i + 2] + … + p[r_i - 1] (n...
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().countOfPeaks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:13", "tests_total": 8...
cpp
{ "raw_signature": "vector<int> countOfPeaks(vector<int>& nums, vector<vector<int>>& queries) {", "container": "Solution", "callable": "countOfPeaks", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "queries", "type": "vector<vector<int>>&" } ], ...
3,190
find-minimum-operations-to-make-all-elements-divisible-by-three
Easy
You are given an integer array nums. In one operation, you can add or subtract 1 from any element of nums. Return the minimum number of operations to make all elements of nums divisible by 3. Example 1: Input: nums = [1,2,3,4] Output: 3 Explanation: All array elements can be made divisible by 3 using 3 operations: -...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 4, 5]) == 4\n assert candidate(nums = [1, 1, 1, 1]) == 4\n assert candidate(nums = [3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 2, 4, 5, 7]) == 5\n assert candidate(nums = [1, 2, 4, 5, 7, 8]) == 6\n asser...
[ "[1,2,3,4]", "[3,6,9]" ]
[ "If x % 3 != 0 we can always increment or decrement x such that we only need 1 operation.", "Add min(nums[i] % 3, 3 - (nums[i] % 3)) to the count of operations." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:18", "tests_total": 117, "tes...
cpp
{ "raw_signature": "int minimumOperations(vector<int>& nums) {", "container": "Solution", "callable": "minimumOperations", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
3,191
minimum-operations-to-make-binary-array-elements-equal-to-one-i
Medium
You are given a binary array nums. You can do the following operation on the array any number of times (possibly zero): - Choose any 3 consecutive elements from the array and flip all of them. Flipping an element means changing its value from 0 to 1, and from 1 to 0. Return the minimum number of operations required...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 0, 1, 0, 1]) == 3\n assert candidate(nums = [0, 0, 1, 1, 1, 0, 0]) == -1\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 0, 1, 1, 0]) == 4\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candi...
[ "[0,1,1,1,0,0]", "[0,1,1,1]" ]
[ "If nums[0] is 0, then the only way to change it to 1 is by doing an operation on the first 3 elements of the array.", "After Changing nums[0] to 1, use the same logic on the remaining array." ]
{ "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-30T21:16:20", "tests_total": 109, "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" }
3,192
minimum-operations-to-make-binary-array-elements-equal-to-one-ii
Medium
You are given a binary array nums. You can do the following operation on the array any number of times (possibly zero): - Choose any index i from the array and flip all the elements from index i to the end of the array. Flipping an element means changing its value from 0 to 1, and from 1 to 0. Return the minimum nu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 0, 1, 0, 1]) == 6\n assert candidate(nums = [1, 0, 1, 0, 1]) == 4\n assert candidate(nums = [0, 1, 0, 1, 0]) == 5\n assert candidate(nums = [0, 0, 1, 1, 1, 0]) == 3\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1...
[ "[0,1,1,0,1]", "[1,0,0,0]" ]
[ "The only way to change nums[0] to 1 is by performing an operation with index i = 0.", "Iterate from left to right and perform an operation at each index i where nums[i] is 0, and keep track of how many operations are currently performed on the suffix." ]
{ "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-30T21:16:23", "tests_total": 68, "tests_dr...
cpp
{ "raw_signature": "int minOperations(vector<int>& nums) {", "container": "Solution", "callable": "minOperations", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,193
count-the-number-of-inversions
Hard
You are given an integer n and a 2D array requirements, where requirements[i] = [end_i, cnt_i] represents the end index and the inversion count of each requirement. A pair of indices (i, j) from an integer array nums is called an inversion if: - i < j and nums[i] > nums[j] Return the number of permutations perm of [...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,requirements = [[3, 3], [1, 1], [2, 2], [0, 0]]) == 1\n assert candidate(n = 5,requirements = [[4, 6], [2, 2], [3, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 2,requirements = [[0, 0], [1, 0]]) == 1\n assert candidate...
[ "3\n[[2,2],[0,0]]", "3\n[[2,2],[1,1],[0,0]]", "2\n[[0,0],[1,0]]" ]
[ "Let dp[i][j] denote the number of arrays of length i with j inversions.", "dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] + … + dp[i - 1][0].", "dp[i][j] = 0 if for some x, requirements[x][0] == i and requirements[x][1] != j." ]
{ "canonical_parameter_names": [ "n", "requirements" ], "leetcode_dataset_entry_point": "Solution().numberOfPermutations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:25", "tests...
cpp
{ "raw_signature": "int numberOfPermutations(int n, vector<vector<int>>& requirements) {", "container": "Solution", "callable": "numberOfPermutations", "parameters": [ { "name": "n", "type": "int" }, { "name": "requirements", "type": "vector<vector<int>>&" } ], "retur...
3,194
minimum-average-of-smallest-and-largest-elements
Easy
You have an array of floating point numbers averages which is initially empty. You are given an array nums of n integers where n is even. You repeat the following procedure n / 2 times: - Remove the smallest element, minElement, and the largest element maxElement, from nums. - Add (minElement + maxElement) / 2 to ave...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat...
[ "[7,8,3,4,15,13,4,1]", "[1,9,8,3,10,5]", "[1,2,3,7,8,9]" ]
[ "If nums is sorted, then the elements of averages are (nums[i] + nums[n - i - 1]) / 2 for all i < n / 2." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumAverage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:27", "tests_total": 132, "tests_...
cpp
{ "raw_signature": "double minimumAverage(vector<int>& nums) {", "container": "Solution", "callable": "minimumAverage", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "double", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
3,195
find-the-minimum-area-to-cover-all-ones-i
Medium
You are given a 2D binary array grid. Find a rectangle with horizontal and vertical sides with the smallest area, such that all the 1's in grid lie inside this rectangle. Return the minimum possible area of the rectangle. Example 1: Input: grid = [[0,1,0],[1,0,1]] Output: 6 Explanation: The smallest rectangle has a ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [1, 0, 0]]) == 1\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]) == 20\n assert cand...
[ "[[0,1,0],[1,0,1]]", "[[0,0],[1,0]]" ]
[ "Find the minimum and maximum coordinates of a cell with a value of 1 in both directions." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minimumArea", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:30", "tests_total": 76, "tests_drop...
cpp
{ "raw_signature": "int minimumArea(vector<vector<int>>& grid) {", "container": "Solution", "callable": "minimumArea", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...
3,196
maximize-total-cost-of-alternating-subarrays
Medium
You are given an integer array nums with length n. The cost of a subarray nums[l..r], where 0 <= l <= r < n, is defined as: cost(l, r) = nums[l] - nums[l + 1] + ... + nums[r] * (-1)^{r - l} Your task is to split nums into subarrays such that the total cost of the subarrays is maximized, ensuring each element belongs...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, -3, 8, 7, -2, 6]) == 31\n assert candidate(nums = [5, -3, 2, 7, -6, 1]) == 24\n assert candidate(nums = [5, -3, 2, -4, 6]) == 20\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, -1, 1, -1]) == 4\n ...
[ "[1,-2,3,4]", "[1,-1,1,-1]", "[0]", "[1,-1]" ]
[ "The problem can be solved using dynamic programming.", "Since we can always start a new subarray, the problem is the same as selecting some elements in the array and flipping their signs to negative to maximize the sum. However, we cannot flip the signs of 2 consecutive elements, and the first element in the arr...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maximumTotalCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:32", "tests_total": 105, "test...
cpp
{ "raw_signature": "long long maximumTotalCost(vector<int>& nums) {", "container": "Solution", "callable": "maximumTotalCost", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
3,197
find-the-minimum-area-to-cover-all-ones-ii
Hard
You are given a 2D binary array grid. You need to find 3 non-overlapping rectangles having non-zero areas with horizontal and vertical sides such that all the 1's in grid lie inside these rectangles. Return the minimum possible sum of the area of these rectangles. Note that the rectangles are allowed to touch. Examp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1]]) == 5\n assert candidate(grid = [[1, 1, 0, 0, 1], [1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [0, 0, 1, 1, 0]]) == 10\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 1, 1, 0, 0], [0, 1, 1, 0, 0], [1, 0, 0,...
[ "[[1,0,1],[1,1,1]]", "[[1,0,1,0],[0,1,0,1]]" ]
[ "Consider covering using 2 rectangles. As the rectangles don’t overlap, one of the rectangles must either be vertically above or horizontally left to the other.", "To find the minimum area, check all possible vertical and horizontal splits.", "For 3 rectangles, extend the idea to first covering using one rectan...
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minimumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:34", "tests_total": 62, "tests_dropp...
cpp
{ "raw_signature": "int minimumSum(vector<vector<int>>& grid) {", "container": "Solution", "callable": "minimumSum", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeS...
3,200
maximum-height-of-a-triangle
Easy
You are given two integers red and blue representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1^st row will have 1 ball, the 2^nd row will have 2 balls, the 3^rd row will have 3 balls, and so on. All the balls in a particular row should be the same color...
{ "language": "python", "source": "def check(candidate):\n assert candidate(red = 100,blue = 1) == 2\n assert candidate(red = 3,blue = 7) == 3\n assert candidate(red = 50,blue = 50) == 13\n assert candidate(red = 5,blue = 5) == 3\n assert candidate(red = 1,blue = 1) == 1\n assert candidate(red = 1...
[ "2\n4", "2\n1", "1\n1", "10\n1" ]
[ "Count the max height using both possibilities. That is, red ball as top and blue ball as top.", "For counting the max height, use a simple for loop and remove the number of balls required at this level." ]
{ "canonical_parameter_names": [ "red", "blue" ], "leetcode_dataset_entry_point": "Solution().maxHeightOfTriangle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:39", "tests_total"...
cpp
{ "raw_signature": "int maxHeightOfTriangle(int red, int blue) {", "container": "Solution", "callable": "maxHeightOfTriangle", "parameters": [ { "name": "red", "type": "int" }, { "name": "blue", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/...
3,201
find-the-maximum-length-of-valid-subsequence-i
Medium
You are given an integer array nums. A subsequence sub of nums with length x is called valid if it satisfies: - (sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2. Return the length of the longest valid subsequence of nums. Example 1: Input: nums = [1,2,3,4] Output: 4 Explanatio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(nums = [1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 2, 1, 1, 2, 1, 2]) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candida...
[ "[1,2,3,4]", "[1,2,1,1,2,1,2]", "[1,3]" ]
[ "The possible sequence either contains all even elements, all odd elements, alternate even odd, or alternate odd even elements.", "Considering only the parity of elements, there are only 4 possibilities and we can try all of them.", "When selecting an element with any parity, try to select the earliest one." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:41", "tests_total": 115, "tests_d...
cpp
{ "raw_signature": "int maximumLength(vector<int>& nums) {", "container": "Solution", "callable": "maximumLength", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,202
find-the-maximum-length-of-valid-subsequence-ii
Medium
You are given an integer array nums and a positive integer k. A subsequence sub of nums with length x is called valid if it satisfies: - (sub[0] + sub[1]) % k == (sub[1] + sub[2]) % k == ... == (sub[x - 2] + sub[x - 1]) % k. Return the length of the longest valid subsequence of nums. Example 1: Input: nums = [1,2,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 6, 8, 10],k = 4) == 3\n assert candidate(nums = [1, 4, 2, 3, 1, 4],k = 3) == 4\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 5\n assert candidate(nums = [3, 1, 3, 1, 3, 1, 3, 1],k = 2) == 8\n assert candidate...
[ "[1,2,3,4,5]\n2", "[1,4,2,3,1,4]\n3" ]
[ "Fix the value of (subs[0] + subs[1]) % k from the k possible values. Let it be val.", "Let dp[i] store the maximum length of a subsequence with its last element x such that x % k == i.", "Answer for a subsequence ending at index y is dp[(k + val - (y % k)) % k] + 1." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:44", "tests_total": 125, ...
cpp
{ "raw_signature": "int maximumLength(vector<int>& nums, int k) {", "container": "Solution", "callable": "maximumLength", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcod...
3,203
find-minimum-diameter-after-merging-two-trees
Hard
There exist two undirected trees with n and m nodes, numbered from 0 to n - 1 and from 0 to m - 1, respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges1[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the first tree and ed...
{ "language": "python", "source": "def check(candidate):\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 6\n assert candidate(edges1 = [[0, 1], [0, 2], [0, 3]],edges2 = [[0, 1]]) == 3\n assert candidate(edges1 = [[0, 1], [0, 2], [0, 3], [2,...
[ "[[0,1],[0,2],[0,3]]\n[[0,1]]", "[[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]\n[[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]" ]
[ "Suppose that we connected node a in tree1 with node b in tree2. The diameter length of the resulting tree will be the largest of the following 3 values:\n1. The diameter of tree 1.\n2. The diameter of tree 2.\n3. The length of the longest path that starts at node a and that is completely within Tree 1 + The length...
{ "canonical_parameter_names": [ "edges1", "edges2" ], "leetcode_dataset_entry_point": "Solution().minimumDiameterAfterMerge", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:47", "t...
cpp
{ "raw_signature": "int minimumDiameterAfterMerge(vector<vector<int>>& edges1, vector<vector<int>>& edges2) {", "container": "Solution", "callable": "minimumDiameterAfterMerge", "parameters": [ { "name": "edges1", "type": "vector<vector<int>>&" }, { "name": "edges2", "type": ...
3,206
alternating-groups-i
Easy
There is a circle of red and blue tiles. You are given an array of integers colors. The color of tile i is represented by colors[i]: - colors[i] == 0 means that tile i is red. - colors[i] == 1 means that tile i is blue. Every 3 contiguous tiles in the circle with alternating colors (the middle tile has a different co...
{ "language": "python", "source": "def check(candidate):\n assert candidate(colors = [1, 1, 1, 0, 0, 0, 1, 1, 1]) == 0\n assert candidate(colors = [1, 0, 0, 0, 1, 1, 1, 0]) == 2\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0]) == 7\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1]) == 1\n ass...
[ "[1,1,1]", "[0,1,0,0,1]" ]
[ "For each tile, check that the previous and the next tile have different colors from that tile or not." ]
{ "canonical_parameter_names": [ "colors" ], "leetcode_dataset_entry_point": "Solution().numberOfAlternatingGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:51", "tests_total": 1...
cpp
{ "raw_signature": "int numberOfAlternatingGroups(vector<int>& colors) {", "container": "Solution", "callable": "numberOfAlternatingGroups", "parameters": [ { "name": "colors", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source...
3,207
maximum-points-after-enemy-battles
Medium
You are given an integer array enemyEnergies denoting the energy values of various enemies. You are also given an integer currentEnergy denoting the amount of energy you have initially. You start with 0 points, and all the enemies are unmarked initially. You can perform either of the following operations zero or mul...
{ "language": "python", "source": "def check(candidate):\n assert candidate(enemyEnergies = [1, 1, 1, 1, 1],currentEnergy = 1) == 5\n assert candidate(enemyEnergies = [5, 5, 5, 5, 5],currentEnergy = 15) == 7\n assert candidate(enemyEnergies = [2],currentEnergy = 10) == 5\n assert candidate(enemyEnergies...
[ "[3,2,2]\n2", "[2]\n10" ]
[ "The problem can be solved greedily.", "Mark all the others except the smallest one first.", "Use the smallest one to increase the energy.", "Note that the initial energy should be no less than the smallest enemy." ]
{ "canonical_parameter_names": [ "enemyEnergies", "currentEnergy" ], "leetcode_dataset_entry_point": "Solution().maximumPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:54", ...
cpp
{ "raw_signature": "long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {", "container": "Solution", "callable": "maximumPoints", "parameters": [ { "name": "enemyEnergies", "type": "vector<int>&" }, { "name": "currentEnergy", "type": "int" } ], "ret...
3,208
alternating-groups-ii
Medium
There is a circle of red and blue tiles. You are given an array of integers colors and an integer k. The color of tile i is represented by colors[i]: - colors[i] == 0 means that tile i is red. - colors[i] == 1 means that tile i is blue. An alternating group is every k contiguous tiles in the circle with alternating c...
{ "language": "python", "source": "def check(candidate):\n assert candidate(colors = [1, 1, 0, 1],k = 4) == 0\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0],k = 3) == 8\n assert candidate(colors = [0, 1, 0, 0, 1, 0, 1],k = 6) == 2\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1],k = 3) == 7...
[ "[0,1,0,1,0]\n3", "[0,1,0,0,1,0,1]\n6", "[1,1,0,1]\n4" ]
[ "Try to find a tile that has the same color as its next tile (if it exists).", "Then try to find maximal alternating groups by starting a single for loop from that tile." ]
{ "canonical_parameter_names": [ "colors", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfAlternatingGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:56", "tests_...
cpp
{ "raw_signature": "int numberOfAlternatingGroups(vector<int>& colors, int k) {", "container": "Solution", "callable": "numberOfAlternatingGroups", "parameters": [ { "name": "colors", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", ...
3,209
number-of-subarrays-with-and-value-of-k
Hard
Given an array of integers nums and an integer k, return the number of subarrays of nums where the bitwise AND of the elements of the subarray equals k. Example 1: Input: nums = [1,1,1], k = 1 Output: 6 Explanation: All subarrays contain only 1's. Example 2: Input: nums = [1,1,2], k = 1 Output: 3 Explanation: Subar...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 15\n assert candidate(nums = [10, 9, 8, 7, 6],k = 10) == 1\n assert candidate(nums = [5, 5, 5, 5],k = 5) == 10\n assert candidate(nums = [3, 3, 3, 3, 3, 3],k = 3) == 21\n assert candidate(nums...
[ "[1,1,1]\n1", "[1,1,2]\n1", "[1,2,3]\n2" ]
[ "Let’s say we want to count the number of pairs (l, r) such that nums[l] & nums[l + 1] & … & nums[r] == k.", "Fix the left index l.", "Note that if you increase r for a fixed l, then the AND value of the subarray either decreases or remains unchanged.", "Therefore, consider using binary search.", "To calcul...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().countSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:59", "tests_total": 127, ...
cpp
{ "raw_signature": "long long countSubarrays(vector<int>& nums, int k) {", "container": "Solution", "callable": "countSubarrays", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "long long", "signature_sou...
3,210
find-the-encrypted-string
Easy
You are given a string s and an integer k. Encrypt the string using the following algorithm: - For each character c in s, replace c with the k^th character after c in the string (in a cyclic manner). Return the encrypted string. Example 1: Input: s = "dart", k = 3 Output: "tdar" Explanation: - For i = 0, the 3^rd c...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"hello\",k = 10) == \"hello\"\n assert candidate(s = \"abc\",k = 2) == \"cab\"\n assert candidate(s = \"hello\",k = 7) == \"llohe\"\n assert candidate(s = \"abcdef\",k = 2) == \"cdefab\"\n assert candidate(s = \"world\",...
[ "\"dart\"\n3", "\"aaa\"\n1" ]
[ "Make a new string such that for each character in s, character i will correspond to (i + k) % s.length character in the original string." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().getEncryptedString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:01", "tests_total": 88, ...
cpp
{ "raw_signature": "string getEncryptedString(string s, int k) {", "container": "Solution", "callable": "getEncryptedString", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "int" } ], "return_type": "string", "signature_source": "leetcode/...
3,211
generate-binary-strings-without-adjacent-zeros
Medium
You are given a positive integer n. A binary string x is valid if all substrings of x of length 2 contain at least one "1". Return all valid strings with length n, in any order. Example 1: Input: n = 3 Output: ["010","011","101","110","111"] Explanation: The valid strings of length 3 are: "010", "011", "101", "110"...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ...
[ "3", "1" ]
[ "If we have a string s of length x, we can generate all strings of length x + 1.", "If s has 0 as the last character, we can only append 1, whereas if the last character is 1, we can append both 0 and 1.", "We can use recursion and backtracking to generate all such strings." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().validStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:03", "tests_total": 12, "tests_droppe...
cpp
{ "raw_signature": "vector<string> validStrings(int n) {", "container": "Solution", "callable": "validStrings", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "vector<string>", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,212
count-submatrices-with-equal-frequency-of-x-and-y
Medium
Given a 2D character matrix grid, where grid[i][j] is either 'X', 'Y', or '.', return the number of submatrices that contain: - grid[0][0] - an equal frequency of 'X' and 'Y'. - at least one 'X'. Example 1: Input: grid = [["X","Y","."],["Y",".","."]] Output: 3 Explanation: Example 2: Input: grid = [["X","X"],["X",...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [['X', 'Y', 'X'], ['Y', 'X', 'Y'], ['X', 'Y', 'X']]) == 5\n assert candidate(grid = [['.', '.'], ['.', '.']]) == 0\n assert candidate(grid = [['X', 'X'], ['X', 'Y']]) == 0\n assert candidate(grid = [['X', 'X', 'Y', 'Y'], ...
[ "[[\"X\",\"Y\",\".\"],[\"Y\",\".\",\".\"]]", "[[\"X\",\"X\"],[\"X\",\"Y\"]]", "[[\".\",\".\"],[\".\",\".\"]]" ]
[ "Replace ’X’ with 1, ’Y’ with -1 and ’.’ with 0.", "You need to find how many submatrices grid[0..x][0..y] have a sum of 0 and at least one ’X’.", "Use prefix sum to calculate submatrices sum." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().numberOfSubmatrices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:06", "tests_total": 45, "te...
cpp
{ "raw_signature": "int numberOfSubmatrices(vector<vector<char>>& grid) {", "container": "Solution", "callable": "numberOfSubmatrices", "parameters": [ { "name": "grid", "type": "vector<vector<char>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_sour...
3,213
construct-string-with-minimum-cost
Hard
You are given a string target, an array of strings words, and an integer array costs, both arrays of the same length. Imagine an empty string s. You can perform the following operation any number of times (including zero): - Choose an index i in the range [0, words.length - 1]. - Append words[i] to s. - The cost of ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(target = \"xyz\",words = ['x', 'y', 'z'],costs = [1, 2, 3]) == 6\n assert candidate(target = \"abcd\",words = ['a', 'b', 'c', 'd'],costs = [1, 1, 1, 1]) == 4\n assert candidate(target = \"zzzz\",words = ['zz', 'zzzz'],costs = [2, 1...
[ "\"abcdef\"\n[\"abdef\",\"abc\",\"d\",\"def\",\"ef\"]\n[100,1,1,10,5]", "\"aaaa\"\n[\"z\",\"zz\",\"zzz\"]\n[1,10,100]" ]
[ "Use Dynamic Programming along with Aho-Corasick or Hashing." ]
{ "canonical_parameter_names": [ "target", "words", "costs" ], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:09", "tes...
cpp
{ "raw_signature": "int minimumCost(string target, vector<string>& words, vector<int>& costs) {", "container": "Solution", "callable": "minimumCost", "parameters": [ { "name": "target", "type": "string" }, { "name": "words", "type": "vector<string>&" }, { "name"...
3,216
lexicographically-smallest-string-after-a-swap
Easy
Given a string s containing only digits, return the lexicographically smallest string that can be obtained after swapping adjacent digits in s with the same parity at most once. Digits have the same parity if both are odd or both are even. For example, 5 and 9, as well as 2 and 4, have the same parity, while 6 and 9 d...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"9876543210\") == \"9876543210\"\n assert candidate(s = \"1324\") == \"1324\"\n assert candidate(s = \"111222333\") == \"111222333\"\n assert candidate(s = \"1352468709\") == \"1352468709\"\n assert candidate(s = \"21212...
[ "\"45320\"", "\"001\"" ]
[ "Try all possible swaps satisfying the constraints and find the one that results in the lexicographically smallest string." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().getSmallestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:14", "tests_total": 124, "tests_...
cpp
{ "raw_signature": "string getSmallestString(string s) {", "container": "Solution", "callable": "getSmallestString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,218
minimum-cost-for-cutting-cake-i
Medium
There is an m x n cake that needs to be cut into 1 x 1 pieces. You are given integers m, n, and two arrays: - horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizontal line i. - verticalCut of size n - 1, where verticalCut[j] represents the cost to cut along the vertical line...
{ "language": "python", "source": "def check(candidate):\n assert candidate(m = 5,n = 4,horizontalCut = [1, 2, 3, 4],verticalCut = [2, 4, 6]) == 49\n assert candidate(m = 4,n = 3,horizontalCut = [2, 5, 7],verticalCut = [3, 8]) == 47\n assert candidate(m = 2,n = 2,horizontalCut = [7],verticalCut = [4]) == 1...
[ "3\n2\n[1,3]\n[5]", "2\n2\n[7]\n[4]" ]
[ "The intended solution uses Dynamic Programming.", "Let dp[sx][sy][tx][ty] denote the minimum cost to cut the rectangle into 1 x 1 pieces.", "Iterate on the row or column on which you will perform the next cut, after the cut, the current rectangle will be decomposed into two sub-rectangles." ]
{ "canonical_parameter_names": [ "m", "n", "horizontalCut", "verticalCut" ], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30...
cpp
{ "raw_signature": "int minimumCost(int m, int n, vector<int>& horizontalCut, vector<int>& verticalCut) {", "container": "Solution", "callable": "minimumCost", "parameters": [ { "name": "m", "type": "int" }, { "name": "n", "type": "int" }, { "name": "horizontalC...
3,219
minimum-cost-for-cutting-cake-ii
Hard
There is an m x n cake that needs to be cut into 1 x 1 pieces. You are given integers m, n, and two arrays: - horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizontal line i. - verticalCut of size n - 1, where verticalCut[j] represents the cost to cut along the vertical line...
{ "language": "python", "source": "def check(candidate):\n assert candidate(m = 2,n = 2,horizontalCut = [7],verticalCut = [4]) == 15\n assert candidate(m = 4,n = 3,horizontalCut = [1, 2, 3],verticalCut = [1, 2]) == 17\n assert candidate(m = 3,n = 3,horizontalCut = [1, 2],verticalCut = [1, 2]) == 11\n as...
[ "3\n2\n[1,3]\n[5]", "2\n2\n[7]\n[4]" ]
[ "The intended solution uses a Greedy approach.", "At each step, we will perform a cut on the line with the highest cost.", "If you perform a horizontal cut, can you count the contribution that it adds to each row cut that comes afterward?" ]
{ "canonical_parameter_names": [ "m", "n", "horizontalCut", "verticalCut" ], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30...
cpp
{ "raw_signature": "long long minimumCost(int m, int n, vector<int>& horizontalCut, vector<int>& verticalCut) {", "container": "Solution", "callable": "minimumCost", "parameters": [ { "name": "m", "type": "int" }, { "name": "n", "type": "int" }, { "name": "horiz...
3,222
find-the-winning-player-in-coin-game
Easy
You are given two positive integers x and y, denoting the number of coins with values 75 and 10 respectively. Alice and Bob are playing a game. Each turn, starting with Alice, the player must pick up coins with a total value 115. If the player is unable to do so, they lose the game. Return the name of the player who ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(x = 100,y = 1) == \"Bob\"\n assert candidate(x = 1,y = 100) == \"Alice\"\n assert candidate(x = 1,y = 10) == \"Alice\"\n assert candidate(x = 4,y = 11) == \"Bob\"\n assert candidate(x = 2,y = 7) == \"Alice\"\n assert candi...
[ "2\n7", "4\n11" ]
[ "The only way to make 115 is to use one coin of value 75 and four coins of value 10. Each turn uses up these many coins.", "Hence the number of turns is min(x, y / 4).", "Determine the winner from its parity." ]
{ "canonical_parameter_names": [ "x", "y" ], "leetcode_dataset_entry_point": "Solution().winningPlayer", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:27", "tests_total": 104, "t...
cpp
{ "raw_signature": "string winningPlayer(int x, int y) {", "container": "Solution", "callable": "winningPlayer", "parameters": [ { "name": "x", "type": "int" }, { "name": "y", "type": "int" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", ...
3,223
minimum-length-of-string-after-operations
Medium
You are given a string s. You can perform the following process on s any number of times: - Choose an index i in the string such that there is at least one character to the left of index i that is equal to s[i], and at least one character to the right that is also equal to s[i]. - Delete the closest occurrence of s[i...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzyzyzyyzzyzz\") == 3\n assert candidate(s = \"abcba\") == 5\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"abaacbcbb\") == 5\n assert candidate(s = \"aabbaa\") == 4\n assert ...
[ "\"abaacbcbb\"", "\"aa\"" ]
[ "Only the frequency of each character matters in finding the final answer.", "If a character occurs less than 3 times, we cannot perform any process with it.", "Suppose there is a character that occurs at least 3 times in the string, we can repeatedly delete two of these characters until there are at most 2 occ...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minimumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:29", "tests_total": 47, "tests_dropp...
cpp
{ "raw_signature": "int minimumLength(string s) {", "container": "Solution", "callable": "minimumLength", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,224
minimum-array-changes-to-make-differences-equal
Medium
You are given an integer array nums of size n where n is even, and an integer k. You can perform some changes on the array, where in one change you can replace any element in the array with any integer in the range from 0 to k. You need to perform some changes (possibly none) such that the final array satisfies the f...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995],k = 100000) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5],k = 10) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8],k = 8) == 3\n assert candidate(nums = [1, 3, 5, 7,...
[ "[1,0,1,2,4,3]\n4", "[0,1,2,3,3,6,5,4]\n6" ]
[ "There are at most k + 1 possible values of the integer X.", "How do we calculate the minimum number of changes efficiently if we fix the value of X before applying any changes?" ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().minChanges", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:32", "tests_total": 101, "t...
cpp
{ "raw_signature": "int minChanges(vector<int>& nums, int k) {", "container": "Solution", "callable": "minChanges", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/code...
3,225
maximum-score-from-grid-operations
Hard
You are given a 2D matrix grid of size n x n. Initially, all cells of the grid are colored white. In one operation, you can select any cell of indices (i, j), and color black all the cells of the j^th column starting from the top row down to the i^th row. The grid score is the sum of all grid[i][j] such that cell (i, ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 3, 0, 0], [0, 1, 0, 0, 0], [5, 0, 0, 3, 0], [0, 0, 0, 0, 2]]) == 11\n assert candidate(grid = [[10, 9, 0, 0, 15], [7, 1, 0, 8, 0], [5, 20, 0, 11, 0], [0, 0, 0, 1, 2], [8, 12, 1, 10, 3]]) == 94\n asse...
[ "[[0,0,0,0,0],[0,0,3,0,0],[0,1,0,0,0],[5,0,0,3,0],[0,0,0,0,2]]", "[[10,9,0,0,15],[7,1,0,8,0],[5,20,0,11,0],[0,0,0,1,2],[8,12,1,10,3]]" ]
[ "Use dynamic programming.", "Solve the problem in O(N^4) using a 3-states dp.", "Let dp[i][lastHeight][beforeLastHeight] denote the maximum score if the grid was limited to column i, and the height of column i - 1 is lastHeight and the height of column i - 2 is beforeLastHeight.", "The third state, beforeLast...
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().maximumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:34", "tests_total": 75, "tests_dro...
cpp
{ "raw_signature": "long long maximumScore(vector<vector<int>>& grid) {", "container": "Solution", "callable": "maximumScore", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source":...
3,226
number-of-bit-changes-to-make-two-integers-equal
Easy
You are given two positive integers n and k. You can choose any bit in the binary representation of n that is equal to 1 and change it to 0. Return the number of changes needed to make n equal to k. If it is impossible, return -1. Example 1: Input: n = 13, k = 4 Output: 2 Explanation: Initially, the binary represen...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 1,k = 2) == -1\n assert candidate(n = 31,k = 1) == 4\n assert candidate(n = 15,k = 9) == 2\n assert candidate(n = 8,k = 8) == 0\n assert candidate(n = 1000000,k = 999999) == -1\n assert candidate(n = 7,k = 11) == -1\n ...
[ "13\n4", "21\n21", "14\n13" ]
[ "Find the binary representations of n and k.", "Any bit that is equal to 1 in n and equal to 0 in k needs to be changed." ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().minChanges", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:37", "tests_total": 91, "tests...
cpp
{ "raw_signature": "int minChanges(int n, int k) {", "container": "Solution", "callable": "minChanges", "parameters": [ { "name": "n", "type": "int" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_sourc...
3,227
vowels-game-in-a-string
Medium
Alice and Bob are playing a game on a string. You are given a string s, Alice and Bob will take turns playing the following game where Alice starts first: - On Alice's turn, she has to remove any non-empty substring from s that contains an odd number of vowels. - On Bob's turn, he has to remove any non-empty substrin...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"b\") == False\n assert candidate(s = \"bcbcbc\") == False\n assert candidate(s = \"leetcodeisfun\") == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(s = \"uoiea\") == True\n a...
[ "\"leetcoder\"", "\"bbcd\"" ]
[ "If there are no vowels in the initial string, then Bob wins.", "If the number of vowels in the initial string is odd, then Alice can remove the whole string on her first turn and win.", "What if the number of vowels in the initial string is even? What’s the optimal play for Alice’s first turn?" ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().doesAliceWin", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:39", "tests_total": 121, "tests_dropp...
cpp
{ "raw_signature": "bool doesAliceWin(string s) {", "container": "Solution", "callable": "doesAliceWin", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,228
maximum-number-of-operations-to-move-ones-to-the-end
Medium
You are given a binary string s. You can perform the following operation on the string any number of times: - Choose any index i from the string where i + 1 < s.length such that s[i] == '1' and s[i + 1] == '0'. - Move the character s[i] to the right until it reaches the end of the string or another '1'. For example, ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"00111\") == 0\n assert candidate(s = \"101100110\") == 9\n assert candidate(s = \"000111000\") == 3\n assert candidate(s = \"11110000\") == 4\n assert candidate(s = \"010101010\") == 10\n assert candidate(s = \"10010...
[ "\"1001101\"", "\"00111\"" ]
[ "It is optimal to perform the operation on the lowest index possible each time.", "Traverse the string from left to right and perform the operation every time it is possible." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().maxOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:42", "tests_total": 107, "tests_drop...
cpp
{ "raw_signature": "int maxOperations(string s) {", "container": "Solution", "callable": "maxOperations", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,229
minimum-operations-to-make-array-equal-to-target
Hard
You are given two positive integer arrays nums and target, of the same length. In a single operation, you can select any subarray of nums and increment each element within that subarray by 1 or decrement each element within that subarray by 1. Return the minimum number of operations required to make nums equal to the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 100000000, 1],target = [100000000, 1, 100000000]) == 299999997\n assert candidate(nums = [1, 3, 2],target = [2, 1, 4]) == 5\n assert candidate(nums = [3, 5, 1, 2],target = [4, 6, 2, 4]) == 2\n assert candidate(nums = ...
[ "[3,5,1,2]\n[4,6,2,4]", "[1,3,2]\n[2,1,4]" ]
[ "Change nums'[i] = nums[i] - target[i], so our goal is to make nums' into all 0s.", "Divide and conquer." ]
{ "canonical_parameter_names": [ "nums", "target" ], "leetcode_dataset_entry_point": "Solution().minimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:45", "tests_total...
cpp
{ "raw_signature": "long long minimumOperations(vector<int>& nums, vector<int>& target) {", "container": "Solution", "callable": "minimumOperations", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "target", "type": "vector<int>&" } ], "return_ty...
3,232
find-if-digit-game-can-be-won
Easy
You are given an array of positive integers nums. Alice and Bob are playing a game. In the game, Alice can choose either all single-digit numbers or all double-digit numbers from nums, and the rest of the numbers are given to Bob. Alice wins if the sum of her numbers is strictly greater than the sum of Bob's numbers. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [9, 9, 9, 10, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 14]) == True\n assert candidate(nums = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n ...
[ "[1,2,3,4,10]", "[1,2,3,4,5,14]", "[5,5,5,25]" ]
[ "Alice wins if the sum of all single-digit numbers and the sum of all double-digit numbers are different." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().canAliceWin", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:50", "tests_total": 121, "tests_dro...
cpp
{ "raw_signature": "bool canAliceWin(vector<int>& nums) {", "container": "Solution", "callable": "canAliceWin", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,233
find-the-count-of-numbers-which-are-not-special
Medium
You are given 2 positive integers l and r. For any number x, all positive divisors of x except x are called the proper divisors of x. A number is called special if it has exactly 2 proper divisors. For example: - The number 4 is special because it has proper divisors 1 and 2. - The number 6 is not special because it ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(l = 100,r = 200) == 99\n assert candidate(l = 5,r = 7) == 3\n assert candidate(l = 20,r = 50) == 29\n assert candidate(l = 1,r = 10) == 8\n assert candidate(l = 100,r = 150) == 50\n assert candidate(l = 4,r = 16) == 11\n ...
[ "5\n7", "4\n16" ]
[ "A special number must be a square of a prime number.", "We need to find all primes in the range [sqrt(l), sqrt(r)].", "Use sieve to find primes till sqrt(10^9)." ]
{ "canonical_parameter_names": [ "l", "r" ], "leetcode_dataset_entry_point": "Solution().nonSpecialCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:52", "tests_total": 77, "...
cpp
{ "raw_signature": "int nonSpecialCount(int l, int r) {", "container": "Solution", "callable": "nonSpecialCount", "parameters": [ { "name": "l", "type": "int" }, { "name": "r", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "...
3,234
count-the-number-of-substrings-with-dominant-ones
Medium
You are given a binary string s. Return the number of substrings with dominant ones. A string has dominant ones if the number of ones in the string is greater than or equal to the square of the number of zeros in the string. Example 1: Input: s = "00011" Output: 5 Explanation: The substrings with dominant ones are ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == 10\n assert candidate(s = \"100100100\") == 8\n assert candidate(s = \"1111010101\") == 33\n assert candidate(s = \"000111000\") == 12\n assert candidate(s = \"11110000\") == 15\n assert candidate(s = \"00...
[ "\"00011\"", "\"101101\"" ]
[ "Let us fix the starting index l of the substring and count the number of indices r such that l <= r and the substring s[l..r] has dominant ones.", "A substring with dominant ones has at most sqrt(n) zeros.", "We cannot iterate over every r and check if the s[l..r] has dominant ones. Instead, we iterate over th...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().numberOfSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:54", "tests_total": 165, "tests...
cpp
{ "raw_signature": "int numberOfSubstrings(string s) {", "container": "Solution", "callable": "numberOfSubstrings", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,235
check-if-the-rectangle-corner-is-reachable
Hard
You are given two positive integers xCorner and yCorner, and a 2D array circles, where circles[i] = [x_i, y_i, r_i] denotes a circle with center at (x_i, y_i) and radius r_i. There is a rectangle in the coordinate plane with its bottom left corner at the origin and top right corner at the coordinate (xCorner, yCorner)...
{ "language": "python", "source": "def check(candidate):\n assert candidate(xCorner = 10,yCorner = 10,circles = [[1, 1, 1], [9, 9, 1]]) == False\n assert candidate(xCorner = 1000000000,yCorner = 1000000000,circles = [[500000000, 500000000, 499999999]]) == True\n assert candidate(xCorner = 5,yCorner = 5,cir...
[ "3\n4\n[[2,1,1]]", "3\n3\n[[1,1,2]]", "3\n3\n[[2,1,1],[1,2,1]]", "4\n4\n[[5,5,1]]" ]
[ "Create a graph with n + 4 vertices.", "Vertices 0 to n - 1 represent the circles, vertex n represents upper edge, vertex n + 1 represents right edge, vertex n + 2 represents lower edge, and vertex n + 3 represents left edge.", "Add an edge between these vertices if they intersect or touch.", "Answer will be ...
{ "canonical_parameter_names": [ "xCorner", "yCorner", "circles" ], "leetcode_dataset_entry_point": "Solution().canReachCorner", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:56"...
cpp
{ "raw_signature": "bool canReachCorner(int xCorner, int yCorner, vector<vector<int>>& circles) {", "container": "Solution", "callable": "canReachCorner", "parameters": [ { "name": "xCorner", "type": "int" }, { "name": "yCorner", "type": "int" }, { "name": "circ...
3,238
find-the-number-of-winning-players
Easy
You are given an integer n representing the number of players in a game and a 2D array pick where pick[i] = [x_i, y_i] represents that the player x_i picked a ball of color y_i. Player i wins the game if they pick strictly more than i balls of the same color. In other words, - Player 0 wins if they pick any ball. - P...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 10,pick = [[0, 0], [1, 1], [1, 1], [2, 2], [2, 2], [2, 2], [3, 3], [3, 3], [3, 3], [3, 3]]) == 4\n assert candidate(n = 10,pick = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 1\n assert ...
[ "4\n[[0,0],[1,0],[1,0],[2,1],[2,1],[2,0]]", "5\n[[1,1],[1,2],[1,3],[1,4]]", "5\n[[1,1],[2,4],[2,4],[2,4]]" ]
[ "Keep track of the number of balls of each color for each user using hashing.", "Find the maximum color that occurred for each player." ]
{ "canonical_parameter_names": [ "n", "pick" ], "leetcode_dataset_entry_point": "Solution().winningPlayerCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:02", "tests_total": 6...
cpp
{ "raw_signature": "int winningPlayerCount(int n, vector<vector<int>>& pick) {", "container": "Solution", "callable": "winningPlayerCount", "parameters": [ { "name": "n", "type": "int" }, { "name": "pick", "type": "vector<vector<int>>&" } ], "return_type": "int", "s...