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,462
course-schedule-iv
Medium
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [a_i, b_i] indicates that you must take course a_i first if you want to take course b_i. - For example, the pair [0, 1] indicates that you have to take course 0 befo...
{ "language": "python", "source": "def check(candidate):\n assert candidate(numCourses = 5,prerequisites = [[0, 1], [1, 2], [2, 3], [3, 4]],queries = [[0, 4], [4, 0]]) == [True, False]\n assert candidate(numCourses = 4,prerequisites = [[0, 1], [1, 2], [2, 3]],queries = [[0, 3], [1, 3], [0, 2]]) == [True, True...
[ "6\n[[4,5],[3,4],[2,3],[1,2],[0,1]]\n[[0,5]]", "3\n[[0,1],[1,2]]\n[[0,2]]", "4\n[[0,1],[2,3]]\n[[0,3]]" ]
[ "Imagine if the courses are nodes of a graph. We need to build an array isReachable[i][j].", "Start a bfs from each course i and assign for each course j you visit isReachable[i][j] = True.", "Answer the queries from the isReachable array." ]
{ "canonical_parameter_names": [ "numCourses", "prerequisites", "queries" ], "leetcode_dataset_entry_point": "Solution().checkIfPrerequisite", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-0...
typescript
{ "raw_signature": "function checkIfPrerequisite(numCourses: number, prerequisites: number[][], queries: number[][]): boolean[] {", "container": null, "callable": "checkIfPrerequisite", "parameters": [ { "name": "numCourses", "type": "number" }, { "name": "prerequisites", "ty...
1,463
cherry-pickup-ii
Hard
You are given a rows x cols matrix grid representing a field of cherries where grid[i][j] represents the number of cherries that you can collect from the (i, j) cell. You have two robots that can collect cherries for you: - Robot #1 is located at the top-left corner (0, 0), and - Robot #2 is located at the top-right ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2, 3], [0, 1, 0], [3, 0, 1], [1, 2, 3]]) == 14\n assert candidate(grid = [[5, 0, 0, 5], [0, 4, 4, 0], [0, 4, 4, 0], [5, 0, 0, 5]]) == 36\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, ...
[ "[[3,1,1],[2,5,1],[1,5,5],[2,1,1]]", "[[1,0,0,0,0,0,1],[2,0,0,0,0,3,0],[2,0,9,0,0,0,0],[0,3,0,5,4,0,0],[1,0,2,3,0,0,6]]" ]
[ "Use dynamic programming, define DP[i][j][k]: The maximum cherries that both robots can take starting on the ith row, and column j and k of Robot 1 and 2 respectively." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().cherryPickup", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:20:55", "tests_total": 74, "tests_dro...
typescript
{ "raw_signature": "function cherryPickup(grid: number[][]): number {", "container": null, "callable": "cherryPickup", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,464
maximum-product-of-two-elements-in-an-array
Easy
You are given an array of integers nums. Choose two different indices i and j of that array. Return the maximum value of (nums[i] - 1) * (nums[j] - 1). Example 1: Input: nums = [3,4,5,2] Output: 12 Explanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10]) == 81\n assert candidate(nums = [2, 3, 5, 7, 11, 13]) == 120\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 72\n assert candidate(nums = [1, 1000, 2, 999, 3, 998]) == 997002\n assert ca...
[ "[3,4,5,2]", "[1,5,4,5]", "[3,7]" ]
[ "Use brute force: two loops to select i and j, then select the maximum value of (nums[i]-1)*(nums[j]-1)." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxProduct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:20:57", "tests_total": 96, "tests_dropp...
typescript
{ "raw_signature": "function maxProduct(nums: number[]): number {", "container": null, "callable": "maxProduct", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,465
maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts
Medium
You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and verticalCuts where: - horizontalCuts[i] is the distance from the top of the rectangular cake to the i^th horizontal cut and similarly, and - verticalCuts[j] is the distance from the left of the rectangular cake to the j^th ver...
{ "language": "python", "source": "def check(candidate):\n assert candidate(h = 10,w = 10,horizontalCuts = [2, 5, 7],verticalCuts = [2, 5, 7]) == 9\n assert candidate(h = 5,w = 4,horizontalCuts = [3, 1],verticalCuts = [1]) == 6\n assert candidate(h = 5,w = 4,horizontalCuts = [1, 2, 4],verticalCuts = [1, 3]...
[ "5\n4\n[1,2,4]\n[1,3]", "5\n4\n[3,1]\n[1]", "5\n4\n[3]\n[3]" ]
[ "Sort the arrays, then compute the maximum difference between two consecutive elements for horizontal cuts and vertical cuts.", "The answer is the product of these maximum values in horizontal cuts and vertical cuts." ]
{ "canonical_parameter_names": [ "h", "w", "horizontalCuts", "verticalCuts" ], "leetcode_dataset_entry_point": "Solution().maxArea", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T2...
typescript
{ "raw_signature": "function maxArea(h: number, w: number, horizontalCuts: number[], verticalCuts: number[]): number {", "container": null, "callable": "maxArea", "parameters": [ { "name": "h", "type": "number" }, { "name": "w", "type": "number" }, { "name": "ho...
1,466
reorder-routes-to-make-all-paths-lead-to-the-city-zero
Medium
There are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to orient the roads in one direction because they are too narrow. Roads are represented by connections where connec...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 7,connections = [[1, 0], [2, 0], [3, 1], [4, 0], [5, 0], [6, 4]]) == 0\n assert candidate(n = 6,connections = [[0, 1], [1, 3], [2, 3], [4, 0], [4, 5]]) == 3\n assert candidate(n = 5,connections = [[1, 0], [1, 2], [3, 2], [3, 4]...
[ "6\n[[0,1],[1,3],[2,3],[4,0],[4,5]]", "5\n[[1,0],[1,2],[3,2],[3,4]]", "3\n[[1,0],[2,0]]" ]
[ "Treat the graph as undirected. Start a dfs from the root, if you come across an edge in the forward direction, you need to reverse the edge." ]
{ "canonical_parameter_names": [ "n", "connections" ], "leetcode_dataset_entry_point": "Solution().minReorder", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:02", "tests_total": 57...
typescript
{ "raw_signature": "function minReorder(n: number, connections: number[][]): number {", "container": null, "callable": "minReorder", "parameters": [ { "name": "n", "type": "number" }, { "name": "connections", "type": "number[][]" } ], "return_type": "number", "signa...
1,467
probability-of-a-two-boxes-having-the-same-number-of-distinct-balls
Hard
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i. All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio...
{ "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,1]", "[2,1,1]", "[1,2,1,2]" ]
[ "Check how many ways you can distribute the balls between the boxes.", "Consider that one way you will use (x1, x2, x3, ..., xk) where xi is the number of balls from colour i. The probability of achieving this way randomly is ( (ball1 C x1) * (ball2 C x2) * (ball3 C x3) * ... * (ballk C xk)) / (2n C n).", "The ...
{ "canonical_parameter_names": [ "balls" ], "leetcode_dataset_entry_point": "Solution().getProbability", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:04", "tests_total": 102, "tests...
typescript
{ "raw_signature": "function getProbability(balls: number[]): number {", "container": null, "callable": "getProbability", "parameters": [ { "name": "balls", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
1,470
shuffle-the-array
Easy
Given the array nums consisting of 2n elements in the form [x_1,x_2,...,x_n,y_1,y_2,...,y_n]. Return the array in the form [x_1,y_1,x_2,y_2,...,x_n,y_n]. Example 1: Input: nums = [2,5,1,3,4,7], n = 3 Output: [2,3,5,4,1,7] Explanation: Since x_1=2, x_2=5, x_3=1, y_1=3, y_2=4, y_3=7 then the answer is [2,3,5,4,1,7]. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],n = 6) == [5, 11, 6, 12, 7, 13, 8, 14, 9, 15, 10, 16]\n assert candidate(nums = [2, 5, 1, 3, 4, 7],n = 3) == [2, 3, 5, 4, 1, 7]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 7...
[ "[2,5,1,3,4,7]\n3", "[1,2,3,4,4,3,2,1]\n4", "[1,1,2,2]\n2" ]
[ "Use two pointers to create the new array of 2n elements. The first starting at the beginning and the other starting at (n+1)th position. Alternate between them and create the new array." ]
{ "canonical_parameter_names": [ "nums", "n" ], "leetcode_dataset_entry_point": "Solution().shuffle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:08", "tests_total": 71, "tests...
typescript
{ "raw_signature": "function shuffle(nums: number[], n: number): number[] {", "container": null, "callable": "shuffle", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "n", "type": "number" } ], "return_type": "number[]", "signature_source": "leetc...
1,471
the-k-strongest-values-in-an-array
Medium
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the centre of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in t...
{ "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 ...
[ "[1,2,3,4,5]\n2", "[1,1,3,5,5]\n2", "[6,7,11,7,6,8]\n5" ]
[ "Calculate the centre of the array as defined in the statement.", "Use custom sort function to sort values (Strongest first), then slice the first k." ]
{ "canonical_parameter_names": [ "arr", "k" ], "leetcode_dataset_entry_point": "Solution().getStrongest", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:11", "tests_total": 91, "t...
typescript
{ "raw_signature": "function getStrongest(arr: number[], k: number): number[] {", "container": null, "callable": "getStrongest", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number[]", "signature_source"...
1,473
paint-house-iii
Hard
There is a row of m houses in a small city, each house must be painted with one of the n colors (labeled from 1 to n), some houses that have been painted last summer should not be painted again. A neighborhood is a maximal group of continuous houses that are painted with the same color. - For example: houses = [1,2,2...
{ "language": "python", "source": "def check(candidate):\n assert candidate(houses = [1, 0, 0, 0, 0],cost = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],m = 5,n = 2,target = 2) == 15\n assert candidate(houses = [0, 0, 0, 0, 0],cost = [[10, 20, 30, 40], [20, 30, 40, 50], [30, 40, 50, 60], [40, 50, 60, 70], [50, 60...
[ "[0,0,0,0,0]\n[[1,10],[10,1],[10,1],[1,10],[5,1]]\n5\n2\n3", "[0,2,1,2,0]\n[[1,10],[10,1],[10,1],[1,10],[5,1]]\n5\n2\n3", "[3,1,2,3]\n[[1,1,1],[1,1,1],[1,1,1],[1,1,1]]\n4\n3\n3" ]
[ "Use Dynamic programming.", "Define dp[i][j][k] as the minimum cost where we have k neighborhoods in the first i houses and the i-th house is painted with the color j." ]
{ "canonical_parameter_names": [ "houses", "cost", "m", "n", "target" ], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:...
typescript
{ "raw_signature": "function minCost(houses: number[], cost: number[][], m: number, n: number, target: number): number {", "container": null, "callable": "minCost", "parameters": [ { "name": "houses", "type": "number[]" }, { "name": "cost", "type": "number[][]" }, { ...
1,475
final-prices-with-a-special-discount-in-a-shop
Easy
You are given an integer array prices where prices[i] is the price of the i^th item in a shop. There is a special discount for items in the shop. If you buy the i^th item, then you will receive a discount equivalent to prices[j] where j is the minimum index such that j > i and prices[j] <= prices[i]. Otherwise, you wi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(prices = [5, 5, 5, 5, 5]) == [0, 0, 0, 0, 5]\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(prices = [8, 4, 6, 2, 3]) == [4, 2, 4, 2, 3]\n assert candidate(price...
[ "[8,4,6,2,3]", "[1,2,3,4,5]", "[10,1,1,6]" ]
[ "Use brute force: For the ith item in the shop with a loop find the first position j satisfying the conditions and apply the discount, otherwise, the discount is 0." ]
{ "canonical_parameter_names": [ "prices" ], "leetcode_dataset_entry_point": "Solution().finalPrices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:18", "tests_total": 117, "tests_d...
typescript
{ "raw_signature": "function finalPrices(prices: number[]): number[] {", "container": null, "callable": "finalPrices", "parameters": [ { "name": "prices", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
1,477
find-two-non-overlapping-sub-arrays-each-with-target-sum
Medium
You are given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with a sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [5, 5, 5, 5, 5],target = 10) == 4\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 15) == 5\n assert candidate(arr = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],target = 6) == 6\n assert candidate(arr = [1, 1, 1, 2, 2,...
[ "[3,2,2,4,3]\n3", "[7,3,4,7]\n7", "[4,3,2,6,2,3,4]\n6" ]
[ "Let's create two arrays prefix and suffix where prefix[i] is the minimum length of sub-array ends before i and has sum = k, suffix[i] is the minimum length of sub-array starting at or after i and has sum = k.", "The answer we are searching for is min(prefix[i] + suffix[i]) for all values of i from 0 to n-1 where...
{ "canonical_parameter_names": [ "arr", "target" ], "leetcode_dataset_entry_point": "Solution().minSumOfLengths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:20", "tests_total": ...
typescript
{ "raw_signature": "function minSumOfLengths(arr: number[], target: number): number {", "container": null, "callable": "minSumOfLengths", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "target", "type": "number" } ], "return_type": "number", "signa...
1,478
allocate-mailboxes
Hard
Given the array houses where houses[i] is the location of the i^th house along a street and an integer k, allocate k mailboxes in the street. Return the minimum total distance between each house and its nearest mailbox. The test cases are generated so that the answer fits in a 32-bit integer. Example 1: Input: hous...
{ "language": "python", "source": "def check(candidate):\n assert candidate(houses = [10, 5, 17, 1, 18, 2, 12, 9],k = 3) == 8\n assert candidate(houses = [5, 10, 15, 20, 25],k = 2) == 15\n assert candidate(houses = [3, 6, 14, 10],k = 4) == 0\n assert candidate(houses = [3, 6, 14, 16, 25, 28, 30],k = 2) ...
[ "[1,4,8,10,20]\n3", "[2,3,5,12,18]\n2" ]
[ "If k =1, the minimum distance is obtained allocating the mailbox in the median of the array houses.", "Generalize this idea, using dynamic programming allocating k mailboxes." ]
{ "canonical_parameter_names": [ "houses", "k" ], "leetcode_dataset_entry_point": "Solution().minDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:22", "tests_total": 108, ...
typescript
{ "raw_signature": "function minDistance(houses: number[], k: number): number {", "container": null, "callable": "minDistance", "parameters": [ { "name": "houses", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source"...
1,480
running-sum-of-1d-array
Easy
Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums. Example 1: Input: nums = [1,2,3,4] Output: [1,3,6,10] Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4]. Example 2: Input: nums = [1,1,1,1,1] Output: [1,2,3,4,5]...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, 2, -3, 4, -5]) == [-1, 1, -2, 2, -3]\n assert candidate(nums = [-5]) == [-5]\n assert candidate(nums = [0, -1, 2, -3, 4]) == [0, -1, 1, -2, 2]\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == [1, 0, 1, 0, 1, 0]\n ...
[ "[1,2,3,4]", "[1,1,1,1,1]", "[3,1,2,10,1]" ]
[ "Think about how we can calculate the i-th number in the running sum from the (i-1)-th number." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().runningSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:24", "tests_total": 95, "tests_dropp...
typescript
{ "raw_signature": "function runningSum(nums: number[]): number[] {", "container": null, "callable": "runningSum", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,481
least-number-of-unique-integers-after-k-removals
Medium
Given an array of integers arr and an integer k. Find the least number of unique integers after removing exactly k elements. Example 1: Input: arr = [5,5,4], k = 1 Output: 1 Explanation: Remove the single 4, only 5 is left. Example 2: Input: arr = [4,3,1,1,3,3,2], k = 3 Output: 2 Explanation: Remove 4, 2 and either...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 1, 1, 1, 1],k = 3) == 1\n assert candidate(arr = [1, 2, 3, 4, 5],k = 2) == 3\n assert candidate(arr = [10, 20, 20, 10, 10, 30, 50, 10, 20],k = 4) == 2\n assert candidate(arr = [10, 20, 30, 40, 50, 60],k = 0) == 6\n ...
[ "[5,5,4]\n1", "[4,3,1,1,3,3,2]\n3" ]
[ "Use a map to count the frequencies of the numbers in the array.", "An optimal strategy is to remove the numbers with the smallest count first." ]
{ "canonical_parameter_names": [ "arr", "k" ], "leetcode_dataset_entry_point": "Solution().findLeastNumOfUniqueInts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:27", "tests_tota...
typescript
{ "raw_signature": "function findLeastNumOfUniqueInts(arr: number[], k: number): number {", "container": null, "callable": "findLeastNumOfUniqueInts", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", ...
1,482
minimum-number-of-days-to-make-m-bouquets
Medium
You are given an integer array bloomDay, an integer m and an integer k. You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden. The garden consists of n flowers, the i^th flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet. Return the minimum n...
{ "language": "python", "source": "def check(candidate):\n assert candidate(bloomDay = [1, 10, 3, 10, 2],m = 3,k = 1) == 3\n assert candidate(bloomDay = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],m = 5,k = 2) == 1\n assert candidate(bloomDay = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 5,k = 1) == 5\n assert candidate(blo...
[ "[1,10,3,10,2]\n3\n1", "[1,10,3,10,2]\n3\n2", "[7,7,7,7,12,7,7]\n2\n3" ]
[ "If we can make m or more bouquets at day x, then we can still make m or more bouquets at any day y > x.", "We can check easily if we can make enough bouquets at day x if we can get group adjacent flowers at day x." ]
{ "canonical_parameter_names": [ "bloomDay", "m", "k" ], "leetcode_dataset_entry_point": "Solution().minDays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:29", "tests_total":...
typescript
{ "raw_signature": "function minDays(bloomDay: number[], m: number, k: number): number {", "container": null, "callable": "minDays", "parameters": [ { "name": "bloomDay", "type": "number[]" }, { "name": "m", "type": "number" }, { "name": "k", "type": "numb...
1,486
xor-operation-in-an-array
Easy
You are given an integer n and an integer start. Define an array nums where nums[i] = start + 2 * i (0-indexed) and n == nums.length. Return the bitwise XOR of all elements of nums. Example 1: Input: n = 5, start = 0 Output: 8 Explanation: Array nums is equal to [0, 2, 4, 6, 8] where (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8. Where ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,start = 3) == 8\n assert candidate(n = 8,start = 12) == 0\n assert candidate(n = 7,start = 2) == 0\n assert candidate(n = 3,start = 2) == 0\n assert candidate(n = 10,start = 1) == 2\n assert candidate(n = 5,start = 0...
[ "5\n0", "4\n3" ]
[ "Simulate the process, create an array nums and return the Bitwise XOR of all elements of it." ]
{ "canonical_parameter_names": [ "n", "start" ], "leetcode_dataset_entry_point": "Solution().xorOperation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:33", "tests_total": 92, ...
typescript
{ "raw_signature": "function xorOperation(n: number, start: number): number {", "container": null, "callable": "xorOperation", "parameters": [ { "name": "n", "type": "number" }, { "name": "start", "type": "number" } ], "return_type": "number", "signature_source": "l...
1,487
making-file-names-unique
Medium
Given an array of strings names of size n. You will create n folders in your file system such that, at the i^th minute, you will create a folder with the name names[i]. Since two files cannot have the same name, if you enter a folder name that was previously used, the system will have a suffix addition to its name in ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(names = ['doc', 'doc(1)', 'image', 'doc(1)', 'doc']) == ['doc', 'doc(1)', 'image', 'doc(1)(1)', 'doc(2)']\n assert candidate(names = ['abcd', 'abcde', 'abcd(1)', 'abcd', 'abcd(2)', 'abcd(1)(1)']) == ['abcd', 'abcde', 'abcd(1)', 'abcd(...
[ "[\"pes\",\"fifa\",\"gta\",\"pes(2019)\"]", "[\"gta\",\"gta(1)\",\"gta\",\"avalon\"]", "[\"onepiece\",\"onepiece(1)\",\"onepiece(2)\",\"onepiece(3)\",\"onepiece\"]" ]
[ "Keep a map of each name and the smallest valid integer that can be appended as a suffix to it.", "If the name is not present in the map, you can use it without adding any suffixes.", "If the name is present in the map, append the smallest proper suffix, and add the new name to the map." ]
{ "canonical_parameter_names": [ "names" ], "leetcode_dataset_entry_point": "Solution().getFolderNames", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:36", "tests_total": 66, "tests_...
typescript
{ "raw_signature": "function getFolderNames(names: string[]): string[] {", "container": null, "callable": "getFolderNames", "parameters": [ { "name": "names", "type": "string[]" } ], "return_type": "string[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
1,488
avoid-flood-in-the-city
Medium
Your country has 10^9 lakes. Initially, all the lakes are empty, but when it rains over the n^th lake, the n^th lake becomes full of water. If it rains over a lake that is full of water, there will be a flood. Your goal is to avoid floods in any lake. Given an integer array rains where: - rains[i] > 0 means there wil...
{ "language": "python", "source": "def check(candidate):\n assert candidate(rains = [0, 1, 1, 0, 2, 0, 1]) == []\n assert candidate(rains = [1, 2, 0, 1, 2]) == []\n assert candidate(rains = [1, 0, 2, 0, 0, 1, 0, 2]) == [-1, 1, -1, 2, 1, -1, 1, -1]\n assert candidate(rains = [0, 0, 0, 0]) == [1, 1, 1, 1]...
[ "[1,2,3,4]", "[1,2,0,0,2,1]", "[1,2,0,1,2]" ]
[ "Keep An array of the last day there was rains over each city.", "Keep an array of the days you can dry a lake when you face one.", "When it rains over a lake, check the first possible day you can dry this lake and assign this day to this lake." ]
{ "canonical_parameter_names": [ "rains" ], "leetcode_dataset_entry_point": "Solution().avoidFlood", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:38", "tests_total": 242, "tests_dro...
typescript
{ "raw_signature": "function avoidFlood(rains: number[]): number[] {", "container": null, "callable": "avoidFlood", "parameters": [ { "name": "rains", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
1,489
find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree
Hard
Given a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [a_i, b_i, weight_i] represents a bidirectional and weighted edge between nodes a_i and b_i. A minimum spanning tree (MST) is a subset of the graph's edges that connects all vertices without cycles ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3,edges = [[0, 1, 1], [1, 2, 1], [0, 2, 2]]) == [[0, 1], []]\n assert candidate(n = 5,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 2], [0, 3, 2], [0, 4, 3], [3, 4, 3], [1, 4, 6]]) == [[0, 1], [2, 3, 4, 5]]\n assert candidate(n = 6,edg...
[ "5\n[[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]", "4\n[[0,1,1],[1,2,1],[2,3,1],[0,3,1]]" ]
[ "Use the Kruskal algorithm to find the minimum spanning tree by sorting the edges and picking edges from ones with smaller weights.", "Use a disjoint set to avoid adding redundant edges that result in a cycle.", "To find if one edge is critical, delete that edge and re-run the MST algorithm and see if the weigh...
{ "canonical_parameter_names": [ "n", "edges" ], "leetcode_dataset_entry_point": "Solution().findCriticalAndPseudoCriticalEdges", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:40", ...
typescript
{ "raw_signature": "function findCriticalAndPseudoCriticalEdges(n: number, edges: number[][]): number[][] {", "container": null, "callable": "findCriticalAndPseudoCriticalEdges", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" } ...
1,491
average-salary-excluding-the-minimum-and-maximum-salary
Easy
You are given an array of unique integers salary where salary[i] is the salary of the i^th employee. Return the average salary of employees excluding the minimum and maximum salary. Answers within 10^-5 of the actual answer will be accepted. Example 1: Input: salary = [4000,3000,1000,2000] Output: 2500.00000 Explana...
{ "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...
[ "[4000,3000,1000,2000]", "[1000,2000,3000]" ]
[ "Get the total sum and subtract the minimum and maximum value in the array. Finally divide the result by n - 2." ]
{ "canonical_parameter_names": [ "salary" ], "leetcode_dataset_entry_point": "Solution().average", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:43", "tests_total": 99, "tests_droppe...
typescript
{ "raw_signature": "function average(salary: number[]): number {", "container": null, "callable": "average", "parameters": [ { "name": "salary", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,492
the-kth-factor-of-n
Medium
You are given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0. Consider a list of all factors of n sorted in ascending order, return the k^th factor in this list or return -1 if n has less than k factors. Example 1: Input: n = 12, k = 3 Output: 3 Explanation: Facto...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 1,k = 1) == 1\n assert candidate(n = 49,k = 3) == 49\n assert candidate(n = 100,k = 5) == 10\n assert candidate(n = 7,k = 2) == 7\n assert candidate(n = 17,k = 2) == 17\n assert candidate(n = 1000,k = 15) == 500\n a...
[ "12\n3", "7\n2", "4\n4" ]
[ "The factors of n will be always in the range [1, n].", "Keep a list of all factors sorted. Loop i from 1 to n and add i if n % i == 0. Return the kth factor if it exist in this list." ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().kthFactor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:45", "tests_total": 81, "tests_...
typescript
{ "raw_signature": "function kthFactor(n: number, k: number): number {", "container": null, "callable": "kthFactor", "parameters": [ { "name": "n", "type": "number" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSn...
1,493
longest-subarray-of-1s-after-deleting-one-element
Medium
Given a binary array nums, you should delete one element from it. Return the size of the longest non-empty subarray containing only 1's in the resulting array. Return 0 if there is no such subarray. Example 1: Input: nums = [1,1,0,1] Output: 3 Explanation: After deleting the number in position 2, [1,1,1] contains 3 ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1]) == 4\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 2\n assert candidate(nums = [0, 0, 0]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n as...
[ "[1,1,0,1]", "[0,1,1,1,0,1,1,0,1]", "[1,1,1]" ]
[ "Maintain a sliding window where there is at most one zero in it." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().longestSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:47", "tests_total": 92, "tests_...
typescript
{ "raw_signature": "function longestSubarray(nums: number[]): number {", "container": null, "callable": "longestSubarray", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
1,494
parallel-courses-ii
Hard
You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCourse_i, nextCourse_i], representing a prerequisite relationship between course prevCourse_i and course nextCourse_i: course prevCourse_i has to be taken before cour...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,relations = [[2, 1], [3, 1], [1, 4]],k = 2) == 3\n assert candidate(n = 5,relations = [],k = 3) == 2\n assert candidate(n = 5,relations = [[2, 1], [3, 1], [4, 1], [1, 5]],k = 2) == 4\n assert candidate(n = 3,relations = [[...
[ "4\n[[2,1],[3,1],[1,4]]\n2", "5\n[[2,1],[3,1],[4,1],[1,5]]\n2" ]
[ "Use backtracking with states (bitmask, degrees) where bitmask represents the set of courses, if the ith bit is 1 then the ith course was taken, otherwise, you can take the ith course. Degrees represent the degree for each course (nodes in the graph).", "Note that you can only take nodes (courses) with degree = 0...
{ "canonical_parameter_names": [ "n", "relations", "k" ], "leetcode_dataset_entry_point": "Solution().minNumberOfSemesters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:50", ...
typescript
{ "raw_signature": "function minNumberOfSemesters(n: number, relations: number[][], k: number): number {", "container": null, "callable": "minNumberOfSemesters", "parameters": [ { "name": "n", "type": "number" }, { "name": "relations", "type": "number[][]" }, { ...
1,496
path-crossing
Easy
Given a string path, where path[i] = 'N', 'S', 'E' or 'W', each representing moving one unit north, south, east, or west, respectively. You start at the origin (0, 0) on a 2D plane and walk on the path specified by path. Return true if the path crosses itself at any point, that is, if at any time you are on a location...
{ "language": "python", "source": "def check(candidate):\n assert candidate(path = \"NEESWNWWSNNWNSSSWEWEWEWE\") == True\n assert candidate(path = \"NNNSSSSSSEEEEEEEWWWWWWWWW\") == True\n assert candidate(path = \"NEWSNEWS\") == True\n assert candidate(path = \"EWEWEWEW\") == True\n assert candidate(...
[ "\"NES\"", "\"NESWW\"" ]
[ "Simulate the process while keeping track of visited points.", "Use a set to store previously visited points." ]
{ "canonical_parameter_names": [ "path" ], "leetcode_dataset_entry_point": "Solution().isPathCrossing", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:52", "tests_total": 186, "tests_...
typescript
{ "raw_signature": "function isPathCrossing(path: string): boolean {", "container": null, "callable": "isPathCrossing", "parameters": [ { "name": "path", "type": "string" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
1,497
check-if-array-pairs-are-divisible-by-k
Medium
Given an array of integers arr of even length n and an integer k. We want to divide the array into exactly n / 2 pairs such that the sum of each pair is divisible by k. Return true If you can find a way to do that or false otherwise. Example 1: Input: arr = [1,2,3,4,5,10,6,7,8,9], k = 5 Output: true Explanation: Pa...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8],k = 4) == True\n assert candidate(arr = [0, 0, 0, 0],k = 1) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6],k = 10) == False\n assert candidate(arr = [-1, 1, -2, 2, -3, 3],k = 2) == True\n a...
[ "[1,2,3,4,5,10,6,7,8,9]\n5", "[1,2,3,4,5,6]\n7", "[1,2,3,4,5,6]\n10" ]
[ "Keep an array of the frequencies of ((x % k) + k) % k for each x in arr.", "for each i in [0, k - 1] we need to check if freq[i] == freq[k - i]", "Take care of the case when i == k - i and when i == 0" ]
{ "canonical_parameter_names": [ "arr", "k" ], "leetcode_dataset_entry_point": "Solution().canArrange", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:54", "tests_total": 93, "tes...
typescript
{ "raw_signature": "function canArrange(arr: number[], k: number): boolean {", "container": null, "callable": "canArrange", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "boolean", "signature_source": "lee...
1,498
number-of-subsequences-that-satisfy-the-given-sum-condition
Medium
You are given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too large, return it modulo 10^9 + 7. Example 1: Input: nums = [3,5,6,7], target = 9 Output...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],target = 10) == 31\n assert candidate(nums = [10, 10, 10, 10],target = 20) == 15\n assert candidate(nums = [1, 3, 5, 7],target = 8) == 10\n assert candidate(nums = [1, 2, 3, 4, 5],target = 5) == 10\n as...
[ "[3,5,6,7]\n9", "[3,3,6,8]\n10", "[2,3,3,4,6,7]\n12" ]
[ "Sort the array nums.", "Use two pointers approach: Given an index i (choose it as the minimum in a subsequence) find the maximum j where j ≥ i and nums[i] +nums[j] ≤ target.", "Count the number of subsequences." ]
{ "canonical_parameter_names": [ "nums", "target" ], "leetcode_dataset_entry_point": "Solution().numSubseq", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:56", "tests_total": 81, ...
typescript
{ "raw_signature": "function numSubseq(nums: number[], target: number): number {", "container": null, "callable": "numSubseq", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "target", "type": "number" } ], "return_type": "number", "signature_sourc...
1,499
max-value-of-equation
Hard
You are given an array points containing the coordinates of points on a 2D plane, sorted by the x-values, where points[i] = [x_i, y_i] such that x_i < x_j for all 1 <= i < j <= points.length. You are also given an integer k. Return the maximum value of the equation y_i + y_j + |x_i - x_j| where |x_i - x_j| <= k and 1 ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 3], [2, 0], [5, 10], [6, -10]],k = 1) == 4\n assert candidate(points = [[1, 5], [2, 3], [4, 7], [8, 10]],k = 6) == 21\n assert candidate(points = [[1, 3], [2, 0], [5, 10], [6, -10], [7, 5]],k = 4) == 17\n assert ca...
[ "[[1,3],[2,0],[5,10],[6,-10]]\n1", "[[0,0],[3,0],[9,2]]\n3" ]
[ "Use a priority queue to store for each point i, the tuple [yi-xi, xi]", "Loop through the array and pop elements from the heap if the condition xj - xi > k, where j is the current index and i is the point on top the queue.", "After popping elements from the queue. If the queue is not empty, calculate the equat...
{ "canonical_parameter_names": [ "points", "k" ], "leetcode_dataset_entry_point": "Solution().findMaxValueOfEquation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:21:59", "tests_tot...
typescript
{ "raw_signature": "function findMaxValueOfEquation(points: number[][], k: number): number {", "container": null, "callable": "findMaxValueOfEquation", "parameters": [ { "name": "points", "type": "number[][]" }, { "name": "k", "type": "number" } ], "return_type": "num...
1,502
can-make-arithmetic-progression-from-sequence
Easy
A sequence of numbers is called an arithmetic progression if the difference between any two consecutive elements is the same. Given an array of numbers arr, return true if the array can be rearranged to form an arithmetic progression. Otherwise, return false. Example 1: Input: arr = [3,5,1] Output: true Explanation:...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [2, 4, 6, 8, 10]) == True\n assert candidate(arr = [-1, 1, 0]) == True\n assert candidate(arr = [5, 3, 1, 4, 2]) == True\n assert candidate(arr = [10, 20, 30, 40, 50]) == True\n assert candidate(arr = [10, 5, 15]) == Tr...
[ "[3,5,1]", "[1,2,4]" ]
[ "Consider that any valid arithmetic progression will be in sorted order.", "Sort the array, then check if the differences of all consecutive elements are equal." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().canMakeArithmeticProgression", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:01", "tests_total": 1...
typescript
{ "raw_signature": "function canMakeArithmeticProgression(arr: number[]): boolean {", "container": null, "callable": "canMakeArithmeticProgression", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_s...
1,503
last-moment-before-all-ants-fall-out-of-a-plank
Medium
We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with a speed of 1 unit per second. Some of the ants move to the left, the other move to the right. When two ants moving in two different directions meet at some point, they change their directions and continue moving again...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 15,left = [10, 11, 12],right = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 15\n assert candidate(n = 1,left = [],right = [0]) == 1\n assert candidate(n = 5,left = [5],right = [0]) == 5\n assert candidate(n = 1,left = [1],right = []) ...
[ "4\n[4,3]\n[0,1]", "7\n[]\n[0,1,2,3,4,5,6,7]", "7\n[0,1,2,3,4,5,6,7]\n[]" ]
[ "The ants change their way when they meet is equivalent to continue moving without changing their direction.", "Answer is the max distance for one ant to reach the end of the plank in the facing direction." ]
{ "canonical_parameter_names": [ "n", "left", "right" ], "leetcode_dataset_entry_point": "Solution().getLastMoment", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:03", "tests_t...
typescript
{ "raw_signature": "function getLastMoment(n: number, left: number[], right: number[]): number {", "container": null, "callable": "getLastMoment", "parameters": [ { "name": "n", "type": "number" }, { "name": "left", "type": "number[]" }, { "name": "right", ...
1,504
count-submatrices-with-all-ones
Medium
Given an m x n binary matrix mat, return the number of submatrices that have all ones. Example 1: Input: mat = [[1,0,1],[1,1,0],[1,1,0]] Output: 13 Explanation: There are 6 rectangles of side 1x1. There are 2 rectangles of side 1x2. There are 3 rectangles of side 2x1. There is 1 rectangle of side 2x2. There is 1 rect...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[0, 0], [0, 0]]) == 0\n assert candidate(mat = [[1, 0, 1], [1, 1, 0], [1, 1, 0]]) == 13\n assert candidate(mat = [[1, 0], [0, 1]]) == 2\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 60\n asser...
[ "[[1,0,1],[1,1,0],[1,1,0]]", "[[0,1,1,0],[0,1,1,1],[1,1,1,0]]" ]
[ "For each row i, create an array nums where: if mat[i][j] == 0 then nums[j] = 0 else nums[j] = nums[j-1] +1.", "In the row i, number of rectangles between column j and k(inclusive) and ends in row i, is equal to SUM(min(nums[j, .. idx])) where idx go from j to k. Expected solution is O(n^3)." ]
{ "canonical_parameter_names": [ "mat" ], "leetcode_dataset_entry_point": "Solution().numSubmat", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:05", "tests_total": 90, "tests_dropped...
typescript
{ "raw_signature": "function numSubmat(mat: number[][]): number {", "container": null, "callable": "numSubmat", "parameters": [ { "name": "mat", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,505
minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits
Hard
You are given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times. Return the minimum integer you can obtain also as a string. Example 1: Input: num = "4321", k = 4 Output: "1342" Explanation: The steps to obtai...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = \"36789\",k = 1000) == \"36789\"\n assert candidate(num = \"100\",k = 1) == \"010\"\n assert candidate(num = \"9876543210\",k = 9) == \"0987654321\"\n assert candidate(num = \"9876543210\",k = 100) == \"0123456789\"\n a...
[ "\"4321\"\n4", "\"100\"\n1", "\"36789\"\n1000" ]
[ "We want to make the smaller digits the most significant digits in the number.", "For each index i, check the smallest digit in a window of size k and append it to the answer. Update the indices of all digits in this range accordingly." ]
{ "canonical_parameter_names": [ "num", "k" ], "leetcode_dataset_entry_point": "Solution().minInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:07", "tests_total": 106, "te...
typescript
{ "raw_signature": "function minInteger(num: string, k: number): string {", "container": null, "callable": "minInteger", "parameters": [ { "name": "num", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "string", "signature_source": "leetcode/...
1,507
reformat-date
Easy
Given a date string in the form Day Month Year, where: - Day is in the set {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}. - Month is in the set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}. - Year is in the range [1900, 2100]. Convert the date string to the format YYYY-MM-D...
{ "language": "python", "source": "def check(candidate):\n assert candidate(date = \"15th Aug 2022\") == \"2022-08-15\"\n assert candidate(date = \"22nd Aug 1999\") == \"1999-08-22\"\n assert candidate(date = \"3rd Mar 1987\") == \"1987-03-03\"\n assert candidate(date = \"3rd Nov 2022\") == \"2022-11-03...
[ "\"20th Oct 2052\"", "\"6th Jun 1933\"", "\"26th May 1960\"" ]
[ "Handle the conversions of day, month and year separately.", "Notice that days always have a two-word ending, so if you erase the last two characters of this days you'll get the number." ]
{ "canonical_parameter_names": [ "date" ], "leetcode_dataset_entry_point": "Solution().reformatDate", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:10", "tests_total": 111, "tests_dr...
typescript
{ "raw_signature": "function reformatDate(date: string): string {", "container": null, "callable": "reformatDate", "parameters": [ { "name": "date", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,508
range-sum-of-sorted-subarray-sums
Medium
You are given the array nums consisting of n positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4],n = 4,left = 3,right = 4) == 6\n assert candidate(nums = [10, 20, 30],n = 3,left = 1,right = 3) == 60\n assert candidate(nums = [5, 1, 2],n = 3,left = 1,right = 4) == 11\n assert candidate(nums = [1, 2, 3, 4]...
[ "[1,2,3,4]\n4\n1\n5", "[1,2,3,4]\n4\n3\n4", "[1,2,3,4]\n4\n1\n10" ]
[ "Compute all sums and save it in array.", "Then just go from LEFT to RIGHT index and calculate answer modulo 1e9 + 7." ]
{ "canonical_parameter_names": [ "nums", "n", "left", "right" ], "leetcode_dataset_entry_point": "Solution().rangeSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:13", "...
typescript
{ "raw_signature": "function rangeSum(nums: number[], n: number, left: number, right: number): number {", "container": null, "callable": "rangeSum", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "n", "type": "number" }, { "name": "left", ...
1,509
minimum-difference-between-largest-and-smallest-value-in-three-moves
Medium
You are given an integer array nums. In one move, you can choose one element of nums and change it to any value. Return the minimum difference between the largest and smallest value of nums after performing at most three moves. Example 1: Input: nums = [5,3,2,4] Output: 0 Explanation: We can make at most 3 moves. I...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 100, 20]) == 0\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 6\n assert candidate(nums = ...
[ "[5,3,2,4]", "[1,5,0,10,14]", "[3,100,20]" ]
[ "The minimum difference possible is obtained by removing three elements between the three smallest and three largest values in the array." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:15", "tests_total": 109, "tests_d...
typescript
{ "raw_signature": "function minDifference(nums: number[]): number {", "container": null, "callable": "minDifference", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
1,510
stone-game-iv
Hard
Alice and Bob take turns playing a game, with Alice starting first. Initially, there are n stones in a pile. On each player's turn, that player makes a move consisting of removing any non-zero square number of stones in the pile. Also, if a player cannot make a move, he/she loses the game. Given a positive integer n...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 101) == True\n assert candidate(n = 3) == True\n assert candidate(n = 100) == True\n assert candidate(n = 30) == True\n assert candidate(n = 5) == False\n assert candidate(n = 4) == True\n assert candidate(n = 200) ...
[ "1", "2", "4" ]
[ "Use dynamic programming to keep track of winning and losing states. Given some number of stones, Alice can win if she can force Bob onto a losing state." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().winnerSquareGame", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:18", "tests_total": 24, "tests_dr...
typescript
{ "raw_signature": "function winnerSquareGame(n: number): boolean {", "container": null, "callable": "winnerSquareGame", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,512
number-of-good-pairs
Easy
Given an array of integers nums, return the number of good pairs. A pair (i, j) is called good if nums[i] == nums[j] and i < j. Example 1: Input: nums = [1,2,3,1,1,3] Output: 4 Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed. Example 2: Input: nums = [1,1,1,1] Output: 6 Explanation: Each p...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 6, 7, 8, 9, 5]) == 1\n assert candidate(nums = [1, 1, 1, 1]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7])...
[ "[1,2,3,1,1,3]", "[1,1,1,1]", "[1,2,3]" ]
[ "Count how many times each number appears. If a number appears n times, then n * (n – 1) // 2 good pairs can be made with this number." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().numIdenticalPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:20", "tests_total": 102, "tes...
typescript
{ "raw_signature": "function numIdenticalPairs(nums: number[]): number {", "container": null, "callable": "numIdenticalPairs", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
1,513
number-of-substrings-with-only-1s
Medium
Given a binary string s, return the number of substrings with all characters 1's. Since the answer may be too large, return it modulo 10^9 + 7. Example 1: Input: s = "0110111" Output: 9 Explanation: There are 9 substring in total with only 1's characters. "1" -> 5 times. "11" -> 3 times. "111" -> 1 time. Example 2: ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"1100110011\") == 9\n assert candidate(s = \"101\") == 2\n assert candidate(s = \"1001001001\") == 4\n assert candidate(s = \"1111101111\") == 25\n assert candidate(s = \"110110110110110\") == 15\n assert candidate(s ...
[ "\"0110111\"", "\"101\"", "\"111111\"" ]
[ "Count number of 1s in each consecutive-1 group. For a group with n consecutive 1s, the total contribution of it to the final answer is (n + 1) * n // 2." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().numSub", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:22", "tests_total": 28, "tests_dropped": 0,...
typescript
{ "raw_signature": "function numSub(s: string): number {", "container": null, "callable": "numSub", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,514
path-with-maximum-probability
Medium
You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with a probability of success of traversing that edge succProb[i]. Given two nodes start and end, find the path with the maximum probability of succe...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat...
[ "3\n[[0,1],[1,2],[0,2]]\n[0.5,0.5,0.2]\n0\n2", "3\n[[0,1],[1,2],[0,2]]\n[0.5,0.5,0.3]\n0\n2", "3\n[[0,1]]\n[0.5]\n0\n2" ]
[ "Multiplying probabilities will result in precision errors.", "Take log probabilities to sum up numbers instead of multiplying them.", "Use Dijkstra's algorithm to find the minimum path between the two nodes after negating all costs." ]
{ "canonical_parameter_names": [ "n", "edges", "succProb", "start_node", "end_node" ], "leetcode_dataset_entry_point": "Solution().maxProbability", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched...
typescript
{ "raw_signature": "function maxProbability(n: number, edges: number[][], succProb: number[], start_node: number, end_node: number): number {", "container": null, "callable": "maxProbability", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "numb...
1,515
best-position-for-a-service-centre
Hard
A delivery company wants to build a new service center in a new city. The company knows the positions of all the customers in this city on a 2D-Map and wants to build the new center in a position such that the sum of the euclidean distances to all customers is minimum. Given an array positions where positions[i] = [x_...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat...
[ "[[0,1],[1,0],[1,2],[2,1]]", "[[1,1],[3,3]]" ]
[ "The problem can be reworded as, giving a set of points on a 2d-plane, return the geometric median.", "Loop over each triplet of points (positions[i], positions[j], positions[k]) where i < j < k, get the centre of the circle which goes throw the 3 points, check if all other points lie in this circle." ]
{ "canonical_parameter_names": [ "positions" ], "leetcode_dataset_entry_point": "Solution().getMinDistSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:27", "tests_total": 104, "te...
typescript
{ "raw_signature": "function getMinDistSum(positions: number[][]): number {", "container": null, "callable": "getMinDistSum", "parameters": [ { "name": "positions", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcod...
1,518
water-bottles
Easy
There are numBottles water bottles that are initially full of water. You can exchange numExchange empty water bottles from the market with one full water bottle. The operation of drinking a full water bottle turns it into an empty bottle. Given the two integers numBottles and numExchange, return the maximum number of...
{ "language": "python", "source": "def check(candidate):\n assert candidate(numBottles = 10,numExchange = 2) == 19\n assert candidate(numBottles = 20,numExchange = 6) == 23\n assert candidate(numBottles = 100,numExchange = 10) == 111\n assert candidate(numBottles = 5,numExchange = 5) == 6\n assert ca...
[ "9\n3", "15\n4" ]
[ "Simulate the process until there are not enough empty bottles for even one full bottle of water." ]
{ "canonical_parameter_names": [ "numBottles", "numExchange" ], "leetcode_dataset_entry_point": "Solution().numWaterBottles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:29", "te...
typescript
{ "raw_signature": "function numWaterBottles(numBottles: number, numExchange: number): number {", "container": null, "callable": "numWaterBottles", "parameters": [ { "name": "numBottles", "type": "number" }, { "name": "numExchange", "type": "number" } ], "return_type"...
1,519
number-of-nodes-in-the-sub-tree-with-the-same-label
Medium
You are given a tree (i.e. a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of the tree is the node 0, and each node of the tree has a label which is a lower-case character given in the string labels (i.e. The node with the number i has t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [0, 3]],labels = \"bbbb\") == [4, 2, 1, 1]\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],labels = \"cbabaa\") == [1, 2, 2, 1, 1, 1]\n assert candidate(n = 6,edges = [[0, 1]...
[ "7\n[[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]]\n\"abaedcd\"", "4\n[[0,1],[1,2],[0,3]]\n\"bbbb\"", "5\n[[0,1],[0,2],[1,3],[0,4]]\n\"aabab\"" ]
[ "Start traversing the tree and each node should return a vector to its parent node.", "The vector should be of length 26 and have the count of all the labels in the sub-tree of this node." ]
{ "canonical_parameter_names": [ "n", "edges", "labels" ], "leetcode_dataset_entry_point": "Solution().countSubTrees", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:32", "tests...
typescript
{ "raw_signature": "function countSubTrees(n: number, edges: number[][], labels: string): number[] {", "container": null, "callable": "countSubTrees", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" }, { "name": "labels...
1,520
maximum-number-of-non-overlapping-substrings
Hard
Given a string s of lowercase letters, you need to find the maximum number of non-empty substrings of s that meet the following conditions: 1. The substrings do not overlap, that is for any two substrings s[i..j] and s[x..y], either j < x or i > y is true. 2. A substring that contains a certain character c must also c...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ...
[ "\"adefaddaccc\"", "\"abbaccd\"" ]
[ "Notice that it's impossible for any two valid substrings to overlap unless one is inside another.", "We can start by finding the starting and ending index for each character.", "From these indices, we can form the substrings by expanding each character's range if necessary (if another character exists in the r...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().maxNumOfSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:34", "tests_total": 59, "tests_...
typescript
{ "raw_signature": "function maxNumOfSubstrings(s: string): string[] {", "container": null, "callable": "maxNumOfSubstrings", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
1,521
find-a-value-of-a-mysterious-function-closest-to-target
Hard
Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible. Return the minimum possible value of |func(arr, l, r) - target|. Notice that func should be called with the v...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [7, 7, 7, 7, 7, 7],target = 8) == 1\n assert candidate(arr = [1000000],target = 1000000) == 0\n assert candidate(arr = [2, 4, 6, 8, 10],target = 7) == 1\n assert candidate(arr = [5, 5, 5, 5, 5],target = 5) == 0\n assert...
[ "[9,12,3,7,15]\n5", "[1000000,1000000,1000000]\n1", "[1,2,4,8,16]\n0" ]
[ "If the and value of sub-array arr[i...j] is ≥ the and value of the sub-array arr[i...j+1].", "For each index i using binary search or ternary search find the index j where |target - AND(arr[i...j])| is minimum, minimize this value with the global answer." ]
{ "canonical_parameter_names": [ "arr", "target" ], "leetcode_dataset_entry_point": "Solution().closestToTarget", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:36", "tests_total": ...
typescript
{ "raw_signature": "function closestToTarget(arr: number[], target: number): number {", "container": null, "callable": "closestToTarget", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "target", "type": "number" } ], "return_type": "number", "signa...
1,523
count-odd-numbers-in-an-interval-range
Easy
Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive). Example 1: Input: low = 3, high = 7 Output: 3 Explanation: The odd numbers between 3 and 7 are [3,5,7]. Example 2: Input: low = 8, high = 10 Output: 1 Explanation: The odd numbers between 8 and 10 are [9]...
{ "language": "python", "source": "def check(candidate):\n assert candidate(low = 3,high = 7) == 3\n assert candidate(low = 0,high = 1000000000) == 500000000\n assert candidate(low = 0,high = 1) == 1\n assert candidate(low = 500000000,high = 500000000) == 0\n assert candidate(low = 1,high = 100000000...
[ "3\n7", "8\n10" ]
[ "If the range (high - low + 1) is even, the number of even and odd numbers in this range will be the same.", "If the range (high - low + 1) is odd, the solution will depend on the parity of high and low." ]
{ "canonical_parameter_names": [ "low", "high" ], "leetcode_dataset_entry_point": "Solution().countOdds", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:38", "tests_total": 93, "t...
typescript
{ "raw_signature": "function countOdds(low: number, high: number): number {", "container": null, "callable": "countOdds", "parameters": [ { "name": "low", "type": "number" }, { "name": "high", "type": "number" } ], "return_type": "number", "signature_source": "leetc...
1,524
number-of-sub-arrays-with-odd-sum
Medium
Given an array of integers arr, return the number of subarrays with an odd sum. Since the answer can be very large, return it modulo 10^9 + 7. Example 1: Input: arr = [1,3,5] Output: 4 Explanation: All subarrays are [[1],[1,3],[1,3,5],[3],[3,5],[5]] All sub-arrays sum are [1,4,9,3,8,5]. Odd sums are [1,9,3,5] so the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [2, 4, 6, 8, 10]) == 0\n assert candidate(arr = [100, 100, 100, 100, 100]) == 0\n assert candidate(arr = [50, 50, 50, 50, 50]) == 0\n assert candidate(arr = [1, 2, 3]) == 4\n assert candidate(arr = [2, 2, 2, 2, 2]) == 0...
[ "[1,3,5]", "[2,4,6]", "[1,2,3,4,5,6,7]" ]
[ "Can we use the accumulative sum to keep track of all the odd-sum sub-arrays ?", "if the current accu sum is odd, we care only about previous even accu sums and vice versa." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().numOfSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:41", "tests_total": 87, "tests_dr...
typescript
{ "raw_signature": "function numOfSubarrays(arr: number[]): number {", "container": null, "callable": "numOfSubarrays", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
1,525
number-of-good-ways-to-split-a-string
Medium
You are given a string s. A split is called good if you can split s into two non-empty strings s_left and s_right where their concatenation is equal to s (i.e., s_left + s_right = s) and the number of distinct letters in s_left and s_right is the same. Return the number of good splits you can make in s. Example 1: ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"xyzxyzxyz\") == 4\n assert candidate(s = \"aabbcc\") == 1\n assert candidate(s = \"abcde\") == 0\n assert candidate(s = \"abcdefghij\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 1\n assert candid...
[ "\"aacaba\"", "\"abcd\"" ]
[ "Use two HashMap to store the counts of distinct letters in the left and right substring divided by the current index." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().numSplits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:43", "tests_total": 81, "tests_dropped":...
typescript
{ "raw_signature": "function numSplits(s: string): number {", "container": null, "callable": "numSplits", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,526
minimum-number-of-increments-on-subarrays-to-form-a-target-array
Hard
You are given an integer array target. You have an integer array initial of the same size as target with all elements initially zeros. In one operation you can choose any subarray from initial and increment each value by one. Return the minimum number of operations to form a target array from initial. The test cases...
{ "language": "python", "source": "def check(candidate):\n assert candidate(target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(target = [1, 2, 3, 4, 5]) == 5\n assert candidate(target = [5, 4, 3, 2, 1]) == 5\n assert candidate(target = [100000]) == 100000\n assert candidate(target = [...
[ "[1,2,3,2,1]", "[3,1,1,2]", "[3,1,5,4,2]" ]
[ "For a given range of values in target, an optimal strategy is to increment the entire range by the minimum value. The minimum in a range could be obtained with Range minimum query or Segment trees algorithm." ]
{ "canonical_parameter_names": [ "target" ], "leetcode_dataset_entry_point": "Solution().minNumberOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:46", "tests_total": 105, ...
typescript
{ "raw_signature": "function minNumberOperations(target: number[]): number {", "container": null, "callable": "minNumberOperations", "parameters": [ { "name": "target", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetc...
1,528
shuffle-string
Easy
You are given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the i^th position moves to indices[i] in the shuffled string. Return the shuffled string. Example 1: Input: s = "codeleet", indices = [4,5,6,7,0,2,1,3] Output: "leetcode" Explanation: As...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"codeleet\",indices = [4, 5, 6, 7, 0, 2, 1, 3]) == \"leetcode\"\n assert candidate(s = \"aaiougrt\",indices = [4, 0, 2, 6, 7, 3, 1, 5]) == \"arigatou\"\n assert candidate(s = \"aiohn\",indices = [3, 1, 4, 2, 0]) == \"nihao\"\n...
[ "\"codeleet\"\n[4,5,6,7,0,2,1,3]", "\"abc\"\n[0,1,2]" ]
[ "You can create an auxiliary string t of length n.", "Assign t[indexes[i]] to s[i] for each i from 0 to n-1." ]
{ "canonical_parameter_names": [ "s", "indices" ], "leetcode_dataset_entry_point": "Solution().restoreString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:48", "tests_total": 61,...
typescript
{ "raw_signature": "function restoreString(s: string, indices: number[]): string {", "container": null, "callable": "restoreString", "parameters": [ { "name": "s", "type": "string" }, { "name": "indices", "type": "number[]" } ], "return_type": "string", "signature_s...
1,529
minimum-suffix-flips
Medium
You are given a 0-indexed binary string target of length n. You have another binary string s of length n that is initially set to all zeros. You want to make s equal to target. In one operation, you can pick an index i where 0 <= i < n and flip all bits in the inclusive range [i, n - 1]. Flip means changing '0' to '1'...
{ "language": "python", "source": "def check(candidate):\n assert candidate(target = \"00000\") == 0\n assert candidate(target = \"00110\") == 2\n assert candidate(target = \"1100110011\") == 5\n assert candidate(target = \"000111000111\") == 3\n assert candidate(target = \"001100\") == 2\n assert...
[ "\"10111\"", "\"101\"", "\"00000\"" ]
[ "Consider a strategy where the choice of bulb with number i is increasing. In such a strategy, you no longer need to worry about bulbs that have been set to the left." ]
{ "canonical_parameter_names": [ "target" ], "leetcode_dataset_entry_point": "Solution().minFlips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:50", "tests_total": 117, "tests_drop...
typescript
{ "raw_signature": "function minFlips(target: string): number {", "container": null, "callable": "minFlips", "parameters": [ { "name": "target", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,531
string-compression-ii
Hard
Run-length encoding is a string compression method that works by replacing consecutive identical characters (repeated 2 or more times) with the concatenation of the character and the number marking the count of the characters (length of the run). For example, to compress the string "aabccc" we replace "aa" by "a2" and ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcabcabc\",k = 5) == 3\n assert candidate(s = \"aaabcccd\",k = 2) == 4\n assert candidate(s = \"aabcc\",k = 1) == 4\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 20) == 32\n assert...
[ "\"aaabcccd\"\n2", "\"aabbaa\"\n2", "\"aaaaaaaaaaa\"\n0" ]
[ "Use dynamic programming.", "The state of the DP can be the current index and the remaining characters to delete.", "Having a prefix sum for each character can help you determine for a certain character c in some specific range, how many characters you need to delete to merge all occurrences of c in that range....
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().getLengthOfOptimalCompression", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:55", "tests_t...
typescript
{ "raw_signature": "function getLengthOfOptimalCompression(s: string, k: number): number {", "container": null, "callable": "getLengthOfOptimalCompression", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "number"...
1,534
count-good-triplets
Easy
Given an array of integers arr, and three integers a, b and c. You need to find the number of good triplets. A triplet (arr[i], arr[j], arr[k]) is good if the following conditions are true: - 0 <= i < j < k < arr.length - |arr[i] - arr[j]| <= a - |arr[j] - arr[k]| <= b - |arr[i] - arr[k]| <= c Where |x| denotes the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [3, 0, 1, 1, 9, 7],a = 7,b = 2,c = 3) == 4\n assert candidate(arr = [1, 3, 5, 7, 9],a = 2,b = 3,c = 4) == 3\n assert candidate(arr = [1, 1, 2, 2, 3],a = 0,b = 0,c = 1) == 0\n assert candidate(arr = [10, 20, 30, 40, 50],a =...
[ "[3,0,1,1,9,7]\n7\n2\n3", "[1,1,2,2,3]\n0\n0\n1" ]
[ "Notice that the constraints are small enough for a brute force solution to pass.", "Loop through all triplets, and count the ones that are good." ]
{ "canonical_parameter_names": [ "arr", "a", "b", "c" ], "leetcode_dataset_entry_point": "Solution().countGoodTriplets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:22:57", ...
typescript
{ "raw_signature": "function countGoodTriplets(arr: number[], a: number, b: number, c: number): number {", "container": null, "callable": "countGoodTriplets", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "a", "type": "number" }, { "name": "b"...
1,535
find-the-winner-of-an-array-game
Medium
Given an integer array arr of distinct integers and an integer k. A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of the game, we compare arr[0] with arr[1], the larger integer wins and remains at position 0, and the smaller integer moves to the end of the arra...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [2, 1, 3, 5, 4, 6, 7],k = 2) == 5\n assert candidate(arr = [7, 10, 5, 3, 8],k = 3) == 10\n assert candidate(arr = [5, 4, 3, 2, 1],k = 1) == 5\n assert candidate(arr = [3, 2, 1],k = 10) == 3\n assert candidate(arr = [100...
[ "[2,1,3,5,4,6,7]\n2", "[3,2,1]\n10" ]
[ "If k ≥ arr.length return the max element of the array.", "If k < arr.length simulate the game until a number wins k consecutive games." ]
{ "canonical_parameter_names": [ "arr", "k" ], "leetcode_dataset_entry_point": "Solution().getWinner", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:00", "tests_total": 105, "tes...
typescript
{ "raw_signature": "function getWinner(arr: number[], k: number): number {", "container": null, "callable": "getWinner", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcod...
1,536
minimum-swaps-to-arrange-a-binary-grid
Medium
Given an n x n binary grid, in one step you can choose two adjacent rows of the grid and swap them. A grid is said to be valid if all the cells above the main diagonal are zeros. Return the minimum number of steps needed to make the grid valid, or -1 if the grid cannot be valid. The main diagonal of a grid is the di...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 1], [1, 1, 0], [1, 0, 0]]) == 3\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == -1\n assert candidate(grid = [[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1]]) == -1\n assert candidate(grid ...
[ "[[0,0,1],[1,1,0],[1,0,0]]", "[[0,1,1,0],[0,1,1,0],[0,1,1,0],[0,1,1,0]]", "[[1,0,0],[1,1,0],[1,1,1]]" ]
[ "For each row of the grid calculate the most right 1 in the grid in the array maxRight.", "To check if there exist answer, sort maxRight and check if maxRight[i] ≤ i for all possible i's.", "If there exist an answer, simulate the swaps." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minSwaps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:02", "tests_total": 71, "tests_dropped...
typescript
{ "raw_signature": "function minSwaps(grid: number[][]): number {", "container": null, "callable": "minSwaps", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,537
get-the-maximum-score
Hard
You are given two sorted arrays of distinct integers nums1 and nums2. A valid path is defined as follows: - Choose array nums1 or nums2 to traverse (from index-0). - Traverse the current array from left to right. - If you are reading any value that is present in nums1 and nums2 you are allowed to change your path to ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [10000000],nums2 = [10000000]) == 10000000\n assert candidate(nums1 = [2, 4, 5, 8, 10],nums2 = [4, 6, 8, 9]) == 30\n assert candidate(nums1 = [1, 2, 3],nums2 = [4, 5, 6, 7, 8, 9, 10]) == 49\n assert candidate(nums1 = [1,...
[ "[2,4,5,8,10]\n[4,6,8,9]", "[1,3,5,7,9]\n[3,5,100]", "[1,2,3,4,5]\n[6,7,8,9,10]" ]
[ "Partition the array by common integers, and choose the path with larger sum with a DP technique." ]
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().maxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:05", "tests_total": 110, "...
typescript
{ "raw_signature": "function maxSum(nums1: number[], nums2: number[]): number {", "container": null, "callable": "maxSum", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" } ], "return_type": "number", "signature_source"...
1,539
kth-missing-positive-number
Easy
Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. Return the k^th positive integer that is missing from this array. Example 1: Input: arr = [2,3,4,7,11], k = 5 Output: 9 Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5^th missing positive i...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 20\n assert candidate(arr = [10, 20, 30],k = 15) == 16\n assert candidate(arr = [2, 3, 4, 7, 11],k = 5) == 9\n assert candidate(arr = [5, 6, 7, 8, 9],k = 1) == 1\n assert candi...
[ "[2,3,4,7,11]\n5", "[1,2,3,4]\n2" ]
[ "Keep track of how many positive numbers are missing as you scan the array." ]
{ "canonical_parameter_names": [ "arr", "k" ], "leetcode_dataset_entry_point": "Solution().findKthPositive", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:07", "tests_total": 109, ...
typescript
{ "raw_signature": "function findKthPositive(arr: number[], k: number): number {", "container": null, "callable": "findKthPositive", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_sourc...
1,540
can-convert-string-in-k-moves
Medium
Given two strings s and t, your goal is to convert s into t in k moves or less. During the i^th (1 <= i <= k) move you can: - Choose any index j (1-indexed) from s, such that 1 <= j <= s.length and j has not been chosen in any previous move, and shift the character at that index i times. - Do nothing. Shifting a cha...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc\",t = \"abc\",k = 0) == True\n assert candidate(s = \"aaa\",t = \"zzz\",k = 702) == True\n assert candidate(s = \"abc\",t = \"bcd\",k = 10) == False\n assert candidate(s = \"abc\",t = \"xyz\",k = 702) == True\n asse...
[ "\"input\"\n\"ouput\"\n9", "\"abc\"\n\"bcd\"\n10", "\"aab\"\n\"bbb\"\n27" ]
[ "Observe that shifting a letter x times has the same effect of shifting the letter x + 26 times.", "You need to check whether k is large enough to cover all shifts with the same remainder after modulo 26." ]
{ "canonical_parameter_names": [ "s", "t", "k" ], "leetcode_dataset_entry_point": "Solution().canConvertString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:10", "tests_total...
typescript
{ "raw_signature": "function canConvertString(s: string, t: string, k: number): boolean {", "container": null, "callable": "canConvertString", "parameters": [ { "name": "s", "type": "string" }, { "name": "t", "type": "string" }, { "name": "k", "type": "num...
1,541
minimum-insertions-to-balance-a-parentheses-string
Medium
Given a parentheses string s containing only the characters '(' and ')'. A parentheses string is balanced if: - Any left parenthesis '(' must have a corresponding two consecutive right parenthesis '))'. - Left parenthesis '(' must go before the corresponding two consecutive right parenthesis '))'. In other words, we ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"(()))\") == 1\n assert candidate(s = \"))())(\") == 3\n assert candidate(s = \"())\") == 0\n assert candidate(s = \"(()(())))))))))))()()\") == 6\n assert candidate(s = \"(()))(()))(()))(()))(())))()\") == 5\n assert...
[ "\"(()))\"", "\"())\"", "\"))())(\"" ]
[ "Use a stack to keep opening brackets. If you face single closing ')' add 1 to the answer and consider it as '))'.", "If you have '))' with empty stack, add 1 to the answer, If after finishing you have x opening remaining in the stack, add 2x to the answer." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minInsertions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:12", "tests_total": 115, "tests_drop...
typescript
{ "raw_signature": "function minInsertions(s: string): number {", "container": null, "callable": "minInsertions", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,542
find-longest-awesome-substring
Hard
You are given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it a palindrome. Return the length of the maximum length awesome substring of s. Example 1: Input: s = "3242415" Output: 5 Explanation: "24241" is the longest awesome substring, we ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == 4\n assert candidate(s = \"1000000001\") == 10\n assert candidate(s = \"9876543210\") == 1\n assert candidate(s = \"213123\") == 6\n assert candidate(s = \"9437493749\") == 9\n assert candidate(s = \"1221\...
[ "\"3242415\"", "\"12345678\"", "\"213123\"" ]
[ "Given the character counts, under what conditions can a palindrome be formed ?", "From left to right, use bitwise xor-operation to compute for any prefix the number of times modulo 2 of each digit. (mask ^= (1<<(s[i]-'0')).", "Expected complexity is O(n*A) where A is the alphabet (10)." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().longestAwesome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:14", "tests_total": 133, "tests_dro...
typescript
{ "raw_signature": "function longestAwesome(s: string): number {", "container": null, "callable": "longestAwesome", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,544
make-the-string-great
Easy
Given a string s of lower and upper case English letters. A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where: - 0 <= i <= s.length - 2 - s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa. To make the string good, you can choose two a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefg\") == \"abcdefg\"\n assert candidate(s = \"ABCDEFG\") == \"ABCDEFG\"\n assert candidate(s = \"vVtTkKsSiIdDgGhHjJfFcCrRlLpPoOeEaAqQzZxXcCvVbBnNmM\") == \"\"\n assert candidate(s = \"aAbBcCdDeEfFgG\") == \"\"\n as...
[ "\"leEeetcode\"", "\"abBAcC\"", "\"s\"" ]
[ "The order you choose 2 characters to remove doesn't matter.", "Keep applying the mentioned step to s till the length of the string is not changed." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().makeGood", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:16", "tests_total": 107, "tests_dropped":...
typescript
{ "raw_signature": "function makeGood(s: string): string {", "container": null, "callable": "makeGood", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,545
find-kth-bit-in-nth-binary-string
Medium
Given two positive integers n and k, the binary string S_n is formed as follows: - S_1 = "0" - S_i = S_{i - 1} + "1" + reverse(invert(S_{i - 1})) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0)...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 6,k = 31) == \"1\"\n assert candidate(n = 4,k = 11) == \"1\"\n assert candidate(n = 14,k = 511) == \"1\"\n assert candidate(n = 15,k = 545) == \"0\"\n assert candidate(n = 17,k = 65536) == \"1\"\n assert candidate(n = ...
[ "3\n1", "4\n11" ]
[ "Since n is small, we can simply simulate the process of constructing S1 to Sn." ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().findKthBit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:18", "tests_total": 85, "tests...
typescript
{ "raw_signature": "function findKthBit(n: number, k: number): string {", "container": null, "callable": "findKthBit", "parameters": [ { "name": "n", "type": "number" }, { "name": "k", "type": "number" } ], "return_type": "string", "signature_source": "leetcode/code...
1,546
maximum-number-of-non-overlapping-subarrays-with-sum-equals-target
Medium
Given an array nums and an integer target, return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target. Example 1: Input: nums = [1,1,1,1,1], target = 2 Output: 2 Explanation: There are 2 non-overlapping subarrays [1,1,1,1,1] with sum equals to targ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],target = 10) == 2\n assert candidate(nums = [1, 2, 3, 4, 5],target = 9) == 1\n assert candidate(nums = [-1, 3, 5, 1, 4, 2, -9],target = 6) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5],target = 15) == ...
[ "[1,1,1,1,1]\n2", "[-1,3,5,1,4,2,-9]\n6" ]
[ "Keep track of prefix sums to quickly look up what subarray that sums \"target\" can be formed at each step of scanning the input array.", "It can be proved that greedily forming valid subarrays as soon as one is found is optimal." ]
{ "canonical_parameter_names": [ "nums", "target" ], "leetcode_dataset_entry_point": "Solution().maxNonOverlapping", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:21", "tests_total...
typescript
{ "raw_signature": "function maxNonOverlapping(nums: number[], target: number): number {", "container": null, "callable": "maxNonOverlapping", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "target", "type": "number" } ], "return_type": "number", ...
1,547
minimum-cost-to-cut-a-stick
Hard
Given a wooden stick of length n units. The stick is labelled from 0 to n. For example, a stick of length 6 is labelled as follows: Given an integer array cuts where cuts[i] denotes a position you should perform a cut at. You should perform the cuts in order, you can change the order of the cuts as you wish. The cos...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 15,cuts = [3, 5, 10]) == 30\n assert candidate(n = 100,cuts = [50, 25, 75, 10, 90, 60, 30, 40, 80]) == 330\n assert candidate(n = 15,cuts = [1, 5, 9, 13]) == 35\n assert candidate(n = 7,cuts = [1, 3, 4, 5]) == 16\n assert...
[ "7\n[1,3,4,5]", "9\n[5,6,1,4,2]" ]
[ "Build a dp array where dp[i][j] is the minimum cost to achieve all the cuts between i and j.", "When you try to get the minimum cost between i and j, try all possible cuts k between them, dp[i][j] = min(dp[i][k] + dp[k][j]) + (j - i) for all possible cuts k between them." ]
{ "canonical_parameter_names": [ "n", "cuts" ], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:23", "tests_total": 97, "tests...
typescript
{ "raw_signature": "function minCost(n: number, cuts: number[]): number {", "container": null, "callable": "minCost", "parameters": [ { "name": "n", "type": "number" }, { "name": "cuts", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/...
1,550
three-consecutive-odds
Easy
Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false. Example 1: Input: arr = [2,6,4,1] Output: false Explanation: There are no three consecutive odds. Example 2: Input: arr = [1,2,34,3,4,5,7,23,12] Output: true Explanation: [5,7,23] are three cons...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 3, 2, 5, 7, 9]) == True\n assert candidate(arr = [2, 4, 6, 8, 10]) == False\n assert candidate(arr = [1, 1, 1, 1, 1, 1]) == True\n assert candidate(arr = [1000, 999, 998, 997]) == False\n assert candidate(arr = [2, ...
[ "[2,6,4,1]", "[1,2,34,3,4,5,7,23,12]" ]
[ "Check every three consecutive numbers in the array for parity." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().threeConsecutiveOdds", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:28", "tests_total": 131, "t...
typescript
{ "raw_signature": "function threeConsecutiveOdds(arr: number[]): boolean {", "container": null, "callable": "threeConsecutiveOdds", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcod...
1,551
minimum-operations-to-make-array-equal
Medium
You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e., 0 <= i < n). In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 to arr[y] (i.e., perform arr[x] -=1 and arr[y] += 1). The goal is to make all the elements of the arra...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 100) == 2500\n assert candidate(n = 10000) == 25000000\n assert candidate(n = 6) == 9\n assert candidate(n = 1) == 0\n assert candidate(n = 1000) == 250000\n assert candidate(n = 10) =...
[ "3", "6" ]
[ "Build the array arr using the given formula, define target = sum(arr) / n", "What is the number of operations needed to convert arr so that all elements equal target ?" ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:30", "tests_total": 53, "tests_dropp...
typescript
{ "raw_signature": "function minOperations(n: number): number {", "container": null, "callable": "minOperations", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,552
magnetic-force-between-two-balls
Medium
In the universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the i^th basket is at position[i], Morty has m balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(position = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 5) == 2\n assert candidate(position = [5, 4, 3, 2, 1, 1000000000],m = 2) == 999999999\n assert candidate(position = [1, 3, 5, 7, 9],m = 4) == 2\n assert candidate(position = [1, 3, ...
[ "[1,2,3,4,7]\n3", "[5,4,3,2,1,1000000000]\n2" ]
[ "If you can place balls such that the answer is x then you can do it for y where y < x.", "Similarly if you cannot place balls such that the answer is x then you can do it for y where y > x.", "Binary search on the answer and greedily see if it is possible." ]
{ "canonical_parameter_names": [ "position", "m" ], "leetcode_dataset_entry_point": "Solution().maxDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:32", "tests_total": 87, ...
typescript
{ "raw_signature": "function maxDistance(position: number[], m: number): number {", "container": null, "callable": "maxDistance", "parameters": [ { "name": "position", "type": "number[]" }, { "name": "m", "type": "number" } ], "return_type": "number", "signature_sou...
1,553
minimum-number-of-days-to-eat-n-oranges
Hard
There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows: - Eat one orange. - If the number of remaining oranges n is divisible by 2 then you can eat n / 2 oranges. - If the number of remaining oranges n is divisible by 3 then you can eat 2 * (n / 3) oranges. You can only c...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 2000000000) == 32\n assert candidate(n = 100) == 8\n assert candidate(n = 1000) == 10\n assert candidate(n = 5) == 4\n assert candidate(n = 4) == 3\n assert candidate(n = 2) == 2\n ...
[ "10", "6" ]
[ "In each step, choose between 2 options: minOranges = 1 + min( (n%2) + f(n/2), (n%3) + f(n/3) ) where f(n) is the minimum number of days to eat n oranges." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().minDays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:35", "tests_total": 234, "tests_dropped": ...
typescript
{ "raw_signature": "function minDays(n: number): number {", "container": null, "callable": "minDays", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,556
thousand-separator
Easy
Given an integer n, add a dot (".") as the thousands separator and return it in string format. Example 1: Input: n = 987 Output: "987" Example 2: Input: n = 1234 Output: "1.234" Constraints: - 0 <= n <= 2^31 - 1
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 0) == \"0\"\n assert candidate(n = 1234) == \"1.234\"\n assert candidate(n = 1000000) == \"1.000.000\"\n assert candidate(n = 2147483647) == \"2.147.483.647\"\n assert candidate(n = 123456789) == \"123.456.789\"\n asse...
[ "987", "1234" ]
[ "Scan from the back of the integer and use dots to connect blocks with length 3 except the last block." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().thousandSeparator", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:39", "tests_total": 50, "tests_d...
typescript
{ "raw_signature": "function thousandSeparator(n: number): string {", "container": null, "callable": "thousandSeparator", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,557
minimum-number-of-vertices-to-reach-all-nodes
Medium
Given a directed acyclic graph, with n vertices numbered from 0 to n-1, and an array edges where edges[i] = [from_i, to_i] represents a directed edge from node from_i to node to_i. Find the smallest set of vertices from which all nodes in the graph are reachable. It's guaranteed that a unique solution exists. Notice ...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ...
[ "6\n[[0,1],[0,2],[2,5],[3,4],[4,2]]", "5\n[[0,1],[2,1],[3,1],[1,4],[2,4]]" ]
[ "A node that does not have any incoming edge can only be reached by itself.", "Any other node with incoming edges can be reached from some other node.", "We only have to count the number of nodes with zero incoming edges." ]
{ "canonical_parameter_names": [ "n", "edges" ], "leetcode_dataset_entry_point": "Solution().findSmallestSetOfVertices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:41", "tests_t...
typescript
{ "raw_signature": "function findSmallestSetOfVertices(n: number, edges: number[][]): number[] {", "container": null, "callable": "findSmallestSetOfVertices", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" } ], "return_type"...
1,558
minimum-numbers-of-function-calls-to-make-target-array
Medium
You are given an integer array nums. You have an integer array arr of the same length with all values set to 0 initially. You also have the following modify function: You want to use the modify function to convert arr to nums using the minimum number of calls. Return the minimum number of function calls to make nums ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1000000000]) == 43\n assert candidate(nums = [10, 20, 30]) == 12\n assert candidate(nums = [10, 15, 20]) == 12\n assert candidate(nums = [1, 1, 1, 1]) == 4\n assert candidate(nums = [3, 3, 3, 3]) == 9\n assert c...
[ "[1,5]", "[2,2]", "[4,2,5]" ]
[ "Work backwards: try to go from nums to arr.", "You should try to divide by 2 as much as possible, but you can only divide by 2 if everything is even." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:44", "tests_total": 98, "tests_dr...
typescript
{ "raw_signature": "function minOperations(nums: number[]): number {", "container": null, "callable": "minOperations", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
1,559
detect-cycles-in-2d-grid
Medium
Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid. A cycle is a path of length 4 or more in the grid that starts and ends at the same cell. From a given cell, you can move to one of the cells adjacent to it - in one of the four directions...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [['a', 'b', 'c'], ['b', 'c', 'a'], ['c', 'a', 'b']]) == False\n assert candidate(grid = [['a', 'a', 'a', 'a'], ['a', 'b', 'b', 'a'], ['a', 'b', 'b', 'a'], ['a', 'a', 'a', 'a']]) == True\n assert candidate(grid = [['a', 'b'],...
[ "[[\"a\",\"a\",\"a\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"a\",\"a\",\"a\"]]", "[[\"c\",\"c\",\"c\",\"a\"],[\"c\",\"d\",\"c\",\"c\"],[\"c\",\"c\",\"e\",\"c\"],[\"f\",\"c\",\"c\",\"c\"]]", "[[\"a\",\"b\",\"b\"],[\"b\",\"z\",\"b\"],[\"b\",\"b\",\"a\"]]" ]
[ "Keep track of the parent (previous position) to avoid considering an invalid path.", "Use DFS or BFS and keep track of visited cells to see if there is a cycle." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().containsCycle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:46", "tests_total": 74, "tests_dr...
typescript
{ "raw_signature": "function containsCycle(grid: string[][]): boolean {", "container": null, "callable": "containsCycle", "parameters": [ { "name": "grid", "type": "string[][]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,560
most-visited-sector-in-a-circular-track
Easy
Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The i^th round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, round 1 starts at sector rounds[0] ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,rounds = [1, 3, 1, 2]) == [1, 2]\n assert candidate(n = 7,rounds = [1, 3, 5, 7]) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(n = 6,rounds = [3, 6, 2, 4, 1]) == [1, 3, 4, 5, 6]\n assert candidate(n = 6,rounds = [3, 6, 2, 5]...
[ "4\n[1,3,1,2]", "2\n[2,1,2,1,2,1,2,1,2]", "7\n[1,3,5,7]" ]
[ "For each round increment the visits of the sectors visited during the marathon with 1.", "Determine the max number of visits, and return any sector visited the max number of visits." ]
{ "canonical_parameter_names": [ "n", "rounds" ], "leetcode_dataset_entry_point": "Solution().mostVisited", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:48", "tests_total": 98, ...
typescript
{ "raw_signature": "function mostVisited(n: number, rounds: number[]): number[] {", "container": null, "callable": "mostVisited", "parameters": [ { "name": "n", "type": "number" }, { "name": "rounds", "type": "number[]" } ], "return_type": "number[]", "signature_sou...
1,561
maximum-number-of-coins-you-can-get
Medium
There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows: - In each step, you will choose any 3 piles of coins (not necessarily consecutive). - Of your choice, Alice will pick the pile with the maximum number of coins. - You will pick the next pile with the maximum number o...
{ "language": "python", "source": "def check(candidate):\n assert candidate(piles = [1, 12, 2, 11, 3, 10, 4, 9, 5, 8, 6, 7]) == 32\n assert candidate(piles = [2, 4, 1, 2, 7, 8]) == 9\n assert candidate(piles = [9, 8, 7, 6, 5, 1, 2, 3, 4]) == 18\n assert candidate(piles = [10000, 10000, 10000, 1, 1, 1, 2...
[ "[2,4,1,2,7,8]", "[2,4,5]", "[9,8,7,6,5,1,2,3,4]" ]
[ "Which pile of coins will you never be able to pick up?", "Bob is forced to take the last pile of coins, no matter what it is. Which pile should you give to him?" ]
{ "canonical_parameter_names": [ "piles" ], "leetcode_dataset_entry_point": "Solution().maxCoins", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:50", "tests_total": 99, "tests_droppe...
typescript
{ "raw_signature": "function maxCoins(piles: number[]): number {", "container": null, "callable": "maxCoins", "parameters": [ { "name": "piles", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,562
find-latest-group-of-size-m
Medium
Given an array arr that represents a permutation of numbers from 1 to n. You have a binary string of size n that initially has all its bits set to zero. At each step i (assuming both the binary string and arr are 1-indexed) from 1 to n, the bit at position arr[i] is set to 1. You are also given an integer m. Find the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5],m = 3) == 3\n assert candidate(arr = [1, 3, 5, 2, 4],m = 1) == 4\n assert candidate(arr = [2, 1, 3, 5, 4],m = 1) == 4\n assert candidate(arr = [3, 5, 1, 2, 4],m = 1) == 4\n assert candidate(arr = [5, 4, ...
[ "[3,5,1,2,4]\n1", "[3,1,5,4,2]\n2" ]
[ "Since the problem asks for the latest step, can you start the searching from the end of arr?", "Use a map to store the current “1” groups.", "At each step (going backwards) you need to split one group and update the map." ]
{ "canonical_parameter_names": [ "arr", "m" ], "leetcode_dataset_entry_point": "Solution().findLatestStep", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:53", "tests_total": 106, ...
typescript
{ "raw_signature": "function findLatestStep(arr: number[], m: number): number {", "container": null, "callable": "findLatestStep", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "m", "type": "number" } ], "return_type": "number", "signature_source"...
1,563
stone-game-v
Hard
There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue. In each round of the game, Alice divides the row into two non-empty rows (i.e. left row and right row), then Bob calculates the value of each row which is the sum of the values of all t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(stoneValue = [1, 2, 3, 4, 5]) == 10\n assert candidate(stoneValue = [5, 3, 1, 4, 2]) == 9\n assert candidate(stoneValue = [1, 3, 5, 7, 9, 11, 13]) == 35\n assert candidate(stoneValue = [3, 6, 2, 8, 7, 4, 5]) == 23\n assert ca...
[ "[6,2,3,4,5,5]", "[7,7,7,7,7,7,7]", "[4]" ]
[ "We need to try all possible divisions for the current row to get the max score.", "As calculating all possible divisions will lead us to calculate some sub-problems more than once, we need to think of dynamic programming." ]
{ "canonical_parameter_names": [ "stoneValue" ], "leetcode_dataset_entry_point": "Solution().stoneGameV", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:23:55", "tests_total": 93, "tests...
typescript
{ "raw_signature": "function stoneGameV(stoneValue: number[]): number {", "container": null, "callable": "stoneGameV", "parameters": [ { "name": "stoneValue", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,566
detect-pattern-of-length-m-repeated-k-or-more-times
Easy
Given an array of positive integers arr, find a pattern of length m that is repeated k or more times. A pattern is a subarray (consecutive sub-sequence) that consists of one or more values, repeated multiple times consecutively without overlapping. A pattern is defined by its length and the number of repetitions. Ret...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 4, 4, 4, 4],m = 1,k = 3) == True\n assert candidate(arr = [2, 2, 2, 2, 2, 2],m = 2,k = 2) == True\n assert candidate(arr = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3],m = 2,k = 5) == True\n assert candidate(arr = [2, 2, 2, 2, 2,...
[ "[1,2,4,4,4,4]\n1\n3", "[1,2,1,2,1,1,1,3]\n2\n2", "[1,2,1,2,1,3]\n2\n3" ]
[ "Use a three-layer loop to check all possible patterns by iterating through all possible starting positions, all indexes less than m, and if the character at the index is repeated k times." ]
{ "canonical_parameter_names": [ "arr", "m", "k" ], "leetcode_dataset_entry_point": "Solution().containsPattern", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:00", "tests_tota...
typescript
{ "raw_signature": "function containsPattern(arr: number[], m: number, k: number): boolean {", "container": null, "callable": "containsPattern", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "m", "type": "number" }, { "name": "k", "type"...
1,567
maximum-length-of-subarray-with-positive-product
Medium
Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive. A subarray of an array is a consecutive sequence of zero or more values taken out of that array. Return the maximum length of a subarray with positive product. Example 1: Input: nums = [1,-2,-3,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, 2, -3, 4, -5]) == 4\n assert candidate(nums = [-1, -2, -3, 0, 1]) == 2\n assert candidate(nums = [-1]) == 0\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 2, 3, 0, -1, -2, -3]) == 3\n assert ...
[ "[1,-2,-3,4]", "[0,1,-2,-3,-4]", "[-1,-2,-3,0,1]" ]
[ "Split the whole array into subarrays by zeroes since a subarray with positive product cannot contain any zero.", "If the subarray has even number of negative numbers, the whole subarray has positive product.", "Otherwise, we have two choices, either - remove the prefix till the first negative element in this s...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().getMaxLen", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:02", "tests_total": 122, "tests_dropp...
typescript
{ "raw_signature": "function getMaxLen(nums: number[]): number {", "container": null, "callable": "getMaxLen", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,568
minimum-number-of-days-to-disconnect-island
Hard
You are given an m x n binary grid grid where 1 represents land and 0 represents water. An island is a maximal 4-directionally (horizontal or vertical) connected group of 1's. The grid is said to be connected if we have exactly one island, otherwise is said disconnected. In one day, we are allowed to change any singl...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 2\n assert candidate(grid = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == 0\n assert candidate(grid = [[1, 1]]) == 2\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0...
[ "[[0,1,1,0],[0,1,1,0],[0,0,0,0]]", "[[1,1]]" ]
[ "Return 0 if the grid is already disconnected.", "Return 1 if changing a single land to water disconnect the island.", "Otherwise return 2.", "We can disconnect the grid within at most 2 days." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minDays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:04", "tests_total": 73, "tests_dropped"...
typescript
{ "raw_signature": "function minDays(grid: number[][]): number {", "container": null, "callable": "minDays", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,569
number-of-ways-to-reorder-array-to-get-same-bst
Hard
Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number of different ways to reorder nums so that the constructed BST is identical to that formed from the origi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2]) == 0\n assert candidate(nums = [9, 4, 10, 2, 5, 8, 11, 1, 3, 6, 7]) == 3149\n assert candidate(nums = [6, 2, 9, 1, 3, 8, 10, 4, 5, 7]) == 1511\n assert candidate(nums = [1, 2, 3]) == 0\n assert candidate(num...
[ "[2,1,3]", "[3,4,5,1,2]", "[1,2,3]" ]
[ "Use a divide and conquer strategy.", "The first number will always be the root. Consider the numbers smaller and larger than the root separately. When merging the results together, how many ways can you order x elements in x+y positions?" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().numOfWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:07", "tests_total": 74, "tests_droppe...
typescript
{ "raw_signature": "function numOfWays(nums: number[]): number {", "container": null, "callable": "numOfWays", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,572
matrix-diagonal-sum
Easy
Given a square matrix mat, return the sum of the matrix diagonals. Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal. Example 1: Input: mat = [[1,2,3], [4,5,6], [7,8,9]] Output: 25 Expl...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[7, 3, 1, 9], [3, 4, 6, 9], [6, 9, 6, 6], [9, 5, 8, 5]]) == 55\n assert candidate(mat = [[5]]) == 5\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 25\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [...
[ "[[1,2,3],[4,5,6],[7,8,9]]", "[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]]", "[[5]]" ]
[ "There will be overlap of elements in the primary and secondary diagonals if and only if the length of the matrix is odd, which is at the center." ]
{ "canonical_parameter_names": [ "mat" ], "leetcode_dataset_entry_point": "Solution().diagonalSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:09", "tests_total": 54, "tests_dropp...
typescript
{ "raw_signature": "function diagonalSum(mat: number[][]): number {", "container": null, "callable": "diagonalSum", "parameters": [ { "name": "mat", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,573
number-of-ways-to-split-a-string
Medium
Given a binary string s, you can split s into 3 non-empty strings s1, s2, and s3 where s1 + s2 + s3 = s. Return the number of ways s can be split such that the number of ones is the same in s1, s2, and s3. Since the answer may be too large, return it modulo 10^9 + 7. Example 1: Input: s = "10101" Output: 4 Explanati...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"101010101\") == 0\n assert candidate(s = \"10101010101\") == 4\n assert candidate(s = \"0000\") == 3\n assert candidate(s = \"0000000\") == 15\n assert candidate(s = \"010101010\") == 0\n assert candidate(s = \"11100...
[ "\"10101\"", "\"1001\"", "\"0000\"" ]
[ "There is no way if the sum (number of '1's) is not divisible by the number of splits. So sum%3 should be 0.", "Preffix s1 , and suffix s3 should have sum/3 characters '1'.", "Follow up: Can you generalize the problem with numbers between [-10^9, 10^9] such the sum between subarrays s1, s2, s3 are the same?" ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().numWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:11", "tests_total": 84, "tests_dropped": 0...
typescript
{ "raw_signature": "function numWays(s: string): number {", "container": null, "callable": "numWays", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,574
shortest-subarray-to-be-removed-to-make-array-sorted
Medium
Given an integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing. Return the length of the shortest subarray to remove. A subarray is a contiguous subsequence of the array. Example 1: Input: arr = [1,2,3,10,4,2,3,5] Output: 3 Explanation: The shortest ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [5, 4, 3, 2, 1]) == 4\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1]) == 9\n assert candidate(arr = [1, 2, 3]) == 0\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 10\n assert candidate(arr ...
[ "[11,10,18,14,12,11,16,20,13,11]", "[17,32,32,29,4,29,19,5,26,35,35,6,10,27,11,35,0,31]", "[1,8,34,2,3,22,18,27,3,1,0,12,21,23,8,7,17]" ]
[ "The key is to find the longest non-decreasing subarray starting with the first element or ending with the last element, respectively.", "After removing some subarray, the result is the concatenation of a sorted prefix and a sorted suffix, where the last element of the prefix is smaller than the first element of ...
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().findLengthOfShortestSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:14", "tests_total": 1...
typescript
{ "raw_signature": "function findLengthOfShortestSubarray(arr: number[]): number {", "container": null, "callable": "findLengthOfShortestSubarray", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_sou...
1,575
count-all-possible-routes
Hard
You are given an array of distinct positive integers locations where locations[i] represents the position of city i. You are also given integers start, finish and fuel representing the starting city, ending city, and the initial amount of fuel you have, respectively. At each step, if you are at city i, you can pick an...
{ "language": "python", "source": "def check(candidate):\n assert candidate(locations = [4, 3, 1],start = 1,finish = 0,fuel = 6) == 5\n assert candidate(locations = [1, 2, 3, 4, 5],start = 0,finish = 4,fuel = 10) == 1208\n assert candidate(locations = [5, 2, 1],start = 0,finish = 2,fuel = 3) == 0\n asse...
[ "[2,3,6,8,4]\n1\n3\n5", "[4,3,1]\n1\n0\n6", "[5,2,1]\n0\n2\n3" ]
[ "Use dynamic programming to solve this problem with each state defined by the city index and fuel left.", "Since the array contains distinct integers fuel will always be spent in each move and so there can be no cycles." ]
{ "canonical_parameter_names": [ "locations", "start", "finish", "fuel" ], "leetcode_dataset_entry_point": "Solution().countRoutes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T2...
typescript
{ "raw_signature": "function countRoutes(locations: number[], start: number, finish: number, fuel: number): number {", "container": null, "callable": "countRoutes", "parameters": [ { "name": "locations", "type": "number[]" }, { "name": "start", "type": "number" }, { ...
1,576
replace-all-s-to-avoid-consecutive-repeating-characters
Easy
Given a string s containing only lowercase English letters and the '?' character, convert all the '?' characters into lowercase letters such that the final string does not contain any consecutive repeating characters. You cannot modify the non '?' characters. It is guaranteed that there are no consecutive repeating ch...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"?zs\") == \"azs\"\n assert candidate(s = \"b?a\") == \"bca\"\n assert candidate(s = \"a?b?\") == \"acba\"\n assert candidate(s = \"zz?z?zz\") == \"zzazazz\"\n assert candidate(s = \"z?z\") == \"zaz\"\n assert candida...
[ "\"?zs\"", "\"ubv?w\"" ]
[ "Processing string from left to right, whenever you get a ‘?’, check left character and right character, and select a character not equal to either of them", "Do take care to compare with replaced occurrence of ‘?’ when checking the left character." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().modifyString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:18", "tests_total": 122, "tests_dropp...
typescript
{ "raw_signature": "function modifyString(s: string): string {", "container": null, "callable": "modifyString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,577
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Medium
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules: - Type 1: Triplet (i, j, k) if nums1[i]^2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length. - Type 2: Triplet (i, j, k) if nums2[i]^2 == nums1[j] * nums1[k] ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [3, 5, 7],nums2 = [9, 25, 49]) == 0\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [25, 25, 25, 25]) == 0\n assert candidate(nums1 = [10, 5, 2],nums2 = [100, 25, 4]) == 1\n assert candidate(nums1 = [2, 3, 5],nums2 = [2,...
[ "[7,4]\n[5,2,8,9]", "[1,1]\n[1,1,1]", "[7,7,8,3]\n[1,2,9,7]" ]
[ "Precalculate the frequencies of all nums1[i]^2 and nums2[i]^2" ]
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().numTriplets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:20", "tests_total": 121...
typescript
{ "raw_signature": "function numTriplets(nums1: number[], nums2: number[]): number {", "container": null, "callable": "numTriplets", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" } ], "return_type": "number", "signatu...
1,578
minimum-time-to-make-rope-colorful
Medium
Alice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the i^th balloon. Alice wants the rope to be colorful. She does not want two consecutive balloons to be of the same color, so she asks Bob for help. Bob can remove some balloons from the rope to make it col...
{ "language": "python", "source": "def check(candidate):\n assert candidate(colors = \"abcabc\",neededTime = [1, 2, 3, 1, 2, 3]) == 0\n assert candidate(colors = \"aaaaa\",neededTime = [5, 4, 3, 2, 1]) == 10\n assert candidate(colors = \"abacabadabacaba\",neededTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12...
[ "\"abaac\"\n[1,2,3,4,5]", "\"abc\"\n[1,2,3]", "\"aabaa\"\n[1,2,3,4,1]" ]
[ "Maintain the running sum and max value for repeated letters." ]
{ "canonical_parameter_names": [ "colors", "neededTime" ], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:23", "tests_total": 9...
typescript
{ "raw_signature": "function minCost(colors: string, neededTime: number[]): number {", "container": null, "callable": "minCost", "parameters": [ { "name": "colors", "type": "string" }, { "name": "neededTime", "type": "number[]" } ], "return_type": "number", "signatu...
1,579
remove-max-number-of-edges-to-keep-graph-fully-traversable
Hard
Alice and Bob have an undirected graph of n nodes and three types of edges: - Type 1: Can be traversed by Alice only. - Type 2: Can be traversed by Bob only. - Type 3: Can be traversed by both Alice and Bob. Given an array edges where edges[i] = [type_i, u_i, v_i] represents a bidirectional edge of type type_i betwee...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,edges = [[1, 1, 2], [2, 2, 3], [3, 3, 4], [3, 4, 5], [1, 2, 3], [2, 3, 4]]) == -1\n assert candidate(n = 4,edges = [[3, 1, 2], [3, 2, 3], [1, 1, 3], [1, 2, 4], [1, 1, 2], [2, 3, 4]]) == 2\n assert candidate(n = 4,edges = [[3,...
[ "4\n[[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]", "4\n[[3,1,2],[3,2,3],[1,1,4],[2,1,4]]", "4\n[[3,2,3],[1,1,2],[2,3,4]]" ]
[ "Build the network instead of removing extra edges.", "Suppose you have the final graph (after removing extra edges). Consider the subgraph with only the edges that Alice can traverse. What structure does this subgraph have? How many edges are there?", "Use disjoint set union data structure for both Alice and B...
{ "canonical_parameter_names": [ "n", "edges" ], "leetcode_dataset_entry_point": "Solution().maxNumEdgesToRemove", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:25", "tests_total":...
typescript
{ "raw_signature": "function maxNumEdgesToRemove(n: number, edges: number[][]): number {", "container": null, "callable": "maxNumEdgesToRemove", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" } ], "return_type": "number", ...
1,582
special-positions-in-a-binary-matrix
Easy
Given an m x n binary matrix mat, return the number of special positions in mat. A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed). Example 1: Input: mat = [[1,0,0],[0,0,1],[1,0,0]] Output: 1 Explanation: (1, 2) is a special posi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[1, 0], [0, 1]]) == 2\n assert candidate(mat = [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 0]]) == 2\n assert candidate(mat = [[1, 0, 0], [0, 0, 1], [1, 0, 0]]) == 1\n assert candidate(mat = [[0, 0, 0, 0], [0, 1,...
[ "[[1,0,0],[0,0,1],[1,0,0]]", "[[1,0,0],[0,1,0],[0,0,1]]" ]
[ "Keep track of 1s in each row and in each column. Then while iterating over matrix, if the current position is 1 and current row as well as current column contains exactly one occurrence of 1." ]
{ "canonical_parameter_names": [ "mat" ], "leetcode_dataset_entry_point": "Solution().numSpecial", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:30", "tests_total": 70, "tests_droppe...
typescript
{ "raw_signature": "function numSpecial(mat: number[][]): number {", "container": null, "callable": "numSpecial", "parameters": [ { "name": "mat", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,584
min-cost-to-connect-all-points
Medium
You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [x_i, y_i]. The cost of connecting two points [x_i, y_i] and [x_j, y_j] is the manhattan distance between them: |x_i - x_j| + |y_i - y_j|, where |val| denotes the absolute value of val. Return the minimum co...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[0, 0], [2, 2], [4, 4], [6, 6], [8, 8]]) == 16\n assert candidate(points = [[1, 1], [0, 0], [2, 2], [3, 3], [4, 4]]) == 8\n assert candidate(points = [[-1000000, 1000000], [1000000, -1000000], [0, 0]]) == 4000000\n ass...
[ "[[0,0],[2,2],[3,10],[5,2],[7,0]]", "[[3,12],[-2,5],[-4,1]]" ]
[ "Connect each pair of points with a weighted edge, the weight being the manhattan distance between those points.", "The problem is now the cost of minimum spanning tree in graph with above edges." ]
{ "canonical_parameter_names": [ "points" ], "leetcode_dataset_entry_point": "Solution().minCostConnectPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:34", "tests_total": 104, ...
typescript
{ "raw_signature": "function minCostConnectPoints(points: number[][]): number {", "container": null, "callable": "minCostConnectPoints", "parameters": [ { "name": "points", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": ...
1,585
check-if-string-is-transformable-with-substring-sort-operations
Hard
Given two strings s and t, transform string s into string t using the following operation any number of times: - Choose a non-empty substring in s and sort it in place so the characters are in ascending order. - For example, applying the operation on the underlined substring in "14234" results in "12344". Return tr...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"9876543210\",t = \"0123456789\") == True\n assert candidate(s = \"1221\",t = \"1122\") == True\n assert candidate(s = \"987654321\",t = \"123456789\") == True\n assert candidate(s = \"123\",t = \"321\") == False\n asser...
[ "\"84532\"\n\"34852\"", "\"34521\"\n\"23415\"", "\"12345\"\n\"12435\"" ]
[ "Suppose the first digit you need is 'd'. How can you determine if it's possible to get that digit there?", "Consider swapping adjacent characters to maintain relative ordering." ]
{ "canonical_parameter_names": [ "s", "t" ], "leetcode_dataset_entry_point": "Solution().isTransformable", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:37", "tests_total": 147, ...
typescript
{ "raw_signature": "function isTransformable(s: string, t: string): boolean {", "container": null, "callable": "isTransformable", "parameters": [ { "name": "s", "type": "string" }, { "name": "t", "type": "string" } ], "return_type": "boolean", "signature_source": "l...
1,588
sum-of-all-odd-length-subarrays
Easy
Given an array of positive integers arr, return the sum of all possible odd-length subarrays of arr. A subarray is a contiguous subsequence of the array. Example 1: Input: arr = [1,4,2,5,3] Output: 58 Explanation: The odd-length subarrays of arr and their sums are: [1] = 1 [4] = 4 [2] = 2 [5] = 5 [3] = 3 [1,4,2] = 7...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == 8760\n assert candidate(arr = [2, 4, 6, 8, 10]) == 114\n assert candidate(arr = [1, 2]) == 3\n assert candidate(arr = [5]) == 5\n assert candidate(arr = [3, 1, 4, 1, 5,...
[ "[1,4,2,5,3]", "[1,2]", "[10,11,12]" ]
[ "You can brute force – try every (i,j) pair, and if the length is odd, go through and add the sum to the answer." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().sumOddLengthSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:39", "tests_total": 104, "...
typescript
{ "raw_signature": "function sumOddLengthSubarrays(arr: number[]): number {", "container": null, "callable": "sumOddLengthSubarrays", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcod...
1,589
maximum-sum-obtained-of-any-permutation
Medium
We have an array of integers, nums, and an array of requests where requests[i] = [start_i, end_i]. The i^th request asks for the sum of nums[start_i] + nums[start_i + 1] + ... + nums[end_i - 1] + nums[end_i]. Both start_i and end_i are 0-indexed. Return the maximum total sum of all requests among all permutations of n...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 10],requests = [[0, 2], [1, 3], [1, 1]]) == 47\n assert candidate(nums = [10, 20, 30, 40, 50],requests = [[0, 0], [1, 2], [2, 3], [3, 4]]) == 240\n assert candidate(nums = [0, 0, 0, 0, 0],requests = [[0, 0], ...
[ "[1,2,3,4,5]\n[[1,3],[0,1]]", "[1,2,3,4,5,6]\n[[0,1]]", "[1,2,3,4,5,10]\n[[0,2],[1,3],[1,1]]" ]
[ "Indexes with higher frequencies should be bound with larger values" ]
{ "canonical_parameter_names": [ "nums", "requests" ], "leetcode_dataset_entry_point": "Solution().maxSumRangeQuery", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:41", "tests_tota...
typescript
{ "raw_signature": "function maxSumRangeQuery(nums: number[], requests: number[][]): number {", "container": null, "callable": "maxSumRangeQuery", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "requests", "type": "number[][]" } ], "return_type": "n...
1,590
make-sum-divisible-by-p
Medium
Given an array of positive integers nums, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by p. It is not allowed to remove the whole array. Return the length of the smallest subarray that you need to remove, or -1 if it's impossible. A subarray is defined as a c...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5, 5],p = 3) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],p = 2) == 1\n assert candidate(nums = [7, 8, 9, 10, 11],p = 11) == 4\n assert candidate(nums = [1, 2, 3, 4, 5],p = 10) == 1\n assert candidate(nu...
[ "[3,1,4,2]\n6", "[6,3,5,2]\n9", "[1,2,3]\n3" ]
[ "Use prefix sums to calculate the subarray sums.", "Suppose you know the remainder for the sum of the entire array. How does removing a subarray affect that remainder? What remainder does the subarray need to have in order to make the rest of the array sum up to be divisible by k?", "Use a map to keep track of ...
{ "canonical_parameter_names": [ "nums", "p" ], "leetcode_dataset_entry_point": "Solution().minSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:44", "tests_total": 76, "t...
typescript
{ "raw_signature": "function minSubarray(nums: number[], p: number): number {", "container": null, "callable": "minSubarray", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "p", "type": "number" } ], "return_type": "number", "signature_source": "l...
1,591
strange-printer-ii
Hard
There is a strange printer with the following two special requirements: - On each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up the existing colors in the rectangle. - Once the printer has used a color for the above operation, the same color cannot be used a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(targetGrid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == True\n assert candidate(targetGrid = [[1, 1, 1, 1], [1, 2, 2, 1], [1, 2, 2, 1], [1, 1, 1, 1]]) == True\n assert candidate(targetGrid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == True\n ...
[ "[[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]]", "[[1,1,1,1],[1,1,3,3],[1,1,3,4],[5,5,1,4]]", "[[1,2,1],[2,1,2],[1,2,1]]" ]
[ "Try thinking in reverse. Given the grid, how can you tell if a colour was painted last?" ]
{ "canonical_parameter_names": [ "targetGrid" ], "leetcode_dataset_entry_point": "Solution().isPrintable", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:46", "tests_total": 65, "test...
typescript
{ "raw_signature": "function isPrintable(targetGrid: number[][]): boolean {", "container": null, "callable": "isPrintable", "parameters": [ { "name": "targetGrid", "type": "number[][]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcod...
1,592
rearrange-spaces-between-words
Easy
You are given a string text of words that are placed among some number of spaces. Each word consists of one or more lowercase English letters and are separated by at least one space. It's guaranteed that text contains at least one word. Rearrange the spaces so that there is an equal number of spaces between every pair...
{ "language": "python", "source": "def check(candidate):\n assert candidate(text = \" leading and trailing spaces \") == \"leading and trailing spaces \"\n assert candidate(text = \"one\") == \"one\"\n assert candidate(text = \" a \") == \"a \"\n assert candidate(text = \"hello world\") == \...
[ "\" this is a sentence \"", "\" practice makes perfect\"" ]
[ "Count the total number of spaces and words. Then use the integer division to determine the numbers of spaces to add between each word and at the end." ]
{ "canonical_parameter_names": [ "text" ], "leetcode_dataset_entry_point": "Solution().reorderSpaces", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:48", "tests_total": 135, "tests_d...
typescript
{ "raw_signature": "function reorderSpaces(text: string): string {", "container": null, "callable": "reorderSpaces", "parameters": [ { "name": "text", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,593
split-a-string-into-the-max-number-of-unique-substrings
Medium
Given a string s, return the maximum number of unique substrings that the given string can be split into. You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique. A substr...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aaaabbbb\") == 5\n assert candidate(s = \"abac\") == 3\n assert candidate(s = \"abcdef\") == 6\n assert candidate(s = \"aaaaaaaab\") == 4\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"zzzzzzz\") == 3\n ...
[ "\"ababccc\"", "\"aba\"", "\"aa\"" ]
[ "Use a set to keep track of which substrings have been used already", "Try each possible substring at every position and backtrack if a complete split is not possible" ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().maxUniqueSplit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:51", "tests_total": 102, "tests_dro...
typescript
{ "raw_signature": "function maxUniqueSplit(s: string): number {", "container": null, "callable": "maxUniqueSplit", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,594
maximum-non-negative-product-in-a-matrix
Medium
You are given a m x n matrix grid. Initially, you are located at the top-left corner (0, 0), and in each step, you can only move right or down in the matrix. Among all possible paths starting from the top-left corner (0, 0) and ending in the bottom-right corner (m - 1, n - 1), find the path with the maximum non-negati...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[-1, -2, -3], [-2, -3, -3], [-3, -3, -2]]) == -1\n assert candidate(grid = [[-1, 0], [-2, -1]]) == 0\n assert candidate(grid = [[-4, 3], [-3, -4]]) == 48\n assert candidate(grid = [[0, 0], [0, 0]]) == 0\n assert candi...
[ "[[-1,-2,-3],[-2,-3,-3],[-3,-3,-2]]", "[[1,-2,1],[1,-2,1],[3,-4,1]]", "[[1,3],[0,-4]]" ]
[ "Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().maxProductPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:53", "tests_total": 111, "tests_...
typescript
{ "raw_signature": "function maxProductPath(grid: number[][]): number {", "container": null, "callable": "maxProductPath", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,598
crawler-log-folder
Easy
The Leetcode file system keeps a log each time some user performs a change folder operation. The operations are described below: - "../" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder). - "./" : Remain in the same folder. - "x/" : Move to the child...
{ "language": "python", "source": "def check(candidate):\n assert candidate(logs = ['d1/', '../', '../', '../']) == 0\n assert candidate(logs = ['d1/', 'd2/', '../', 'd21/', './']) == 2\n assert candidate(logs = ['d1/', '../', 'd2/', '../', 'd3/', '../', 'd4/', '../', 'd5/', '../']) == 0\n assert candid...
[ "[\"d1/\",\"d2/\",\"../\",\"d21/\",\"./\"]", "[\"d1/\",\"d2/\",\"./\",\"d3/\",\"../\",\"d31/\"]", "[\"d1/\",\"../\",\"../\",\"../\"]" ]
[ "Simulate the process but don’t move the pointer beyond the main folder." ]
{ "canonical_parameter_names": [ "logs" ], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:24:57", "tests_total": 87, "tests_dr...
typescript
{ "raw_signature": "function minOperations(logs: string[]): number {", "container": null, "callable": "minOperations", "parameters": [ { "name": "logs", "type": "string[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
1,599
maximum-profit-of-operating-a-centennial-wheel
Medium
You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas counterclockwise, which costs you runningCost dollars. You are given an array customers of length n where customers[i] is the number of new customers arriving ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(customers = [50, 50, 50, 50, 50],boardingCost = 100,runningCost = 1) == 63\n assert candidate(customers = [5, 5, 0, 8, 2],boardingCost = 6,runningCost = 3) == 6\n assert candidate(customers = [0, 0, 0, 0, 0],boardingCost = 1,runnin...
[ "[8,3]\n5\n6", "[10,9,6]\n6\n4", "[3,4,0,5,1]\n1\n92" ]
[ "Think simulation", "Note that the number of turns will never be more than 50 / 4 * n" ]
{ "canonical_parameter_names": [ "customers", "boardingCost", "runningCost" ], "leetcode_dataset_entry_point": "Solution().minOperationsMaxProfit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2...
typescript
{ "raw_signature": "function minOperationsMaxProfit(customers: number[], boardingCost: number, runningCost: number): number {", "container": null, "callable": "minOperationsMaxProfit", "parameters": [ { "name": "customers", "type": "number[]" }, { "name": "boardingCost", "typ...
1,601
maximum-number-of-achievable-transfer-requests
Hard
We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in. You are given an array requests where requests[i] = [from_i, to_i] represents an employee's request to transfer from building from_i to building to...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 6,requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]]) == 6\n assert candidate(n = 4,requests = [[0, 1], [1, 0], [0, 2], [2, 0], [0, 3], [3, 0]]) == 6\n assert candidate(n = 4,requests = [[0, 3], [3, 1], [1, 2], [2, 0]]...
[ "5\n[[0,1],[1,0],[0,1],[1,2],[2,0],[3,4]]", "3\n[[0,0],[1,2],[2,1]]", "4\n[[0,3],[3,1],[1,2],[2,0]]" ]
[ "Think brute force", "When is a subset of requests okay?" ]
{ "canonical_parameter_names": [ "n", "requests" ], "leetcode_dataset_entry_point": "Solution().maximumRequests", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:02", "tests_total": ...
typescript
{ "raw_signature": "function maximumRequests(n: number, requests: number[][]): number {", "container": null, "callable": "maximumRequests", "parameters": [ { "name": "n", "type": "number" }, { "name": "requests", "type": "number[][]" } ], "return_type": "number", "s...
1,604
alert-using-same-key-card-three-or-more-times-in-a-one-hour-period
Medium
LeetCode company workers use key-cards to unlock office doors. Each time a worker uses their key-card, the security system saves the worker's name and the time when it was used. The system emits an alert if any worker uses the key-card three or more times in a one-hour period. You are given a list of strings keyName a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(keyName = ['daniel', 'daniel', 'daniel', 'luis', 'luis', 'luis', 'luis'],keyTime = ['10:00', '10:40', '11:00', '09:00', '11:00', '13:00', '15:00']) == ['daniel']\n assert candidate(keyName = ['amy', 'amy', 'amy', 'adam', 'adam', 'adam...
[ "[\"daniel\",\"daniel\",\"daniel\",\"luis\",\"luis\",\"luis\",\"luis\"]\n[\"10:00\",\"10:40\",\"11:00\",\"09:00\",\"11:00\",\"13:00\",\"15:00\"]", "[\"alice\",\"alice\",\"alice\",\"bob\",\"bob\",\"bob\",\"bob\"]\n[\"12:01\",\"12:00\",\"18:00\",\"21:00\",\"21:20\",\"21:30\",\"23:00\"]" ]
[ "Group the times by the name of the card user, then sort each group" ]
{ "canonical_parameter_names": [ "keyName", "keyTime" ], "leetcode_dataset_entry_point": "Solution().alertNames", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:25:07", "tests_total": ...
typescript
{ "raw_signature": "function alertNames(keyName: string[], keyTime: string[]): string[] {", "container": null, "callable": "alertNames", "parameters": [ { "name": "keyName", "type": "string[]" }, { "name": "keyTime", "type": "string[]" } ], "return_type": "string[]", ...