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,605
find-valid-matrix-given-row-and-column-sums
Medium
You are given two arrays rowSum and colSum of non-negative integers where rowSum[i] is the sum of the elements in the i^th row and colSum[j] is the sum of the elements of the j^th column of a 2D matrix. In other words, you do not know the elements of the matrix, but you do know the sums of each row and column. Find an...
{ "language": "python", "source": "def check(candidate):\n assert candidate(rowSum = [10, 15],colSum = [12, 13]) == [[10, 0], [2, 13]]\n assert candidate(rowSum = [5, 5, 5],colSum = [5, 5, 5]) == [[5, 0, 0], [0, 5, 0], [0, 0, 5]]\n assert candidate(rowSum = [10, 20],colSum = [15, 15]) == [[10, 0], [5, 15]]...
[ "[3,8]\n[4,7]", "[5,7,10]\n[8,6,8]" ]
[ "Find the smallest rowSum or colSum, and let it be x. Place that number in the grid, and subtract x from rowSum and colSum. Continue until all the sums are satisfied." ]
{ "canonical_parameter_names": [ "rowSum", "colSum" ], "leetcode_dataset_entry_point": "Solution().restoreMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:10", "tests_total":...
typescript
{ "raw_signature": "function restoreMatrix(rowSum: number[], colSum: number[]): number[][] {", "container": null, "callable": "restoreMatrix", "parameters": [ { "name": "rowSum", "type": "number[]" }, { "name": "colSum", "type": "number[]" } ], "return_type": "number[...
1,606
find-servers-that-handled-most-number-of-requests
Hard
You have k servers numbered from 0 to k-1 that are being used to handle multiple requests simultaneously. Each server has infinite computational capacity but cannot handle more than one request at a time. The requests are assigned to servers according to a specific algorithm: - The i^th (0-indexed) request arrives. - ...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ...
[ "3\n[1,2,3,4,5]\n[5,2,3,3,3]", "3\n[1,2,3,4]\n[1,2,1,2]", "3\n[1,2,3]\n[10,12,11]" ]
[ "To speed up the next available server search, keep track of the available servers in a sorted structure such as an ordered set.", "To determine if a server is available, keep track of the end times for each task in a heap and add the server to the available set once the soonest task ending time is less than or e...
{ "canonical_parameter_names": [ "k", "arrival", "load" ], "leetcode_dataset_entry_point": "Solution().busiestServers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:13", "test...
typescript
{ "raw_signature": "function busiestServers(k: number, arrival: number[], load: number[]): number[] {", "container": null, "callable": "busiestServers", "parameters": [ { "name": "k", "type": "number" }, { "name": "arrival", "type": "number[]" }, { "name": "load...
1,608
special-array-with-x-elements-greater-than-or-equal-x
Easy
You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x. Notice that x does not have to be an element in nums. Return x if the array is special, otherwise, return -1. It can be proven ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 10\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == 3\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]...
[ "[3,5]", "[0,0]", "[0,4,3,0,4]" ]
[ "Count the number of elements greater than or equal to x for each x in the range [0, nums.length].", "If for any x, the condition satisfies, return that x. Otherwise, there is no answer." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().specialArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:15", "tests_total": 75, "tests_dro...
typescript
{ "raw_signature": "function specialArray(nums: number[]): number {", "container": null, "callable": "specialArray", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,610
maximum-number-of-visible-points
Hard
You are given an array points, an integer angle, and your location, where location = [pos_x, pos_y] and points[i] = [x_i, y_i] both denote integral coordinates on the X-Y plane. Initially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, pos_x and...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 0], [0, 1], [-1, 0], [0, -1]],angle = 90,location = [0, 0]) == 2\n assert candidate(points = [[100, 100], [100, 99], [99, 100], [99, 99]],angle = 45,location = [100, 100]) == 3\n assert candidate(points = [[0, 0], [5,...
[ "[[2,1],[2,2],[3,3]]\n90\n[1,1]", "[[2,1],[2,2],[3,4],[1,1]]\n90\n[1,1]", "[[1,0],[2,1]]\n13\n[1,1]" ]
[ "Sort the points by polar angle with the original position. Now only a consecutive collection of points would be visible from any coordinate.", "We can use two pointers to keep track of visible points for each start point", "For handling the cyclic condition, it’d be helpful to append the point list to itself a...
{ "canonical_parameter_names": [ "points", "angle", "location" ], "leetcode_dataset_entry_point": "Solution().visiblePoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:20", ...
typescript
{ "raw_signature": "function visiblePoints(points: number[][], angle: number, location: number[]): number {", "container": null, "callable": "visiblePoints", "parameters": [ { "name": "points", "type": "number[][]" }, { "name": "angle", "type": "number" }, { "na...
1,611
minimum-one-bit-operations-to-make-integers-zero
Hard
Given an integer n, you must transform it into 0 using the following operations any number of times: - Change the rightmost (0^th) bit in the binary representation of n. - Change the i^th bit in the binary representation of n if the (i-1)^th bit is set to 1 and the (i-2)^th through 0^th bits are set to 0. Return the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 0) == 0\n assert candidate(n = 8) == 15\n assert candidate(n = 3) == 2\n assert candidate(n = 100) == 71\n assert candidate(n = 15) == 10\n assert candidate(n = 16) == 31\n assert candidate(n = 31) == 21\n assert...
[ "3", "6" ]
[ "The fastest way to convert n to zero is to remove all set bits starting from the leftmost one. Try some simple examples to learn the rule of how many steps are needed to remove one set bit.", "consider n=2^k case first, then solve for all n." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().minimumOneBitOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:22", "tests_total": 71, "t...
typescript
{ "raw_signature": "function minimumOneBitOperations(n: number): number {", "container": null, "callable": "minimumOneBitOperations", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
1,614
maximum-nesting-depth-of-the-parentheses
Easy
Given a valid parentheses string s, return the nesting depth of s. The nesting depth is the maximum number of nested parentheses. Example 1: Input: s = "(1+(2*3)+((8)/4))+1" Output: 3 Explanation: Digit 8 is inside of 3 nested parentheses in the string. Example 2: Input: s = "(1)+((2))+(((3)))" Output: 3 Explanatio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"(1+(2*3)+((8)/4))+1\") == 3\n assert candidate(s = \"()()()\") == 1\n assert candidate(s = \"(1+2)\") == 1\n assert candidate(s = \"1+(2*3)\") == 1\n assert candidate(s = \"(())\") == 2\n assert candidate(s = \"((1+3...
[ "\"(1+(2*3)+((8)/4))+1\"", "\"(1)+((2))+(((3)))\"", "\"()(())((()()))\"" ]
[ "The depth of any character in the VPS is the ( number of left brackets before it ) - ( number of right brackets before it )" ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().maxDepth", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:24", "tests_total": 101, "tests_dropped":...
typescript
{ "raw_signature": "function maxDepth(s: string): number {", "container": null, "callable": "maxDepth", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,615
maximal-network-rank
Medium
There is an infrastructure of n cities with some number of roads connecting these cities. Each roads[i] = [a_i, b_i] indicates that there is a bidirectional road between cities a_i and b_i. The network rank of two different cities is defined as the total number of directly connected roads to either city. If a road is ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,roads = [[0, 1], [0, 3], [1, 2], [1, 3]]) == 4\n assert candidate(n = 100,roads = []) == 0\n assert candidate(n = 6,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5]]) == 5\n assert candidate(n = 10,roads = [[0, 1], [0, 2], ...
[ "4\n[[0,1],[0,3],[1,2],[1,3]]", "5\n[[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]]", "8\n[[0,1],[1,2],[2,3],[2,4],[5,6],[5,7]]" ]
[ "Try every pair of different cities and calculate its network rank.", "The network rank of two vertices is almost the sum of their degrees.", "How can you efficiently check if there is a road connecting two different cities?" ]
{ "canonical_parameter_names": [ "n", "roads" ], "leetcode_dataset_entry_point": "Solution().maximalNetworkRank", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:26", "tests_total": ...
typescript
{ "raw_signature": "function maximalNetworkRank(n: number, roads: number[][]): number {", "container": null, "callable": "maximalNetworkRank", "parameters": [ { "name": "n", "type": "number" }, { "name": "roads", "type": "number[][]" } ], "return_type": "number", "s...
1,616
split-two-strings-to-make-palindrome
Medium
You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: a_prefix and a_suffix where a = a_prefix + a_suffix, and splitting b into two strings: b_prefix and b_suffix where b = b_prefix + b_suffix. Check if a_prefix + b_suffix or b_pref...
{ "language": "python", "source": "def check(candidate):\n assert candidate(a = \"abcdefg\",b = \"gfedcba\") == True\n assert candidate(a = \"aabbcc\",b = \"ccbbdd\") == True\n assert candidate(a = \"ulacfd\",b = \"jizalu\") == True\n assert candidate(a = \"aabbaa\",b = \"aabbaa\") == True\n assert c...
[ "\"x\"\n\"y\"", "\"xbdef\"\n\"xecab\"", "\"ulacfd\"\n\"jizalu\"" ]
[ "Try finding the largest prefix from a that matches a suffix in b", "Try string matching" ]
{ "canonical_parameter_names": [ "a", "b" ], "leetcode_dataset_entry_point": "Solution().checkPalindromeFormation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:29", "tests_total"...
typescript
{ "raw_signature": "function checkPalindromeFormation(a: string, b: string): boolean {", "container": null, "callable": "checkPalindromeFormation", "parameters": [ { "name": "a", "type": "string" }, { "name": "b", "type": "string" } ], "return_type": "boolean", "sig...
1,617
count-subtrees-with-max-distance-between-cities
Hard
There are n cities numbered from 1 to n. You are given an array edges of size n-1, where edges[i] = [u_i, v_i] represents a bidirectional edge between cities u_i and v_i. There exists a unique path between each pair of cities. In other words, the cities form a tree. A subtree is a subset of cities where every city is ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == [5, 8, 9, 0, 0]\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 4], [4, 5]]) == [4, 3, 2, 1]\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6]...
[ "4\n[[1,2],[2,3],[2,4]]", "2\n[[1,2]]", "3\n[[1,2],[2,3]]" ]
[ "Iterate through every possible subtree by doing a bitmask on which vertices to include. How can you determine if a subtree is valid (all vertices are connected)?", "To determine connectivity, count the number of reachable vertices starting from any included vertex and only traveling on edges connecting 2 vertice...
{ "canonical_parameter_names": [ "n", "edges" ], "leetcode_dataset_entry_point": "Solution().countSubgraphsForEachDiameter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:31", "tes...
typescript
{ "raw_signature": "function countSubgraphsForEachDiameter(n: number, edges: number[][]): number[] {", "container": null, "callable": "countSubgraphsForEachDiameter", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" } ], "retu...
1,619
mean-of-array-after-removing-some-elements
Easy
Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements. Answers within 10^-5 of the actual answer will be considered accepted. Example 1: Input: arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3] Output: 2.00000 Explanation: After erasing ...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat...
[ "[1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]", "[6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]", "[6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]" ]
[ "Sort the given array.", "Remove the first and last 5% of the sorted array." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().trimMean", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:33", "tests_total": 50, "tests_dropped"...
typescript
{ "raw_signature": "function trimMean(arr: number[]): number {", "container": null, "callable": "trimMean", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,620
coordinate-with-maximum-network-quality
Medium
You are given an array of network towers towers, where towers[i] = [x_i, y_i, q_i] denotes the i^th network tower with location (x_i, y_i) and quality factor q_i. All the coordinates are integral coordinates on the X-Y plane, and the distance between the two coordinates is the Euclidean distance. You are also given an...
{ "language": "python", "source": "def check(candidate):\n assert candidate(towers = [[23, 11, 21]],radius = 9) == [23, 11]\n assert candidate(towers = [[5, 5, 15], [6, 6, 20], [7, 7, 25]],radius = 3) == [6, 6]\n assert candidate(towers = [[1, 2, 5], [2, 1, 7], [3, 1, 9]],radius = 2) == [2, 1]\n assert ...
[ "[[1,2,5],[2,1,7],[3,1,9]]\n2", "[[23,11,21]]\n9", "[[1,2,13],[2,1,7],[0,1,9]]\n2" ]
[ "The constraints are small enough to consider every possible coordinate and calculate its quality." ]
{ "canonical_parameter_names": [ "towers", "radius" ], "leetcode_dataset_entry_point": "Solution().bestCoordinate", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:36", "tests_total"...
typescript
{ "raw_signature": "function bestCoordinate(towers: number[][], radius: number): number[] {", "container": null, "callable": "bestCoordinate", "parameters": [ { "name": "towers", "type": "number[][]" }, { "name": "radius", "type": "number" } ], "return_type": "number[...
1,621
number-of-sets-of-k-non-overlapping-line-segments
Medium
Given n points on a 1-D plane, where the i^th point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments such that each segment covers two or more points. The endpoints of each segment must have integral coordinates. The k line segments do not have to cover all n poin...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3,k = 1) == 3\n assert candidate(n = 1000,k = 500) == 70047606\n assert candidate(n = 30,k = 7) == 796297179\n assert candidate(n = 6,k = 3) == 28\n assert candidate(n = 8,k = 4) == 165\n assert candidate(n = 5,k = 2) ...
[ "4\n2", "3\n1", "30\n7" ]
[ "Try to use dynamic programming where the current index and remaining number of line segments to form can describe any intermediate state.", "To make the computation of each state in constant time, we could add another flag to the state that indicates whether or not we are in the middle of placing a line (placed ...
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfSets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:38", "tests_total": 58, "tes...
typescript
{ "raw_signature": "function numberOfSets(n: number, k: number): number {", "container": null, "callable": "numberOfSets", "parameters": [ { "name": "n", "type": "number" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/...
1,624
largest-substring-between-two-equal-characters
Easy
Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1. A substring is a contiguous sequence of characters within a string. Example 1: Input: s = "aa" Output: 0 Explanation: The optimal substring here is an empt...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbaa\") == 4\n assert candidate(s = \"xyzx\") == 2\n assert candidate(s = \"a\") == -1\n assert candidate(s = \"aa\") == 0\n assert candidate(s = \"abcda\") == 3\n assert candidate(s = \"abcabc\") == 2\n assert ...
[ "\"aa\"", "\"abca\"", "\"cbzxy\"" ]
[ "Try saving the first and last position of each character", "Try finding every pair of indexes with equal characters" ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().maxLengthBetweenEqualCharacters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:40", "tests_total": ...
typescript
{ "raw_signature": "function maxLengthBetweenEqualCharacters(s: string): number {", "container": null, "callable": "maxLengthBetweenEqualCharacters", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_sourc...
1,625
lexicographically-smallest-string-after-applying-operations
Medium
You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b. You can apply either of the following two operations any number of times and in any order on s: - Add a to all odd indices of s (0-indexed). Digits post 9 are cycled back to 0. For example, if s = "3456" and a = 5, s b...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"5525\",a = 9,b = 2) == \"2050\"\n assert candidate(s = \"9876543210\",a = 7,b = 4) == \"1098765432\"\n assert candidate(s = \"74\",a = 5,b = 1) == \"24\"\n assert candidate(s = \"8900\",a = 3,b = 3) == \"0018\"\n assert...
[ "\"5525\"\n9\n2", "\"74\"\n5\n1", "\"0011\"\n4\n2" ]
[ "Since the length of s is even, the total number of possible sequences is at most 10 * 10 * s.length.", "You can generate all possible sequences and take their minimum.", "Keep track of already generated sequences so they are not processed again." ]
{ "canonical_parameter_names": [ "s", "a", "b" ], "leetcode_dataset_entry_point": "Solution().findLexSmallestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:42", "tests_...
typescript
{ "raw_signature": "function findLexSmallestString(s: string, a: number, b: number): string {", "container": null, "callable": "findLexSmallestString", "parameters": [ { "name": "s", "type": "string" }, { "name": "a", "type": "number" }, { "name": "b", "ty...
1,626
best-team-with-no-conflicts
Medium
You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team. However, the basketball team is not allowed to have conflicts. A conflict exists if a younger player has a strict...
{ "language": "python", "source": "def check(candidate):\n assert candidate(scores = [1000000, 999999, 999998],ages = [1, 2, 3]) == 1000000\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],ages = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(scores = [50, 50, 50, 50],ages = [1, 2, 3,...
[ "[1,3,5,10,15]\n[1,2,3,4,5]", "[4,5,6,5]\n[2,1,2,1]", "[1,2,3,5]\n[8,9,10,1]" ]
[ "First, sort players by age and break ties by their score. You can now consider the players from left to right.", "If you choose to include a player, you must only choose players with at least that score later on." ]
{ "canonical_parameter_names": [ "scores", "ages" ], "leetcode_dataset_entry_point": "Solution().bestTeamScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:44", "tests_total": 1...
typescript
{ "raw_signature": "function bestTeamScore(scores: number[], ages: number[]): number {", "container": null, "callable": "bestTeamScore", "parameters": [ { "name": "scores", "type": "number[]" }, { "name": "ages", "type": "number[]" } ], "return_type": "number", "sig...
1,627
graph-connectivity-with-threshold
Hard
We have n cities labeled from 1 to n. Two different cities with labels x and y are directly connected by a bidirectional road if and only if x and y share a common divisor strictly greater than some threshold. More formally, cities with labels x and y have a road between them if there exists an integer z such that all ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 6,threshold = 0,queries = [[4, 5], [3, 4], [3, 2], [2, 6], [1, 3]]) == [True, True, True, True, True]\n assert candidate(n = 10,threshold = 3,queries = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == [False, False, False, False, Fal...
[ "6\n2\n[[1,4],[2,5],[3,6]]", "6\n0\n[[4,5],[3,4],[3,2],[2,6],[1,3]]", "5\n1\n[[4,5],[4,5],[3,2],[2,3],[3,4]]" ]
[ "How to build the graph of the cities?", "Connect city i with all its multiples 2*i, 3*i, ...", "Answer the queries using union-find data structure." ]
{ "canonical_parameter_names": [ "n", "threshold", "queries" ], "leetcode_dataset_entry_point": "Solution().areConnected", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:47", "t...
typescript
{ "raw_signature": "function areConnected(n: number, threshold: number, queries: number[][]): boolean[] {", "container": null, "callable": "areConnected", "parameters": [ { "name": "n", "type": "number" }, { "name": "threshold", "type": "number" }, { "name": "qu...
1,629
slowest-key
Easy
A newly designed keypad was tested, where a tester pressed a sequence of n keys, one at a time. You are given a string keysPressed of length n, where keysPressed[i] was the i^th key pressed in the testing sequence, and a sorted list releaseTimes, where releaseTimes[i] was the time the i^th key was released. Both array...
{ "language": "python", "source": "def check(candidate):\n assert candidate(releaseTimes = [2, 3, 7, 10, 15],keysPressed = \"zzzaa\") == \"a\"\n assert candidate(releaseTimes = [5, 10, 15, 20, 25],keysPressed = \"zabzc\") == \"z\"\n assert candidate(releaseTimes = [5, 15, 25, 35, 45, 55],keysPressed = \"ab...
[ "[9,29,49,50]\n\"cbcd\"", "[12,23,36,46,62]\n\"spuda\"" ]
[ "Get for each press its key and amount of time taken.", "Iterate on the presses, maintaining the answer so far.", "The current press will change the answer if and only if its amount of time taken is longer than that of the previous answer, or they are equal but the key is larger than that of the previous answer...
{ "canonical_parameter_names": [ "releaseTimes", "keysPressed" ], "leetcode_dataset_entry_point": "Solution().slowestKey", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:49", "tests...
typescript
{ "raw_signature": "function slowestKey(releaseTimes: number[], keysPressed: string): string {", "container": null, "callable": "slowestKey", "parameters": [ { "name": "releaseTimes", "type": "number[]" }, { "name": "keysPressed", "type": "string" } ], "return_type": ...
1,630
arithmetic-subarrays
Medium
A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1] - s[i] == s[1] - s[0] for all valid i. For example, these are arithmetic sequences: 1, 3, 5, 7, 9 7...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1],l = [0, 0, 2, 3],r = [1, 2, 4, 4]) == [True, True, True, True]\n assert candidate(nums = [5, 5, 5, 5, 5],l = [0, 1, 2],r = [1, 2, 3]) == [True, True, True]\n assert candidate(nums = [0, 3, 5, 7, 9],l = [0, 1,...
[ "[4,6,5,9,3,7]\n[0,0,2]\n[2,3,5]", "[-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10]\n[0,1,6,4,8,7]\n[4,4,9,7,9,10]" ]
[ "To check if a given sequence is arithmetic, just check that the difference between every two consecutive elements is the same.", "If and only if a set of numbers can make an arithmetic sequence, then its sorted version makes an arithmetic sequence. So to check a set of numbers, sort it, and check if that sequenc...
{ "canonical_parameter_names": [ "nums", "l", "r" ], "leetcode_dataset_entry_point": "Solution().checkArithmeticSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:51", "...
typescript
{ "raw_signature": "function checkArithmeticSubarrays(nums: number[], l: number[], r: number[]): boolean[] {", "container": null, "callable": "checkArithmeticSubarrays", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "l", "type": "number[]" }, { ...
1,631
path-with-minimum-effort
Medium
You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0), and you hope to travel to the bottom-right cell, (rows-1, columns-1) (i.e., 0-indexed). You can move ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(heights = [[4, 3, 4, 10, 5, 5, 9, 2], [10, 8, 2, 10, 9, 7, 5, 6], [5, 8, 1, 10, 10, 7, 7, 2], [5, 10, 2, 8, 3, 9, 7, 9], [7, 6, 6, 8, 6, 6, 4, 4], [4, 9, 6, 10, 2, 1, 2, 7], [5, 10, 3, 7, 7, 5, 10, 10]]) == 4\n assert candidate(height...
[ "[[1,2,2],[3,8,2],[5,3,5]]", "[[1,2,3],[3,8,4],[5,3,5]]", "[[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]" ]
[ "Consider the grid as a graph, where adjacent cells have an edge with cost of the difference between the cells.", "If you are given threshold k, check if it is possible to go from (0, 0) to (n-1, m-1) using only edges of ≤ k cost.", "Binary search the k value." ]
{ "canonical_parameter_names": [ "heights" ], "leetcode_dataset_entry_point": "Solution().minimumEffortPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:53", "tests_total": 69, "t...
typescript
{ "raw_signature": "function minimumEffortPath(heights: number[][]): number {", "container": null, "callable": "minimumEffortPath", "parameters": [ { "name": "heights", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
1,632
rank-transform-of-a-matrix
Hard
Given an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col]. The rank is an integer that represents how large an element is compared to other elements. It is calculated using the following rules: - The rank is an integer starting from 1. - If two elements p and q are in th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[-1, -2], [-3, -4]]) == [[3, 2], [2, 1]]\n assert candidate(matrix = [[20, -21, 14], [-19, 4, 19], [22, -47, 24], [-19, 4, 19]]) == [[4, 2, 3], [1, 3, 4], [5, 1, 6], [1, 3, 4]]\n assert candidate(matrix = [[1, 2], [3, 4]]...
[ "[[1,2],[3,4]]", "[[7,7],[7,7]]", "[[20,-21,14],[-19,4,19],[22,-47,24],[-19,4,19]]" ]
[ "Sort the cells by value and process them in increasing order.", "The rank of a cell is the maximum rank in its row and column plus one.", "Handle the equal cells by treating them as components using a union-find data structure." ]
{ "canonical_parameter_names": [ "matrix" ], "leetcode_dataset_entry_point": "Solution().matrixRankTransform", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:56", "tests_total": 96, "...
typescript
{ "raw_signature": "function matrixRankTransform(matrix: number[][]): number[][] {", "container": null, "callable": "matrixRankTransform", "parameters": [ { "name": "matrix", "type": "number[][]" } ], "return_type": "number[][]", "signature_source": "leetcode/codeSnippets", "type_sou...
1,636
sort-array-by-increasing-frequency
Easy
Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order. Return the sorted array. Example 1: Input: nums = [1,1,2,2,2,3] Output: [3,1,1,2,2,2] Explanation: '3' has a frequency of 1, '1' has a f...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 2, 2, 2, 3]) == [3, 1, 1, 2, 2, 2]\n assert candidate(nums = [10, 10, 20, 20, 30]) == [30, 20, 20, 10, 10]\n assert candidate(nums = [7, 7, 7, 6, 6, 5, 5, 5, 5]) == [6, 6, 7, 7, 7, 5, 5, 5, 5]\n assert candidate(nu...
[ "[1,1,2,2,2,3]", "[2,3,1,3,2]", "[-1,1,-6,4,5,-6,1,4,1]" ]
[ "Count the frequency of each value.", "Use a custom comparator to compare values by their frequency. If two values have the same frequency, compare their values." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().frequencySort", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:58", "tests_total": 117, "tests_d...
typescript
{ "raw_signature": "function frequencySort(nums: number[]): number[] {", "container": null, "callable": "frequencySort", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
1,637
widest-vertical-area-between-two-points-containing-no-points
Easy
Given n points on a 2D plane where points[i] = [x_i, y_i], Return the widest vertical area between two points such that no points are inside the area. A vertical area is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The widest vertical area is the one with the maximum width. No...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 1\n assert candidate(points = [[1, 10], [3, 3], [5, 5], [7, 7], [9, 9]]) == 2\n assert candidate(points = [[5, 1], [4, 1], [3, 1], [2, 1], [1, 1]]) == 1\n assert candidate(po...
[ "[[8,7],[9,9],[7,4],[9,7]]", "[[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]" ]
[ "Try sorting the points", "Think whether the y-axis of a point is relevant" ]
{ "canonical_parameter_names": [ "points" ], "leetcode_dataset_entry_point": "Solution().maxWidthOfVerticalArea", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:00", "tests_total": 104,...
typescript
{ "raw_signature": "function maxWidthOfVerticalArea(points: number[][]): number {", "container": null, "callable": "maxWidthOfVerticalArea", "parameters": [ { "name": "points", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_sourc...
1,638
count-substrings-that-differ-by-one-character
Medium
Given two strings s and t, find the number of ways you can choose a non-empty substring of s and replace a single character by a different character such that the resulting substring is a substring of t. In other words, find the number of substrings in s that differ from some substring in t by exactly one character. F...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc\",t = \"abcd\") == 9\n assert candidate(s = \"abcde\",t = \"bcdef\") == 21\n assert candidate(s = \"aaaa\",t = \"bbbb\") == 16\n assert candidate(s = \"xyz\",t = \"xya\") == 9\n assert candidate(s = \"python\",t = \...
[ "\"aba\"\n\"baba\"", "\"ab\"\n\"bb\"" ]
[ "Take every substring of s, change a character, and see how many substrings of t match that substring.", "Use a Trie to store all substrings of t as a dictionary." ]
{ "canonical_parameter_names": [ "s", "t" ], "leetcode_dataset_entry_point": "Solution().countSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:02", "tests_total": 156, ...
typescript
{ "raw_signature": "function countSubstrings(s: string, t: string): number {", "container": null, "callable": "countSubstrings", "parameters": [ { "name": "s", "type": "string" }, { "name": "t", "type": "string" } ], "return_type": "number", "signature_source": "lee...
1,639
number-of-ways-to-form-a-target-string-given-a-dictionary
Hard
You are given a list of strings of the same length words and a string target. Your task is to form target using the given words under the following rules: - target should be formed from left to right. - To form the i^th character (0-indexed) of target, you can choose the k^th character of the j^th string in words if ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['a', 'b', 'c'],target = \"abc\") == 0\n assert candidate(words = ['abc', 'def'],target = \"ad\") == 0\n assert candidate(words = ['mississippi'],target = \"issi\") == 15\n assert candidate(words = ['aaa', 'aaa', 'aaa'],...
[ "[\"acca\",\"bbbb\",\"caca\"]\n\"aba\"", "[\"abba\",\"baab\"]\n\"bab\"" ]
[ "For each index i, store the frequency of each character in the ith row.", "Use dynamic programing to calculate the number of ways to get the target string using the frequency array." ]
{ "canonical_parameter_names": [ "words", "target" ], "leetcode_dataset_entry_point": "Solution().numWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:05", "tests_total": 148, ...
typescript
{ "raw_signature": "function numWays(words: string[], target: string): number {", "container": null, "callable": "numWays", "parameters": [ { "name": "words", "type": "string[]" }, { "name": "target", "type": "string" } ], "return_type": "number", "signature_source"...
1,640
check-array-formation-through-concatenation
Easy
You are given an array of distinct integers arr and an array of integer arrays pieces, where the integers in pieces are distinct. Your goal is to form arr by concatenating the arrays in pieces in any order. However, you are not allowed to reorder the integers in each array pieces[i]. Return true if it is possible to f...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [10, 20, 30, 40, 50],pieces = [[10, 20], [30, 40, 50]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5],pieces = [[2, 3], [1, 4], [5]]) == False\n assert candidate(arr = [91, 4, 64, 78],pieces = [[78], [4, 64], [91]]) == Tru...
[ "[15,88]\n[[88],[15]]", "[49,18,16]\n[[16,18,49]]", "[91,4,64,78]\n[[78],[4,64],[91]]" ]
[ "Note that the distinct part means that every position in the array belongs to only one piece", "Note that you can get the piece every position belongs to naively" ]
{ "canonical_parameter_names": [ "arr", "pieces" ], "leetcode_dataset_entry_point": "Solution().canFormArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:07", "tests_total": 99,...
typescript
{ "raw_signature": "function canFormArray(arr: number[], pieces: number[][]): boolean {", "container": null, "callable": "canFormArray", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "pieces", "type": "number[][]" } ], "return_type": "boolean", "s...
1,641
count-sorted-vowel-strings
Medium
Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted. A string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet. Example 1: Input: n = 1 Output: 5 Explanation: The 5 sorted...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 35\n assert candidate(n = 4) == 70\n assert candidate(n = 33) == 66045\n assert candidate(n = 2) == 15\n assert candidate(n = 20) == 10626\n assert candidate(n = 1) == 5\n assert candidate(n = 50) == 316251\n ...
[ "1", "2", "33" ]
[ "For each character, its possible values will depend on the value of its previous character, because it needs to be not smaller than it.", "Think backtracking. Build a recursive function count(n, last_character) that counts the number of valid strings of length n and whose first characters are not less than last_...
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().countVowelStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:09", "tests_total": 24, "tests_d...
typescript
{ "raw_signature": "function countVowelStrings(n: number): number {", "container": null, "callable": "countVowelStrings", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,642
furthest-building-you-can-reach
Medium
You are given an integer array heights representing the heights of buildings, some bricks, and some ladders. You start your journey from building 0 and move to the next building by possibly using bricks or ladders. While moving from building i to building i+1 (0-indexed), - If the current building's height is greate...
{ "language": "python", "source": "def check(candidate):\n assert candidate(heights = [10, 15, 20, 25, 30],bricks = 0,ladders = 2) == 2\n assert candidate(heights = [3, 1, 2, 1, 5],bricks = 2,ladders = 1) == 4\n assert candidate(heights = [5, 5, 5, 5, 5],bricks = 0,ladders = 0) == 4\n assert candidate(h...
[ "[4,2,7,6,9,14,12]\n5\n1", "[4,12,2,7,3,18,20,3,19]\n10\n2", "[14,3,19,3]\n17\n0" ]
[ "Assume the problem is to check whether you can reach the last building or not.", "You'll have to do a set of jumps, and choose for each one whether to do it using a ladder or bricks. It's always optimal to use ladders in the largest jumps.", "Iterate on the buildings, maintaining the largest r jumps and the su...
{ "canonical_parameter_names": [ "heights", "bricks", "ladders" ], "leetcode_dataset_entry_point": "Solution().furthestBuilding", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:12...
typescript
{ "raw_signature": "function furthestBuilding(heights: number[], bricks: number, ladders: number): number {", "container": null, "callable": "furthestBuilding", "parameters": [ { "name": "heights", "type": "number[]" }, { "name": "bricks", "type": "number" }, { ...
1,643
kth-smallest-instructions
Hard
Bob is standing at cell (0, 0), and he wants to reach destination: (row, column). He can only travel right and down. You are going to help Bob by providing instructions for him to reach destination. The instructions are represented as a string, where each character is either: - 'H', meaning move horizontally (go righ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(destination = [3, 3],k = 5) == \"HVHHVV\"\n assert candidate(destination = [2, 3],k = 1) == \"HHHVV\"\n assert candidate(destination = [4, 4],k = 10) == \"HHVVHHVV\"\n assert candidate(destination = [3, 3],k = 10) == \"HVVVHH\"\...
[ "[2,3]\n1", "[2,3]\n2", "[2,3]\n3" ]
[ "There are nCr(row + column, row) possible instructions to reach (row, column).", "Try building the instructions one step at a time. How many instructions start with \"H\", and how does this compare with k?" ]
{ "canonical_parameter_names": [ "destination", "k" ], "leetcode_dataset_entry_point": "Solution().kthSmallestPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:14", "tests_total...
typescript
{ "raw_signature": "function kthSmallestPath(destination: number[], k: number): string {", "container": null, "callable": "kthSmallestPath", "parameters": [ { "name": "destination", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "string", ...
1,646
get-maximum-in-generated-array
Easy
You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way: - nums[0] = 0 - nums[1] = 1 - nums[2 * i] = nums[i] when 2 <= 2 * i <= n - nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n Return the maximum integer in the array nums. Example 1: Input: n ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 0) == 0\n assert candidate(n = 3) == 2\n assert candidate(n = 100) == 21\n assert candidate(n = 99) == 21\n assert candidate(n = 2) == 1\n assert candidate(n = 20) == 7\n assert candidate(n = 1) == 1\n assert can...
[ "7", "2", "3" ]
[ "Try generating the array.", "Make sure not to fall in the base case of 0." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().getMaximumGenerated", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:18", "tests_total": 31, "tests...
typescript
{ "raw_signature": "function getMaximumGenerated(n: number): number {", "container": null, "callable": "getMaximumGenerated", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,647
minimum-deletions-to-make-character-frequencies-unique
Medium
A string s is called good if there are no two different characters in s that have the same frequency. Given a string s, return the minimum number of characters you need to delete to make s good. The frequency of a character in a string is the number of times it appears in the string. For example, in the string "aab",...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aab\") == 0\n assert candidate(s = \"aabacabadabaeabafabagabahabaiabajabakabalabamabanabaoabapabaqabarabasabataabuabavabawabaxabayabajabaz\") == 22\n assert candidate(s = \"abcabcabc\") == 3\n assert candidate(s = \"aabbbc...
[ "\"aab\"", "\"aaabbbcc\"", "\"ceabaacb\"" ]
[ "As we can only delete characters, if we have multiple characters having the same frequency, we must decrease all the frequencies of them, except one.", "Sort the alphabet characters by their frequencies non-increasingly.", "Iterate on the alphabet characters, keep decreasing the frequency of the current charac...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minDeletions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:21", "tests_total": 23, "tests_droppe...
typescript
{ "raw_signature": "function minDeletions(s: string): number {", "container": null, "callable": "minDeletions", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,648
sell-diminishing-valued-colored-balls
Medium
You have an inventory of different colored balls, and there is a customer that wants orders balls of any color. The customer weirdly values the colored balls. Each colored ball's value is the number of balls of that color you currently have in your inventory. For example, if you own 6 yellow balls, the customer would ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(inventory = [10, 10, 10],orders = 5) == 48\n assert candidate(inventory = [3, 5],orders = 6) == 19\n assert candidate(inventory = [1, 2, 3, 4, 5],orders = 10) == 30\n assert candidate(inventory = [1, 1, 1, 1, 1],orders = 3) == 3...
[ "[2,5]\n4", "[3,5]\n6" ]
[ "Greedily sell the most expensive ball.", "There is some value k where all balls of value > k are sold, and some, (maybe 0) of balls of value k are sold.", "Use binary search to find this value k, and use maths to find the total sum." ]
{ "canonical_parameter_names": [ "inventory", "orders" ], "leetcode_dataset_entry_point": "Solution().maxProfit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:23", "tests_total": ...
typescript
{ "raw_signature": "function maxProfit(inventory: number[], orders: number): number {", "container": null, "callable": "maxProfit", "parameters": [ { "name": "inventory", "type": "number[]" }, { "name": "orders", "type": "number" } ], "return_type": "number", "signa...
1,649
create-sorted-array-through-instructions
Hard
Given an integer array instructions, you are asked to create a sorted array from the elements in instructions. You start with an empty container nums. For each element from left to right in instructions, insert it into nums. The cost of each insertion is the minimum of the following: - The number of elements currently...
{ "language": "python", "source": "def check(candidate):\n assert candidate(instructions = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(instructions = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(instructions = [50000, 50001, 50002, 50003, 50004, 50005, 50006, 50007, 50008, ...
[ "[1,5,6,2]", "[1,2,3,6,5,4]", "[1,3,3,3,2,4,2,1,2]" ]
[ "This problem is closely related to finding the number of inversions in an array", "if i know the position in which i will insert the i-th element in I can find the minimum cost to insert it" ]
{ "canonical_parameter_names": [ "instructions" ], "leetcode_dataset_entry_point": "Solution().createSortedArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:26", "tests_total": 113...
typescript
{ "raw_signature": "function createSortedArray(instructions: number[]): number {", "container": null, "callable": "createSortedArray", "parameters": [ { "name": "instructions", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source"...
1,652
defuse-the-bomb
Easy
You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n and a key k. To decrypt the code, you must replace every number. All the numbers are replaced simultaneously. - If k > 0, replace the i^th number with the sum of the next k numbers. - If k...
{ "language": "python", "source": "def check(candidate):\n assert candidate(code = [7, 8, 9],k = 1) == [8, 9, 7]\n assert candidate(code = [6, 5, 4, 3, 2, 1],k = -1) == [1, 6, 5, 4, 3, 2]\n assert candidate(code = [1, 1, 1, 1, 1],k = -1) == [1, 1, 1, 1, 1]\n assert candidate(code = [5, 7, 1, 4],k = 3) =...
[ "[5,7,1,4]\n3", "[1,2,3,4]\n0", "[2,4,9,3]\n-2" ]
[ "As the array is circular, use modulo to find the correct index.", "The constraints are low enough for a brute-force solution." ]
{ "canonical_parameter_names": [ "code", "k" ], "leetcode_dataset_entry_point": "Solution().decrypt", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:28", "tests_total": 119, "test...
typescript
{ "raw_signature": "function decrypt(code: number[], k: number): number[] {", "container": null, "callable": "decrypt", "parameters": [ { "name": "code", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number[]", "signature_source": "leetc...
1,653
minimum-deletions-to-make-string-balanced
Medium
You are given a string s consisting only of characters 'a' and 'b'. You can delete any number of characters in s to make s balanced. s is balanced if there is no pair of indices (i,j) such that i < j and s[i] = 'b' and s[j]= 'a'. Return the minimum number of deletions needed to make s balanced. Example 1: Input: s ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aaaaaabbbb\") == 0\n assert candidate(s = \"bbbaaaaa\") == 3\n assert candidate(s = \"bbbaaaaabbbb\") == 3\n assert candidate(s = \"aabbaa\") == 2\n assert candidate(s = \"abababab\") == 3\n assert candidate(s = \"aa...
[ "\"aababbab\"", "\"bbaaaaabb\"" ]
[ "You need to find for every index the number of Bs before it and the number of A's after it", "You can speed up the finding of A's and B's in suffix and prefix using preprocessing" ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minimumDeletions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:30", "tests_total": 190, "tests_d...
typescript
{ "raw_signature": "function minimumDeletions(s: string): number {", "container": null, "callable": "minimumDeletions", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,654
minimum-jumps-to-reach-home
Medium
A certain bug's home is on the x-axis at position x. Help them get there from position 0. The bug jumps according to the following rules: - It can jump exactly a positions forward (to the right). - It can jump exactly b positions backward (to the left). - It cannot jump backward twice in a row. - It cannot jump to an...
{ "language": "python", "source": "def check(candidate):\n assert candidate(forbidden = [2, 4, 6, 8, 10],a = 2,b = 1,x = 1) == -1\n assert candidate(forbidden = [5, 6, 7],a = 1,b = 1,x = 10) == -1\n assert candidate(forbidden = [1, 6, 2, 14, 5, 17, 4],a = 16,b = 9,x = 7) == 2\n assert candidate(forbidde...
[ "[14,4,18,1,15]\n3\n15\n9", "[8,3,16,6,12,20]\n15\n13\n11", "[1,6,2,14,5,17,4]\n16\n9\n7" ]
[ "Think of the line as a graph", "to handle the no double back jumps condition you can handle it by holding the state of your previous jump" ]
{ "canonical_parameter_names": [ "forbidden", "a", "b", "x" ], "leetcode_dataset_entry_point": "Solution().minimumJumps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:32", ...
typescript
{ "raw_signature": "function minimumJumps(forbidden: number[], a: number, b: number, x: number): number {", "container": null, "callable": "minimumJumps", "parameters": [ { "name": "forbidden", "type": "number[]" }, { "name": "a", "type": "number" }, { "name": "...
1,655
distribute-repeating-integers
Hard
You are given an array of n integers, nums, where there are at most 50 unique values in the array. You are also given an array of m customer order quantities, quantity, where quantity[i] is the amount of integers the i^th customer ordered. Determine if it is possible to distribute nums such that: - The i^th customer g...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 2, 2],quantity = [2, 2]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3],quantity = [3, 3]) == True\n assert candidate(nums = [10, 10, 10, 20, 20, 20, 30, 30, 30, 40, 40, 40, 50, 50, 50, 60, 60, 60, 70, ...
[ "[1,2,3,4]\n[2]", "[1,2,3,3]\n[2]", "[1,1,2,2]\n[2,2]" ]
[ "Count the frequencies of each number. For example, if nums = [4,4,5,5,5], frequencies = [2,3].", "Each customer wants all of their numbers to be the same. This means that each customer will be assigned to one number.", "Use dynamic programming. Iterate through the numbers' frequencies, and choose some subset o...
{ "canonical_parameter_names": [ "nums", "quantity" ], "leetcode_dataset_entry_point": "Solution().canDistribute", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:35", "tests_total":...
typescript
{ "raw_signature": "function canDistribute(nums: number[], quantity: number[]): boolean {", "container": null, "callable": "canDistribute", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "quantity", "type": "number[]" } ], "return_type": "boolean", ...
1,657
determine-if-two-strings-are-close
Medium
Two strings are considered close if you can attain one from the other using the following operations: - Operation 1: Swap any two existing characters. - For example, abcde -> aecdb - Operation 2: Transform every occurrence of one existing character into another existing character, and do the same with the other char...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word1 = \"leetcode\",word2 = \"coeddlet\") == False\n assert candidate(word1 = \"aaa\",word2 = \"bbb\") == False\n assert candidate(word1 = \"aaabbbbccdddd\",word2 = \"bbbbaacdddd\") == False\n assert candidate(word1 = \"abcdefg...
[ "\"abc\"\n\"bca\"", "\"a\"\n\"aa\"", "\"cabbba\"\n\"abbccc\"" ]
[ "Operation 1 allows you to freely reorder the string.", "Operation 2 allows you to freely reassign the letters' frequencies." ]
{ "canonical_parameter_names": [ "word1", "word2" ], "leetcode_dataset_entry_point": "Solution().closeStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:37", "tests_total": 10...
typescript
{ "raw_signature": "function closeStrings(word1: string, word2: string): boolean {", "container": null, "callable": "closeStrings", "parameters": [ { "name": "word1", "type": "string" }, { "name": "word2", "type": "string" } ], "return_type": "boolean", "signature_s...
1,658
minimum-operations-to-reduce-x-to-zero
Medium
You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations. Return the minimum number of operations to reduce x to exactly 0 if it is possi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],x = 15) == 5\n assert candidate(nums = [1, 1, 4, 2, 3],x = 5) == 2\n assert candidate(nums = [10, 20, 30, 40, 50],x = 100) == 3\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000],x = 30000) == 3...
[ "[1,1,4,2,3]\n5", "[5,6,7,8,9]\n4", "[3,2,20,1,1,3]\n10" ]
[ "Think in reverse; instead of finding the minimum prefix + suffix, find the maximum subarray.", "Finding the maximum subarray is standard and can be done greedily." ]
{ "canonical_parameter_names": [ "nums", "x" ], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:39", "tests_total": 107, ...
typescript
{ "raw_signature": "function minOperations(nums: number[], x: number): number {", "container": null, "callable": "minOperations", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "x", "type": "number" } ], "return_type": "number", "signature_source"...
1,659
maximize-grid-happiness
Hard
You are given four integers, m, n, introvertsCount, and extrovertsCount. You have an m x n grid, and there are two types of people: introverts and extroverts. There are introvertsCount introverts and extrovertsCount extroverts. You should decide how many people you want to live in the grid and assign each of them one ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(m = 5,n = 5,introvertsCount = 6,extrovertsCount = 6) == 1240\n assert candidate(m = 1,n = 1,introvertsCount = 0,extrovertsCount = 1) == 40\n assert candidate(m = 5,n = 1,introvertsCount = 0,extrovertsCount = 0) == 0\n assert can...
[ "2\n3\n1\n2", "3\n1\n2\n1", "2\n2\n4\n0" ]
[ "For each cell, it has 3 options, either it is empty, or contains an introvert, or an extrovert.", "You can do DP where you maintain the state of the previous row, the number of remaining introverts and extroverts, the current row and column, and try the 3 options for each cell.", "Assume that the previous colu...
{ "canonical_parameter_names": [ "m", "n", "introvertsCount", "extrovertsCount" ], "leetcode_dataset_entry_point": "Solution().getMaxGridHappiness", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at...
typescript
{ "raw_signature": "function getMaxGridHappiness(m: number, n: number, introvertsCount: number, extrovertsCount: number): number {", "container": null, "callable": "getMaxGridHappiness", "parameters": [ { "name": "m", "type": "number" }, { "name": "n", "type": "number" },...
1,662
check-if-two-string-arrays-are-equivalent
Easy
Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise. A string is represented by an array if the array elements concatenated in order forms the string. Example 1: Input: word1 = ["ab", "c"], word2 = ["a", "bc"] Output: true Explanation: word1 represent...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word1 = ['abc', 'd', 'defg'],word2 = ['abcddefg']) == True\n assert candidate(word1 = ['x'],word2 = ['y']) == False\n assert candidate(word1 = ['different'],word2 = ['string']) == False\n assert candidate(word1 = ['hello', 'worl...
[ "[\"ab\", \"c\"]\n[\"a\", \"bc\"]", "[\"a\", \"cb\"]\n[\"ab\", \"c\"]", "[\"abc\", \"d\", \"defg\"]\n[\"abcddefg\"]" ]
[ "Concatenate all strings in the first array into a single string in the given order, the same for the second array.", "Both arrays represent the same string if and only if the generated strings are the same." ]
{ "canonical_parameter_names": [ "word1", "word2" ], "leetcode_dataset_entry_point": "Solution().arrayStringsAreEqual", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:44", "tests_to...
typescript
{ "raw_signature": "function arrayStringsAreEqual(word1: string[], word2: string[]): boolean {", "container": null, "callable": "arrayStringsAreEqual", "parameters": [ { "name": "word1", "type": "string[]" }, { "name": "word2", "type": "string[]" } ], "return_type": "...
1,663
smallest-string-with-a-given-numeric-value
Medium
The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on. The numeric value of a string consisting of lowercase characters is defined as the sum of its characters' numeric value...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 7,k = 100) == \"aaaszzz\"\n assert candidate(n = 1,k = 26) == \"z\"\n assert candidate(n = 4,k = 40) == \"aalz\"\n assert candidate(n = 5,k = 73) == \"aaszz\"\n assert candidate(n = 10,k = 260) == \"zzzzzzzzzz\"\n asse...
[ "3\n27", "5\n73" ]
[ "Think greedily.", "If you build the string from the end to the beginning, it will always be optimal to put the highest possible character at the current index." ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().getSmallestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:46", "tests_total": 65, ...
typescript
{ "raw_signature": "function getSmallestString(n: number, k: number): string {", "container": null, "callable": "getSmallestString", "parameters": [ { "name": "n", "type": "number" }, { "name": "k", "type": "number" } ], "return_type": "string", "signature_source": ...
1,664
ways-to-make-a-fair-array
Medium
You are given an integer array nums. You can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may change after the removal. For example, if nums = [6,1,7,4,1]: - Choosing to remove index 1 results in nums = [6,7,4,1]. - Choosing to remove index 2 results in nums = [6,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 0\n assert candidate(nums = [1, 2]) == 0\n assert candidate(nums = [2, 1, 6, 4]) == 1\n assert cand...
[ "[2,1,6,4]", "[1,1,1]", "[1,2,3]" ]
[ "The parity of the indices after the removed element changes.", "Calculate prefix sums for even and odd indices separately to calculate for each index in O(1)." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().waysToMakeFair", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:49", "tests_total": 100, "tests_...
typescript
{ "raw_signature": "function waysToMakeFair(nums: number[]): number {", "container": null, "callable": "waysToMakeFair", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,665
minimum-initial-energy-to-finish-tasks
Hard
You are given an array tasks where tasks[i] = [actual_i, minimum_i]: - actual_i is the actual amount of energy you spend to finish the i^th task. - minimum_i is the minimum amount of energy you require to begin the i^th task. For example, if the task is [10, 12] and your current energy is 11, you cannot start this ta...
{ "language": "python", "source": "def check(candidate):\n assert candidate(tasks = [[10, 15], [20, 25], [30, 35]]) == 65\n assert candidate(tasks = [[10, 15], [5, 10], [3, 7]]) == 22\n assert candidate(tasks = [[10, 10], [15, 15], [5, 5]]) == 30\n assert candidate(tasks = [[1, 7], [2, 8], [3, 9], [4, 1...
[ "[[1,2],[2,4],[4,8]]", "[[1,3],[2,4],[10,11],[10,12],[8,9]]", "[[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]" ]
[ "We can easily figure that the f(x) : does x solve this array is monotonic so binary Search is doable", "Figure a sorting pattern" ]
{ "canonical_parameter_names": [ "tasks" ], "leetcode_dataset_entry_point": "Solution().minimumEffort", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:51", "tests_total": 104, "tests_...
typescript
{ "raw_signature": "function minimumEffort(tasks: number[][]): number {", "container": null, "callable": "minimumEffort", "parameters": [ { "name": "tasks", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,668
maximum-repeating-substring
Easy
For a string sequence, a string word is k-repeating if word concatenated k times is a substring of sequence. The word's maximum k-repeating value is the highest value k where word is k-repeating in sequence. If word is not a substring of sequence, word's maximum k-repeating value is 0. Given strings sequence and word,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(sequence = \"ababc\",word = \"ac\") == 0\n assert candidate(sequence = \"banana\",word = \"ana\") == 1\n assert candidate(sequence = \"abcabcabc\",word = \"abc\") == 3\n assert candidate(sequence = \"aaaa\",word = \"aa\") == 2\n...
[ "\"ababc\"\n\"ab\"", "\"ababc\"\n\"ba\"", "\"ababc\"\n\"ac\"" ]
[ "The constraints are low enough for a brute force approach.", "Try every k value from 0 upwards until word is no longer k-repeating." ]
{ "canonical_parameter_names": [ "sequence", "word" ], "leetcode_dataset_entry_point": "Solution().maxRepeating", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:53", "tests_total": ...
typescript
{ "raw_signature": "function maxRepeating(sequence: string, word: string): number {", "container": null, "callable": "maxRepeating", "parameters": [ { "name": "sequence", "type": "string" }, { "name": "word", "type": "string" } ], "return_type": "number", "signature...
1,671
minimum-number-of-removals-to-make-mountain-array
Hard
You may recall that an array arr is a mountain array if and only if: - arr.length >= 3 - There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that: - arr[0] < arr[1] < ... < arr[i - 1] < arr[i] - arr[i] > arr[i + 1] > ... > arr[arr.length - 1] Given an integer array nums, return the minimum numb...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 1]) == 0\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) ...
[ "[1,3,1]", "[2,1,1,5,6,2,3,1]" ]
[ "Think the opposite direction instead of minimum elements to remove the maximum mountain subsequence", "Think of LIS it's kind of close" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumMountainRemovals", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:58", "tests_total": 107, ...
typescript
{ "raw_signature": "function minimumMountainRemovals(nums: number[]): number {", "container": null, "callable": "minimumMountainRemovals", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "l...
1,672
richest-customer-wealth
Easy
You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i^th customer has in the j^th bank. Return the wealth that the richest customer has. A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum we...
{ "language": "python", "source": "def check(candidate):\n assert candidate(accounts = [[10, 10], [20, 20], [30, 30], [40, 40]]) == 80\n assert candidate(accounts = [[100], [100], [100]]) == 100\n assert candidate(accounts = [[10, 20, 30], [5, 15, 25], [1, 2, 3]]) == 60\n assert candidate(accounts = [[1...
[ "[[1,2,3],[3,2,1]]", "[[1,5],[7,3],[3,5]]", "[[2,8,7],[7,1,3],[1,9,5]]" ]
[ "Calculate the wealth of each customer", "Find the maximum element in array." ]
{ "canonical_parameter_names": [ "accounts" ], "leetcode_dataset_entry_point": "Solution().maximumWealth", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:00", "tests_total": 85, "test...
typescript
{ "raw_signature": "function maximumWealth(accounts: number[][]): number {", "container": null, "callable": "maximumWealth", "parameters": [ { "name": "accounts", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
1,673
find-the-most-competitive-subsequence
Medium
Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k. An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array. We define that a subsequence a is more competitive than a subsequence b (of the same length)...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 9, 8, 7, 6, 5, 4, 3, 2],k = 1) == [1]\n assert candidate(nums = [2, 4, 3, 3, 5, 4, 9, 6],k = 4) == [2, 3, 3, 4]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == [5, 4, 3, 2, 1]\n assert candidate(nu...
[ "[3,5,2,6]\n2", "[2,4,3,3,5,4,9,6]\n4" ]
[ "In lexicographical order, the elements to the left have higher priority than those that come after. Can you think of a strategy that incrementally builds the answer from left to right?" ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().mostCompetitive", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:03", "tests_total": 106,...
typescript
{ "raw_signature": "function mostCompetitive(nums: number[], k: number): number[] {", "container": null, "callable": "mostCompetitive", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number[]", "signature...
1,674
minimum-moves-to-make-array-complementary
Medium
You are given an integer array nums of even length n and an integer limit. In one move, you can replace any integer from nums with another integer between 1 and limit, inclusive. The array nums is complementary if for all indices i (0-indexed), nums[i] + nums[n - 1 - i] equals the same number. For example, the array [...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 3, 3, 3],limit = 5) == 0\n assert candidate(nums = [1, 1, 1, 1],limit = 10) == 0\n assert candidate(nums = [5, 3, 5, 3],limit = 10) == 0\n assert candidate(nums = [1, 5, 5, 1],limit = 5) == 2\n assert candidate(num...
[ "[1,2,4,3]\n4", "[1,2,2,1]\n2", "[1,2,1,2]\n2" ]
[ "Given a target sum x, each pair of nums[i] and nums[n-1-i] would either need 0, 1, or 2 modifications.", "Can you find the optimal target sum x value such that the sum of modifications is minimized?", "Create a difference array to efficiently sum all the modifications." ]
{ "canonical_parameter_names": [ "nums", "limit" ], "leetcode_dataset_entry_point": "Solution().minMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:05", "tests_total": 112, ...
typescript
{ "raw_signature": "function minMoves(nums: number[], limit: number): number {", "container": null, "callable": "minMoves", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "limit", "type": "number" } ], "return_type": "number", "signature_source": ...
1,675
minimize-deviation-in-array
Hard
You are given an array nums of n positive integers. You can perform two types of operations on any element of the array any number of times: - If the element is even, divide it by 2. - For example, if the array is [1,2,3,4], then you can do this operation on the last element, and the array will be [1,2,3,2]. - If t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1000000000]) == 1953123\n assert candidate(nums = [3, 9, 6, 12]) == 3\n assert candidate(nums = [3, 9, 7, 3]) == 3\n assert candidate(nums = [2, 10, 8]) == 3\n assert candidate(nums = [5, 3, 11, 24, 2]) == 9\n a...
[ "[1,2,3,4]", "[4,1,5,20,3]", "[2,10,8]" ]
[ "Assume you start with the minimum possible value for each number so you can only multiply a number by 2 till it reaches its maximum possible value.", "If there is a better solution than the current one, then it must have either its maximum value less than the current maximum value, or the minimum value larger th...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumDeviation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:08", "tests_total": 105, "test...
typescript
{ "raw_signature": "function minimumDeviation(nums: number[]): number {", "container": null, "callable": "minimumDeviation", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,678
goal-parser-interpretation
Easy
You own a Goal Parser that can interpret a string command. The command consists of an alphabet of "G", "()" and/or "(al)" in some order. The Goal Parser will interpret "G" as the string "G", "()" as the string "o", and "(al)" as the string "al". The interpreted strings are then concatenated in the original order. Give...
{ "language": "python", "source": "def check(candidate):\n assert candidate(command = \"G()()()()(al)\") == \"Gooooal\"\n assert candidate(command = \"G\") == \"G\"\n assert candidate(command = \"()\") == \"o\"\n assert candidate(command = \"(al)G(al)()()G\") == \"alGalooG\"\n assert candidate(comman...
[ "\"G()(al)\"", "\"G()()()()(al)\"", "\"(al)G(al)()()G\"" ]
[ "You need to check at most 2 characters to determine which character comes next." ]
{ "canonical_parameter_names": [ "command" ], "leetcode_dataset_entry_point": "Solution().interpret", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:10", "tests_total": 95, "tests_dro...
typescript
{ "raw_signature": "function interpret(command: string): string {", "container": null, "callable": "interpret", "parameters": [ { "name": "command", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,679
max-number-of-k-sum-pairs
Medium
You are given an integer array nums and an integer k. In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array. Return the maximum number of operations you can perform on the array. Example 1: Input: nums = [1,2,3,4], k = 5 Output: 2 Explanation: Starting with nums...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 1, 3, 4, 3],k = 6) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 5\n assert candidate(nums = [1000000000],k = 1000000000) == 0\n assert candidate(nums = [1, 5, 4, 2, 9, 6, 5, 3, 4, 7, 8, 10],...
[ "[1,2,3,4]\n5", "[3,1,3,4,3]\n6" ]
[ "The abstract problem asks to count the number of disjoint pairs with a given sum k.", "For each possible value x, it can be paired up with k - x.", "The number of such pairs equals to min(count(x), count(k-x)), unless that x = k / 2, where the number of such pairs will be floor(count(x) / 2)." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maxOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:13", "tests_total": 68, ...
typescript
{ "raw_signature": "function maxOperations(nums: number[], k: number): number {", "container": null, "callable": "maxOperations", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source"...
1,680
concatenation-of-consecutive-binary-numbers
Medium
Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 10^9+ 7. Example 1: Input: n = 1 Output: 1 Explanation: "1" in binary corresponds to the decimal value 1. Example 2: Input: n = 3 Output: 27 Explanation: In binary, 1, 2, a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 27\n assert candidate(n = 100000) == 757631812\n assert candidate(n = 100) == 310828084\n assert candidate(n = 12) == 505379714\n assert candidate(n = 10000) == 356435599\n assert candidate(n = 20) == 632668867\n...
[ "1", "3", "12" ]
[ "Express the nth number value in a recursion formula and think about how we can do a fast evaluation." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().concatenatedBinary", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:15", "tests_total": 28, "tests_...
typescript
{ "raw_signature": "function concatenatedBinary(n: number): number {", "container": null, "callable": "concatenatedBinary", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
1,681
minimum-incompatibility
Hard
You are given an integer array nums and an integer k. You are asked to distribute this array into k subsets of equal size such that there are no two equal elements in the same subset. A subset's incompatibility is the difference between the maximum and minimum elements in that array. Return the minimum possible sum o...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 1) == 15\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],k = 8) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8],k = 4) == 4\n ...
[ "[1,2,1,4]\n2", "[6,3,8,1,3,1,2,2]\n4", "[5,3,3,6,3,3]\n3" ]
[ "The constraints are small enough for a backtrack solution but not any backtrack solution", "If we use a naive n^k don't you think it can be optimized" ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().minimumIncompatibility", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:17", "tests_total...
typescript
{ "raw_signature": "function minimumIncompatibility(nums: number[], k: number): number {", "container": null, "callable": "minimumIncompatibility", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", ...
1,684
count-the-number-of-consistent-strings
Easy
You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed. Return the number of consistent strings in the array words. Example 1: Input: allowed = "ab", words = ["ad","bd","aaab","baa","badab"] O...
{ "language": "python", "source": "def check(candidate):\n assert candidate(allowed = \"ijkl\",words = ['i', 'j', 'k', 'l', 'ij', 'ik', 'il', 'jk', 'jl', 'kl', 'ijkl']) == 11\n assert candidate(allowed = \"abcdef\",words = ['a', 'ab', 'abc', 'abcd', 'abcde', 'abcdef']) == 6\n assert candidate(allowed = \"c...
[ "\"ab\"\n[\"ad\",\"bd\",\"aaab\",\"baa\",\"badab\"]", "\"abc\"\n[\"a\",\"b\",\"c\",\"ab\",\"ac\",\"bc\",\"abc\"]", "\"cad\"\n[\"cc\",\"acd\",\"b\",\"ba\",\"bac\",\"bad\",\"ac\",\"d\"]" ]
[ "A string is incorrect if it contains a character that is not allowed", "Constraints are small enough for brute force" ]
{ "canonical_parameter_names": [ "allowed", "words" ], "leetcode_dataset_entry_point": "Solution().countConsistentStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:22", "test...
typescript
{ "raw_signature": "function countConsistentStrings(allowed: string, words: string[]): number {", "container": null, "callable": "countConsistentStrings", "parameters": [ { "name": "allowed", "type": "string" }, { "name": "words", "type": "string[]" } ], "return_type"...
1,685
sum-of-absolute-differences-in-a-sorted-array
Medium
You are given an integer array nums sorted in non-decreasing order. Build and return an integer array result with the same length as nums such that result[i] is equal to the summation of absolute differences between nums[i] and all the other elements in the array. In other words, result[i] is equal to sum(|nums[i]-nu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1]) == [0, 0, 0, 0, 0]\n assert candidate(nums = [100, 200, 300, 400, 500]) == [1000, 700, 600, 700, 1000]\n assert candidate(nums = [1, 1, 1, 1]) == [0, 0, 0, 0]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, ...
[ "[2,3,5]", "[1,4,6,8,10]" ]
[ "Absolute difference is the same as max(a, b) - min(a, b). How can you use this fact with the fact that the array is sorted?", "For nums[i], the answer is (nums[i] - nums[0]) + (nums[i] - nums[1]) + ... + (nums[i] - nums[i-1]) + (nums[i+1] - nums[i]) + (nums[i+2] - nums[i]) + ... + (nums[n-1] - nums[i]).", "It ...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().getSumAbsoluteDifferences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:24", "tests_total": 69,...
typescript
{ "raw_signature": "function getSumAbsoluteDifferences(nums: number[]): number[] {", "container": null, "callable": "getSumAbsoluteDifferences", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_sou...
1,686
stone-game-vi
Medium
Alice and Bob take turns playing a game, with Alice starting first. There are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and Bob may value the stones differently. You are given two integer arrays of length n, aliceValues and bo...
{ "language": "python", "source": "def check(candidate):\n assert candidate(aliceValues = [1, 2],bobValues = [3, 1]) == 0\n assert candidate(aliceValues = [1, 2, 3, 4, 5],bobValues = [5, 4, 3, 2, 1]) == 1\n assert candidate(aliceValues = [9, 9, 9, 9, 9],bobValues = [1, 1, 1, 1, 1]) == 1\n assert candida...
[ "[1,3]\n[2,1]", "[1,2]\n[3,1]", "[2,4,3]\n[1,6,7]" ]
[ "When one takes the stone, they not only get the points, but they take them away from the other player too.", "Greedily choose the stone with the maximum aliceValues[i] + bobValues[i]." ]
{ "canonical_parameter_names": [ "aliceValues", "bobValues" ], "leetcode_dataset_entry_point": "Solution().stoneGameVI", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:27", "tests_t...
typescript
{ "raw_signature": "function stoneGameVI(aliceValues: number[], bobValues: number[]): number {", "container": null, "callable": "stoneGameVI", "parameters": [ { "name": "aliceValues", "type": "number[]" }, { "name": "bobValues", "type": "number[]" } ], "return_type": ...
1,687
delivering-boxes-from-storage-to-ports
Hard
You have the task of delivering some boxes from storage to their ports using only one ship. However, this ship has a limit on the number of boxes and the total weight that it can carry. You are given an array boxes, where boxes[i] = [ports_i, weight_i], and three integers portsCount, maxBoxes, and maxWeight. - ports_...
{ "language": "python", "source": "def check(candidate):\n assert candidate(boxes = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],portsCount = 1,maxBoxes = 5,maxWeight = 5) == 4\n assert candidate(boxes = [[2, 2], [2, 2], [3, 3], [3, 3], [4, 4], [4, 4]],portsCount = 4,maxBox...
[ "[[1,1],[2,1],[1,1]]\n2\n3\n3", "[[1,2],[3,3],[3,1],[3,1],[2,4]]\n3\n3\n6", "[[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]]\n3\n6\n7" ]
[ "Try to think of the most basic dp which is n^2 now optimize it", "Think of any range query data structure to optimize" ]
{ "canonical_parameter_names": [ "boxes", "portsCount", "maxBoxes", "maxWeight" ], "leetcode_dataset_entry_point": "Solution().boxDelivering", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "20...
typescript
{ "raw_signature": "function boxDelivering(boxes: number[][], portsCount: number, maxBoxes: number, maxWeight: number): number {", "container": null, "callable": "boxDelivering", "parameters": [ { "name": "boxes", "type": "number[][]" }, { "name": "portsCount", "type": "numbe...
1,688
count-of-matches-in-tournament
Easy
You are given an integer n, the number of teams in a tournament that has strange rules: - If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round. - If the current number of teams is odd, one team randomly advances ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 100) == 99\n assert candidate(n = 14) == 13\n assert candidate(n = 200) == 199\n assert candidate(n = 17) == 16\n assert candidate(n = 2) == 1\n assert candidate(n = 199) == 198\n a...
[ "7", "14" ]
[ "Simulate the tournament as given in the statement.", "Be careful when handling odd integers." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().numberOfMatches", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:32", "tests_total": 60, "tests_dro...
typescript
{ "raw_signature": "function numberOfMatches(n: number): number {", "container": null, "callable": "numberOfMatches", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,689
partitioning-into-minimum-number-of-deci-binary-numbers
Medium
A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not. Given a string n that represents a positive decimal integer, return the minimum number of positive deci-binary numbers needed so that they sum ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = \"9876543210\") == 9\n assert candidate(n = \"111\") == 1\n assert candidate(n = \"123456789\") == 9\n assert candidate(n = \"1\") == 1\n assert candidate(n = \"82734\") == 8\n assert candidate(n = \"32\") == 3\n as...
[ "\"32\"", "\"82734\"", "\"27346209830709182346\"" ]
[ "Think about if the input was only one digit. Then you need to add up as many ones as the value of this digit.", "If the input has multiple digits, then you can solve for each digit independently, and merge the answers to form numbers that add up to that input.", "Thus the answer is equal to the max digit." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().minPartitions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:34", "tests_total": 72, "tests_dropp...
typescript
{ "raw_signature": "function minPartitions(n: string): number {", "container": null, "callable": "minPartitions", "parameters": [ { "name": "n", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,690
stone-game-vii
Medium
Alice and Bob take turns playing a game, with Alice starting first. There are n stones arranged in a row. On each player's turn, they can remove either the leftmost stone or the rightmost stone from the row and receive points equal to the sum of the remaining stones' values in the row. The winner is the one with the h...
{ "language": "python", "source": "def check(candidate):\n assert candidate(stones = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 30\n assert candidate(stones = [2, 3, 4, 1, 5, 6, 7, 8, 9, 10]) == 28\n assert candidate(stones = [1, 2, 3, 4, 5]) == 6\n assert candidate(stones = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) ==...
[ "[5,3,1,4,2]", "[7,90,5,1,100,10,10,2]" ]
[ "The constraints are small enough for an N^2 solution.", "Try using dynamic programming." ]
{ "canonical_parameter_names": [ "stones" ], "leetcode_dataset_entry_point": "Solution().stoneGameVII", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:36", "tests_total": 109, "tests_...
typescript
{ "raw_signature": "function stoneGameVII(stones: number[]): number {", "container": null, "callable": "stoneGameVII", "parameters": [ { "name": "stones", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,691
maximum-height-by-stacking-cuboids
Hard
Given n cuboids where the dimensions of the i^th cuboid is cuboids[i] = [width_i, length_i, height_i] (0-indexed). Choose a subset of cuboids and place them on each other. You can place cuboid i on cuboid j if width_i <= width_j and length_i <= length_j and height_i <= height_j. You can rearrange any cuboid's dimensio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(cuboids = [[4, 6, 7], [1, 2, 3], [4, 5, 6], [10, 12, 32]]) == 48\n assert candidate(cuboids = [[10, 10, 10], [5, 5, 5], [20, 20, 20]]) == 35\n assert candidate(cuboids = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]) == 6\n assert candidate...
[ "[[50,45,20],[95,37,53],[45,23,12]]", "[[38,25,45],[76,35,3]]", "[[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]" ]
[ "Does the dynamic programming sound like the right algorithm after sorting?", "Let's say box1 can be placed on top of box2. No matter what orientation box2 is in, we can rotate box1 so that it can be placed on top. Why don't we orient everything such that height is the biggest?" ]
{ "canonical_parameter_names": [ "cuboids" ], "leetcode_dataset_entry_point": "Solution().maxHeight", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:38", "tests_total": 108, "tests_dr...
typescript
{ "raw_signature": "function maxHeight(cuboids: number[][]): number {", "container": null, "callable": "maxHeight", "parameters": [ { "name": "cuboids", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,694
reformat-phone-number
Easy
You are given a phone number as a string number. number consists of digits, spaces ' ', and/or dashes '-'. You would like to reformat the phone number in a certain manner. Firstly, remove all spaces and dashes. Then, group the digits from left to right into blocks of length 3 until there are 4 or fewer digits. The fin...
{ "language": "python", "source": "def check(candidate):\n assert candidate(number = \"12 345 678\") == \"123-456-78\"\n assert candidate(number = \"1234-5678-9012\") == \"123-456-789-012\"\n assert candidate(number = \"12 345 678 90\") == \"123-456-78-90\"\n assert candidate(number = \"123456789\") == ...
[ "\"1-23-45 6\"", "\"123 4-567\"", "\"123 4-5678\"" ]
[ "Discard all the spaces and dashes.", "Use a while loop. While the string still has digits, check its length and see which rule to apply." ]
{ "canonical_parameter_names": [ "number" ], "leetcode_dataset_entry_point": "Solution().reformatNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:43", "tests_total": 161, "test...
typescript
{ "raw_signature": "function reformatNumber(number: string): string {", "container": null, "callable": "reformatNumber", "parameters": [ { "name": "number", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,695
maximum-erasure-value
Medium
You are given an array of positive integers nums and want to erase a subarray containing unique elements. The score you get by erasing the subarray is equal to the sum of its elements. Return the maximum score you can get by erasing exactly one subarray. An array b is called to be a subarray of a if it forms a contig...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6]) == 18\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == 6\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 1, 1, 1]) == 55\n ...
[ "[4,2,4,5,6]", "[5,2,1,2,5,2,1,2,5]" ]
[ "The main point here is for the subarray to contain unique elements for each index. Only the first subarrays starting from that index have unique elements.", "This can be solved using the two pointers technique" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maximumUniqueSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:45", "tests_total": 105, ...
typescript
{ "raw_signature": "function maximumUniqueSubarray(nums: number[]): number {", "container": null, "callable": "maximumUniqueSubarray", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetc...
1,696
jump-game-vi
Medium
You are given a 0-indexed integer array nums and an integer k. You are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you can jump from index i to any index in the range [i + 1, min(n - 1, i + k)] inclusive. You want to reac...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 55\n assert candidate(nums = [1, -1, -2, 4, -7, 3],k = 2) == 7\n assert candidate(nums = [10, -5, -2, 4, 0, 3],k = 3) == 17\n assert candidate(nums = [-1, -2, -3, -4, -5],k = 4) =...
[ "[1,-1,-2,4,-7,3]\n2", "[10,-5,-2,4,0,3]\n3", "[1,-5,-20,4,-1,3,-6,-3]\n2" ]
[ "Let dp[i] be \"the maximum score to reach the end starting at index i\". The answer for dp[i] is nums[i] + max{dp[i+j]} for 1 <= j <= k. That gives an O(n*k) solution.", "Instead of checking every j for every i, keep track of the largest dp[i] values in a heap and calculate dp[i] from right to left. When the lar...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maxResult", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:48", "tests_total": 92, "tes...
typescript
{ "raw_signature": "function maxResult(nums: number[], k: number): number {", "container": null, "callable": "maxResult", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetc...
1,697
checking-existence-of-edge-length-limited-paths
Hard
An undirected graph of n nodes is defined by edgeList, where edgeList[i] = [u_i, v_i, dis_i] denotes an edge between nodes u_i and v_i with distance dis_i. Note that there may be multiple edges between two nodes. Given an array queries, where queries[j] = [p_j, q_j, limit_j], your task is to determine for each queries...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3,edgeList = [[0, 1, 2], [1, 2, 4], [2, 0, 8], [1, 0, 16]],queries = [[0, 1, 2], [0, 2, 5]]) == [False, True]\n assert candidate(n = 7,edgeList = [[0, 1, 5], [1, 2, 7], [2, 3, 10], [3, 4, 3], [4, 5, 2], [5, 6, 6], [6, 0, 1]],queri...
[ "3\n[[0,1,2],[1,2,4],[2,0,8],[1,0,16]]\n[[0,1,2],[0,2,5]]", "5\n[[0,1,10],[1,2,5],[2,3,9],[3,4,13]]\n[[0,4,14],[1,4,13]]" ]
[ "All the queries are given in advance. Is there a way you can reorder the queries to avoid repeated computations?" ]
{ "canonical_parameter_names": [ "n", "edgeList", "queries" ], "leetcode_dataset_entry_point": "Solution().distanceLimitedPathsExist", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:...
typescript
{ "raw_signature": "function distanceLimitedPathsExist(n: number, edgeList: number[][], queries: number[][]): boolean[] {", "container": null, "callable": "distanceLimitedPathsExist", "parameters": [ { "name": "n", "type": "number" }, { "name": "edgeList", "type": "number[][]...
1,700
number-of-students-unable-to-eat-lunch
Easy
The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches. The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(students = [0, 1, 0, 1],sandwiches = [1, 0, 1, 0]) == 0\n assert candidate(students = [1, 1, 1, 0, 0, 1],sandwiches = [1, 0, 0, 0, 1, 1]) == 3\n assert candidate(students = [0, 0, 1, 1],sandwiches = [1, 1, 0, 0]) == 0\n assert c...
[ "[1,1,0,0]\n[0,1,0,1]", "[1,1,1,0,0,1]\n[1,0,0,0,1,1]" ]
[ "Simulate the given in the statement", "Calculate those who will eat instead of those who will not." ]
{ "canonical_parameter_names": [ "students", "sandwiches" ], "leetcode_dataset_entry_point": "Solution().countStudents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:55", "tests_t...
typescript
{ "raw_signature": "function countStudents(students: number[], sandwiches: number[]): number {", "container": null, "callable": "countStudents", "parameters": [ { "name": "students", "type": "number[]" }, { "name": "sandwiches", "type": "number[]" } ], "return_type": ...
1,701
average-waiting-time
Medium
There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrival_i, time_i]: - arrival_i is the arrival time of the i^th customer. The arrival times are sorted in non-decreasing order. - time_i is the time needed to prepare the order of the i^th customer. When a customer arriv...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat...
[ "[[1,2],[2,5],[4,3]]", "[[5,2],[5,4],[10,3],[20,1]]" ]
[ "Iterate on the customers, maintaining the time the chef will finish the previous orders.", "If that time is before the current arrival time, the chef starts immediately. Else, the current customer waits till the chef finishes, and then the chef starts.", "Update the running time by the time when the chef start...
{ "canonical_parameter_names": [ "customers" ], "leetcode_dataset_entry_point": "Solution().averageWaitingTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:57", "tests_total": 92, ...
typescript
{ "raw_signature": "function averageWaitingTime(customers: number[][]): number {", "container": null, "callable": "averageWaitingTime", "parameters": [ { "name": "customers", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source"...
1,702
maximum-binary-string-after-change
Medium
You are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times: - Operation 1: If the number contains the substring "00", you can replace it with "10". - For example, "00010" -> "10010" - Operation 2: If the number contains the substring "10", y...
{ "language": "python", "source": "def check(candidate):\n assert candidate(binary = \"01010101010\") == \"11111011111\"\n assert candidate(binary = \"01\") == \"01\"\n assert candidate(binary = \"000001\") == \"111101\"\n assert candidate(binary = \"1111\") == \"1111\"\n assert candidate(binary = \"...
[ "\"000110\"", "\"01\"" ]
[ "Note that with the operations, you can always make the string only contain at most 1 zero." ]
{ "canonical_parameter_names": [ "binary" ], "leetcode_dataset_entry_point": "Solution().maximumBinaryString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:59", "tests_total": 133, ...
typescript
{ "raw_signature": "function maximumBinaryString(binary: string): string {", "container": null, "callable": "maximumBinaryString", "parameters": [ { "name": "binary", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
1,703
minimum-adjacent-swaps-for-k-consecutive-ones
Hard
You are given an integer array, nums, and an integer k. nums comprises of only 0's and 1's. In one move, you can choose two adjacent indices and swap their values. Return the minimum number of moves required so that nums has k consecutive 1's. Example 1: Input: nums = [1,0,0,1,0,1], k = 2 Output: 1 Explanation: In 1...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 1, 1, 1, 0, 0, 1, 1, 1],k = 4) == 2\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1],k = 3) == 6\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 1, 1],k = 3) == 5\n assert candidate(nums = [1, 0, 1, 0...
[ "[1,0,0,1,0,1]\n2", "[1,0,0,0,0,0,1,1]\n3", "[1,1,0,1]\n2" ]
[ "Choose k 1s and determine how many steps are required to move them into 1 group.", "Maintain a sliding window of k 1s, and maintain the steps required to group them.", "When you slide the window across, should you move the group to the right? Once you move the group to the right, it will never need to slide to...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().minMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:02", "tests_total": 99, "test...
typescript
{ "raw_signature": "function minMoves(nums: number[], k: number): number {", "container": null, "callable": "minMoves", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcod...
1,704
determine-if-string-halves-are-alike
Easy
You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half. Two strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters. Re...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aAeEiIoOuU\") == True\n assert candidate(s = \"Leetcode\") == True\n assert candidate(s = \"AbCdEfGh\") == True\n assert candidate(s = \"textbook\") == False\n assert candidate(s = \"cOdInGQuEsTiOn\") == False\n asse...
[ "\"book\"", "\"textbook\"" ]
[ "Create a function that checks if a character is a vowel, either uppercase or lowercase." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().halvesAreAlike", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:04", "tests_total": 175, "tests_dro...
typescript
{ "raw_signature": "function halvesAreAlike(s: string): boolean {", "container": null, "callable": "halvesAreAlike", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,705
maximum-number-of-eaten-apples
Medium
There is a special kind of apple tree that grows apples every day for n days. On the i^th day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + days[i] the apples will be rotten and cannot be eaten. On some days, the apple tree does not grow any apples, which are denoted by apples[i]...
{ "language": "python", "source": "def check(candidate):\n assert candidate(apples = [0, 0, 0, 0],days = [0, 0, 0, 0]) == 0\n assert candidate(apples = [1, 3, 2],days = [3, 5, 2]) == 6\n assert candidate(apples = [5, 5, 5, 5, 5],days = [1, 2, 3, 4, 5]) == 9\n assert candidate(apples = [5, 5, 5, 5, 5],da...
[ "[1,2,3,5,2]\n[3,2,1,4,2]", "[3,0,0,0,0,2]\n[3,0,0,0,0,2]" ]
[ "It's optimal to finish the apples that will rot first before those that will rot last", "You need a structure to keep the apples sorted by their finish time" ]
{ "canonical_parameter_names": [ "apples", "days" ], "leetcode_dataset_entry_point": "Solution().eatenApples", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:06", "tests_total": 72,...
typescript
{ "raw_signature": "function eatenApples(apples: number[], days: number[]): number {", "container": null, "callable": "eatenApples", "parameters": [ { "name": "apples", "type": "number[]" }, { "name": "days", "type": "number[]" } ], "return_type": "number", "signatu...
1,706
where-will-the-ball-fall
Medium
You have a 2-D grid of size m x n representing a box, and you have n balls. The box is open on the top and bottom sides. Each cell in the box has a diagonal board spanning two corners of the cell that can redirect a ball to the right or to the left. - A board that redirects the ball to the right spans the top-left co...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == [-1, -1, -1]\n assert candidate(grid = [[1, -1, 1, -1, 1, -1], [1, -1, 1, -1, 1, -1], [-1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, -1, 1]]) == [-1, -1, -1, -1, -1, -1]\n assert candidate(grid =...
[ "[[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]]", "[[-1]]", "[[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1],[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1]]" ]
[ "Use DFS.", "Traverse the path of the ball downwards until you reach the bottom or get stuck." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().findBall", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:08", "tests_total": 65, "tests_dropped...
typescript
{ "raw_signature": "function findBall(grid: number[][]): number[] {", "container": null, "callable": "findBall", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,707
maximum-xor-with-an-element-from-array
Hard
You are given an array nums consisting of non-negative integers. You are also given a queries array, where queries[i] = [x_i, m_i]. The answer to the i^th query is the maximum bitwise XOR value of x_i and any element of nums that does not exceed m_i. In other words, the answer is max(nums[j] XOR x_i) for all j such th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 4, 8, 16],queries = [[10, 15], [30, 20], [5, 5]]) == [14, 31, 7]\n assert candidate(nums = [100, 200, 300, 400],queries = [[150, 250], [10, 100], [450, 500]]) == [242, 110, 422]\n assert candidate(nums = [7, 8, 9],que...
[ "[0,1,2,3,4]\n[[3,1],[1,3],[5,6]]", "[5,2,4,6,6,3]\n[[12,4],[8,1],[6,3]]" ]
[ "In problems involving bitwise operations, we often think on the bits level. In this problem, we can think that to maximize the result of an xor operation, we need to maximize the most significant bit, then the next one, and so on.", "If there's some number in the array that is less than m and whose the most sign...
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().maximizeXor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:11", "tests_total": 83...
typescript
{ "raw_signature": "function maximizeXor(nums: number[], queries: number[][]): number[] {", "container": null, "callable": "maximizeXor", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "queries", "type": "number[][]" } ], "return_type": "number[]", ...
1,710
maximum-units-on-a-truck
Easy
You are assigned to put some amount of boxes onto one truck. You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxes_i, numberOfUnitsPerBox_i]: - numberOfBoxes_i is the number of boxes of type i. - numberOfUnitsPerBox_iis the number of units in each box of the type i. You are also given an integer truck...
{ "language": "python", "source": "def check(candidate):\n assert candidate(boxTypes = [[1, 3], [2, 2], [3, 1]],truckSize = 4) == 8\n assert candidate(boxTypes = [[1, 1], [2, 2], [3, 3], [4, 4]],truckSize = 1) == 4\n assert candidate(boxTypes = [[2, 1], [4, 4], [3, 3]],truckSize = 5) == 19\n assert cand...
[ "[[1,3],[2,2],[3,1]]\n4", "[[5,10],[2,5],[4,7],[3,9]]\n10" ]
[ "If we have space for at least one box, it's always optimal to put the box with the most units.", "Sort the box types with the number of units per box non-increasingly.", "Iterate on the box types and take from each type as many as you can." ]
{ "canonical_parameter_names": [ "boxTypes", "truckSize" ], "leetcode_dataset_entry_point": "Solution().maximumUnits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:16", "tests_tot...
typescript
{ "raw_signature": "function maximumUnits(boxTypes: number[][], truckSize: number): number {", "container": null, "callable": "maximumUnits", "parameters": [ { "name": "boxTypes", "type": "number[][]" }, { "name": "truckSize", "type": "number" } ], "return_type": "num...
1,711
count-good-meals
Medium
A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two. You can pick any two different foods to make a good meal. Given an array of integers deliciousness where deliciousness[i] is the deliciousness of the i^th item of food, return the number of differ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(deliciousness = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 0\n assert candidate(deliciousness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(deliciousness = [2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 15\n assert...
[ "[1,3,5,7,9]", "[1,1,1,3,3,3,7]" ]
[ "Note that the number of powers of 2 is at most 21 so this turns the problem to a classic find the number of pairs that sum to a certain value but for 21 values", "You need to use something fasters than the NlogN approach since there is already the log of iterating over the powers so one idea is two pointers" ]
{ "canonical_parameter_names": [ "deliciousness" ], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:18", "tests_total": 101, "t...
typescript
{ "raw_signature": "function countPairs(deliciousness: number[]): number {", "container": null, "callable": "countPairs", "parameters": [ { "name": "deliciousness", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
1,712
ways-to-split-array-into-three-subarrays
Medium
A split of an integer array is good if: - The array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left to right. - The sum of the elements in left is less than or equal to the sum of the elements in mid, and the sum of the elements in mid is less than or equal to the sum...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10000, 10000, 10000]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 12\n assert candidate(nums = [1, 3, 2, 3, 1, 1, 1, 3, 2, 3]) == 9\n assert candidate(nums = [9, 4, 2, 5, 1]) == 0\n assert candidate...
[ "[1,1,1]", "[1,2,2,2,5,0]", "[3,2,1]" ]
[ "Create a prefix array to efficiently find the sum of subarrays.", "As we are dividing the array into three subarrays, there are two \"walls\". Iterate over the right wall positions and find where the left wall could be for each right wall position.", "Use binary search to find the left-most position and right-...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().waysToSplit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:21", "tests_total": 93, "tests_drop...
typescript
{ "raw_signature": "function waysToSplit(nums: number[]): number {", "container": null, "callable": "waysToSplit", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,713
minimum-operations-to-make-a-subsequence
Hard
You are given an array target that consists of distinct integers and another integer array arr that can have duplicates. In one operation, you can insert any integer at any position in arr. For example, if arr = [1,4,1,2], you can add 3 in the middle and make it [1,4,3,1,2]. Note that you can insert the integer at the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(target = [1, 2, 3, 4, 5],arr = [5, 4, 3, 2, 1]) == 4\n assert candidate(target = [3, 1, 5, 8, 9],arr = [1, 5, 3, 8, 9]) == 1\n assert candidate(target = [1],arr = [1, 1, 1, 1]) == 0\n assert candidate(target = [6, 4, 8, 1, 3, 2]...
[ "[5,1,3]\n[9,4,2,3,4]", "[6,4,8,1,3,2]\n[4,7,6,2,3,8,6,1]" ]
[ "The problem can be reduced to computing Longest Common Subsequence between both arrays.", "Since one of the arrays has distinct elements, we can consider that these elements describe an arrangement of numbers, and we can replace each element in the other array with the index it appeared at in the first array.", ...
{ "canonical_parameter_names": [ "target", "arr" ], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:24", "tests_total": 11...
typescript
{ "raw_signature": "function minOperations(target: number[], arr: number[]): number {", "container": null, "callable": "minOperations", "parameters": [ { "name": "target", "type": "number[]" }, { "name": "arr", "type": "number[]" } ], "return_type": "number", "signa...
1,716
calculate-money-in-leetcode-bank
Easy
Hercy wants to save money for his first car. He puts money in the Leetcode bank every day. He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sunday, he will put in $1 more than the day before. On every subsequent Monday, he will put in $1 more than the previous Monday. Given n, return the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 30) == 165\n assert candidate(n = 4) == 10\n assert candidate(n = 20) == 96\n assert candidate(n = 1) == 1\n assert candidate(n = 1000) == 74926\n assert candidate(n = 7) == 28\n assert candidate(n = 10) == 37\n ...
[ "4", "10", "20" ]
[ "Simulate the process by keeping track of how much money Hercy is putting in and which day of the week it is, and use this information to deduce how much money Hercy will put in the next day." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().totalMoney", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:29", "tests_total": 50, "tests_dropped"...
typescript
{ "raw_signature": "function totalMoney(n: number): number {", "container": null, "callable": "totalMoney", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,717
maximum-score-from-removing-substrings
Medium
You are given a string s and two integers x and y. You can perform two types of operations any number of times. - Remove substring "ab" and gain x points. - For example, when removing "ab" from "cabxbae" it becomes "cxbae". - Remove substring "ba" and gain y points. - For example, when removing "ba" from "cabxbae"...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"ababababababababababababababababababababab\",x = 1,y = 1) == 21\n assert candidate(s = \"abbaabba\",x = 7,y = 8) == 31\n assert candidate(s = \"abababab\",x = 10,y = 10) == 40\n assert candidate(s = \"ababab\",x = 10,y = 1...
[ "\"cdbcbbaaabab\"\n4\n5", "\"aabbaaxybbaabb\"\n5\n4" ]
[ "Note that it is always more optimal to take one type of substring before another", "You can use a stack to handle erasures" ]
{ "canonical_parameter_names": [ "s", "x", "y" ], "leetcode_dataset_entry_point": "Solution().maximumGain", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:31", "tests_total": 15...
typescript
{ "raw_signature": "function maximumGain(s: string, x: number, y: number): number {", "container": null, "callable": "maximumGain", "parameters": [ { "name": "s", "type": "string" }, { "name": "x", "type": "number" }, { "name": "y", "type": "number" } ...
1,718
construct-the-lexicographically-largest-valid-sequence
Medium
Given an integer n, find a sequence with elements in the range [1, n] that satisfies all of the following: - The integer 1 occurs once in the sequence. - Each integer between 2 and n occurs twice in the sequence. - For every integer i between 2 and n, the distance between the two occurrences of i is exactly i. The di...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == [3, 1, 2, 3, 2]\n assert candidate(n = 15) == [15, 13, 14, 10, 8, 12, 5, 3, 11, 9, 3, 5, 8, 10, 13, 15, 14, 12, 9, 11, 7, 4, 6, 1, 2, 4, 2, 7, 6]\n assert candidate(n = 4) == [4, 2, 3, 2, 4, 3, 1]\n assert candidate(n ...
[ "3", "5" ]
[ "Heuristic algorithm may work." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().constructDistancedSequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:33", "tests_total": 18, ...
typescript
{ "raw_signature": "function constructDistancedSequence(n: number): number[] {", "container": null, "callable": "constructDistancedSequence", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "l...
1,719
number-of-ways-to-reconstruct-a-tree
Hard
You are given an array pairs, where pairs[i] = [x_i, y_i], and: - There are no duplicates. - x_i < y_i Let ways be the number of rooted trees that satisfy the following conditions: - The tree consists of nodes whose values appeared in pairs. - A pair [x_i, y_i] exists in pairs if and only if x_i is an ancestor of y_...
{ "language": "python", "source": "def check(candidate):\n assert candidate(pairs = [[1, 2], [2, 3], [2, 4], [3, 5], [4, 5]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [1, 5]]) == 0\n assert candidate(pairs = [[1, 3], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(pairs = [[1, 2...
[ "[[1,2],[2,3]]", "[[1,2],[2,3],[1,3]]", "[[1,2],[2,3],[2,4],[1,5]]" ]
[ "Think inductively. The first step is to get the root. Obviously, the root should be in pairs with all the nodes. If there isn't exactly one such node, then there are 0 ways.", "The number of pairs involving a node must be less than or equal to that number of its parent.", "Actually, if it's equal, then there i...
{ "canonical_parameter_names": [ "pairs" ], "leetcode_dataset_entry_point": "Solution().checkWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:36", "tests_total": 80, "tests_dropp...
typescript
{ "raw_signature": "function checkWays(pairs: number[][]): number {", "container": null, "callable": "checkWays", "parameters": [ { "name": "pairs", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,720
decode-xored-array
Easy
There is a hidden integer array arr that consists of n non-negative integers. It was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3]. You are given the encoded array. You are also given an integer first, ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(encoded = [10, 5, 15],first = 0) == [0, 10, 15, 0]\n assert candidate(encoded = [0, 0, 0],first = 7) == [7, 7, 7, 7]\n assert candidate(encoded = [9, 5, 6],first = 0) == [0, 9, 12, 10]\n assert candidate(encoded = [10, 5, 15, 20...
[ "[1,2,3]\n1", "[6,2,7,3]\n4" ]
[ "Since that encoded[i] = arr[i] XOR arr[i+1], then arr[i+1] = encoded[i] XOR arr[i].", "Iterate on i from beginning to end, and set arr[i+1] = encoded[i] XOR arr[i]." ]
{ "canonical_parameter_names": [ "encoded", "first" ], "leetcode_dataset_entry_point": "Solution().decode", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:38", "tests_total": 97, ...
typescript
{ "raw_signature": "function decode(encoded: number[], first: number): number[] {", "container": null, "callable": "decode", "parameters": [ { "name": "encoded", "type": "number[]" }, { "name": "first", "type": "number" } ], "return_type": "number[]", "signature_sou...
1,722
minimize-hamming-distance-after-swap-operations
Medium
You are given two integer arrays, source and target, both of length n. You are also given an array allowedSwaps where each allowedSwaps[i] = [a_i, b_i] indicates that you are allowed to swap the elements at index a_i and index b_i (0-indexed) of array source. Note that you can swap elements at a specific pair of indice...
{ "language": "python", "source": "def check(candidate):\n assert candidate(source = [4, 3, 2, 1],target = [1, 2, 3, 4],allowedSwaps = [[0, 3], [1, 2], [0, 1], [2, 3]]) == 0\n assert candidate(source = [4, 3, 2, 1],target = [1, 2, 3, 4],allowedSwaps = [[0, 2], [1, 3]]) == 4\n assert candidate(source = [1, ...
[ "[1,2,3,4]\n[2,1,4,5]\n[[0,1],[2,3]]", "[1,2,3,4]\n[1,3,2,4]\n[]", "[5,1,2,4,3]\n[1,5,4,2,3]\n[[0,4],[4,2],[1,3],[1,4]]" ]
[ "The source array can be imagined as a graph where each index is a node and each allowedSwaps[i] is an edge.", "Nodes within the same component can be freely swapped with each other.", "For each component, find the number of common elements. The elements that are not in common will contribute to the total Hammi...
{ "canonical_parameter_names": [ "source", "target", "allowedSwaps" ], "leetcode_dataset_entry_point": "Solution().minimumHammingDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-3...
typescript
{ "raw_signature": "function minimumHammingDistance(source: number[], target: number[], allowedSwaps: number[][]): number {", "container": null, "callable": "minimumHammingDistance", "parameters": [ { "name": "source", "type": "number[]" }, { "name": "target", "type": "number...
1,723
find-minimum-time-to-finish-all-jobs
Hard
You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the i^th job. There are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The working time of a worker is the sum of the time it takes to complete all jobs assigned to them. Your goal i...
{ "language": "python", "source": "def check(candidate):\n assert candidate(jobs = [1, 2, 4, 7, 8],k = 2) == 11\n assert candidate(jobs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 4) == 20\n assert candidate(jobs = [6, 5, 4, 3, 2, 1],k = 6) == 6\n assert candidate(jobs = [12, 11, 10, 9, 8, 7, 6, 5, 4,...
[ "[3,2,3]\n3", "[1,2,4,7,8]\n2" ]
[ "We can select a subset of tasks and assign it to a worker then solve the subproblem on the remaining tasks" ]
{ "canonical_parameter_names": [ "jobs", "k" ], "leetcode_dataset_entry_point": "Solution().minimumTimeRequired", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:45", "tests_total": ...
typescript
{ "raw_signature": "function minimumTimeRequired(jobs: number[], k: number): number {", "container": null, "callable": "minimumTimeRequired", "parameters": [ { "name": "jobs", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signa...
1,725
number-of-rectangles-that-can-form-the-largest-square
Easy
You are given an array rectangles where rectangles[i] = [l_i, w_i] represents the i^th rectangle of length l_i and width w_i. You can cut the i^th rectangle to form a square with a side length of k if both k <= l_i and k <= w_i. For example, if you have a rectangle [4,6], you can cut it to get a square with a side len...
{ "language": "python", "source": "def check(candidate):\n assert candidate(rectangles = [[1, 2], [2, 1], [3, 4], [4, 3]]) == 2\n assert candidate(rectangles = [[2, 3], [3, 7], [4, 3], [3, 7]]) == 3\n assert candidate(rectangles = [[5, 8], [3, 9], [5, 12], [16, 5]]) == 3\n assert candidate(rectangles = ...
[ "[[5,8],[3,9],[5,12],[16,5]]", "[[2,3],[3,7],[4,3],[3,7]]" ]
[ "What is the length of the largest square the can be cut out of some rectangle? It'll be equal to min(rectangle.length, rectangle.width). Replace each rectangle with this value.", "Calculate maxSize by iterating over the given rectangles and maximizing the answer with their values denoted in the first hint.", "...
{ "canonical_parameter_names": [ "rectangles" ], "leetcode_dataset_entry_point": "Solution().countGoodRectangles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:47", "tests_total": 83,...
typescript
{ "raw_signature": "function countGoodRectangles(rectangles: number[][]): number {", "container": null, "callable": "countGoodRectangles", "parameters": [ { "name": "rectangles", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_sou...
1,726
tuple-with-same-product
Medium
Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d. Example 1: Input: nums = [2,3,4,6] Output: 8 Explanation: There are 8 valid tuples: (2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3) (3,4,2,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 16\n assert candidate(nums = [7, 8, 9, 14, 21]) == 0\n assert candidate(nums = [7, 11, 13, 19, 23, 29, 31]) == 0\n assert candidate(nums ...
[ "[2,3,4,6]", "[1,2,4,5,10]" ]
[ "Note that all of the integers are distinct. This means that each time a product is formed it must be formed by two unique integers.", "Count the frequency of each product of 2 distinct numbers. Then calculate the permutations formed." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().tupleSameProduct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:50", "tests_total": 105, "test...
typescript
{ "raw_signature": "function tupleSameProduct(nums: number[]): number {", "container": null, "callable": "tupleSameProduct", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,727
largest-submatrix-with-rearrangements
Medium
You are given a binary matrix matrix of size m x n, and you are allowed to rearrange the columns of the matrix in any order. Return the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally. Example 1: Input: matrix = [[0,0,1],[1,1,1],[1,0,1]] Ou...
{ "language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[0, 1], [1, 0]]) == 1\n assert candidate(matrix = [[1, 1, 0], [1, 0, 1]]) == 2\n assert candidate(matrix = [[0, 0, 1], [1, 1, 1], [1, 0, 1]]) == 4\n assert candidate(matrix = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]])...
[ "[[0,0,1],[1,1,1],[1,0,1]]", "[[1,0,1,0,1]]", "[[1,1,0],[1,0,1]]" ]
[ "For each column, find the number of consecutive ones ending at each position.", "For each row, sort the cumulative ones in non-increasing order and \"fit\" the largest submatrix." ]
{ "canonical_parameter_names": [ "matrix" ], "leetcode_dataset_entry_point": "Solution().largestSubmatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:52", "tests_total": 83, "tes...
typescript
{ "raw_signature": "function largestSubmatrix(matrix: number[][]): number {", "container": null, "callable": "largestSubmatrix", "parameters": [ { "name": "matrix", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcod...
1,728
cat-and-mouse-ii
Hard
A game is played by a cat and a mouse named Cat and Mouse. The environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food. - Players are represented by the characters 'C'(Cat),'M'(Mouse). - Floors are represented by the character '.' and can be walked o...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = ['...M.', '.F#C.', '.....'],catJump = 2,mouseJump = 2) == True\n assert candidate(grid = ['M....', '.....', 'C.F..'],catJump = 1,mouseJump = 1) == False\n assert candidate(grid = ['C.......', '........', '........', '..........
[ "[\"####F\",\"#C...\",\"M....\"]\n1\n2", "[\"M.C...F\"]\n1\n4", "[\"M.C...F\"]\n1\n3" ]
[ "Try working backward: consider all trivial states you know to be winning or losing, and work backward to determine which other states can be labeled as winning or losing." ]
{ "canonical_parameter_names": [ "grid", "catJump", "mouseJump" ], "leetcode_dataset_entry_point": "Solution().canMouseWin", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:54", ...
typescript
{ "raw_signature": "function canMouseWin(grid: string[], catJump: number, mouseJump: number): boolean {", "container": null, "callable": "canMouseWin", "parameters": [ { "name": "grid", "type": "string[]" }, { "name": "catJump", "type": "number" }, { "name": "mo...
1,732
find-the-highest-altitude
Easy
There is a biker going on a road trip. The road trip consists of n + 1 points at various altitudes. The biker starts his trip on point 0 with altitude equal 0. You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i and i + 1 for all (0 <= i < n). Return the highest a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(gain = [4, 3, 2, 1, 0, -1, -2, -3, -4]) == 10\n assert candidate(gain = [-1, -2, -3, -4]) == 0\n assert candidate(gain = [-10, -20, -30, -40, -50]) == 0\n assert candidate(gain = [1, 2, 3, 4, 5, 6, 7, 8, 9, 100]) == 145\n ass...
[ "[-5,1,5,0,-7]", "[-4,-3,-2,-1,4,3,2]" ]
[ "Let's note that the altitude of an element is the sum of gains of all the elements behind it", "Getting the altitudes can be done by getting the prefix sum array of the given array" ]
{ "canonical_parameter_names": [ "gain" ], "leetcode_dataset_entry_point": "Solution().largestAltitude", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:59", "tests_total": 110, "tests...
typescript
{ "raw_signature": "function largestAltitude(gain: number[]): number {", "container": null, "callable": "largestAltitude", "parameters": [ { "name": "gain", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
1,733
minimum-number-of-people-to-teach
Medium
On a social network consisting of m users and some friendships between users, two users can communicate with each other if they know a common language. You are given an integer n, an array languages, and an array friendships where: - There are n languages numbered 1 through n, - languages[i] is the set of languages t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,languages = [[1], [2], [3], [4]],friendships = [[1, 2], [2, 3], [3, 4], [4, 1]]) == 3\n assert candidate(n = 3,languages = [[1, 2], [2, 3], [3, 1]],friendships = [[1, 2], [2, 3], [3, 1]]) == 0\n assert candidate(n = 5,languag...
[ "2\n[[1],[2],[1,2]]\n[[1,2],[1,3],[2,3]]", "3\n[[2],[1,3],[1,2],[3]]\n[[1,4],[1,2],[3,4],[2,3]]" ]
[ "You can just use brute force and find out for each language the number of users you need to teach", "Note that a user can appear in multiple friendships but you need to teach that user only once" ]
{ "canonical_parameter_names": [ "n", "languages", "friendships" ], "leetcode_dataset_entry_point": "Solution().minimumTeachings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:0...
typescript
{ "raw_signature": "function minimumTeachings(n: number, languages: number[][], friendships: number[][]): number {", "container": null, "callable": "minimumTeachings", "parameters": [ { "name": "n", "type": "number" }, { "name": "languages", "type": "number[][]" }, { ...
1,734
decode-xored-permutation
Medium
There is an integer array perm that is a permutation of the first n positive integers, where n is always odd. It was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[i + 1]. For example, if perm = [1,3,2], then encoded = [2,1]. Given the encoded array, return the ori...
{ "language": "python", "source": "def check(candidate):\n assert candidate(encoded = [15, 8, 12, 4, 1]) == [11, 4, 12, 0, 4, 5]\n assert candidate(encoded = [1, 7, 6, 5, 4, 3]) == [1, 0, 7, 1, 4, 0, 3]\n assert candidate(encoded = [6, 5, 4, 6]) == [2, 4, 1, 5, 3]\n assert candidate(encoded = [8, 12, 4,...
[ "[3,1]", "[6,5,4,6]" ]
[ "Compute the XOR of the numbers between 1 and n, and think about how it can be used. Let it be x.", "Think why n is odd.", "perm[0] = x XOR encoded[1] XOR encoded[3] XOR encoded[5] ...", "perm[i] = perm[i-1] XOR encoded[i-1]" ]
{ "canonical_parameter_names": [ "encoded" ], "leetcode_dataset_entry_point": "Solution().decode", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:04", "tests_total": 110, "tests_dropp...
typescript
{ "raw_signature": "function decode(encoded: number[]): number[] {", "container": null, "callable": "decode", "parameters": [ { "name": "encoded", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,736
latest-time-by-replacing-hidden-digits
Easy
You are given a string time in the form of hh:mm, where some of the digits in the string are hidden (represented by ?). The valid times are those inclusively between 00:00 and 23:59. Return the latest valid time you can get from time by replacing the hidden digits. Example 1: Input: time = "2?:?0" Output: "23:50" ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(time = \"?3:?0\") == \"23:50\"\n assert candidate(time = \"1?:22\") == \"19:22\"\n assert candidate(time = \"1?:??\") == \"19:59\"\n assert candidate(time = \"0?:59\") == \"09:59\"\n assert candidate(time = \"23:?9\") == \"23...
[ "\"2?:?0\"", "\"0?:3?\"", "\"1?:22\"" ]
[ "Trying out all possible solutions from biggest to smallest would fit in the time limit.", "To check if the solution is okay, you need to find out if it's valid and matches every character" ]
{ "canonical_parameter_names": [ "time" ], "leetcode_dataset_entry_point": "Solution().maximumTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:06", "tests_total": 96, "tests_drop...
typescript
{ "raw_signature": "function maximumTime(time: string): string {", "container": null, "callable": "maximumTime", "parameters": [ { "name": "time", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,737
change-minimum-characters-to-satisfy-one-of-three-conditions
Medium
You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter. Your goal is to satisfy one of the following three conditions: - Every letter in a is strictly less than every letter in b in the alphabet. - Every letter in b is stri...
{ "language": "python", "source": "def check(candidate):\n assert candidate(a = \"abc\",b = \"bcd\") == 2\n assert candidate(a = \"aba\",b = \"caa\") == 2\n assert candidate(a = \"xyzz\",b = \"zzzz\") == 2\n assert candidate(a = \"abcd\",b = \"dcba\") == 4\n assert candidate(a = \"aaaabbbb\",b = \"cc...
[ "\"aba\"\n\"caa\"", "\"dabadd\"\n\"cda\"" ]
[ "Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter.", "For the first 2 conditions, take care that you can only change cha...
{ "canonical_parameter_names": [ "a", "b" ], "leetcode_dataset_entry_point": "Solution().minCharacters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:09", "tests_total": 128, "t...
typescript
{ "raw_signature": "function minCharacters(a: string, b: string): number {", "container": null, "callable": "minCharacters", "parameters": [ { "name": "a", "type": "string" }, { "name": "b", "type": "string" } ], "return_type": "number", "signature_source": "leetcod...
1,738
find-kth-largest-xor-coordinate-value
Medium
You are given a 2D matrix of size m x n, consisting of non-negative integers. You are also given an integer k. The value of coordinate (a, b) of the matrix is the XOR of all matrix[i][j] where 0 <= i <= a < m and 0 <= j <= b < n (0-indexed). Find the k^th largest value (1-indexed) of all the coordinates of matrix. E...
{ "language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[5, 2, 3], [1, 6, 4]],k = 5) == 4\n assert candidate(matrix = [[0, 0, 0], [0, 0, 0], [0, 0, 0]],k = 9) == 0\n assert candidate(matrix = [[5, 2, 3], [1, 6, 4], [7, 8, 9]],k = 9) == 0\n assert candidate(matrix = [[10, 12...
[ "[[5,2],[1,6]]\n1", "[[5,2],[1,6]]\n2", "[[5,2],[1,6]]\n3" ]
[ "Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix." ]
{ "canonical_parameter_names": [ "matrix", "k" ], "leetcode_dataset_entry_point": "Solution().kthLargestValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:11", "tests_total": 87...
typescript
{ "raw_signature": "function kthLargestValue(matrix: number[][], k: number): number {", "container": null, "callable": "kthLargestValue", "parameters": [ { "name": "matrix", "type": "number[][]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signa...
1,739
building-boxes
Hard
You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: - You can place the boxes anywhere on the floor. - If box x is placed on top ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 8) == 6\n assert candidate(n = 3) == 3\n assert candidate(n = 100) == 34\n assert candidate(n = 15) == 9\n assert candidate(n = 4) == 3\n assert candidate(n = 1000000) == 16443\n assert candidate(n = 20) == 10\n ...
[ "3", "4", "10" ]
[ "Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in?", "The first box should always start in the corner" ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().minimumBoxes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:13", "tests_total": 101, "tests_dropp...
typescript
{ "raw_signature": "function minimumBoxes(n: number): number {", "container": null, "callable": "minimumBoxes", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,742
maximum-number-of-balls-in-a-box
Easy
You are working in a ball factory where you have n balls numbered from lowLimit up to highLimit inclusive (i.e., n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from 1 to infinity. Your job at this factory is to put each ball in the box with a number equal to the sum of digits of the ball's nu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(lowLimit = 999,highLimit = 1000) == 1\n assert candidate(lowLimit = 1000,highLimit = 10000) == 615\n assert candidate(lowLimit = 50000,highLimit = 50500) == 44\n assert candidate(lowLimit = 99,highLimit = 999) == 70\n assert ...
[ "1\n10", "5\n15", "19\n28" ]
[ "Note that both lowLimit and highLimit are of small constraints so you can iterate on all number between them", "You can simulate the boxes by counting for each box the number of balls with digit sum equal to that box number" ]
{ "canonical_parameter_names": [ "lowLimit", "highLimit" ], "leetcode_dataset_entry_point": "Solution().countBalls", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:18", "tests_total...
typescript
{ "raw_signature": "function countBalls(lowLimit: number, highLimit: number): number {", "container": null, "callable": "countBalls", "parameters": [ { "name": "lowLimit", "type": "number" }, { "name": "highLimit", "type": "number" } ], "return_type": "number", "sig...
1,743
restore-the-array-from-adjacent-pairs
Medium
There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums. You are given a 2D integer array adjacentPairs of size n - 1 where each adjacentPairs[i] = [u_i, v_i] indicates that the elements u_i and v_i are adjacent in n...
{ "language": "python", "source": "def check(candidate):\n assert candidate(adjacentPairs = [[-1, 0], [0, 1], [1, 2], [2, 3], [3, -2]]) == [-1, 0, 1, 2, 3, -2]\n assert candidate(adjacentPairs = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60]]) == [10, 20, 30, 40, 50, 60]\n assert candidate(adjacentPairs...
[ "[[2,1],[3,4],[3,2]]", "[[4,-2],[1,4],[-3,1]]", "[[100000,-100000]]" ]
[ "Find the first element of nums - it will only appear once in adjacentPairs.", "The adjacent pairs are like edges of a graph. Perform a depth-first search from the first element." ]
{ "canonical_parameter_names": [ "adjacentPairs" ], "leetcode_dataset_entry_point": "Solution().restoreArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:20", "tests_total": 79, "...
typescript
{ "raw_signature": "function restoreArray(adjacentPairs: number[][]): number[] {", "container": null, "callable": "restoreArray", "parameters": [ { "name": "adjacentPairs", "type": "number[][]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source"...
1,744
can-you-eat-your-favorite-candy-on-your-favorite-day
Medium
You are given a (0-indexed) array of positive integers candiesCount where candiesCount[i] represents the number of candies of the i^th type you have. You are also given a 2D array queries where queries[i] = [favoriteType_i, favoriteDay_i, dailyCap_i]. You play a game with the following rules: - You start eating candi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(candiesCount = [7, 4, 5, 3, 8],queries = [[0, 2, 2], [4, 2, 4], [2, 13, 1000000000]]) == [True, False, True]\n assert candidate(candiesCount = [5, 2, 6, 4, 1],queries = [[3, 1, 2], [4, 10, 3], [3, 10, 100], [4, 100, 30], [1, 3, 1]]) =...
[ "[7,4,5,3,8]\n[[0,2,2],[4,2,4],[2,13,1000000000]]", "[5,2,6,4,1]\n[[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]" ]
[ "The query is true if and only if your favorite day is in between the earliest and latest possible days to eat your favorite candy.", "To get the earliest day, you need to eat dailyCap candies every day. To get the latest day, you need to eat 1 candy every day.", "The latest possible day is the total number of ...
{ "canonical_parameter_names": [ "candiesCount", "queries" ], "leetcode_dataset_entry_point": "Solution().canEat", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:23", "tests_total":...
typescript
{ "raw_signature": "function canEat(candiesCount: number[], queries: number[][]): boolean[] {", "container": null, "callable": "canEat", "parameters": [ { "name": "candiesCount", "type": "number[]" }, { "name": "queries", "type": "number[][]" } ], "return_type": "bool...
1,745
palindrome-partitioning-iv
Hard
Given a string s, return true if it is possible to split the string s into three non-empty palindromic substrings. Otherwise, return false. A string is said to be palindrome if it the same string when reversed. Example 1: Input: s = "abcbdd" Output: true Explanation: "abcbdd" = "a" + "bcb" + "dd", and all three subs...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcba\") == True\n assert candidate(s = \"abcdcba\") == True\n assert candidate(s = \"aabbaa\") == True\n assert candidate(s = \"aaaaa\") == True\n assert candidate(s = \"abacdfgdcaba\") == False\n assert candidate(s...
[ "\"abcbdd\"", "\"bcbddxy\"" ]
[ "Preprocess checking palindromes in O(1)", "Note that one string is a prefix and another one is a suffix you can try brute forcing the rest" ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().checkPartitioning", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:25", "tests_total": 165, "tests_...
typescript
{ "raw_signature": "function checkPartitioning(s: string): boolean {", "container": null, "callable": "checkPartitioning", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
1,748
sum-of-unique-elements
Easy
You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array. Return the sum of all the unique elements of nums. Example 1: Input: nums = [1,2,3,2] Output: 4 Explanation: The unique elements are [1,3], and the sum is 4. Example 2: Input: nums = [1,1,1,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10]) == 54\n assert candidate(nums = [10, 20, 20, 10, 30]) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [1]) == 1\n assert candidate(nu...
[ "[1,2,3,2]", "[1,1,1,1,1]", "[1,2,3,4,5]" ]
[ "Use a dictionary to count the frequency of each number." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().sumOfUnique", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:30", "tests_total": 99, "tests_drop...
typescript
{ "raw_signature": "function sumOfUnique(nums: number[]): number {", "container": null, "callable": "sumOfUnique", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }