question_id
int64
1
3.24k
task_id
stringlengths
3
77
difficulty
stringclasses
3 values
problem_description
stringlengths
193
3.69k
canonical_tests
dict
public_tests
listlengths
1
5
hints
listlengths
0
8
metadata
dict
language
stringclasses
9 values
interface
dict
1,189
maximum-number-of-balloons
Easy
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible. You can use each character in text at most once. Return the maximum number of instances that can be formed. Example 1: Input: text = "nlaebolko" Output: 1 Example 2: Input: text = "loonbalxballp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(text = \"bbaalllooonn\") == 1\n assert candidate(text = \"ppooaallbboonn\") == 1\n assert candidate(text = \"leetcode\") == 0\n assert candidate(text = \"balloonballoonballoonballoonballoon\") == 5\n assert candidate(text = \...
[ "\"nlaebolko\"", "\"loonbalxballpoon\"", "\"leetcode\"" ]
[ "Count the frequency of letters in the given string.", "Find the letter than can make the minimum number of instances of the word \"balloon\"." ]
{ "canonical_parameter_names": [ "text" ], "leetcode_dataset_entry_point": "Solution().maxNumberOfBalloons", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:50", "tests_total": 117, "t...
cpp
{ "raw_signature": "int maxNumberOfBalloons(string text) {", "container": "Solution", "callable": "maxNumberOfBalloons", "parameters": [ { "name": "text", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,190
reverse-substrings-between-each-pair-of-parentheses
Medium
You are given a string s that consists of lower case English letters and brackets. Reverse the strings in each pair of matching parentheses, starting from the innermost one. Your result should not contain any brackets. Example 1: Input: s = "(abcd)" Output: "dcba" Example 2: Input: s = "(u(love)i)" Output: "ilove...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"(a(b(c)d)e)\") == \"ebcda\"\n assert candidate(s = \"(a(b)c(d(e)f)g)\") == \"gdefcba\"\n assert candidate(s = \"(abc)(def)\") == \"cbafed\"\n assert candidate(s = \"(a(b)c(d)e(f)g)\") == \"gfedcba\"\n assert candidate(s...
[ "\"(abcd)\"", "\"(u(love)i)\"", "\"(ed(et(oc))el)\"" ]
[ "Find all brackets in the string.", "Does the order of the reverse matter ?", "The order does not matter." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().reverseParentheses", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:53", "tests_total": 93, "tests_...
cpp
{ "raw_signature": "string reverseParentheses(string s) {", "container": "Solution", "callable": "reverseParentheses", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,191
k-concatenation-maximum-sum
Medium
Given an integer array arr and an integer k, modify the array by repeating it k times. For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2]. Return the maximum sub-array sum in the modified array. Note that the length of the sub-array can be 0 and its sum in that case is 0. As th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1],k = 1) == 1\n assert candidate(arr = [-1, 0, 1],k = 3) == 1\n assert candidate(arr = [1, -2, 1],k = 5) == 2\n assert candidate(arr = [3, -2, 2, -3],k = 3) == 3\n assert candidate(arr = [10000, -10000],k = 2) == 1000...
[ "[1,2]\n3", "[1,-2,1]\n5", "[-1,-2]\n7" ]
[ "How to solve the problem for k=1 ?", "Use Kadane's algorithm for k=1.", "What are the possible cases for the answer ?", "The answer is the maximum between, the answer for k=1, the sum of the whole array multiplied by k, or the maximum suffix sum plus the maximum prefix sum plus (k-2) multiplied by the whole ...
{ "canonical_parameter_names": [ "arr", "k" ], "leetcode_dataset_entry_point": "Solution().kConcatenationMaxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:55", "tests_total": ...
cpp
{ "raw_signature": "int kConcatenationMaxSum(vector<int>& arr, int k) {", "container": "Solution", "callable": "kConcatenationMaxSum", "parameters": [ { "name": "arr", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_sourc...
1,192
critical-connections-in-a-network
Hard
There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [a_i, b_i] represents a connection between servers a_i and b_i. Any server can reach other servers directly or indirectly through the network. A critical connection is a connection...
{ "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 ...
[ "4\n[[0,1],[1,2],[2,0],[1,3]]", "2\n[[0,1]]" ]
[ "Use Tarjan's algorithm." ]
{ "canonical_parameter_names": [ "n", "connections" ], "leetcode_dataset_entry_point": "Solution().criticalConnections", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:57", "tests_t...
cpp
{ "raw_signature": "vector<vector<int>> criticalConnections(int n, vector<vector<int>>& connections) {", "container": "Solution", "callable": "criticalConnections", "parameters": [ { "name": "n", "type": "int" }, { "name": "connections", "type": "vector<vector<int>>&" } ...
1,200
minimum-absolute-difference
Easy
Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements. Return a list of pairs in ascending order(with respect to pairs), each pair [a, b] follows - a, b are from arr - a < b - b - a equals to the minimum absolute difference of any two elements in ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [5, 1, 4, 1, 3]) == [[1, 1]]\n assert candidate(arr = [4, 2, 1, 3]) == [[1, 2], [2, 3], [3, 4]]\n assert candidate(arr = [3, 8, -10, 23, 19, -4, -14, 27]) == [[-14, -10], [19, 23], [23, 27]]\n assert candidate(arr = [10000...
[ "[4,2,1,3]", "[1,3,6,10,15]", "[3,8,-10,23,19,-4,-14,27]" ]
[ "Find the minimum absolute difference between two elements in the array.", "The minimum absolute difference must be a difference between two consecutive elements in the sorted array." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().minimumAbsDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:08", "tests_total": 101, "t...
cpp
{ "raw_signature": "vector<vector<int>> minimumAbsDifference(vector<int>& arr) {", "container": "Solution", "callable": "minimumAbsDifference", "parameters": [ { "name": "arr", "type": "vector<int>&" } ], "return_type": "vector<vector<int>>", "signature_source": "leetcode/codeSnippets"...
1,201
ugly-number-iii
Medium
An ugly number is a positive integer that is divisible by a, b, or c. Given four integers n, a, b, and c, return the n^th ugly number. Example 1: Input: n = 3, a = 2, b = 3, c = 5 Output: 4 Explanation: The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10... The 3^rd is 4. Example 2: Input: n = 4, a = 2, b = 3, c = 4 Outp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,a = 2,b = 3,c = 4) == 6\n assert candidate(n = 1,a = 2,b = 3,c = 5) == 2\n assert candidate(n = 3,a = 2,b = 3,c = 5) == 4\n assert candidate(n = 10,a = 2,b = 7,c = 13) == 16\n assert candidate(n = 10,a = 5,b = 7,c = 15)...
[ "3\n2\n3\n5", "4\n2\n3\n4", "5\n2\n11\n13" ]
[ "Write a function f(k) to determine how many ugly numbers smaller than k. As f(k) is non-decreasing, try binary search.", "Find all ugly numbers in [1, LCM(a, b, c)] (LCM is Least Common Multiple). Use inclusion-exclusion principle to expand the result." ]
{ "canonical_parameter_names": [ "n", "a", "b", "c" ], "leetcode_dataset_entry_point": "Solution().nthUglyNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:10", "tests...
cpp
{ "raw_signature": "int nthUglyNumber(int n, int a, int b, int c) {", "container": "Solution", "callable": "nthUglyNumber", "parameters": [ { "name": "n", "type": "int" }, { "name": "a", "type": "int" }, { "name": "b", "type": "int" }, { "nam...
1,202
smallest-string-with-swaps
Medium
You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string. You can swap the characters at any pair of indices in the given pairs any number of times. Return the lexicographically smallest string that s can be changed to after us...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"acbd\",pairs = [[0, 3], [1, 2]]) == \"abcd\"\n assert candidate(s = \"cba\",pairs = [[0, 1], [1, 2]]) == \"abc\"\n assert candidate(s = \"aabbcc\",pairs = [[0, 1], [2, 3], [4, 5]]) == \"aabbcc\"\n assert candidate(s = \"zy...
[ "\"dcab\"\n[[0,3],[1,2]]", "\"dcab\"\n[[0,3],[1,2],[0,2]]", "\"cba\"\n[[0,1],[1,2]]" ]
[ "Think of it as a graph problem.", "Consider the pairs as connected nodes in the graph, what can you do with a connected component of indices ?", "We can sort each connected component alone to get the lexicographically minimum string." ]
{ "canonical_parameter_names": [ "s", "pairs" ], "leetcode_dataset_entry_point": "Solution().smallestStringWithSwaps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:13", "tests_tot...
cpp
{ "raw_signature": "string smallestStringWithSwaps(string s, vector<vector<int>>& pairs) {", "container": "Solution", "callable": "smallestStringWithSwaps", "parameters": [ { "name": "s", "type": "string" }, { "name": "pairs", "type": "vector<vector<int>>&" } ], "retu...
1,203
sort-items-by-groups-respecting-dependencies
Hard
There are n items each belonging to zero or one of m groups where group[i] is the group that the i-th item belongs to and it's equal to -1 if the i-th item belongs to no group. The items and the groups are zero indexed. A group can have no item belonging to it. Return a sorted list of the items such that: - The items...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 8,m = 2,group = [-1, -1, 1, 0, 0, 1, 0, -1],beforeItems = [[], [6], [5], [6], [3, 6], [], [], []]) == [6, 3, 4, 5, 2, 0, 7, 1]\n assert candidate(n = 5,m = 3,group = [0, 0, 1, 1, -1],beforeItems = [[], [2], [3], [], [1, 3]]) == [3...
[ "8\n2\n[-1,-1,1,0,0,1,0,-1]\n[[],[6],[5],[6],[3,6],[],[],[]]", "8\n2\n[-1,-1,1,0,0,1,0,-1]\n[[],[6],[5],[6],[3],[],[4],[]]" ]
[ "Think of it as a graph problem.", "We need to find a topological order on the dependency graph.", "Build two graphs, one for the groups and another for the items." ]
{ "canonical_parameter_names": [ "n", "m", "group", "beforeItems" ], "leetcode_dataset_entry_point": "Solution().sortItems", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:15"...
cpp
{ "raw_signature": "vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {", "container": "Solution", "callable": "sortItems", "parameters": [ { "name": "n", "type": "int" }, { "name": "m", "type": "int" }, { "name": "group",...
1,207
unique-number-of-occurrences
Easy
Given an array of integers arr, return true if the number of occurrences of each value in the array is unique or false otherwise. Example 1: Input: arr = [1,2,2,1,1,3] Output: true Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences. Example 2: Input: a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [-3, 0, 1, -3, 1, 1, 1, -3, 10, 0]) == True\n assert candidate(arr = [1, 2]) == False\n assert candidate(arr = [5]) == True\n assert candidate(arr = [5, 5, 5, 5, 5]) == True\n assert candidate(arr = [1, 1, 2, 2, 3, 3]) ...
[ "[1,2,2,1,1,3]", "[1,2]", "[-3,0,1,-3,1,1,1,-3,10,0]" ]
[ "Find the number of occurrences of each element in the array using a hash map.", "Iterate through the hash map and check if there is a repeated value." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().uniqueOccurrences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:17", "tests_total": 107, "test...
cpp
{ "raw_signature": "bool uniqueOccurrences(vector<int>& arr) {", "container": "Solution", "callable": "uniqueOccurrences", "parameters": [ { "name": "arr", "type": "vector<int>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
1,208
get-equal-substrings-within-budget
Medium
You are given two strings s and t of the same length and an integer maxCost. You want to change s to t. Changing the i^th character of s to i^th character of t costs |s[i] - t[i]| (i.e., the absolute difference between the ASCII values of the characters). Return the maximum length of a substring of s that can be chan...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"a\",t = \"b\",maxCost = 1) == 1\n assert candidate(s = \"a\",t = \"a\",maxCost = 0) == 1\n assert candidate(s = \"krrgw\",t = \"grkwa\",maxCost = 3) == 1\n assert candidate(s = \"abcd\",t = \"abce\",maxCost = 1) == 4\n ...
[ "\"abcd\"\n\"bcdf\"\n3", "\"abcd\"\n\"cdef\"\n3", "\"abcd\"\n\"acde\"\n0" ]
[ "Calculate the differences between s[i] and t[i].", "Use a sliding window to track the longest valid substring." ]
{ "canonical_parameter_names": [ "s", "t", "maxCost" ], "leetcode_dataset_entry_point": "Solution().equalSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:19", "tests_t...
cpp
{ "raw_signature": "int equalSubstring(string s, string t, int maxCost) {", "container": "Solution", "callable": "equalSubstring", "parameters": [ { "name": "s", "type": "string" }, { "name": "t", "type": "string" }, { "name": "maxCost", "type": "int" ...
1,209
remove-all-adjacent-duplicates-in-string-ii
Medium
You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together. We repeatedly make k duplicate removals on s until we no longer can. Return the final strin...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"a\",k = 2) == \"a\"\n assert candidate(s = \"mississippi\",k = 2) == \"m\"\n assert candidate(s = \"deeedbbcccbdaa\",k = 3) == \"aa\"\n assert candidate(s = \"abcd\",k = 2) == \"abcd\"\n assert candidate(s = \"abcde\",k...
[ "\"abcd\"\n2", "\"deeedbbcccbdaa\"\n3", "\"pbbcggttciiippooaais\"\n2" ]
[ "Use a stack to store the characters, when there are k same characters, delete them.", "To make it more efficient, use a pair to store the value and the count of each character." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().removeDuplicates", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:21", "tests_total": 107, ...
cpp
{ "raw_signature": "string removeDuplicates(string s, int k) {", "container": "Solution", "callable": "removeDuplicates", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "int" } ], "return_type": "string", "signature_source": "leetcode/code...
1,210
minimum-moves-to-reach-target-with-rotations
Hard
In an n*n grid, there is a snake that spans 2 cells and starts moving from the top left corner at (0, 0) and (0, 1). The grid has empty cells represented by zeros and blocked cells represented by ones. The snake wants to reach the lower right corner at (n-1, n-2) and (n-1, n-1). In one move the snake can: - Move one ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0, 0, 0, 1], [1, 1, 0, 0, 1, 0], [0, 0, 0, 0, 1, 1], [0, 0, 1, 0, 1, 0], [0, 1, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0]]) == 11\n assert candidate(grid = [[0, 0, 1], [0, 1, 0], [0, 0, 0]]) == -1\n assert candidate(grid = [[0...
[ "[[0,0,0,0,0,1],[1,1,0,0,1,0],[0,0,0,0,1,1],[0,0,1,0,1,0],[0,1,1,0,0,0],[0,1,1,0,0,0]]\r", "[[0,0,1,1,1,1],[0,0,0,0,1,1],[1,1,0,0,0,1],[1,1,1,0,0,1],[1,1,1,0,0,1],[1,1,1,0,0,0]]\r" ]
[ "Use BFS to find the answer.", "The state of the BFS is the position (x, y) along with a binary value that specifies if the position is horizontal or vertical." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minimumMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:23", "tests_total": 64, "tests_dro...
cpp
{ "raw_signature": "int minimumMoves(vector<vector<int>>& grid) {", "container": "Solution", "callable": "minimumMoves", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/c...
1,217
minimum-cost-to-move-chips-to-the-same-position
Easy
We have n chips, where the position of the i^th chip is position[i]. We need to move all the chips to the same position. In one step, we can change the position of the i^th chip from position[i] to: - position[i] + 2 or position[i] - 2 with cost = 0. - position[i] + 1 or position[i] - 1 with cost = 1. Return the min...
{ "language": "python", "source": "def check(candidate):\n assert candidate(position = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(position = [1, 1000000000]) == 1\n assert candidate(position = [1, 2, 2, 2, 3, 3, 3]) == 3\n assert candidate(position = [5, 5, 5, 5, 5]) == 0\n assert candid...
[ "[1,2,3]", "[2,2,2,3,3]", "[1,1000000000]" ]
[ "The first move keeps the parity of the element as it is.", "The second move changes the parity of the element.", "Since the first move is free, if all the numbers have the same parity, the answer would be zero.", "Find the minimum cost to make all the numbers have the same parity." ]
{ "canonical_parameter_names": [ "position" ], "leetcode_dataset_entry_point": "Solution().minCostToMoveChips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:35", "tests_total": 105, ...
cpp
{ "raw_signature": "int minCostToMoveChips(vector<int>& position) {", "container": "Solution", "callable": "minCostToMoveChips", "parameters": [ { "name": "position", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
1,218
longest-arithmetic-subsequence-of-given-difference
Medium
Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference. A subsequence is a sequence that can be derived from arr by deleting some or no elements wit...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [3, 0, -3, 4, -5, 0, -7, 1],difference = -3) == 3\n assert candidate(arr = [1, 2, 3, 4],difference = 1) == 4\n assert candidate(arr = [1, 3, 5, 7],difference = 1) == 1\n assert candidate(arr = [1, 1, 1, 1, 1],difference = ...
[ "[1,2,3,4]\n1", "[1,3,5,7]\n1", "[1,5,7,8,5,3,4,2,1]\n-2" ]
[ "Use dynamic programming.", "Let dp[i] be the maximum length of a subsequence of the given difference whose last element is i.", "dp[i] = 1 + dp[i-k]" ]
{ "canonical_parameter_names": [ "arr", "difference" ], "leetcode_dataset_entry_point": "Solution().longestSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:37", "tests_t...
cpp
{ "raw_signature": "int longestSubsequence(vector<int>& arr, int difference) {", "container": "Solution", "callable": "longestSubsequence", "parameters": [ { "name": "arr", "type": "vector<int>&" }, { "name": "difference", "type": "int" } ], "return_type": "int", "s...
1,219
path-with-maximum-gold
Medium
In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: - Every time you are located in a cell you will collect all the gold in that cell. - From your position, you ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 0, 7, 0], [2, 0, 6, 8], [0, 4, 5, 0], [3, 0, 3, 0], [9, 0, 20, 0]]) == 42\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 6], [7, 0, 0, 0], [0, 0, 0, 8]]) == 8\n assert candidate(grid = [[0, 6, 0], [5, 8, 7], [0, 9, ...
[ "[[0,6,0],[5,8,7],[0,9,0]]", "[[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]" ]
[ "Use recursion to try all such paths and find the one with the maximum value." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().getMaximumGold", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:39", "tests_total": 99, "tests_d...
cpp
{ "raw_signature": "int getMaximumGold(vector<vector<int>>& grid) {", "container": "Solution", "callable": "getMaximumGold", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
1,220
count-vowels-permutation
Hard
Given an integer n, your task is to count how many strings of length n can be formed under the following rules: - Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u') - Each vowel 'a' may only be followed by an 'e'. - Each vowel 'e' may only be followed by an 'a' or an 'i'. - Each vowel 'i' may not be follow...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 1000) == 89945857\n assert candidate(n = 100) == 173981881\n assert candidate(n = 20000) == 759959057\n assert candidate(n = 200) == 670333618\n assert candidate(n = 10000) == 76428576\n assert candidate(n = 5000) == 5...
[ "1", "2" ]
[ "Use dynamic programming.", "Let dp[i][j] be the number of strings of length i that ends with the j-th vowel.", "Deduce the recurrence from the given relations between vowels." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().countVowelPermutation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:41", "tests_total": 26, "tes...
cpp
{ "raw_signature": "int countVowelPermutation(int n) {", "container": "Solution", "callable": "countVowelPermutation", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,221
split-a-string-in-balanced-strings
Easy
Balanced strings are those that have an equal quantity of 'L' and 'R' characters. Given a balanced string s, split it into some number of substrings such that: - Each substring is balanced. Return the maximum number of balanced strings you can obtain. Example 1: Input: s = "RLRRLLRLRL" Output: 4 Explanation: s can...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"RRLLRRLL\") == 2\n assert candidate(s = \"RLRRRLLRLL\") == 2\n assert candidate(s = \"RRRRLLLLRRRRLLLL\") == 2\n assert candidate(s = \"LRRLLRRL\") == 4\n assert candidate(s = \"LLLLRRRRLLRRRR\") == 2\n assert candid...
[ "\"RLRRLLRLRL\"", "\"RLRRRLLRLL\"", "\"LLLLRRRR\"" ]
[ "Loop from left to right maintaining a balance variable when it gets an L increase it by one otherwise decrease it by one.", "Whenever the balance variable reaches zero then we increase the answer by one." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().balancedStringSplit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:43", "tests_total": 118, "test...
cpp
{ "raw_signature": "int balancedStringSplit(string s) {", "container": "Solution", "callable": "balancedStringSplit", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,222
queens-that-can-attack-the-king
Medium
On a 0-indexed 8 x 8 chessboard, there can be multiple black queens and one white king. You are given a 2D integer array queens where queens[i] = [xQueen_i, yQueen_i] represents the position of the i^th black queen on the chessboard. You are also given an integer array king of length 2 where king = [xKing, yKing] repr...
{ "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 ...
[ "[[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]]\n[0,0]", "[[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]]\n[3,3]" ]
[ "Check 8 directions around the King.", "Find the nearest queen in each direction." ]
{ "canonical_parameter_names": [ "queens", "king" ], "leetcode_dataset_entry_point": "Solution().queensAttacktheKing", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:46", "tests_tot...
cpp
{ "raw_signature": "vector<vector<int>> queensAttacktheKing(vector<vector<int>>& queens, vector<int>& king) {", "container": "Solution", "callable": "queensAttacktheKing", "parameters": [ { "name": "queens", "type": "vector<vector<int>>&" }, { "name": "king", "type": "vector<...
1,223
dice-roll-simulation
Hard
A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times. Given an array of integers rollMax and an integer n, return the number of distinct sequences that can be obtained w...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,rollMax = [2, 2, 2, 2, 2, 2]) == 7200\n assert candidate(n = 1,rollMax = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(n = 1,rollMax = [15, 15, 15, 15, 15, 15]) == 6\n assert candidate(n = 10,rollMax = [2, 3, 4, 5, 6, 7]) ==...
[ "2\n[1,1,2,2,2,3]", "2\n[1,1,1,1,1,1]", "3\n[1,1,1,2,2,3]" ]
[ "Think on Dynamic Programming.", "DP(pos, last) which means we are at the position pos having as last the last character seen." ]
{ "canonical_parameter_names": [ "n", "rollMax" ], "leetcode_dataset_entry_point": "Solution().dieSimulator", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:48", "tests_total": 41, ...
cpp
{ "raw_signature": "int dieSimulator(int n, vector<int>& rollMax) {", "container": "Solution", "callable": "dieSimulator", "parameters": [ { "name": "n", "type": "int" }, { "name": "rollMax", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "lee...
1,224
maximum-equal-frequency
Hard
Given an array nums of positive integers, return the longest possible length of an array prefix of nums, such that it is possible to remove exactly one element from this prefix so that every number that has appeared in it will have the same number of occurrences. If after removing one element there are no remaining el...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10, 1, 1, 1, 2, 2, 3]) == 7\n assert candidate(nums = [1, 2, 2, 2, 1, 1]) == 5\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, ...
[ "[2,2,1,1,5,3,3,5]", "[1,1,1,2,2,2,3,3,3,4,4,4,5]" ]
[ "Keep track of the min and max frequencies.", "The number to be eliminated must have a frequency of 1, same as the others or the same +1." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxEqualFreq", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:50", "tests_total": 104, "tests_dr...
cpp
{ "raw_signature": "int maxEqualFreq(vector<int>& nums) {", "container": "Solution", "callable": "maxEqualFreq", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,227
airplane-seat-assignment-probability
Medium
n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of the passengers will: - Take their own seat if it is still available, and - Pick other seats randomly when they find their seat occupied Return the probability that the n^...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat...
[ "1", "2" ]
[ "Let f(n) denote the probability of the n-th person getting correct seat in n-person case, then: f(1) = 1 (base case, trivial) f(2) = 1/2 (also trivial)", "Try to calculate f(3), f(4), and f(5) using the base cases. What is the value of them? f(i) for i >= 2 will also be 1/2.", "Try to proof why f(i) = 1/2 for ...
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().nthPersonGetsNthSeat", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:52", "tests_total": 32, "test...
cpp
{ "raw_signature": "double nthPersonGetsNthSeat(int n) {", "container": "Solution", "callable": "nthPersonGetsNthSeat", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "double", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,232
check-if-it-is-a-straight-line
Easy
You are given an integer array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane. Example 1: Input: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]] Output: true Example 2: Input: coordinates = [[1,1],[2,2],[3,4],[4...
{ "language": "python", "source": "def check(candidate):\n assert candidate(coordinates = [[0, 0], [0, 1], [0, 2], [0, 3]]) == True\n assert candidate(coordinates = [[-10000, -10000], [0, 0], [10000, 10000]]) == True\n assert candidate(coordinates = [[-4, -3], [1, 0], [3, -1], [0, -1], [-5, 2]]) == False\n...
[ "[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]", "[[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]" ]
[ "If there're only 2 points, return true.", "Check if all other points lie on the line defined by the first 2 points.", "Use cross product to check collinearity." ]
{ "canonical_parameter_names": [ "coordinates" ], "leetcode_dataset_entry_point": "Solution().checkStraightLine", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:03", "tests_total": 125,...
cpp
{ "raw_signature": "bool checkStraightLine(vector<vector<int>>& coordinates) {", "container": "Solution", "callable": "checkStraightLine", "parameters": [ { "name": "coordinates", "type": "vector<vector<int>>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", ...
1,233
remove-sub-folders-from-the-filesystem
Medium
Given a list of folders folder, return the folders after removing all sub-folders in those folders. You may return the answer in any order. If a folder[i] is located within another folder[j], it is called a sub-folder of it. A sub-folder of folder[j] must start with folder[j], followed by a "/". For example, "/a/b" is...
{ "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 ...
[ "[\"/a\",\"/a/b\",\"/c/d\",\"/c/d/e\",\"/c/f\"]", "[\"/a\",\"/a/b/c\",\"/a/b/d\"]", "[\"/a/b/c\",\"/a/b/ca\",\"/a/b/d\"]" ]
[ "Sort the folders lexicographically.", "Insert the current element in an array and then loop until we get rid of all of their subfolders, repeat this until no element is left." ]
{ "canonical_parameter_names": [ "folder" ], "leetcode_dataset_entry_point": "Solution().removeSubfolders", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:06", "tests_total": 97, "tes...
cpp
{ "raw_signature": "vector<string> removeSubfolders(vector<string>& folder) {", "container": "Solution", "callable": "removeSubfolders", "parameters": [ { "name": "folder", "type": "vector<string>&" } ], "return_type": "vector<string>", "signature_source": "leetcode/codeSnippets", "t...
1,234
replace-the-substring-for-balanced-string
Medium
You are given a string s of length n containing only four kinds of characters: 'Q', 'W', 'E', and 'R'. A string is said to be balanced if each of its characters appears n / 4 times where n is the length of the string. Return the minimum length of the substring that can be replaced with any other string of the same le...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"QQQQQQQQWWWWEEEEEEEERRRRRRRR\") == 14\n assert candidate(s = \"QQQQWWER\") == 2\n assert candidate(s = \"QQQQWWWWEEEERRRR\") == 0\n assert candidate(s = \"QQWWRRER\") == 1\n assert candidate(s = \"QQQQWWWEERRR\") == 1\n...
[ "\"QWER\"", "\"QQWE\"", "\"QQQW\"" ]
[ "Use 2-pointers algorithm to make sure all amount of characters outside the 2 pointers are smaller or equal to n/4.", "That means you need to count the amount of each letter and make sure the amount is enough." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().balancedString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:08", "tests_total": 158, "tests_dro...
cpp
{ "raw_signature": "int balancedString(string s) {", "container": "Solution", "callable": "balancedString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,235
maximum-profit-in-job-scheduling
Hard
We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i]. You're given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range. If you choose a job that en...
{ "language": "python", "source": "def check(candidate):\n assert candidate(startTime = [1, 10, 4, 3, 8, 9],endTime = [2, 11, 5, 7, 9, 10],profit = [3, 1, 5, 6, 4, 3]) == 17\n assert candidate(startTime = [1, 3, 5, 6, 7],endTime = [3, 5, 9, 8, 9],profit = [50, 20, 60, 40, 30]) == 130\n assert candidate(sta...
[ "[1,2,3,3]\n[3,4,5,6]\n[50,10,40,70]", "[1,2,3,4,6]\n[3,5,10,6,9]\n[20,20,100,70,60]", "[1,1,1]\n[2,3,4]\n[5,6,4]" ]
[ "Think on DP.", "Sort the elements by starting time, then define the dp[i] as the maximum profit taking elements from the suffix starting at i.", "Use binarySearch (lower_bound/upper_bound on C++) to get the next index for the DP transition." ]
{ "canonical_parameter_names": [ "startTime", "endTime", "profit" ], "leetcode_dataset_entry_point": "Solution().jobScheduling", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:10"...
cpp
{ "raw_signature": "int jobScheduling(vector<int>& startTime, vector<int>& endTime, vector<int>& profit) {", "container": "Solution", "callable": "jobScheduling", "parameters": [ { "name": "startTime", "type": "vector<int>&" }, { "name": "endTime", "type": "vector<int>&" ...
1,238
circular-permutation-in-binary-representation
Medium
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : - p[0] = start - p[i] and p[i+1] differ by only one bit in their binary representation. - p[0] and p[2^n -1] must also differ by only one bit in their binary representation. Example 1: Input: n = 2, start = 3 Outpu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 1,start = 0) == [0, 1]\n assert candidate(n = 12,start = 2048) == [2048, 0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8, 24, 25, 27, 26, 30, 31, 29, 28, 20, 21, 23, 22, 18, 19, 17, 16, 48, 49, 51, 50, 54, 55, 53, 52, 60, 61,...
[ "2\n3", "3\n2" ]
[ "Use gray code to generate a n-bit sequence.", "Rotate the sequence such that its first element is start." ]
{ "canonical_parameter_names": [ "n", "start" ], "leetcode_dataset_entry_point": "Solution().circularPermutation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:13", "tests_total":...
cpp
{ "raw_signature": "vector<int> circularPermutation(int n, int start) {", "container": "Solution", "callable": "circularPermutation", "parameters": [ { "name": "n", "type": "int" }, { "name": "start", "type": "int" } ], "return_type": "vector<int>", "signature_sourc...
1,239
maximum-length-of-a-concatenated-string-with-unique-characters
Medium
You are given an array of strings arr. A string s is formed by the concatenation of a subsequence of arr that has unique characters. Return the maximum possible length of s. A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining ele...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = ['abcd', 'abef', 'cdgh', 'cdef']) == 8\n assert candidate(arr = ['un', 'iq', 'ue']) == 4\n assert candidate(arr = ['abcdefghijklmnopqrstuvwxyz']) == 26\n assert candidate(arr = ['unique', 'strings', 'with', 'no', 'common',...
[ "[\"un\",\"iq\",\"ue\"]", "[\"cha\",\"r\",\"act\",\"ers\"]", "[\"abcdefghijklmnopqrstuvwxyz\"]" ]
[ "You can try all combinations and keep mask of characters you have.", "You can use DP." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().maxLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:15", "tests_total": 87, "tests_dropped...
cpp
{ "raw_signature": "int maxLength(vector<string>& arr) {", "container": "Solution", "callable": "maxLength", "parameters": [ { "name": "arr", "type": "vector<string>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,240
tiling-a-rectangle-with-the-fewest-squares
Hard
Given a rectangle of size n x m, return the minimum number of integer-sided squares that tile the rectangle. Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 8,m = 8) == 1\n assert candidate(n = 1,m = 1) == 1\n assert candidate(n = 7,m = 7) == 1\n assert candidate(n = 9,m = 10) == 6\n assert candidate(n = 7,m = 8) == 7\n assert candidate(n = 6,m = 7) == 5\n assert candid...
[ "2\n3", "5\n8", "11\n13" ]
[ "Can you use backtracking to solve this problem ?.", "Suppose you've placed a bunch of squares. Where is the natural spot to place the next square ?.", "The maximum number of squares to be placed will be ≤ max(n,m)." ]
{ "canonical_parameter_names": [ "n", "m" ], "leetcode_dataset_entry_point": "Solution().tilingRectangle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:17", "tests_total": 66, "...
cpp
{ "raw_signature": "int tilingRectangle(int n, int m) {", "container": "Solution", "callable": "tilingRectangle", "parameters": [ { "name": "n", "type": "int" }, { "name": "m", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "...
1,247
minimum-swaps-to-make-strings-equal
Medium
You are given two strings s1 and s2 of equal length consisting of letters "x" and "y" only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings, which means: swap s1[i] and s2[j]. Return the minimum number of swaps required to make s1 and s2 equa...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s1 = \"xyyy\",s2 = \"yxxx\") == 3\n assert candidate(s1 = \"xx\",s2 = \"yy\") == 1\n assert candidate(s1 = \"xxyy\",s2 = \"xyxy\") == 2\n assert candidate(s1 = \"xxyyxyxyxx\",s2 = \"xyyxyxxxyx\") == 4\n assert candidate(s1 = ...
[ "\"xx\"\n\"yy\"", "\"xy\"\n\"yx\"", "\"xx\"\n\"xy\"" ]
[ "First, ignore all the already matched positions, they don't affect the answer at all. For the unmatched positions, there are three basic cases (already given in the examples):", "(\"xx\", \"yy\") => 1 swap, (\"xy\", \"yx\") => 2 swaps", "So the strategy is, apply case 1 as much as possible, then apply case 2 i...
{ "canonical_parameter_names": [ "s1", "s2" ], "leetcode_dataset_entry_point": "Solution().minimumSwap", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:28", "tests_total": 103, "t...
cpp
{ "raw_signature": "int minimumSwap(string s1, string s2) {", "container": "Solution", "callable": "minimumSwap", "parameters": [ { "name": "s1", "type": "string" }, { "name": "s2", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippe...
1,248
count-number-of-nice-subarrays
Medium
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays. Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: num...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 2\n assert candidate(nums = [2],k = 1) == 0\n assert candidate(nums = [2, 4, 6],k = 1) == 0\n assert candidate(nums = [1, ...
[ "[1,1,2,1,1]\n3", "[2,4,6]\n1", "[2,2,2,1,2,2,1,2,2,2]\n2" ]
[ "After replacing each even by zero and every odd by one can we use prefix sum to find answer ?", "Can we use two pointers to count number of sub-arrays ?", "Can we store the indices of odd numbers and for each k indices count the number of sub-arrays that contains them ?" ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:30", "tests_total": 68...
cpp
{ "raw_signature": "int numberOfSubarrays(vector<int>& nums, int k) {", "container": "Solution", "callable": "numberOfSubarrays", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": ...
1,249
minimum-remove-to-make-valid-parentheses
Medium
Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a parentheses string is valid if and only if: - It is the empty string, co...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"(a(b)c)d(e(fg)h\") == \"(a(b)c)de(fg)h\"\n assert candidate(s = \"()\") == \"()\"\n assert candidate(s = \"))(()\") == \"()\"\n assert candidate(s = \"ab(c(d)e)f(g(h)i)j(kl)\") == \"ab(c(d)e)f(g(h)i)j(kl)\"\n assert can...
[ "\"lee(t(c)o)de)\"", "\"a)b(c)d\"", "\"))((\"" ]
[ "Each prefix of a balanced parentheses has a number of open parentheses greater or equal than closed parentheses, similar idea with each suffix.", "Check the array from left to right, remove characters that do not meet the property mentioned above, same idea in backward way." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minRemoveToMakeValid", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:33", "tests_total": 77, "test...
cpp
{ "raw_signature": "string minRemoveToMakeValid(string s) {", "container": "Solution", "callable": "minRemoveToMakeValid", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
1,250
check-if-it-is-a-good-array
Hard
Given an array nums of positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers. The array is said to be good if you can obtain a sum of 1 from the array by any possible subset and multiplicand. Return True if the array is good otherwise return False....
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 13, 19]) == True\n assert candidate(nums = [100, 200, 300, 400]) == False\n assert candidate(nums = [7, 13, 19, 29]) == True\n assert candidate(nums = [29, 6, 10]) == True\n assert candidate(nums = [7, 14, 21, 35])...
[ "[12,5,7,23]", "[29,6,10]", "[3,6]" ]
[ "Eq. ax+by=1 has solution x, y if gcd(a,b) = 1.", "Can you generalize the formula?. Check Bézout's lemma." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().isGoodArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:35", "tests_total": 138, "tests_dro...
cpp
{ "raw_signature": "bool isGoodArray(vector<int>& nums) {", "container": "Solution", "callable": "isGoodArray", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,252
cells-with-odd-values-in-a-matrix
Easy
There is an m x n matrix that is initialized to all 0's. There is also a 2D array indices where each indices[i] = [r_i, c_i] represents a 0-indexed location to perform some increment operations on the matrix. For each location indices[i], do both of the following: 1. Increment all the cells on row r_i. 2. Increment a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(m = 2,n = 3,indices = [[0, 1], [1, 1]]) == 6\n assert candidate(m = 50,n = 50,indices = [[0, 0], [1, 1], [2, 2], [3, 3]]) == 368\n assert candidate(m = 4,n = 5,indices = [[0, 1], [0, 1], [1, 2], [2, 3], [3, 4]]) == 9\n assert ca...
[ "2\n3\n[[0,1],[1,1]]", "2\n2\n[[1,1],[0,0]]" ]
[ "Simulation : With small constraints, it is possible to apply changes to each row and column and count odd cells after applying it.", "You can accumulate the number you should add to each row and column and then you can count the number of odd cells." ]
{ "canonical_parameter_names": [ "m", "n", "indices" ], "leetcode_dataset_entry_point": "Solution().oddCells", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:38", "tests_total":...
cpp
{ "raw_signature": "int oddCells(int m, int n, vector<vector<int>>& indices) {", "container": "Solution", "callable": "oddCells", "parameters": [ { "name": "m", "type": "int" }, { "name": "n", "type": "int" }, { "name": "indices", "type": "vector<vector<in...
1,253
reconstruct-a-2-row-binary-matrix
Medium
Given the following details of a matrix with n columns and 2 rows : - The matrix is a binary matrix, which means each element in the matrix can be 0 or 1. - The sum of elements of the 0-th(upper) row is given as upper. - The sum of elements of the 1-st(lower) row is given as lower. - The sum of elements in the i-th co...
{ "language": "python", "source": "def check(candidate):\n assert candidate(upper = 2,lower = 3,colsum = [2, 2, 1, 1]) == []\n assert candidate(upper = 1,lower = 1,colsum = [1, 0, 1]) == [[0, 0, 1], [1, 0, 0]]\n assert candidate(upper = 4,lower = 2,colsum = [2, 1, 1, 0, 0]) == []\n assert candidate(uppe...
[ "2\n1\n[1,1,1]", "2\n3\n[2,2,1,1]", "5\n5\n[2,1,2,0,1,0,1,2,0,1]" ]
[ "You cannot do anything about colsum[i] = 2 case or colsum[i] = 0 case. Then you put colsum[i] = 1 case to the upper row until upper has reached. Then put the rest into lower row.", "Fill 0 and 2 first, then fill 1 in the upper row or lower row in turn but be careful about exhausting permitted 1s in each row." ]
{ "canonical_parameter_names": [ "upper", "lower", "colsum" ], "leetcode_dataset_entry_point": "Solution().reconstructMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:40", ...
cpp
{ "raw_signature": "vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int>& colsum) {", "container": "Solution", "callable": "reconstructMatrix", "parameters": [ { "name": "upper", "type": "int" }, { "name": "lower", "type": "int" }, { "name": "...
1,254
number-of-closed-islands
Medium
Given a 2D grid consists of 0s (land) and 1s (water). An island is a maximal 4-directionally connected group of 0s and a closed island is an island totally (all left, top, right, bottom) surrounded by 1s. Return the number of closed islands. Example 1: Input: grid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]]) == 2\n assert candidate(grid = [[0, 0, 1, 0, 0], [0, 1, 0, 1, 0]...
[ "[[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]]", "[[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]]", "[[1,1,1,1,1,1,1],[1,0,0,0,0,0,1],[1,0,1,1,1,0,1],[1,0,1,0,1,0,1],[1,0,1,1,1,0,1],[1,0,0,0,0,0,1],[1,1,1,1,1,1,1]]" ]
[ "Exclude connected group of 0s on the corners because they are not closed island.", "Return number of connected component of 0s on the grid." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().closedIsland", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:43", "tests_total": 63, "tests_dro...
cpp
{ "raw_signature": "int closedIsland(vector<vector<int>>& grid) {", "container": "Solution", "callable": "closedIsland", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/c...
1,255
maximum-score-words-formed-by-letters
Hard
Given a list of words, list of single letters (might be repeating) and score of every character. Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times). It is not necessary to use all characters in letters and each letter can only be used once....
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['xxxz', 'ax', 'bx', 'cx'],letters = ['z', 'a', 'b', 'c', 'x', 'x', 'x'],score = [4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 10]) == 27\n assert candidate(words = ['leetcode'],letters = ['l', 'e...
[ "[\"dog\",\"cat\",\"dad\",\"good\"]\n[\"a\",\"a\",\"c\",\"d\",\"d\",\"d\",\"g\",\"o\",\"o\"]\n[1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]", "[\"xxxz\",\"ax\",\"bx\",\"cx\"]\n[\"z\",\"a\",\"b\",\"c\",\"x\",\"x\",\"x\"]\n[4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,10]", "[\"leetcode\"]\n[\"l\",\"...
[ "Note that words.length is small. This means you can iterate over every subset of words (2^N)." ]
{ "canonical_parameter_names": [ "words", "letters", "score" ], "leetcode_dataset_entry_point": "Solution().maxScoreWords", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:45", "...
cpp
{ "raw_signature": "int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {", "container": "Solution", "callable": "maxScoreWords", "parameters": [ { "name": "words", "type": "vector<string>&" }, { "name": "letters", "type": "vector<char>&" }...
1,260
shift-2d-grid
Easy
Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operation: - Element at grid[i][j] moves to grid[i][j + 1]. - Element at grid[i][n - 1] moves to grid[i + 1][0]. - Element at grid[m - 1][n - 1] moves to grid[0][0]. Return the 2D grid after applying shift operation k ti...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[3, 8, 1, 9], [19, 7, 2, 5], [4, 6, 11, 10], [12, 0, 21, 13]],k = 4) == [[12, 0, 21, 13], [3, 8, 1, 9], [19, 7, 2, 5], [4, 6, 11, 10]]\n assert candidate(grid = [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]],k = 2) == [[-8, -9, -1...
[ "[[1,2,3],[4,5,6],[7,8,9]]\n1", "[[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]]\n4", "[[1,2,3],[4,5,6],[7,8,9]]\n9" ]
[ "Simulate step by step. move grid[i][j] to grid[i][j+1]. handle last column of the grid.", "Put the matrix row by row to a vector. take k % vector.length and move last k of the vector to the beginning. put the vector to the matrix back the same way." ]
{ "canonical_parameter_names": [ "grid", "k" ], "leetcode_dataset_entry_point": "Solution().shiftGrid", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:56", "tests_total": 84, "tes...
cpp
{ "raw_signature": "vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {", "container": "Solution", "callable": "shiftGrid", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" }, { "name": "k", "type": "int" } ], "return_type": "vector<vecto...
1,262
greatest-sum-divisible-by-three
Medium
Given an integer array nums, return the maximum possible sum of elements of the array such that it is divisible by three. Example 1: Input: nums = [3,6,5,1,8] Output: 18 Explanation: Pick numbers 3, 6, 1 and 8 their sum is 18 (maximum sum divisible by 3). Example 2: Input: nums = [4] Output: 0 Explanation: Since 4 ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 18\n assert candidate(nums = [2, 3, 5, 7, 11]) == 21\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 30\n assert candidate(nums = [4]) == 0\n assert candidate(nums = [100...
[ "[3,6,5,1,8]", "[4]", "[1,2,3,4,4]" ]
[ "Represent the state as DP[pos][mod]: maximum possible sum starting in the position \"pos\" in the array where the current sum modulo 3 is equal to mod." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxSumDivThree", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:58", "tests_total": 139, "tests_...
cpp
{ "raw_signature": "int maxSumDivThree(vector<int>& nums) {", "container": "Solution", "callable": "maxSumDivThree", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
1,263
minimum-moves-to-move-a-box-to-their-target-location
Hard
A storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations. The game is represented by an m x n grid of characters grid where each element is a wall, floor, or box. Your task is to move the box 'B' to the target position 'T' under the following rules: - The ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [['#', '#', '#', '#', '#', '#'], ['#', 'T', '#', '#', '#', '#'], ['#', '.', '.', 'B', '.', '#'], ['#', '.', '#', '#', '.', '#'], ['#', '.', '.', '.', 'S', '#'], ['#', '#', '#', '#', '#', '#']]) == 3\n assert candidate(grid = [[...
[ "[[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],[\"#\",\"T\",\"#\",\"#\",\"#\",\"#\"],[\"#\",\".\",\".\",\"B\",\".\",\"#\"],[\"#\",\".\",\"#\",\"#\",\".\",\"#\"],[\"#\",\".\",\".\",\".\",\"S\",\"#\"],[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]", "[[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],[\"#\",\"T\",\"#\",\"#\",\"#\",\"#\"],[\"...
[ "We represent the search state as (player_row, player_col, box_row, box_col).", "You need to count only the number of pushes. Then inside of your BFS check if the box could be pushed (in any direction) given the current position of the player." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minPushBox", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:00", "tests_total": 82, "tests_dropp...
cpp
{ "raw_signature": "int minPushBox(vector<vector<char>>& grid) {", "container": "Solution", "callable": "minPushBox", "parameters": [ { "name": "grid", "type": "vector<vector<char>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...
1,266
minimum-time-visiting-all-points
Easy
On a 2D plane, there are n points with integer coordinates points[i] = [x_i, y_i]. Return the minimum time in seconds to visit all the points in the order given by points. You can move according to these rules: - In 1 second, you can either: - move vertically by one unit, - move horizontally by one unit, or - m...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[0, 0], [1, 1], [0, 0], [1, 1]]) == 3\n assert candidate(points = [[5, 5], [5, 5], [5, 5], [5, 5]]) == 0\n assert candidate(points = [[-5, -5], [-4, -4], [-3, -3], [-2, -2]]) == 3\n assert candidate(points = [[0, 0], [...
[ "[[1,1],[3,4],[-1,0]]", "[[3,2],[-2,2]]" ]
[ "To walk from point A to point B there will be an optimal strategy to walk ?", "Advance in diagonal as possible then after that go in straight line.", "Repeat the process until visiting all the points." ]
{ "canonical_parameter_names": [ "points" ], "leetcode_dataset_entry_point": "Solution().minTimeToVisitAllPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:03", "tests_total": 120...
cpp
{ "raw_signature": "int minTimeToVisitAllPoints(vector<vector<int>>& points) {", "container": "Solution", "callable": "minTimeToVisitAllPoints", "parameters": [ { "name": "points", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", ...
1,267
count-servers-that-communicate
Medium
You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row or on the same column. Return the number of servers that communicate with any other serv...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1, 0], [0, 0, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0]]) == 6\n assert candidate(grid = [[1, 0], [1, 1]]) == 3\n assert candidate(grid = [[1, 1, 0, 0, 0], [1, 0, 1, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 1, 1]]) == 8\n assert...
[ "[[1,0],[0,1]]", "[[1,0],[1,1]]", "[[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]" ]
[ "Store number of computer in each row and column.", "Count all servers that are not isolated." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().countServers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:05", "tests_total": 50, "tests_dro...
cpp
{ "raw_signature": "int countServers(vector<vector<int>>& grid) {", "container": "Solution", "callable": "countServers", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/c...
1,268
search-suggestions-system
Medium
You are given an array of strings products and a string searchWord. Design a system that suggests at most three product names from products after each character of searchWord is typed. Suggested products should have common prefix with searchWord. If there are more than three products with a common prefix return the th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(products = ['keyboard', 'keypad', 'keys', 'kick'],searchWord = \"key\") == [['keyboard', 'keypad', 'keys'], ['keyboard', 'keypad', 'keys'], ['keyboard', 'keypad', 'keys']]\n assert candidate(products = ['keyboard', 'keypad', 'mousepad...
[ "[\"mobile\",\"mouse\",\"moneypot\",\"monitor\",\"mousepad\"]\n\"mouse\"", "[\"havana\"]\n\"havana\"" ]
[ "Brute force is a good choice because length of the string is ≤ 1000.", "Binary search the answer.", "Use Trie data structure to store the best three matching. Traverse the Trie." ]
{ "canonical_parameter_names": [ "products", "searchWord" ], "leetcode_dataset_entry_point": "Solution().suggestedProducts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:07", "tes...
cpp
{ "raw_signature": "vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {", "container": "Solution", "callable": "suggestedProducts", "parameters": [ { "name": "products", "type": "vector<string>&" }, { "name": "searchWord", "type": "string" ...
1,269
number-of-ways-to-stay-in-the-same-place-after-some-steps
Hard
You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time). Given two integers steps and arrLen, return the number of ways such that your po...
{ "language": "python", "source": "def check(candidate):\n assert candidate(steps = 5,arrLen = 3) == 21\n assert candidate(steps = 10,arrLen = 5) == 2187\n assert candidate(steps = 5,arrLen = 5) == 21\n assert candidate(steps = 2,arrLen = 4) == 2\n assert candidate(steps = 3,arrLen = 2) == 4\n ass...
[ "3\n2", "2\n4", "4\n2" ]
[ "Try with Dynamic programming, dp(pos,steps): number of ways to back pos = 0 using exactly \"steps\" moves.", "Notice that the computational complexity does not depend of \"arrlen\"." ]
{ "canonical_parameter_names": [ "steps", "arrLen" ], "leetcode_dataset_entry_point": "Solution().numWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:09", "tests_total": 65, ...
cpp
{ "raw_signature": "int numWays(int steps, int arrLen) {", "container": "Solution", "callable": "numWays", "parameters": [ { "name": "steps", "type": "int" }, { "name": "arrLen", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", ...
1,275
find-winner-on-a-tic-tac-toe-game
Easy
Tic-tac-toe is played by two players A and B on a 3 x 3 grid. The rules of Tic-Tac-Toe are: - Players take turns placing characters into empty squares ' '. - The first player A always places 'X' characters, while the second player B always places 'O' characters. - 'X' and 'O' characters are always placed into empty sq...
{ "language": "python", "source": "def check(candidate):\n assert candidate(moves = [[0, 0], [1, 1], [2, 2], [1, 0], [1, 2], [2, 0], [2, 1]]) == \"Pending\"\n assert candidate(moves = [[0, 0], [2, 0], [1, 1], [2, 1], [2, 2]]) == \"A\"\n assert candidate(moves = [[0, 2], [1, 1], [2, 0]]) == \"Pending\"\n ...
[ "[[0,0],[2,0],[1,1],[2,1],[2,2]]", "[[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]", "[[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]" ]
[ "It's straightforward to check if A or B won or not, check for each row/column/diag if all the three are the same.", "Then if no one wins, the game is a draw iff the board is full, i.e. moves.length = 9 otherwise is pending." ]
{ "canonical_parameter_names": [ "moves" ], "leetcode_dataset_entry_point": "Solution().tictactoe", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:18", "tests_total": 114, "tests_drop...
cpp
{ "raw_signature": "string tictactoe(vector<vector<int>>& moves) {", "container": "Solution", "callable": "tictactoe", "parameters": [ { "name": "moves", "type": "vector<vector<int>>&" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode...
1,276
number-of-burgers-with-no-waste-of-ingredients
Medium
Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as follows: - Jumbo Burger: 4 tomato slices and 1 cheese slice. - Small Burger: 2 Tomato slices and 1 cheese slice. Return [total_jumbo, total_small] so that the number of remaining tomatoSlices equal to 0 and the number of rem...
{ "language": "python", "source": "def check(candidate):\n assert candidate(tomatoSlices = 10000000,cheeseSlices = 5000000) == [0, 5000000]\n assert candidate(tomatoSlices = 16,cheeseSlices = 7) == [1, 6]\n assert candidate(tomatoSlices = 14,cheeseSlices = 5) == [2, 3]\n assert candidate(tomatoSlices = ...
[ "16\n7", "17\n4", "4\n17" ]
[ "Can we have an answer if the number of tomatoes is odd ?", "If we have answer will be there multiple answers or just one answer ?", "Let us define number of jumbo burgers as X and number of small burgers as Y We have to find an x and y in this equation", "1. 4X + 2Y = tomato", "2. X + Y = cheese" ]
{ "canonical_parameter_names": [ "tomatoSlices", "cheeseSlices" ], "leetcode_dataset_entry_point": "Solution().numOfBurgers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:21", "te...
cpp
{ "raw_signature": "vector<int> numOfBurgers(int tomatoSlices, int cheeseSlices) {", "container": "Solution", "callable": "numOfBurgers", "parameters": [ { "name": "tomatoSlices", "type": "int" }, { "name": "cheeseSlices", "type": "int" } ], "return_type": "vector<int...
1,277
count-square-submatrices-with-all-ones
Medium
Given a m * n matrix of ones and zeros, return how many square submatrices have all ones. Example 1: Input: matrix = [ [0,1,1,1], [1,1,1,1], [0,1,1,1] ] Output: 15 Explanation: There are 10 squares of side 1. There are 4 squares of side 2. There is 1 square of side 3. Total number of squares = 10 + 4 + 1 = 15....
{ "language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[1, 0, 1, 0, 1], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [1, 0, 1, 0, 1]]) == 24\n assert candidate(matrix = [[1]]) == 1\n assert candidate(matrix = [[0]]) == 0\n assert candidate(matrix = [[0, 1, 1, 1], [1,...
[ "[[0,1,1,1],[1,1,1,1],[0,1,1,1]]", "[[1,0,1],[1,1,0],[1,1,0]]" ]
[ "Create an additive table that counts the sum of elements of submatrix with the superior corner at (0,0).", "Loop over all subsquares in O(n^3) and check if the sum make the whole array to be ones, if it checks then add 1 to the answer." ]
{ "canonical_parameter_names": [ "matrix" ], "leetcode_dataset_entry_point": "Solution().countSquares", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:23", "tests_total": 67, "tests_d...
cpp
{ "raw_signature": "int countSquares(vector<vector<int>>& matrix) {", "container": "Solution", "callable": "countSquares", "parameters": [ { "name": "matrix", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
1,278
palindrome-partitioning-iii
Hard
You are given a string s containing lowercase letters and an integer k. You need to : - First, change some characters of s to other lowercase English letters. - Then divide s into k non-empty disjoint substrings such that each substring is a palindrome. Return the minimal number of characters that you need to change ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc\",k = 2) == 1\n assert candidate(s = \"abababa\",k = 4) == 1\n assert candidate(s = \"aaaa\",k = 2) == 0\n assert candidate(s = \"leetcode\",k = 8) == 0\n assert candidate(s = \"abcd\",k = 2) == 1\n assert candid...
[ "\"abc\"\n2", "\"aabbc\"\n3", "\"leetcode\"\n8" ]
[ "For each substring calculate the minimum number of steps to make it palindrome and store it in a table.", "Create a dp(pos, cnt) which means the minimum number of characters changed for the suffix of s starting on pos splitting the suffix on cnt chunks." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().palindromePartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:25", "tests_total": 89,...
cpp
{ "raw_signature": "int palindromePartition(string s, int k) {", "container": "Solution", "callable": "palindromePartition", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/code...
1,281
subtract-the-product-and-sum-of-digits-of-an-integer
Easy
Given an integer number n, return the difference between the product of its digits and the sum of its digits. Example 1: Input: n = 234 Output: 15 Explanation: Product of digits = 2 * 3 * 4 = 24 Sum of digits = 2 + 3 + 4 = 9 Result = 24 - 9 = 15 Example 2: Input: n = 4421 Output: 21 Explanation: Product of digits =...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 99999) == 59004\n assert candidate(n = 11111) == -4\n assert candidate(n = 789) == 480\n assert candidate(n = 1111) == -3\n assert candidate(n = 234) == 15\n assert candidate(n = 12345) == 105\n assert candidate(n =...
[ "234", "4421" ]
[ "How to compute all digits of the number ?", "Use modulus operator (%) to compute the last digit.", "Generalise modulus operator idea to compute all digits." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().subtractProductAndSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:27", "tests_total": 55, "tes...
cpp
{ "raw_signature": "int subtractProductAndSum(int n) {", "container": "Solution", "callable": "subtractProductAndSum", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,282
group-the-people-given-the-group-size-they-belong-to
Medium
There are n people that are split into some unknown number of groups. Each person is labeled with a unique ID from 0 to n - 1. You are given an integer array groupSizes, where groupSizes[i] is the size of the group that person i is in. For example, if groupSizes[1] = 3, then person 1 must be in a group of size 3. Ret...
{ "language": "python", "source": "def check(candidate):\n assert candidate(groupSizes = [1, 2, 2, 1, 1]) == [[0], [3], [4], [1, 2]]\n assert candidate(groupSizes = [1, 1, 1, 1, 1, 1]) == [[0], [1], [2], [3], [4], [5]]\n assert candidate(groupSizes = [1, 2, 2, 1]) == [[0], [3], [1, 2]]\n assert candidat...
[ "[3,3,3,3,3,1,3]", "[2,1,3,3,3,2]" ]
[ "Put people's IDs with same groupSize into buckets, then split each bucket into groups.", "Greedy fill until you need a new group." ]
{ "canonical_parameter_names": [ "groupSizes" ], "leetcode_dataset_entry_point": "Solution().groupThePeople", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:29", "tests_total": 83, "t...
cpp
{ "raw_signature": "vector<vector<int>> groupThePeople(vector<int>& groupSizes) {", "container": "Solution", "callable": "groupThePeople", "parameters": [ { "name": "groupSizes", "type": "vector<int>&" } ], "return_type": "vector<vector<int>>", "signature_source": "leetcode/codeSnippet...
1,283
find-the-smallest-divisor-given-a-threshold
Medium
Given an array of integers nums and an integer threshold, we will choose a positive integer divisor, divide all the array by it, and sum the division's result. Find the smallest divisor such that the result mentioned above is less than or equal to threshold. Each result of the division is rounded to the nearest intege...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],threshold = 15) == 10\n assert candidate(nums = [44, 22, 33, 11, 1],threshold = 5) == 44\n assert candidate(nums = [1, 1, 1, 1, 1],threshold = 5) == 1\n assert candidate(nums = [10, 20, 30, 40, 50],th...
[ "[1,2,5,9]\n6", "[44,22,33,11,1]\n5" ]
[ "Examine every possible number for solution. Choose the largest of them.", "Use binary search to reduce the time complexity." ]
{ "canonical_parameter_names": [ "nums", "threshold" ], "leetcode_dataset_entry_point": "Solution().smallestDivisor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:32", "tests_tota...
cpp
{ "raw_signature": "int smallestDivisor(vector<int>& nums, int threshold) {", "container": "Solution", "callable": "smallestDivisor", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "threshold", "type": "int" } ], "return_type": "int", "signatu...
1,284
minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix
Hard
Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing 1 to 0 and 0 to 1). A pair of cells are called neighbors if they share one edge. Return the minimum number of steps required to convert mat to a zero matrix or -1 if you ca...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[0, 0], [0, 1]]) == 3\n assert candidate(mat = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 5\n assert candidate(mat = [[1, 1], [1, 1]]) == 4\n assert candidate(mat = [[0]]) == 0\n assert candidate(mat = [[1, 1, 0], [0, 0, 0]...
[ "[[0,0],[0,1]]", "[[0]]", "[[1,0,0],[1,0,0]]" ]
[ "Flipping same index two times is like not flipping it at all. Each index can be flipped one time. Try all possible combinations. O(2^(n*m))." ]
{ "canonical_parameter_names": [ "mat" ], "leetcode_dataset_entry_point": "Solution().minFlips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:34", "tests_total": 53, "tests_dropped"...
cpp
{ "raw_signature": "int minFlips(vector<vector<int>>& mat) {", "container": "Solution", "callable": "minFlips", "parameters": [ { "name": "mat", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
1,287
element-appearing-more-than-25-in-sorted-array
Easy
Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer. Example 1: Input: arr = [1,2,2,6,6,6,6,7,10] Output: 6 Example 2: Input: arr = [1,1] Output: 1 Constraints: - 1 <= arr.length <= 10^4 - 0 <= arr[i] <= 10^5
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(arr = [1, 1]) == 1\n assert candidate(arr = [1, 2, 2, 2, 3, 4, 5, 6]) == 2\n assert candidate(arr = [1, 1, 2, 3, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10]) == 4\n a...
[ "[1,2,2,6,6,6,6,7,10]", "[1,1]" ]
[ "Divide the array in four parts [1 - 25%] [25 - 50 %] [50 - 75 %] [75% - 100%]", "The answer should be in one of the ends of the intervals.", "In order to check which is element is the answer we can count the frequency with binarySearch." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().findSpecialInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:36", "tests_total": 83, "test...
cpp
{ "raw_signature": "int findSpecialInteger(vector<int>& arr) {", "container": "Solution", "callable": "findSpecialInteger", "parameters": [ { "name": "arr", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
1,288
remove-covered-intervals
Medium
Given an array intervals where intervals[i] = [l_i, r_i] represent the interval [l_i, r_i), remove all intervals that are covered by another interval in the list. The interval [a, b) is covered by the interval [c, d) if and only if c <= a and b <= d. Return the number of remaining intervals. Example 1: Input: inter...
{ "language": "python", "source": "def check(candidate):\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 4\n assert candidate(intervals = [[1, 100], [2, 50], [3, 75]]) == 1\n assert candidate(intervals = [[1, 3], [2, 4], [3, 5]]) == 3\n assert candidate(intervals = [[1, 4], [3, 6], [...
[ "[[52141,92589],[52991,93486],[46321,59199],[51955,78788],[18533,23127]]", "[[14041,32641],[24914,51477],[4983,81235],[62018,77987],[31523,32192],[74196,96194],[16126,52652],[59901,67707],[36502,51366],[56437,86744]]" ]
[ "How to check if an interval is covered by another?", "Compare each interval to all others and check if it is covered by any interval." ]
{ "canonical_parameter_names": [ "intervals" ], "leetcode_dataset_entry_point": "Solution().removeCoveredIntervals", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:38", "tests_total": 1...
cpp
{ "raw_signature": "int removeCoveredIntervals(vector<vector<int>>& intervals) {", "container": "Solution", "callable": "removeCoveredIntervals", "parameters": [ { "name": "intervals", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets"...
1,289
minimum-falling-path-sum-ii
Hard
Given an n x n integer matrix grid, return the minimum sum of a falling path with non-zero shifts. A falling path with non-zero shifts is a choice of exactly one element from each row of grid such that no two elements chosen in adjacent rows are in the same column. Example 1: Input: grid = [[1,2,3],[4,5,6],[7,8,9]] ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[3, 1, 1], [1, 2, 3], [2, 3, 4]]) == 5\n assert candidate(grid = [[10, 20, 30], [30, 20, 10], [10, 10, 10]]) == 30\n assert candidate(grid = [[7]]) == 7\n assert candidate(grid = [[3, 1, 1], [1, 7, 6], [2, 7, 7]]) == 9\n...
[ "[[1,2,3],[4,5,6],[7,8,9]]", "[[7]]" ]
[ "Use dynamic programming.", "Let dp[i][j] be the answer for the first i rows such that column j is chosen from row i.", "Use the concept of cumulative array to optimize the complexity of the solution." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minFallingPathSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:40", "tests_total": 83, "test...
cpp
{ "raw_signature": "int minFallingPathSum(vector<vector<int>>& grid) {", "container": "Solution", "callable": "minFallingPathSum", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "...
1,291
sequential-digits
Medium
An integer has sequential digits if and only if each digit in the number is one more than the previous digit. Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits. Example 1: Input: low = 100, high = 300 Output: [123,234] Example 2: Input: low = 1000, high = 13000...
{ "language": "python", "source": "def check(candidate):\n assert candidate(low = 567,high = 6789) == [567, 678, 789, 1234, 2345, 3456, 4567, 5678, 6789]\n assert candidate(low = 500,high = 700) == [567, 678]\n assert candidate(low = 10,high = 100) == [12, 23, 34, 45, 56, 67, 78, 89]\n assert candidate(...
[ "100\n300", "1000\n13000" ]
[ "Generate all numbers with sequential digits and check if they are in the given range.", "Fix the starting digit then do a recursion that tries to append all valid digits." ]
{ "canonical_parameter_names": [ "low", "high" ], "leetcode_dataset_entry_point": "Solution().sequentialDigits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:45", "tests_total": 8...
cpp
{ "raw_signature": "vector<int> sequentialDigits(int low, int high) {", "container": "Solution", "callable": "sequentialDigits", "parameters": [ { "name": "low", "type": "int" }, { "name": "high", "type": "int" } ], "return_type": "vector<int>", "signature_source": ...
1,292
maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold
Medium
Given a m x n matrix mat and an integer threshold, return the maximum side-length of a square with a sum less than or equal to threshold or return 0 if there is no such square. Example 1: Input: mat = [[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], threshold = 4 Output: 2 Explanation: The maximum side length of sq...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],threshold = 10) == 3\n assert candidate(mat = [[1, 1, 3, 2, 4, 3, 2], [1, 1, 3, 2, 4, 3, 2], [1, 1, 3, 2, 4, 3, 2]],threshold = 4) == 2\n assert candidate(mat = [[2, 2,...
[ "[[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]]\n4", "[[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]]\n1" ]
[ "Store prefix sum of all grids in another 2D array.", "Try all possible solutions and if you cannot find one return 0.", "If x is a valid answer then any y < x is also valid answer. Use binary search to find answer." ]
{ "canonical_parameter_names": [ "mat", "threshold" ], "leetcode_dataset_entry_point": "Solution().maxSideLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:47", "tests_total":...
cpp
{ "raw_signature": "int maxSideLength(vector<vector<int>>& mat, int threshold) {", "container": "Solution", "callable": "maxSideLength", "parameters": [ { "name": "mat", "type": "vector<vector<int>>&" }, { "name": "threshold", "type": "int" } ], "return_type": "int", ...
1,293
shortest-path-in-a-grid-with-obstacles-elimination
Hard
You are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an empty cell in one step. Return the minimum number of steps to walk from the upper left corner (0, 0) to the lower right corner (m - 1, n - 1) given that you can eliminate...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 1, 0, 0, 0, 1, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 1, 0, 0, 0, 0]],k = 2) == 9\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 0, 0], [0, 1, 1, 0]],k = 2) == 6\n assert candidate(grid = [[0, 0, 0], ...
[ "[[0,0,0],[1,1,0],[0,0,0],[0,1,1],[0,0,0]]\n1", "[[0,1,1],[1,1,1],[1,0,0]]\n1" ]
[ "Use BFS.", "BFS on (x,y,r) x,y is coordinate, r is remain number of obstacles you can remove." ]
{ "canonical_parameter_names": [ "grid", "k" ], "leetcode_dataset_entry_point": "Solution().shortestPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:50", "tests_total": 75, "...
cpp
{ "raw_signature": "int shortestPath(vector<vector<int>>& grid, int k) {", "container": "Solution", "callable": "shortestPath", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_sou...
1,295
find-numbers-with-even-number-of-digits
Easy
Given an array nums of integers, return how many of them contain an even number of digits. Example 1: Input: nums = [12,345,2,6,7896] Output: 2 Explanation: 12 contains 2 digits (even number of digits). 345 contains 3 digits (odd number of digits). 2 contains 1 digit (odd number of digits). 6 contains 1 digit (odd nu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 100, 1000, 10000, 100000]) == 3\n assert candidate(nums = [10, 100, 1000, 10000]) == 2\n assert candidate(nums = [10, 22, 333, 4444, 55555]) == 3\n assert candidate(nums = [100000, 10000, 1000, 100, 10]) == 3\n as...
[ "[12,345,2,6,7896]", "[555,901,482,1771]" ]
[ "How to compute the number of digits of a number ?", "Divide the number by 10 again and again to get the number of digits." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:52", "tests_total": 110, "tests_dro...
cpp
{ "raw_signature": "int findNumbers(vector<int>& nums) {", "container": "Solution", "callable": "findNumbers", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,296
divide-array-in-sets-of-k-consecutive-numbers
Medium
Given an array of integers nums and a positive integer k, check whether it is possible to divide this array into sets of k consecutive numbers. Return true if it is possible. Otherwise, return false. Example 1: Input: nums = [1,2,3,3,4,4,5,6], k = 4 Output: true Explanation: Array can be divided into [1,2,3,4] and [...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 3, 4, 4, 5, 6],k = 4) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5],k = 2) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 4) == True\n assert candidate(nums = [1, ...
[ "[1,2,3,3,4,4,5,6]\n4", "[3,2,1,2,3,4,3,4,5,9,10,11]\n3", "[3,3,2,2,1,1]\n3" ]
[ "If the smallest number in the possible-to-split array is V, then numbers V+1, V+2, ... V+k-1 must contain there as well.", "You can iteratively find k sets and remove them from array until it becomes empty.", "Failure to do so would mean that array is unsplittable." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().isPossibleDivide", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:54", "tests_total": 90,...
cpp
{ "raw_signature": "bool isPossibleDivide(vector<int>& nums, int k) {", "container": "Solution", "callable": "isPossibleDivide", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "bool", "signature_source": ...
1,297
maximum-number-of-occurrences-of-a-substring
Medium
Given a string s, return the maximum number of occurrences of any substring under the following rules: - The number of unique characters in the substring must be less than or equal to maxLetters. - The substring size must be between minSize and maxSize inclusive. Example 1: Input: s = "aababcaab", maxLetters = 2, mi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aaaa\",maxLetters = 1,minSize = 3,maxSize = 3) == 2\n assert candidate(s = \"abacabadabacaba\",maxLetters = 3,minSize = 3,maxSize = 5) == 4\n assert candidate(s = \"xyzxyzxyz\",maxLetters = 3,minSize = 3,maxSize = 3) == 3\n ...
[ "\"aababcaab\"\n2\n3\n4", "\"aaaa\"\n1\n3\n3" ]
[ "Check out the constraints, (maxSize <=26).", "This means you can explore all substrings in O(n * 26).", "Find the Maximum Number of Occurrences of a Substring with bruteforce." ]
{ "canonical_parameter_names": [ "s", "maxLetters", "minSize", "maxSize" ], "leetcode_dataset_entry_point": "Solution().maxFreq", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:1...
cpp
{ "raw_signature": "int maxFreq(string s, int maxLetters, int minSize, int maxSize) {", "container": "Solution", "callable": "maxFreq", "parameters": [ { "name": "s", "type": "string" }, { "name": "maxLetters", "type": "int" }, { "name": "minSize", "type":...
1,298
maximum-candies-you-can-get-from-boxes
Hard
You have n boxes labeled from 0 to n - 1. You are given four arrays: status, candies, keys, and containedBoxes where: - status[i] is 1 if the i^th box is open and 0 if the i^th box is closed, - candies[i] is the number of candies in the i^th box, - keys[i] is a list of the labels of the boxes you can open after openin...
{ "language": "python", "source": "def check(candidate):\n assert candidate(status = [0, 0, 0],candies = [100, 200, 300],keys = [[1, 2], [0, 2], [0, 1]],containedBoxes = [[1, 2], [0, 2], [0, 1]],initialBoxes = [0]) == 0\n assert candidate(status = [0, 0, 0],candies = [10, 20, 30],keys = [[1], [2], []],contain...
[ "[1,0,1,0]\n[7,5,4,100]\n[[],[],[1],[]]\n[[1,2],[3],[],[]]\n[0]", "[1,0,0,0,0,0]\n[1,1,1,1,1,1]\n[[1,2,3,4,5],[],[],[],[],[]]\n[[1,2,3,4,5],[],[],[],[],[]]\n[0]" ]
[ "Use Breadth First Search (BFS) to traverse all possible boxes you can open. Only push to the queue the boxes the you have with their keys." ]
{ "canonical_parameter_names": [ "status", "candies", "keys", "containedBoxes", "initialBoxes" ], "leetcode_dataset_entry_point": "Solution().maxCandies", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "...
cpp
{ "raw_signature": "int maxCandies(vector<int>& status, vector<int>& candies, vector<vector<int>>& keys, vector<vector<int>>& containedBoxes, vector<int>& initialBoxes) {", "container": "Solution", "callable": "maxCandies", "parameters": [ { "name": "status", "type": "vector<int>&" }, { ...
1,299
replace-elements-with-greatest-element-on-right-side
Easy
Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array. Example 1: Input: arr = [17,18,5,4,6,1] Output: [18,6,6,6,1,-1] Explanation: - index 0 --> the greatest element to the right of in...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, -1]\n assert candidate(arr = [5, 4, 3, 2, 1]) == [4, 3, 2, 1, -1]\n assert candidate(arr = [1, 2, 3, 4, 5]) == [5, 5, 5, 5, -1]\n assert candidate(ar...
[ "[17,18,5,4,6,1]", "[400]" ]
[ "Loop through the array starting from the end.", "Keep the maximum value seen so far." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().replaceElements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:01", "tests_total": 104, "tests_...
cpp
{ "raw_signature": "vector<int> replaceElements(vector<int>& arr) {", "container": "Solution", "callable": "replaceElements", "parameters": [ { "name": "arr", "type": "vector<int>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
1,300
sum-of-mutated-array-closest-to-target
Medium
Given an integer array arr and a target value target, return the integer value such that when we change all the integers larger than value in the given array to be equal to value, the sum of the array gets as close as possible (in absolute difference) to target. In case of a tie, return the minimum such integer. Noti...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5],target = 11) == 3\n assert candidate(arr = [5, 5, 5, 5, 5],target = 17) == 3\n assert candidate(arr = [10, 20, 30, 40, 50],target = 100) == 23\n assert candidate(arr = [2, 3, 5],target = 10) == 5\n asser...
[ "[4,9,3]\n10", "[2,3,5]\n10", "[60864,25176,27249,21296,20204]\n56803" ]
[ "If you draw a graph with the value on one axis and the absolute difference between the target and the array sum, what will you get?", "That graph is uni-modal.", "Use ternary search on that graph to find the best value." ]
{ "canonical_parameter_names": [ "arr", "target" ], "leetcode_dataset_entry_point": "Solution().findBestValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:03", "tests_total": 11...
cpp
{ "raw_signature": "int findBestValue(vector<int>& arr, int target) {", "container": "Solution", "callable": "findBestValue", "parameters": [ { "name": "arr", "type": "vector<int>&" }, { "name": "target", "type": "int" } ], "return_type": "int", "signature_source": ...
1,301
number-of-paths-with-max-score
Hard
You are given a square board of characters. You can move on the board starting at the bottom right square marked with the character 'S'. You need to reach the top left square marked with the character 'E'. The rest of the squares are labeled either with a numeric character 1, 2, ..., 9 or with an obstacle 'X'. In one ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(board = ['E11', 'XXX', '11S']) == [0, 0]\n assert candidate(board = ['EX', 'XS']) == [0, 1]\n assert candidate(board = ['E111', '1X11', '1111', '111S']) == [5, 8]\n assert candidate(board = ['E22', '222', '22S']) == [6, 6]\n ...
[ "[\"E3283\",\"47715\",\"31479\",\"X1X32\",\"721XS\"]", "[\"E8X84\",\"98635\",\"24233\",\"X64X3\",\"281XS\"]", "[\"E3231\",\"3X588\",\"X2715\",\"94342\",\"6X82S\"]" ]
[ "Use dynamic programming to find the path with the max score.", "Use another dynamic programming array to count the number of paths with max score." ]
{ "canonical_parameter_names": [ "board" ], "leetcode_dataset_entry_point": "Solution().pathsWithMaxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:05", "tests_total": 95, "tes...
cpp
{ "raw_signature": "vector<int> pathsWithMaxScore(vector<string>& board) {", "container": "Solution", "callable": "pathsWithMaxScore", "parameters": [ { "name": "board", "type": "vector<string>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_so...
1,304
find-n-unique-integers-sum-up-to-zero
Easy
Given an integer n, return any array containing n unique integers such that they add up to 0. Example 1: Input: n = 5 Output: [-7,-1,1,3,4] Explanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4]. Example 2: Input: n = 3 Output: [-1,0,1] Example 3: Input: n = 1 Output: [0] Constraints: - 1 <=...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == [1, -1, 0]\n assert candidate(n = 100) == [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15, 16, -16, 17, -17, 18, -18, 19, -19, 20, -20, 21, -21, 22, -22, 2...
[ "5", "3", "1" ]
[ "Return an array where the values are symmetric. (+x , -x).", "If n is odd, append value 0 in your returned array." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().sumZero", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:10", "tests_total": 60, "tests_dropped": 0...
cpp
{ "raw_signature": "vector<int> sumZero(int n) {", "container": "Solution", "callable": "sumZero", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,306
jump-game-iii
Medium
Given an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + arr[i] or i - arr[i], check if you can reach any index with value 0. Notice that you can not jump outside of the array at any time. Example 1: Input: arr = [4,2,3,0,3,1,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [5, 0, 5, 0, 5, 0],start = 1) == True\n assert candidate(arr = [5, 0, 0, 0, 0, 0],start = 0) == True\n assert candidate(arr = [4, 2, 3, 0, 3, 1, 2],start = 0) == True\n assert candidate(arr = [0, 1, 0, 1, 0, 1, 0],start = ...
[ "[4,2,3,0,3,1,2]\n5", "[4,2,3,0,3,1,2]\n0", "[3,0,2,1,2]\n2" ]
[ "Think of BFS to solve the problem.", "When you reach a position with a value = 0 then return true." ]
{ "canonical_parameter_names": [ "arr", "start" ], "leetcode_dataset_entry_point": "Solution().canReach", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:14", "tests_total": 111, "...
cpp
{ "raw_signature": "bool canReach(vector<int>& arr, int start) {", "container": "Solution", "callable": "canReach", "parameters": [ { "name": "arr", "type": "vector<int>&" }, { "name": "start", "type": "int" } ], "return_type": "bool", "signature_source": "leetcode/...
1,307
verbal-arithmetic-puzzle
Hard
Given an equation, represented by words on the left side and the result on the right side. You need to check if the equation is solvable under the following rules: - Each character is decoded as one digit (0 - 9). - No two characters can map to the same digit. - Each words[i] and result are decoded as one number with...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['SEND', 'MORE'],result = \"MONEY\") == True\n assert candidate(words = ['A', 'A', 'A', 'A'],result = \"AA\") == False\n assert candidate(words = ['LEET', 'CODE'],result = \"POINT\") == False\n assert candidate(words = [...
[ "[\"SEND\",\"MORE\"]\n\"MONEY\"", "[\"SIX\",\"SEVEN\",\"SEVEN\"]\n\"TWENTY\"", "[\"LEET\",\"CODE\"]\n\"POINT\"" ]
[ "Use Backtracking and pruning to solve this problem.", "If you set the values of some digits (from right to left), the other digits will be constrained." ]
{ "canonical_parameter_names": [ "words", "result" ], "leetcode_dataset_entry_point": "Solution().isSolvable", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:16", "tests_total": 148...
cpp
{ "raw_signature": "bool isSolvable(vector<string>& words, string result) {", "container": "Solution", "callable": "isSolvable", "parameters": [ { "name": "words", "type": "vector<string>&" }, { "name": "result", "type": "string" } ], "return_type": "bool", "signatu...
1,309
decrypt-string-from-alphabet-to-integer-mapping
Easy
You are given a string s formed by digits and '#'. We want to map s to English lowercase characters as follows: - Characters ('a' to 'i') are represented by ('1' to '9') respectively. - Characters ('j' to 'z') are represented by ('10#' to '26#') respectively. Return the string formed after mapping. The test cases ar...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"11#11#11#11#11#11#11#11#11#11#\") == \"kkkkkkkkkk\"\n assert candidate(s = \"12345678910#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"26#25#24#23#22#21#\") == ...
[ "\"10#11#12\"", "\"1326#\"" ]
[ "Scan from right to left, in each step of the scanning check whether there is a trailing \"#\" 2 indexes away." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().freqAlphabets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:19", "tests_total": 43, "tests_dropp...
cpp
{ "raw_signature": "string freqAlphabets(string s) {", "container": "Solution", "callable": "freqAlphabets", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,310
xor-queries-of-a-subarray
Medium
You are given an array arr of positive integers. You are also given the array queries where queries[i] = [left_i,right_i]. For each query i compute the XOR of elements from left_i to right_i (that is, arr[left_i] XOR arr[left_i + 1] XOR ... XOR arr[right_i] ). Return an array answer where answer[i] is the answer to t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [4, 8, 2, 10],queries = [[2, 3], [1, 3], [0, 0], [0, 3]]) == [8, 0, 4, 4]\n assert candidate(arr = [10, 5, 2, 3, 15],queries = [[0, 4], [1, 2], [2, 3], [0, 1], [3, 4]]) == [1, 7, 1, 15, 12]\n assert candidate(arr = [5, 2, 3, ...
[ "[1,3,4,8]\n[[0,1],[1,2],[0,3],[3,3]]", "[4,8,2,10]\n[[2,3],[1,3],[0,0],[0,3]]" ]
[ "What is the result of x ^ y ^ x ?", "Compute the prefix sum for XOR.", "Process the queries with the prefix sum values." ]
{ "canonical_parameter_names": [ "arr", "queries" ], "leetcode_dataset_entry_point": "Solution().xorQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:21", "tests_total": 77, ...
cpp
{ "raw_signature": "vector<int> xorQueries(vector<int>& arr, vector<vector<int>>& queries) {", "container": "Solution", "callable": "xorQueries", "parameters": [ { "name": "arr", "type": "vector<int>&" }, { "name": "queries", "type": "vector<vector<int>>&" } ], "retur...
1,311
get-watched-videos-by-your-friends
Medium
There are n people, each person has a unique id between 0 and n-1. Given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] contain the list of watched videos and the list of friends respectively for the person with id = i. Level 1 of videos are all watched videos by your friends, level 2 of v...
{ "language": "python", "source": "def check(candidate):\n assert candidate(watchedVideos = [['Action', 'Comedy'], ['Action'], ['Comedy', 'Drama'], ['Drama']],friends = [[1, 2], [0, 3], [0, 3], [1, 2]],id = 3,level = 1) == ['Action', 'Comedy', 'Drama']\n assert candidate(watchedVideos = [['X', 'Y'], ['Y', 'Z'...
[ "[[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]]\n[[1,2],[0,3],[0,3],[1,2]]\n0\n1", "[[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]]\n[[1,2],[0,3],[0,3],[1,2]]\n0\n2" ]
[ "Do BFS to find the kth level friends.", "Then collect movies saw by kth level friends and sort them accordingly." ]
{ "canonical_parameter_names": [ "watchedVideos", "friends", "id", "level" ], "leetcode_dataset_entry_point": "Solution().watchedVideosByFriends", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at":...
cpp
{ "raw_signature": "vector<string> watchedVideosByFriends(vector<vector<string>>& watchedVideos, vector<vector<int>>& friends, int id, int level) {", "container": "Solution", "callable": "watchedVideosByFriends", "parameters": [ { "name": "watchedVideos", "type": "vector<vector<string>>&" },...
1,312
minimum-insertion-steps-to-make-a-string-palindrome
Hard
Given a string s. In one step you can insert any character at any index of the string. Return the minimum number of steps to make s palindrome. A Palindrome String is one that reads the same backward as well as forward. Example 1: Input: s = "zzazz" Output: 0 Explanation: The string "zzazz" is already palindrome we...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"race\") == 3\n assert candidate(s = \"noon\") == 0\n assert candidate(s = \"abcba\") == 0\n assert candidate(s = \"abcdef\") == 5\n assert candidate(s = \"zzazz\") == 0\n assert candidate(s = \"google\") == 2\n as...
[ "\"zzazz\"", "\"mbadm\"", "\"leetcode\"" ]
[ "Is dynamic programming suitable for this problem ?", "If we know the longest palindromic sub-sequence is x and the length of the string is n then, what is the answer to this problem? It is n - x as we need n - x insertions to make the remaining characters also palindrome." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minInsertions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:26", "tests_total": 123, "tests_drop...
cpp
{ "raw_signature": "int minInsertions(string s) {", "container": "Solution", "callable": "minInsertions", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,313
decompress-run-length-encoded-list
Easy
We are given a list nums of integers representing a list compressed with run-length encoding. Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0). For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to rig...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 9, 2, 8, 3, 7]) == [9, 8, 8, 7, 7, 7]\n assert candidate(nums = [3, 1, 2, 2]) == [1, 1, 1, 2, 2]\n assert candidate(nums = [2, 5, 3, 1]) == [5, 5, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4]) == [2, 4, 4, 4]\n ...
[ "[1,2,3,4]", "[1,1,2,3]" ]
[ "Decompress the given array by repeating nums[2*i+1] a number of times equal to nums[2*i]." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().decompressRLElist", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:28", "tests_total": 86, "test...
cpp
{ "raw_signature": "vector<int> decompressRLElist(vector<int>& nums) {", "container": "Solution", "callable": "decompressRLElist", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_source": "...
1,314
matrix-block-sum
Medium
Given a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for: - i - k <= r <= i + k, - j - k <= c <= j + k, and - (r, c) is a valid position in the matrix. Example 1: Input: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1 Output: [[12,21,16],[27,45,33],[24...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],k = 2) == [[45, 45, 45], [45, 45, 45], [45, 45, 45]]\n assert candidate(mat = [[1, 2], [3, 4]],k = 1) == [[10, 10], [10, 10]]\n assert candidate(mat = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],k = 1)...
[ "[[1,2,3],[4,5,6],[7,8,9]]\n1", "[[1,2,3],[4,5,6],[7,8,9]]\n2" ]
[ "How to calculate the required sum for a cell (i,j) fast ?", "Use the concept of cumulative sum array.", "Create a cumulative sum matrix where dp[i][j] is the sum of all cells in the rectangle from (0,0) to (i,j), use inclusion-exclusion idea." ]
{ "canonical_parameter_names": [ "mat", "k" ], "leetcode_dataset_entry_point": "Solution().matrixBlockSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:30", "tests_total": 88, ...
cpp
{ "raw_signature": "vector<vector<int>> matrixBlockSum(vector<vector<int>>& mat, int k) {", "container": "Solution", "callable": "matrixBlockSum", "parameters": [ { "name": "mat", "type": "vector<vector<int>>&" }, { "name": "k", "type": "int" } ], "return_type": "vect...
1,316
distinct-echo-substrings
Hard
Return the number of distinct non-empty substrings of text that can be written as the concatenation of some string with itself (i.e. it can be written as a + a where a is some string). Example 1: Input: text = "abcabcabc" Output: 3 Explanation: The 3 substrings are "abcabc", "bcabca" and "cabcab". Example 2: Input:...
{ "language": "python", "source": "def check(candidate):\n assert candidate(text = \"ababab\") == 2\n assert candidate(text = \"abcabcabc\") == 3\n assert candidate(text = \"aaaa\") == 2\n assert candidate(text = \"ab\") == 0\n assert candidate(text = \"abbbabbb\") == 2\n assert candidate(text = \...
[ "\"abcabcabc\"", "\"leetcodeleetcode\"" ]
[ "Given a substring of the text, how to check if it can be written as the concatenation of a string with itself ?", "We can do that in linear time, a faster way is to use hashing.", "Try all substrings and use hashing to check them." ]
{ "canonical_parameter_names": [ "text" ], "leetcode_dataset_entry_point": "Solution().distinctEchoSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:35", "tests_total": 98, ...
cpp
{ "raw_signature": "int distinctEchoSubstrings(string text) {", "container": "Solution", "callable": "distinctEchoSubstrings", "parameters": [ { "name": "text", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnipp...
1,317
convert-integer-to-the-sum-of-two-no-zero-integers
Easy
No-Zero integer is a positive integer that does not contain any 0 in its decimal representation. Given an integer n, return a list of two integers [a, b] where: - a and b are No-Zero integers. - a + b = n The test cases are generated so that there is at least one valid solution. If there are many valid solutions, yo...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 101) == [2, 99]\n assert candidate(n = 1010) == [11, 999]\n assert candidate(n = 11) == [2, 9]\n assert candidate(n = 104) == [5, 99]\n assert candidate(n = 1001) == [2, 999]\n assert candidate(n = 2) == [1, 1]\n as...
[ "19", "139" ]
[ "Loop through all elements from 1 to n.", "Choose A = i and B = n - i then check if A and B are both No-Zero integers." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().getNoZeroIntegers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:37", "tests_total": 115, "tests_...
cpp
{ "raw_signature": "vector<int> getNoZeroIntegers(int n) {", "container": "Solution", "callable": "getNoZeroIntegers", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,318
minimum-flips-to-make-a-or-b-equal-to-c
Medium
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation. Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation:...
{ "language": "python", "source": "def check(candidate):\n assert candidate(a = 10,b = 15,c = 25) == 4\n assert candidate(a = 2,b = 6,c = 5) == 3\n assert candidate(a = 1,b = 2,c = 3) == 0\n assert candidate(a = 8,b = 3,c = 11) == 0\n assert candidate(a = 4,b = 2,c = 7) == 1\n assert candidate(a =...
[ "2\n6\n5", "4\n2\n7", "1\n2\n3" ]
[ "Check the bits one by one whether they need to be flipped." ]
{ "canonical_parameter_names": [ "a", "b", "c" ], "leetcode_dataset_entry_point": "Solution().minFlips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:39", "tests_total": 92, ...
cpp
{ "raw_signature": "int minFlips(int a, int b, int c) {", "container": "Solution", "callable": "minFlips", "parameters": [ { "name": "a", "type": "int" }, { "name": "b", "type": "int" }, { "name": "c", "type": "int" } ], "return_type": "int", "si...
1,319
number-of-operations-to-make-network-connected
Medium
There are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a network where connections[i] = [a_i, b_i] represents a connection between computers a_i and b_i. Any computer can reach any other computer directly or indirectly through the network. You are given an initial computer netw...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 10,connections = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 0\n assert candidate(n = 5,connections = [[0, 1], [1, 2], [3, 4]]) == -1\n assert candidate(n = 6,connections = [[0, 1], [0, 2], [0, ...
[ "4\n[[0,1],[0,2],[1,2]]", "6\n[[0,1],[0,2],[0,3],[1,2],[1,3]]", "6\n[[0,1],[0,2],[0,3],[1,2]]" ]
[ "As long as there are at least (n - 1) connections, there is definitely a way to connect all computers.", "Use DFS to determine the number of isolated computer clusters." ]
{ "canonical_parameter_names": [ "n", "connections" ], "leetcode_dataset_entry_point": "Solution().makeConnected", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:41", "tests_total":...
cpp
{ "raw_signature": "int makeConnected(int n, vector<vector<int>>& connections) {", "container": "Solution", "callable": "makeConnected", "parameters": [ { "name": "n", "type": "int" }, { "name": "connections", "type": "vector<vector<int>>&" } ], "return_type": "int", ...
1,320
minimum-distance-to-type-a-word-using-two-fingers
Hard
You have a keyboard layout as shown above in the X-Y plane, where each English uppercase letter is located at some coordinate. - For example, the letter 'A' is located at coordinate (0, 0), the letter 'B' is located at coordinate (0, 1), the letter 'P' is located at coordinate (2, 3) and the letter 'Z' is located at c...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"QWERTYUIOPASDFGHJKLZXCVBNM\") == 52\n assert candidate(word = \"ZZZZZ\") == 0\n assert candidate(word = \"CAKE\") == 3\n assert candidate(word = \"RHYTHM\") == 9\n assert candidate(word = \"FINGER\") == 8\n assert...
[ "\"CAKE\"", "\"HAPPY\"" ]
[ "Use dynamic programming.", "dp[i][j][k]: smallest movements when you have one finger on i-th char and the other one on j-th char already having written k first characters from word." ]
{ "canonical_parameter_names": [ "word" ], "leetcode_dataset_entry_point": "Solution().minimumDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:44", "tests_total": 450, "tests...
cpp
{ "raw_signature": "int minimumDistance(string word) {", "container": "Solution", "callable": "minimumDistance", "parameters": [ { "name": "word", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,324
print-words-vertically
Medium
Given a string s. Return all the words vertically in the same order in which they appear in s. Words are returned as a list of strings, complete with spaces when is necessary. (Trailing spaces are not allowed). Each word would be put on only one column and that in one column there will be only one word. Example 1: In...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"AB CD\") == ['AC', 'BD']\n assert candidate(s = \"A B C D\") == ['ABCD']\n assert candidate(s = \"A B C D E\") == ['ABCDE']\n assert candidate(s = \"SINGLEWORD\") == ['S', 'I', 'N', 'G', 'L', 'E', 'W', 'O', 'R', 'D']\n ...
[ "\"HOW ARE YOU\"", "\"TO BE OR NOT TO BE\"", "\"CONTEST IS COMING\"" ]
[ "Use the maximum length of words to determine the length of the returned answer. However, don't forget to remove trailing spaces." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().printVertically", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:46", "tests_total": 140, "tests_dr...
cpp
{ "raw_signature": "vector<string> printVertically(string s) {", "container": "Solution", "callable": "printVertically", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "vector<string>", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
1,326
minimum-number-of-taps-to-open-to-water-a-garden
Hard
There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e., the length of the garden is n). There are n + 1 taps located at points [0, 1, ..., n] in the garden. Given an integer n and an integer array ranges of length n + 1 where ranges[i] (0-indexed) means the i-...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 10,ranges = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == -1\n assert candidate(n = 5,ranges = [3, 4, 1, 1, 0, 0]) == 1\n assert candidate(n = 8,ranges = [4, 0, 0, 0, 0, 0, 0, 0, 4]) == 2\n assert candidate(n = 3,ranges = [0, 0, 0, ...
[ "5\n[3,4,1,1,0,0]", "3\n[0,0,0,0]" ]
[ "Create intervals of the area covered by each tap, sort intervals by the left end.", "We need to cover the interval [0, n]. we can start with the first interval and out of all intervals that intersect with it we choose the one that covers the farthest point to the right.", "What if there is a gap between interv...
{ "canonical_parameter_names": [ "n", "ranges" ], "leetcode_dataset_entry_point": "Solution().minTaps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:50", "tests_total": 93, "tes...
cpp
{ "raw_signature": "int minTaps(int n, vector<int>& ranges) {", "container": "Solution", "callable": "minTaps", "parameters": [ { "name": "n", "type": "int" }, { "name": "ranges", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSn...
1,328
break-a-palindrome
Medium
Given a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the resulting string is not a palindrome and that it is the lexicographically smallest one possible. Return the resulting string. If there is no way to replace a character to make...
{ "language": "python", "source": "def check(candidate):\n assert candidate(palindrome = \"refer\") == \"aefer\"\n assert candidate(palindrome = \"abba\") == \"aaba\"\n assert candidate(palindrome = \"rotor\") == \"aotor\"\n assert candidate(palindrome = \"aa\") == \"ab\"\n assert candidate(palindrom...
[ "\"abccba\"", "\"a\"" ]
[ "How to detect if there is impossible to perform the replacement? Only when the length = 1.", "Change the first non 'a' character to 'a'.", "What if the string has only 'a'?", "Change the last character to 'b'." ]
{ "canonical_parameter_names": [ "palindrome" ], "leetcode_dataset_entry_point": "Solution().breakPalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:52", "tests_total": 118, ...
cpp
{ "raw_signature": "string breakPalindrome(string palindrome) {", "container": "Solution", "callable": "breakPalindrome", "parameters": [ { "name": "palindrome", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeS...
1,329
sort-the-matrix-diagonally
Medium
A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix's end. For example, the matrix diagonal starting from mat[2][0], where mat is a 6 x 3 matrix, includes cells mat[2][0], mat[3][1], and mat[...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[1]]) == [[1]]\n assert candidate(mat = [[37, 47, 1, 44], [20, 3, 2, 90], [96, 50, 4, 24]]) == [[3, 2, 1, 44], [20, 4, 24, 90], [96, 50, 37, 47]]\n assert candidate(mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, ...
[ "[[3,3,1,1],[2,2,1,2],[1,1,1,2]]", "[[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]]" ]
[ "Use a data structure to store all values of each diagonal.", "How to index the data structure with the id of the diagonal?", "All cells in the same diagonal (i,j) have the same difference so we can get the diagonal of a cell using the difference i-j." ]
{ "canonical_parameter_names": [ "mat" ], "leetcode_dataset_entry_point": "Solution().diagonalSort", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:55", "tests_total": 81, "tests_drop...
cpp
{ "raw_signature": "vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {", "container": "Solution", "callable": "diagonalSort", "parameters": [ { "name": "mat", "type": "vector<vector<int>>&" } ], "return_type": "vector<vector<int>>", "signature_source": "leetcode/codeSnippets"...
1,330
reverse-subarray-to-maximize-array-value
Hard
You are given an integer array nums. The value of this array is defined as the sum of |nums[i] - nums[i + 1]| for all 0 <= i < nums.length - 1. You are allowed to select any subarray of the given array and reverse it. You can perform this operation only once. Find maximum possible value of the final array. Example 1...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == 9\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 230\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == 22\n assert candidate(nums = [1, -1, 1, -1, 1]) == 8\n assert candid...
[ "[2,3,1,5,4]", "[2,4,9,24,2,1,10]" ]
[ "What's the score after reversing a sub-array [L, R] ?", "It's the score without reversing it + abs(a[R] - a[L-1]) + abs(a[L] - a[R+1]) - abs(a[L] - a[L-1]) - abs(a[R] - a[R+1])", "How to maximize that formula given that abs(x - y) = max(x - y, y - x) ?", "This can be written as max(max(a[R] - a[L - 1], a[L -...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxValueAfterReverse", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:57", "tests_total": 99, "t...
cpp
{ "raw_signature": "int maxValueAfterReverse(vector<int>& nums) {", "container": "Solution", "callable": "maxValueAfterReverse", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/c...
1,331
rank-transform-of-an-array
Easy
Given an array of integers arr, replace each element with its rank. The rank represents how large the element is. The rank has the following rules: - Rank is an integer starting from 1. - The larger the element, the larger the rank. If two elements are equal, their rank must be the same. - Rank should be as small as ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [5, 4, 3, 2, 1]) == [5, 4, 3, 2, 1]\n assert candidate(arr = [-10, 100, 0, 5, 3]) == [1, 5, 2, 4, 3]\n assert candidate(arr = [-10, -20, -30, -40, -50]) == [5, 4, 3, 2, 1]\n assert candidate(arr = [1, 2, 3, 4, 5]) == [1, 2...
[ "[40,10,20,30]", "[100,100,100]", "[37,12,28,9,100,56,80,5,12]" ]
[ "Use a temporary array to copy the array and sort it.", "The rank of each element is the number of unique elements smaller than it in the sorted array plus one." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().arrayRankTransform", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:59", "tests_total": 113, "tes...
cpp
{ "raw_signature": "vector<int> arrayRankTransform(vector<int>& arr) {", "container": "Solution", "callable": "arrayRankTransform", "parameters": [ { "name": "arr", "type": "vector<int>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_source": "...
1,332
remove-palindromic-subsequences
Easy
You are given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s. Return the minimum number of steps to make the given string empty. A string is a subsequence of a given string if it is generated by deleting some characters of a given string without c...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"b\") == 1\n assert candidate(s = \"aabbab\") == 2\n assert candidate(s = \"baba\") == 2\n assert candidate(s = \"aababb\") == 2\n assert candidate(s = \"abbaab\") == 2\n assert candidate(s = \"ab\") == 2\n assert ...
[ "\"ababa\"", "\"abb\"", "\"baabb\"" ]
[ "Use the fact that string contains only 2 characters.", "Are subsequences composed of only one type of letter always palindrome strings ?" ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().removePalindromeSub", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:02", "tests_total": 172, "test...
cpp
{ "raw_signature": "int removePalindromeSub(string s) {", "container": "Solution", "callable": "removePalindromeSub", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,333
filter-restaurants-by-vegan-friendly-price-and-distance
Medium
Given the array restaurants where restaurants[i] = [id_i, rating_i, veganFriendly_i, price_i, distance_i]. You have to filter the restaurants using three filters. The veganFriendly filter will be either true (meaning you should only include restaurants with veganFriendly_i set to true) or false (meaning you can includ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(restaurants = [[1, 4, 1, 40, 10], [2, 8, 0, 50, 5], [3, 8, 1, 30, 4], [4, 10, 0, 10, 3], [5, 1, 1, 15, 1]],veganFriendly = 0,maxPrice = 50,maxDistance = 10) == [4, 3, 2, 1, 5]\n assert candidate(restaurants = [[1, 4, 1, 40, 10], [2, 8...
[ "[[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]]\n1\n50\n10", "[[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]]\n0\n50\n10", "[[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]]\n0\n30\n3" ]
[ "Do the filtering and sort as said. Note that the id may not be the index in the array." ]
{ "canonical_parameter_names": [ "restaurants", "veganFriendly", "maxPrice", "maxDistance" ], "leetcode_dataset_entry_point": "Solution().filterRestaurants", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "f...
cpp
{ "raw_signature": "vector<int> filterRestaurants(vector<vector<int>>& restaurants, int veganFriendly, int maxPrice, int maxDistance) {", "container": "Solution", "callable": "filterRestaurants", "parameters": [ { "name": "restaurants", "type": "vector<vector<int>>&" }, { "name": "...
1,334
find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
Medium
There are n cities numbered from 0 to n-1. Given the array edges where edges[i] = [from_i, to_i, weight_i] represents a bidirectional and weighted edge between cities from_i and to_i, and given the integer distanceThreshold. Return the city with the smallest number of cities that are reachable through some path and wh...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,edges = [[0, 1, 2], [0, 4, 8], [1, 2, 3], [1, 4, 2], [2, 3, 1], [3, 4, 1]],distanceThreshold = 2) == 0\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 1], [1, 3, 4], [2, 3, 1]],distanceThreshold = 4) == 3\n assert candida...
[ "4\n[[0,1,3],[1,2,1],[1,3,4],[2,3,1]]\n4", "5\n[[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]]\n2" ]
[ "Use Floyd-Warshall's algorithm to compute any-point to any-point distances. (Or can also do Dijkstra from every node due to the weights are non-negative).", "For each city calculate the number of reachable cities within the threshold, then search for the optimal city." ]
{ "canonical_parameter_names": [ "n", "edges", "distanceThreshold" ], "leetcode_dataset_entry_point": "Solution().findTheCity", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:06",...
cpp
{ "raw_signature": "int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {", "container": "Solution", "callable": "findTheCity", "parameters": [ { "name": "n", "type": "int" }, { "name": "edges", "type": "vector<vector<int>>&" }, { "name": "...
1,335
minimum-difficulty-of-a-job-schedule
Hard
You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the i^th job, you have to finish all the jobs j where 0 <= j < i). You have to finish at least one task every day. The difficulty of a job schedule is the sum of difficulties of each day of the d days. The difficulty of a day is the maxi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(jobDifficulty = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],d = 10) == 55\n assert candidate(jobDifficulty = [300, 500, 1000],d = 3) == 1800\n assert candidate(jobDifficulty = [6, 5, 4, 3, 2, 1],d = 2) == 7\n assert candidate(jobDifficulty ...
[ "[6,5,4,3,2,1]\n2", "[9,9,9]\n4", "[1,1,1]\n3" ]
[ "Use DP. Try to cut the array into d non-empty sub-arrays. Try all possible cuts for the array.", "Use dp[i][j] where DP states are i the index of the last cut and j the number of remaining cuts. Complexity is O(n * n * d)." ]
{ "canonical_parameter_names": [ "jobDifficulty", "d" ], "leetcode_dataset_entry_point": "Solution().minDifficulty", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:08", "tests_total...
cpp
{ "raw_signature": "int minDifficulty(vector<int>& jobDifficulty, int d) {", "container": "Solution", "callable": "minDifficulty", "parameters": [ { "name": "jobDifficulty", "type": "vector<int>&" }, { "name": "d", "type": "int" } ], "return_type": "int", "signature...
1,337
the-k-weakest-rows-in-a-matrix
Easy
You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1's will appear to the left of all the 0's in each row. A row i is weaker than a row j if one of the following is true: - The number of sold...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]],k = 2) == [0, 1]\n assert candidate(mat = [[0, 0, 0, 0], [1, 0, 0, 0], [1, 1, 0, 0], [1, 1, 1, 0]],k = 2) == [0, 1]\n assert candidate(mat = [[1, 1, 1, 1], ...
[ "[[1,1,0,0,0],[1,1,1,1,0],[1,0,0,0,0],[1,1,0,0,0],[1,1,1,1,1]]\n3", "[[1,0,0,0],[1,1,1,1],[1,0,0,0],[1,0,0,0]]\n2" ]
[ "Sort the matrix row indexes by the number of soldiers and then row indexes." ]
{ "canonical_parameter_names": [ "mat", "k" ], "leetcode_dataset_entry_point": "Solution().kWeakestRows", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:11", "tests_total": 80, "t...
cpp
{ "raw_signature": "vector<int> kWeakestRows(vector<vector<int>>& mat, int k) {", "container": "Solution", "callable": "kWeakestRows", "parameters": [ { "name": "mat", "type": "vector<vector<int>>&" }, { "name": "k", "type": "int" } ], "return_type": "vector<int>", ...
1,338
reduce-array-size-to-the-half
Medium
You are given an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array. Return the minimum size of the set so that at least half of the integers of the array are removed. Example 1: Input: arr = [3,3,3,3,5,5,5,2,2,7] Output: 2 Explanation: Choosing {3,7} wi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [7, 7, 7, 7, 7, 7]) == 1\n assert candidate(arr = [1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6]) == 2\n assert candidate(arr = [1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6]) == ...
[ "[3,3,3,3,5,5,5,2,2,7]", "[7,7,7,7,7,7]" ]
[ "Count the frequency of each integer in the array.", "Start with an empty set, add to the set the integer with the maximum frequency.", "Keep Adding the integer with the max frequency until you remove at least half of the integers." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().minSetSize", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:13", "tests_total": 85, "tests_droppe...
cpp
{ "raw_signature": "int minSetSize(vector<int>& arr) {", "container": "Solution", "callable": "minSetSize", "parameters": [ { "name": "arr", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,340
jump-game-v
Hard
Given an array of integers arr and an integer d. In one step you can jump from index i to index: - i + x where: i + x < arr.length and 0 < x <= d. - i - x where: i - x >= 0 and 0 < x <= d. In addition, you can only jump from index i to index j if arr[i] > arr[j] and arr[i] > arr[k] for all indices k between i and j...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],d = 5) == 10\n assert candidate(arr = [1, 2, 3, 4, 5],d = 4) == 5\n assert candidate(arr = [1, 2, 3, 4, 5],d = 2) == 5\n assert candidate(arr = [3, 3, 3, 3, 3],d = 3) == 1\n assert candid...
[ "[6,4,14,6,8,13,9,7,10,6,12]\n2", "[3,3,3,3,3]\n3", "[7,6,5,4,3,2,1]\n1" ]
[ "Use dynamic programming. dp[i] is max jumps you can do starting from index i. Answer is max(dp[i]).", "dp[i] = 1 + max (dp[j]) where j is all indices you can reach from i." ]
{ "canonical_parameter_names": [ "arr", "d" ], "leetcode_dataset_entry_point": "Solution().maxJumps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:18", "tests_total": 122, "test...
cpp
{ "raw_signature": "int maxJumps(vector<int>& arr, int d) {", "container": "Solution", "callable": "maxJumps", "parameters": [ { "name": "arr", "type": "vector<int>&" }, { "name": "d", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippe...
1,342
number-of-steps-to-reduce-a-number-to-zero
Easy
Given an integer num, return the number of steps to reduce it to zero. In one step, if the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it. Example 1: Input: num = 14 Output: 6 Explanation: Step 1) 14 is even; divide by 2 and obtain 7. Step 2) 7 is odd; subtract 1 and ob...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = 14) == 6\n assert candidate(num = 1000000) == 26\n assert candidate(num = 8) == 4\n assert candidate(num = 65535) == 31\n assert candidate(num = 0) == 0\n assert candidate(num = 2) == 2\n assert candidate(num = 1)...
[ "14", "8", "123" ]
[ "Simulate the process to get the final answer." ]
{ "canonical_parameter_names": [ "num" ], "leetcode_dataset_entry_point": "Solution().numberOfSteps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:20", "tests_total": 59, "tests_dro...
cpp
{ "raw_signature": "int numberOfSteps(int num) {", "container": "Solution", "callable": "numberOfSteps", "parameters": [ { "name": "num", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,343
number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold
Medium
Given an array of integers arr and two integers k and threshold, return the number of sub-arrays of size k and average greater than or equal to threshold. Example 1: Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4 Output: 3 Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [2, 2, 2, 2, 5, 5, 5, 8],k = 3,threshold = 4) == 3\n assert candidate(arr = [5, 5, 5, 5, 5, 5, 5],k = 3,threshold = 5) == 5\n assert candidate(arr = [10000, 10000, 10000],k = 3,threshold = 10000) == 1\n assert candidate(ar...
[ "[2,2,2,2,5,5,5,8]\n3\n4", "[11,13,17,23,29,31,7,5,2,3]\n3\n5" ]
[ "Start with a window of size K and test its average against the threshold.", "Keep moving the window by one element maintaining its size k until you cover the whole array. Count the number of windows that have an average greater than or equal to the threshold." ]
{ "canonical_parameter_names": [ "arr", "k", "threshold" ], "leetcode_dataset_entry_point": "Solution().numOfSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:22", "tes...
cpp
{ "raw_signature": "int numOfSubarrays(vector<int>& arr, int k, int threshold) {", "container": "Solution", "callable": "numOfSubarrays", "parameters": [ { "name": "arr", "type": "vector<int>&" }, { "name": "k", "type": "int" }, { "name": "threshold", "typ...
1,344
angle-between-hands-of-a-clock
Medium
Given two numbers, hour and minutes, return the smaller angle (in degrees) formed between the hour and the minute hand. Answers within 10^-5 of the actual value will be accepted as correct. Example 1: Input: hour = 12, minutes = 30 Output: 165 Example 2: Input: hour = 3, minutes = 30 Output: 75 Example 3: Input:...
{ "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...
[ "12\n30", "3\n30", "3\n15" ]
[ "The tricky part is determining how the minute hand affects the position of the hour hand.", "Calculate the angles separately then find the difference." ]
{ "canonical_parameter_names": [ "hour", "minutes" ], "leetcode_dataset_entry_point": "Solution().angleClock", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:24", "tests_total": 72,...
cpp
{ "raw_signature": "double angleClock(int hour, int minutes) {", "container": "Solution", "callable": "angleClock", "parameters": [ { "name": "hour", "type": "int" }, { "name": "minutes", "type": "int" } ], "return_type": "double", "signature_source": "leetcode/code...
1,345
jump-game-iv
Hard
Given an array of integers arr, you are initially positioned at the first index of the array. In one step you can jump from index i to index: - i + 1 where: i + 1 < arr.length. - i - 1 where: i - 1 >= 0. - j where: arr[i] == arr[j] and i != j. Return the minimum number of steps to reach the last index of the array. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [11, 22, 7, 7, 7, 7, 7, 7, 7, 22, 13]) == 3\n assert candidate(arr = [6, 1, 9, 6, 9, 1, 9, 6, 1, 9]) == 3\n assert candidate(arr = [7, 7, 7, 7, 7, 7, 11, 11, 11, 11, 11, 11]) == 3\n assert candidate(arr = [7, 6, 9, 6, 9, 6...
[ "[100,-23,-23,404,100,23,23,23,3,404]", "[7]", "[7,6,9,6,9,6,9,7]" ]
[ "Build a graph of n nodes where nodes are the indices of the array and edges for node i are nodes i+1, i-1, j where arr[i] == arr[j].", "Start bfs from node 0 and keep distance. The answer is the distance when you reach node n-1." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().minJumps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:27", "tests_total": 60, "tests_dropped"...
cpp
{ "raw_signature": "int minJumps(vector<int>& arr) {", "container": "Solution", "callable": "minJumps", "parameters": [ { "name": "arr", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,346
check-if-n-and-its-double-exist
Easy
Given an array arr of integers, check if there exist two indices i and j such that : - i != j - 0 <= i, j < arr.length - arr[i] == 2 * arr[j] Example 1: Input: arr = [10,2,5,3] Output: true Explanation: For i = 0 and j = 2, arr[i] == 10 == 2 * 5 == 2 * arr[j] Example 2: Input: arr = [3,1,7,11] Output: false Explan...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [2, 4, 6, 8, 10]) == True\n assert candidate(arr = [6, 10, 1, 0, -3, 3]) == True\n assert candidate(arr = [-3, -6, -1, 0, 1, 2, 3]) == True\n assert candidate(arr = [-2, -4, -6, -8, -10]) == True\n assert candidate(arr ...
[ "[10,2,5,3]", "[3,1,7,11]" ]
[ "Loop from i = 0 to arr.length, maintaining in a hashTable the array elements from [0, i - 1].", "On each step of the loop check if we have seen the element 2 * arr[i] so far.", "Also check if we have seen arr[i] / 2 in case arr[i] % 2 == 0." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().checkIfExist", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:29", "tests_total": 147, "tests_dro...
cpp
{ "raw_signature": "bool checkIfExist(vector<int>& arr) {", "container": "Solution", "callable": "checkIfExist", "parameters": [ { "name": "arr", "type": "vector<int>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,347
minimum-number-of-steps-to-make-two-strings-anagram
Medium
You are given two strings of the same length s and t. In one step you can choose any character of t and replace it with another character. Return the minimum number of steps to make t an anagram of s. An Anagram of a string is a string that contains the same characters with a different (or the same) ordering. Exampl...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abacabadabacaba\",t = \"abcadbabacabaab\") == 1\n assert candidate(s = \"transform\",t = \"formartin\") == 1\n assert candidate(s = \"aabbcc\",t = \"ccbbaa\") == 0\n assert candidate(s = \"minimum\",t = \"numinum\") == 2\n...
[ "\"bab\"\n\"aba\"", "\"leetcode\"\n\"practice\"", "\"anagram\"\n\"mangaar\"" ]
[ "Count the frequency of characters of each string.", "Loop over all characters if the frequency of a character in t is less than the frequency of the same character in s then add the difference between the frequencies to the answer." ]
{ "canonical_parameter_names": [ "s", "t" ], "leetcode_dataset_entry_point": "Solution().minSteps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:31", "tests_total": 113, "tests_...
cpp
{ "raw_signature": "int minSteps(string s, string t) {", "container": "Solution", "callable": "minSteps", "parameters": [ { "name": "s", "type": "string" }, { "name": "t", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "ty...
1,349
maximum-students-taking-exam
Hard
Given a m * n matrix seats that represent seats distributions in a classroom. If a seat is broken, it is denoted by '#' character otherwise it is denoted by a '.' character. Students can see the answers of those sitting next to the left, right, upper left and upper right, but he cannot see the answers of the student s...
{ "language": "python", "source": "def check(candidate):\n assert candidate(seats = [['#', '.', '.', '.', '#'], ['.', '#', '.', '#', '.'], ['.', '.', '#', '.', '.'], ['.', '#', '.', '#', '.'], ['#', '.', '.', '.', '#']]) == 10\n assert candidate(seats = [['#', '.', '#', '#', '.', '#'], ['.', '#', '#', '#', '#...
[ "[[\"#\",\".\",\"#\",\"#\",\".\",\"#\"],[\".\",\"#\",\"#\",\"#\",\"#\",\".\"],[\"#\",\".\",\"#\",\"#\",\".\",\"#\"]]", "[[\".\",\"#\"],[\"#\",\"#\"],[\"#\",\".\"],[\"#\",\"#\"],[\".\",\"#\"]]", "[[\"#\",\".\",\".\",\".\",\"#\"],[\".\",\"#\",\".\",\"#\",\".\"],[\".\",\".\",\"#\",\".\",\".\"],[\".\",\"#\",\".\",\...
[ "Students in row i only can see exams in row i+1.", "Use Dynamic programming to compute the result given a (current row, bitmask people seated in previous row)." ]
{ "canonical_parameter_names": [ "seats" ], "leetcode_dataset_entry_point": "Solution().maxStudents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:33", "tests_total": 66, "tests_dro...
cpp
{ "raw_signature": "int maxStudents(vector<vector<char>>& seats) {", "container": "Solution", "callable": "maxStudents", "parameters": [ { "name": "seats", "type": "vector<vector<char>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode...
1,351
count-negative-numbers-in-a-sorted-matrix
Easy
Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid. Example 1: Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]] Output: 8 Explanation: There are 8 negatives number in the matrix. Example 2: Input: grid = [[3,2...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[-1, -1], [-1, -1]]) == 4\n assert candidate(grid = [[-3], [-2], [-1], [0], [1]]) == 0\n assert candidate(grid = [[-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1]]) == 12\n assert candidate(grid = [[-1, -1, -1], [-5,...
[ "[[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]", "[[3,2],[1,0]]" ]
[ "Use binary search for optimization or simply brute force." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().countNegatives", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:36", "tests_total": 96, "tests_d...
cpp
{ "raw_signature": "int countNegatives(vector<vector<int>>& grid) {", "container": "Solution", "callable": "countNegatives", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
1,353
maximum-number-of-events-that-can-be-attended
Medium
You are given an array of events where events[i] = [startDay_i, endDay_i]. Every event i starts at startDay_iand ends at endDay_i. You can attend an event i at any day d where startDay_i <= d <= endDay_i. You can only attend one event at any time d. Return the maximum number of events you can attend. Example 1: Inp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(events = [[1, 100], [1, 100], [1, 100], [1, 100], [1, 100]]) == 5\n assert candidate(events = [[1, 3], [2, 4], [3, 5], [4, 6]]) == 4\n assert candidate(events = [[10, 15], [20, 25], [30, 35], [40, 45], [50, 55]]) == 5\n assert c...
[ "[[1,2],[2,3],[3,4]]", "[[1,2],[2,3],[3,4],[1,2]]" ]
[ "Sort the events by the start time and in case of tie by the end time in ascending order.", "Loop over the sorted events. Attend as much as you can and keep the last day occupied. When you try to attend new event keep in mind the first day you can attend a new event in." ]
{ "canonical_parameter_names": [ "events" ], "leetcode_dataset_entry_point": "Solution().maxEvents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:17:38", "tests_total": 98, "tests_drop...
cpp
{ "raw_signature": "int maxEvents(vector<vector<int>>& events) {", "container": "Solution", "callable": "maxEvents", "parameters": [ { "name": "events", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/cod...