question_id
int64
1
3.24k
task_id
stringlengths
3
77
difficulty
stringclasses
3 values
problem_description
stringlengths
193
3.69k
canonical_tests
dict
public_tests
listlengths
1
5
hints
listlengths
0
8
metadata
dict
language
stringclasses
9 values
interface
dict
2,316
count-unreachable-pairs-of-nodes-in-an-undirected-graph
Medium
You are given an integer n. There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [a_i, b_i] denotes that there exists an undirected edge connecting nodes a_i and b_i. Return the number of pairs of different nodes that are unreachable from each oth...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [3, 4]]) == 11\n assert candidate(n = 6,edges = []) == 15\n assert candidate(n = 3,edges = [[0, 1], [0, 2], [1, 2]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [2, 3]]) == 8\n assert candida...
[ "3\n[[0,1],[0,2],[1,2]]", "7\n[[0,2],[0,5],[2,4],[1,6],[5,4]]" ]
[ "Find the connected components of the graph. To find connected components, you can use Union Find (Disjoint Sets), BFS, or DFS.", "For a node u, the number of nodes that are unreachable from u is the number of nodes that are not in the same connected component as u.", "The number of unreachable nodes from node ...
{ "canonical_parameter_names": [ "n", "edges" ], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:31", "tests_total": 55, "t...
typescript
{ "raw_signature": "function countPairs(n: number, edges: number[][]): number {", "container": null, "callable": "countPairs", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" } ], "return_type": "number", "signature_source"...
2,317
maximum-xor-after-operations
Medium
You are given a 0-indexed integer array nums. In one operation, select any non-negative integer x and an index i, then update nums[i] to be equal to nums[i] AND (nums[i] XOR x). Note that AND is the bitwise AND operation and XOR is the bitwise XOR operation. Return the maximum possible bitwise XOR of all elements of ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [8, 1, 4, 2, 15]) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == 15\n assert candidate(nums = [1, 0, 3, 2]) == 3\n assert candidate(nums = [1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [1, 1, 1, 1]) ...
[ "[3,2,4,6]", "[1,2,3,9,2]" ]
[ "Consider what it means to be able to choose any x for the operation and which integers could be obtained from a given nums[i].", "The given operation can unset any bit in nums[i].", "The nth bit of the XOR of all the elements is 1 if the nth bit is 1 for an odd number of elements. When can we ensure it is odd?...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maximumXOR", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:34", "tests_total": 117, "tests_drop...
typescript
{ "raw_signature": "function maximumXOR(nums: number[]): number {", "container": null, "callable": "maximumXOR", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,318
number-of-distinct-roll-sequences
Hard
You are given an integer n. You roll a fair 6-sided dice n times. Determine the total number of distinct sequences of rolls possible such that the following conditions are satisfied: 1. The greatest common divisor of any adjacent values in the sequence is equal to 1. 2. There is at least a gap of 2 rolls between equal...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 66\n assert candidate(n = 100) == 534856607\n assert candidate(n = 4) == 184\n assert candidate(n = 10000) == 874574246\n assert candidate(n = 2) == 22\n assert candidate(n = 1) == 6\n assert candidate(n = 100...
[ "4", "2" ]
[ "Can you think of a DP solution?", "Consider a state that remembers the last 1 or 2 rolls.", "Do you need to consider the last 3 rolls?" ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().distinctSequences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:36", "tests_total": 21, "tests_d...
typescript
{ "raw_signature": "function distinctSequences(n: number): number {", "container": null, "callable": "distinctSequences", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
2,319
check-if-matrix-is-x-matrix
Easy
A square matrix is said to be an X-Matrix if both of the following conditions hold: 1. All the elements in the diagonals of the matrix are non-zero. 2. All other elements are 0. Given a 2D integer array grid of size n x n representing a square matrix, return true if grid is an X-Matrix. Otherwise, return false. Exam...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2, 0, 0], [0, 0, 0, 3], [0, 0, 4, 0], [0, 5, 0, 0]]) == False\n assert candidate(grid = [[1, 2, 0, 0], [0, 3, 1, 0], [0, 5, 2, 0], [0, 0, 0, 4]]) == False\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0,...
[ "[[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]", "[[5,7,0],[0,3,1],[0,5,0]]" ]
[ "Assuming a 0-indexed matrix, for a given cell on row i and column j, it is in a diagonal if and only if i == j or i == n - 1 - j.", "We can then iterate through the elements in the matrix to check if all the elements in the diagonals are non-zero and all other elements are zero." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().checkXMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:38", "tests_total": 70, "tests_dro...
typescript
{ "raw_signature": "function checkXMatrix(grid: number[][]): boolean {", "container": null, "callable": "checkXMatrix", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
2,320
count-number-of-ways-to-place-houses
Medium
There is a street with n * 2 plots, where there are n plots on each side of the street. The plots on each side are numbered from 1 to n. On each plot, a house can be placed. Return the number of ways houses can be placed such that no two houses are adjacent to each other on the same side of the street. Since the answe...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 25\n assert candidate(n = 100) == 20522904\n assert candidate(n = 10000) == 402613600\n assert candidate(n = 2) == 9\n assert candidate(n = 1) == 4\n assert candidate(n = 1000) == 500478595\n assert candidate(...
[ "1", "2" ]
[ "Try coming up with a DP solution for one side of the street.", "The DP for one side of the street will bear resemblance to the Fibonacci sequence.", "The number of different arrangements on both side of the street is the same." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().countHousePlacements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:41", "tests_total": 33, "test...
typescript
{ "raw_signature": "function countHousePlacements(n: number): number {", "container": null, "callable": "countHousePlacements", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
2,321
maximum-score-of-spliced-array
Hard
You are given two 0-indexed integer arrays nums1 and nums2, both of length n. You can choose two integers left and right where 0 <= left <= right < n and swap the subarray nums1[left...right] with the subarray nums2[left...right]. - For example, if nums1 = [1,2,3,4,5] and nums2 = [11,12,13,14,15] and you choose left ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [20, 40, 20, 70, 30],nums2 = [50, 20, 50, 40, 20]) == 220\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45]) == 150\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [10000, 10000, 10000, 10000, 1...
[ "[60,60,60]\n[10,90,10]", "[20,40,20,70,30]\n[50,20,50,40,20]", "[7,11,13]\n[1,1,1]" ]
[ "Think on Dynamic Programming.", "First assume you will be taking the array a and choose some subarray from b", "Suppose the DP is DP(pos, state). pos is the current position you are in. state is one of {0,1,2}, where 0 means taking the array a, 1 means we are taking the subarray b, and 2 means we are again tak...
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().maximumsSplicedArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:43", "tests_to...
typescript
{ "raw_signature": "function maximumsSplicedArray(nums1: number[], nums2: number[]): number {", "container": null, "callable": "maximumsSplicedArray", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" } ], "return_type": "n...
2,322
minimum-score-after-removals-on-a-tree
Hard
There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the i^th node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [a_i, b_i] indicates that there is an ed...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 5, 5, 4, 11],edges = [[0, 1], [1, 2], [1, 3], [3, 4]]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50],edges = [[0, 1], [0, 2], [0, 3], [3, 4]]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6],edges = [[0, 1], [1, ...
[ "[1,5,5,4,11]\n[[0,1],[1,2],[1,3],[3,4]]", "[5,5,2,4,4,2]\n[[0,1],[1,2],[5,2],[4,3],[1,3]]" ]
[ "Consider iterating over the first edge to remove, and then doing some precalculations on the 2 resulting connected components.", "Will calculating the XOR of each subtree help?" ]
{ "canonical_parameter_names": [ "nums", "edges" ], "leetcode_dataset_entry_point": "Solution().minimumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:45", "tests_total": 55,...
typescript
{ "raw_signature": "function minimumScore(nums: number[], edges: number[][]): number {", "container": null, "callable": "minimumScore", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "edges", "type": "number[][]" } ], "return_type": "number", "sig...
2,325
decode-the-message
Easy
You are given the strings key and message, which represent a cipher key and a secret message, respectively. The steps to decode message are as follows: 1. Use the first appearance of all 26 lowercase English letters in key as the order of the substitution table. 2. Align the substitution table with the regular English...
{ "language": "python", "source": "def check(candidate):\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"cba zyx\") == \"xyz abc\"\n assert candidate(key = \"a quick movement of the enemy will jeopardize five gunboats\",message = \"yfcj myj pyjl ufcj myj pyjl ufcj myj pyjl\") == \"omer gor...
[ "\"the quick brown fox jumps over the lazy dog\"\n\"vkbs bs t suepuv\"", "\"eljuxhpwnyrdgtqkviszcfmabo\"\n\"zwx hnfx lqantp mnoeius ycgk vcnjrdb\"" ]
[ "Iterate through the characters in the key to construct a mapping to the English alphabet.", "Make sure to check that the current character is not already in the mapping (only the first appearance is considered).", "Map the characters in the message according to the constructed mapping." ]
{ "canonical_parameter_names": [ "key", "message" ], "leetcode_dataset_entry_point": "Solution().decodeMessage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:50", "tests_total": 2...
typescript
{ "raw_signature": "function decodeMessage(key: string, message: string): string {", "container": null, "callable": "decodeMessage", "parameters": [ { "name": "key", "type": "string" }, { "name": "message", "type": "string" } ], "return_type": "string", "signature_s...
2,327
number-of-people-aware-of-a-secret
Medium
On day 1, one person discovers a secret. You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the secret. You are also given an integer forget, which means that each person will forget the secret forget days after dis...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 8,delay = 3,forget = 6) == 6\n assert candidate(n = 500,delay = 100,forget = 400) == 5820125\n assert candidate(n = 4,delay = 1,forget = 3) == 6\n assert candidate(n = 1000,delay = 5,forget = 10) == 743819361\n assert can...
[ "6\n2\n4", "4\n1\n3" ]
[ "Let dp[i][j] be the number of people who have known the secret for exactly j + 1 days, at day i.", "If j > 0, dp[i][j] = dp[i – 1][j – 1].", "dp[i][0] = sum(dp[i – 1][j]) for j in [delay – 1, forget – 2]." ]
{ "canonical_parameter_names": [ "n", "delay", "forget" ], "leetcode_dataset_entry_point": "Solution().peopleAwareOfSecret", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:55", ...
typescript
{ "raw_signature": "function peopleAwareOfSecret(n: number, delay: number, forget: number): number {", "container": null, "callable": "peopleAwareOfSecret", "parameters": [ { "name": "n", "type": "number" }, { "name": "delay", "type": "number" }, { "name": "forg...
2,328
number-of-increasing-paths-in-a-grid
Hard
You are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions. Return the number of strictly increasing paths in the grid such that you can start from any cell and end at any cell. Since the answer may be very large, return it modulo 10^9 + 7. Two paths are consid...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 9\n assert candidate(grid = [[4, 3, 2, 1], [3, 2, 1, 4], [2, 1, 4, 3], [1, 4, 3, 2]]) == 64\n assert candidate(grid = [[4, 3, 2, 1], [5, 6, 7, 8]]) == 50\n assert candidate(grid = [[1...
[ "[[1,1],[3,4]]", "[[1],[2]]" ]
[ "How can you calculate the number of increasing paths that start from a cell (i, j)? Think about dynamic programming.", "Define f(i, j) as the number of increasing paths starting from cell (i, j). Try to find how f(i, j) is related to each of f(i, j+1), f(i, j-1), f(i+1, j) and f(i-1, j)." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().countPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:57", "tests_total": 88, "tests_dropp...
typescript
{ "raw_signature": "function countPaths(grid: number[][]): number {", "container": null, "callable": "countPaths", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
2,332
the-latest-time-to-catch-a-bus
Medium
You are given a 0-indexed integer array buses of length n, where buses[i] represents the departure time of the i^th bus. You are also given a 0-indexed integer array passengers of length m, where passengers[j] represents the arrival time of the j^th passenger. All bus departure times are unique. All passenger arrival t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(buses = [50, 60, 70],passengers = [5, 10, 20, 30, 40],capacity = 5) == 70\n assert candidate(buses = [3, 5, 7],passengers = [2, 4, 6, 8],capacity = 1) == 5\n assert candidate(buses = [10, 20],passengers = [2, 17, 18, 19],capacity =...
[ "[10,20]\n[2,17,18,19]\n2", "[20,30,10]\n[19,13,26,4,25,11,21]\n2" ]
[ "Sort the buses and passengers arrays.", "Use 2 pointers to traverse buses and passengers with a simulation of passengers getting on a particular bus." ]
{ "canonical_parameter_names": [ "buses", "passengers", "capacity" ], "leetcode_dataset_entry_point": "Solution().latestTimeCatchTheBus", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T...
typescript
{ "raw_signature": "function latestTimeCatchTheBus(buses: number[], passengers: number[], capacity: number): number {", "container": null, "callable": "latestTimeCatchTheBus", "parameters": [ { "name": "buses", "type": "number[]" }, { "name": "passengers", "type": "number[]" ...
2,333
minimum-sum-of-squared-difference
Medium
You are given two positive 0-indexed integer arrays nums1 and nums2, both of length n. The sum of squared difference of arrays nums1 and nums2 is defined as the sum of (nums1[i] - nums2[i])^2 for each 0 <= i < n. You are also given two positive integers k1 and k2. You can modify any of the elements of nums1 by +1 or ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [5, 5, 5, 5],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45],k1 = 50,k2 = 50) == 0\n assert candidate(nums1 = [100000, 100000],nums2 = [0, 0],k1 = 100...
[ "[1,2,3,4]\n[2,10,20,19]\n0\n0", "[1,4,10,12]\n[5,8,6,9]\n1\n1" ]
[ "There is no difference between the purpose of k1 and k2. Adding +1 to one element in nums1 is same as performing -1 to one element in nums2, and vice versa.", "Reduce the sum of squared difference greedily. One operation of k should use the index that has the current maximum difference.", "Binary search the ma...
{ "canonical_parameter_names": [ "nums1", "nums2", "k1", "k2" ], "leetcode_dataset_entry_point": "Solution().minSumSquareDiff", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:...
typescript
{ "raw_signature": "function minSumSquareDiff(nums1: number[], nums2: number[], k1: number, k2: number): number {", "container": null, "callable": "minSumSquareDiff", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" }, { ...
2,334
subarray-with-elements-greater-than-varying-threshold
Hard
You are given an integer array nums and an integer threshold. Find any subarray of nums of length k such that every element in the subarray is greater than threshold / k. Return the size of any such subarray. If there is no such subarray, return -1. A subarray is a contiguous non-empty sequence of elements within an...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],threshold = 15) == 1\n assert candidate(nums = [10, 10, 10, 10, 10],threshold = 1) == 1\n assert candidate(nums = [5, 5, 5, 5, 5],threshold = 25) == -1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4,...
[ "[1,3,4,3,1]\n6", "[6,5,6,5,8]\n7" ]
[ "For all elements to be greater than the threshold/length, the minimum element in the subarray must be greater than the threshold/length.", "For a given index, could you find the largest subarray such that the given index is the minimum element?", "Could you use a monotonic stack to get the next and previous sm...
{ "canonical_parameter_names": [ "nums", "threshold" ], "leetcode_dataset_entry_point": "Solution().validSubarraySize", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:10", "tests_to...
typescript
{ "raw_signature": "function validSubarraySize(nums: number[], threshold: number): number {", "container": null, "callable": "validSubarraySize", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "threshold", "type": "number" } ], "return_type": "numbe...
2,335
minimum-amount-of-time-to-fill-cups
Easy
You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up 2 cups with different types of water, or 1 cup of any type of water. You are given a 0-indexed integer array amount of length 3 where amount[0], amount[1], and amount[2] denote the number of cold, warm, and hot...
{ "language": "python", "source": "def check(candidate):\n assert candidate(amount = [33, 33, 34]) == 50\n assert candidate(amount = [0, 0, 0]) == 0\n assert candidate(amount = [99, 1, 1]) == 99\n assert candidate(amount = [7, 7, 7]) == 11\n assert candidate(amount = [10, 10, 10]) == 15\n assert c...
[ "[1,4,2]", "[5,4,4]", "[5,0,0]" ]
[ "To minimize the amount of time needed, you want to fill up as many cups as possible in each second. This means that you want to maximize the number of seconds where you are filling up two cups.", "You always want to fill up the two types of water with the most unfilled cups." ]
{ "canonical_parameter_names": [ "amount" ], "leetcode_dataset_entry_point": "Solution().fillCups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:12", "tests_total": 178, "tests_drop...
typescript
{ "raw_signature": "function fillCups(amount: number[]): number {", "container": null, "callable": "fillCups", "parameters": [ { "name": "amount", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,337
move-pieces-to-obtain-a-string
Medium
You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where: - The characters 'L' and 'R' represent pieces, where a piece 'L' can move to the left only if there is a blank space directly to its left, and a piece 'R' can move to the right only if the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(start = \"_R\",target = \"R_\") == False\n assert candidate(start = \"___\",target = \"___\") == True\n assert candidate(start = \"LR\",target = \"LR\") == True\n assert candidate(start = \"_LL_R\",target = \"LL__R\") == True\n ...
[ "\"_L__R__R_\"\n\"L______RR\"", "\"R_L_\"\n\"__LR\"", "\"_R\"\n\"R_\"" ]
[ "After some sequence of moves, can the order of the pieces change?", "Try to match each piece in s with a piece in e." ]
{ "canonical_parameter_names": [ "start", "target" ], "leetcode_dataset_entry_point": "Solution().canChange", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:14", "tests_total": 136,...
typescript
{ "raw_signature": "function canChange(start: string, target: string): boolean {", "container": null, "callable": "canChange", "parameters": [ { "name": "start", "type": "string" }, { "name": "target", "type": "string" } ], "return_type": "boolean", "signature_sourc...
2,338
count-the-number-of-ideal-arrays
Hard
You are given two integers n and maxValue, which are used to describe an ideal array. A 0-indexed integer array arr of length n is considered ideal if the following conditions hold: - Every arr[i] is a value from 1 to maxValue, for 0 <= i < n. - Every arr[i] is divisible by arr[i - 1], for 0 < i < n. Return the numb...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 7,maxValue = 7) == 106\n assert candidate(n = 2,maxValue = 5) == 10\n assert candidate(n = 3,maxValue = 7) == 28\n assert candidate(n = 3,maxValue = 6) == 25\n assert candidate(n = 6,maxValue = 12) == 327\n assert cand...
[ "2\n5", "5\n3" ]
[ "Notice that an ideal array is non-decreasing.", "Consider an alternative problem: where an ideal array must also be strictly increasing. Can you use DP to solve it?", "Will combinatorics help to get an answer from the alternative problem to the actual problem?" ]
{ "canonical_parameter_names": [ "n", "maxValue" ], "leetcode_dataset_entry_point": "Solution().idealArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:17", "tests_total": 80, ...
typescript
{ "raw_signature": "function idealArrays(n: number, maxValue: number): number {", "container": null, "callable": "idealArrays", "parameters": [ { "name": "n", "type": "number" }, { "name": "maxValue", "type": "number" } ], "return_type": "number", "signature_source"...
2,341
maximum-number-of-pairs-in-array
Easy
You are given a 0-indexed integer array nums. In one operation, you may do the following: - Choose two integers in nums that are equal. - Remove both integers from nums, forming a pair. The operation is done on nums as many times as possible. Return a 0-indexed integer array answer of size 2 where answer[0] is the n...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [5, 0]\n assert candidate(nums = [100, 0, 50, 50, 0, 100]) == [3, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 10]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1,...
[ "[1,3,2,1,3,2,2]", "[1,1]", "[0]" ]
[ "What do we need to know to find how many pairs we can make? We need to know the frequency of each integer.", "When will there be a leftover number? When the frequency of an integer is an odd number." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:21", "tests_total": 126, "tests_d...
typescript
{ "raw_signature": "function numberOfPairs(nums: number[]): number[] {", "container": null, "callable": "numberOfPairs", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
2,342
max-sum-of-a-pair-with-equal-sum-of-digits
Medium
You are given a 0-indexed array nums consisting of positive integers. You can choose two indices i and j, such that i != j, and the sum of digits of the number nums[i] is equal to that of nums[j]. Return the maximum value of nums[i] + nums[j] that you can obtain over all possible indices i and j that satisfy the condi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [99, 18, 81, 27]) == 108\n assert candidate(nums = [55, 23, 45, 55, 23]) == 110\n assert candidate(nums = [55, 23, 45, 55]) == 110\n assert candidate(nums = [111, 222, 333, 444]) == -1\n assert candidate(nums = [100000...
[ "[18,43,36,13,7]", "[10,12,19,14]" ]
[ "What is the largest possible sum of digits a number can have?", "Group the array elements by the sum of their digits, and find the largest two elements of each group." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maximumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:24", "tests_total": 121, "tests_drop...
typescript
{ "raw_signature": "function maximumSum(nums: number[]): number {", "container": null, "callable": "maximumSum", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,343
query-kth-smallest-trimmed-number
Medium
You are given a 0-indexed array of strings nums, where each string is of equal length and consists of only digits. You are also given a 0-indexed 2D integer array queries where queries[i] = [k_i, trim_i]. For each queries[i], you need to: - Trim each number in nums to its rightmost trim_i digits. - Determine the inde...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = ['111', '222', '333', '444'],queries = [[1, 1], [2, 2], [3, 3], [4, 3]]) == [0, 1, 2, 3]\n assert candidate(nums = ['123', '456', '789', '012'],queries = [[1, 2], [3, 3], [2, 1]]) == [3, 1, 0]\n assert candidate(nums = ['001...
[ "[\"102\",\"473\",\"251\",\"814\"]\n[[1,1],[2,3],[4,2],[1,2]]", "[\"24\",\"37\",\"96\",\"04\"]\n[[2,1],[2,2]]" ]
[ "Run a simulation to follow the requirement of each query." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().smallestTrimmedNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:26", "tests...
typescript
{ "raw_signature": "function smallestTrimmedNumbers(nums: string[], queries: number[][]): number[] {", "container": null, "callable": "smallestTrimmedNumbers", "parameters": [ { "name": "nums", "type": "string[]" }, { "name": "queries", "type": "number[][]" } ], "retu...
2,344
minimum-deletions-to-make-array-divisible
Hard
You are given two positive integer arrays nums and numsDivide. You can delete any number of elements from nums. Return the minimum number of deletions such that the smallest element in nums divides all the elements of numsDivide. If this is not possible, return -1. Note that an integer x divides y if y % x == 0. Exa...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],numsDivide = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums = [5, 10, 15, 20],numsDivide = [5, 15, 25, 35]) == 0\n assert candidate(nums = [1, 3, 5, 7],numsDivide = [2, 4, 6, 8]) == 0\n assert candidat...
[ "[2,3,2,4,3]\n[9,6,9,3,15]", "[4,3,6]\n[8,2,6,10]" ]
[ "How can we find an integer x that divides all the elements of numsDivide?", "Will finding GCD (Greatest Common Divisor) help here?" ]
{ "canonical_parameter_names": [ "nums", "numsDivide" ], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:29", "tests_total...
typescript
{ "raw_signature": "function minOperations(nums: number[], numsDivide: number[]): number {", "container": null, "callable": "minOperations", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "numsDivide", "type": "number[]" } ], "return_type": "number"...
2,347
best-poker-hand
Easy
You are given an integer array ranks and a character array suits. You have 5 cards where the i^th card has a rank of ranks[i] and a suit of suits[i]. The following are the types of poker hands you can make from best to worst: 1. "Flush": Five cards of the same suit. 2. "Three of a Kind": Three cards of the same rank....
{ "language": "python", "source": "def check(candidate):\n assert candidate(ranks = [7, 7, 7, 8, 9],suits = ['a', 'b', 'c', 'a', 'd']) == \"Three of a Kind\"\n assert candidate(ranks = [10, 10, 2, 12, 9],suits = ['a', 'b', 'c', 'a', 'd']) == \"Pair\"\n assert candidate(ranks = [7, 7, 7, 7, 7],suits = ['a',...
[ "[13,2,3,1,9]\n[\"a\",\"a\",\"a\",\"a\",\"a\"]", "[4,4,2,4,4]\n[\"d\",\"a\",\"a\",\"b\",\"c\"]", "[10,10,2,12,9]\n[\"a\",\"b\",\"c\",\"a\",\"d\"]" ]
[ "Sequentially check the conditions 1 through 4, and return the outcome corresponding to the first met condition." ]
{ "canonical_parameter_names": [ "ranks", "suits" ], "leetcode_dataset_entry_point": "Solution().bestHand", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:33", "tests_total": 100, ...
typescript
{ "raw_signature": "function bestHand(ranks: number[], suits: string[]): string {", "container": null, "callable": "bestHand", "parameters": [ { "name": "ranks", "type": "number[]" }, { "name": "suits", "type": "string[]" } ], "return_type": "string", "signature_sou...
2,348
number-of-zero-filled-subarrays
Medium
Given an integer array nums, return the number of subarrays filled with 0. A subarray is a contiguous non-empty sequence of elements within an array. Example 1: Input: nums = [1,3,0,0,2,0,0,4] Output: 6 Explanation: There are 4 occurrences of [0] as a subarray. There are 2 occurrences of [0,0] as a subarray. There i...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 45\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 55\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 2\n ...
[ "[1,3,0,0,2,0,0,4]", "[0,0,0,2,0,0]", "[2,10,2019]" ]
[ "For each zero, you can calculate the number of zero-filled subarrays that end on that index, which is the number of consecutive zeros behind the current element + 1.", "Maintain the number of consecutive zeros behind the current element, count the number of zero-filled subarrays that end on each index, sum it up...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().zeroFilledSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:36", "tests_total": 99, "tes...
typescript
{ "raw_signature": "function zeroFilledSubarray(nums: number[]): number {", "container": null, "callable": "zeroFilledSubarray", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
2,350
shortest-impossible-sequence-of-rolls
Hard
You are given an integer array rolls of length n and an integer k. You roll a k sided dice numbered from 1 to k, n times, where the result of the i^th roll is rolls[i]. Return the length of the shortest sequence of rolls so that there's no such subsequence in rolls. A sequence of rolls of length len is the result of ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(rolls = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 2\n assert candidate(rolls = [1, 1, 1, 1, 1],k = 1) == 6\n assert candidate(rolls = [1, 2, 3, 1, 2, 3, 1, 2, 3],k = 3) == 4\n assert candidate(rolls = [6, 5, 4, 3, 2, 1, 6, 5, 4...
[ "[4,2,1,2,3,3,2,4,1]\n4", "[1,1,2,2]\n2", "[1,1,3,2,2,2,3,3]\n4" ]
[ "How can you find the minimum index such that all sequences of length 1 can be formed from the start until that index?", "Starting from the previous minimum index, what is the next index such that all sequences of length 2 can be formed?", "Can you extend the idea to sequences of length 3 and more?" ]
{ "canonical_parameter_names": [ "rolls", "k" ], "leetcode_dataset_entry_point": "Solution().shortestSequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:38", "tests_total": 97...
typescript
{ "raw_signature": "function shortestSequence(rolls: number[], k: number): number {", "container": null, "callable": "shortestSequence", "parameters": [ { "name": "rolls", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature...
2,351
first-letter-to-appear-twice
Easy
Given a string s consisting of lowercase English letters, return the first letter to appear twice. Note: - A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b. - s will contain at least one letter that appears twice. Example 1: Input: s = "abccbaacz" O...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"alphabet\") == \"a\"\n assert candidate(s = \"finding\") == \"i\"\n assert candidate(s = \"xyzxyz\") == \"x\"\n assert candidate(s = \"zabcdefghijkkl\") == \"k\"\n assert candidate(s = \"first\") == None\n assert can...
[ "\"abccbaacz\"", "\"abcdd\"" ]
[ "Iterate through the string from left to right. Keep track of the elements you have already seen in a set.", "If the current element is already in the set, return that element." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().repeatedCharacter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:40", "tests_total": 132, "tests_...
typescript
{ "raw_signature": "function repeatedCharacter(s: string): string {", "container": null, "callable": "repeatedCharacter", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
2,352
equal-row-and-column-pairs
Medium
Given a 0-indexed n x n integer matrix grid, return the number of pairs (r_i, c_j) such that row r_i and column c_j are equal. A row and column pair is considered equal if they contain the same elements in the same order (i.e., an equal array). Example 1: Input: grid = [[3,2,1],[1,7,6],[2,7,7]] Output: 1 Explanation...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 9\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 9\n assert candidate(grid = [[5]]) == 1\n assert candidate(grid = [[3, 2, 1], [1, 7, 6], [2, 7, 7]]) == 1\n assert...
[ "[[3,2,1],[1,7,6],[2,7,7]]", "[[3,1,2,2],[1,4,4,5],[2,4,2,2],[2,4,2,2]]" ]
[ "We can use nested loops to compare every row against every column.", "Another loop is necessary to compare the row and column element by element.", "It is also possible to hash the arrays and compare the hashed values instead." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().equalPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:43", "tests_total": 64, "tests_dropp...
typescript
{ "raw_signature": "function equalPairs(grid: number[][]): number {", "container": null, "callable": "equalPairs", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
2,354
number-of-excellent-pairs
Hard
You are given a 0-indexed positive integer array nums and a positive integer k. A pair of numbers (num1, num2) is called excellent if the following conditions are satisfied: - Both the numbers num1 and num2 exist in the array nums. - The sum of the number of set bits in num1 OR num2 and num1 AND num2 is greater than ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [2, 4, 8, 16],k = 3) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 4) == 93\n assert candidate(nums = [1, 2, 4, 8, 16, 32],k = 3) == 0\n asse...
[ "[1,2,3,1]\n3", "[5,1,1]\n10" ]
[ "Can you find a different way to describe the second condition?", "The sum of the number of set bits in (num1 OR num2) and (num1 AND num2) is equal to the sum of the number of set bits in num1 and num2." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().countExcellentPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:45", "tests_total": ...
typescript
{ "raw_signature": "function countExcellentPairs(nums: number[], k: number): number {", "container": null, "callable": "countExcellentPairs", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signa...
2,357
make-array-zero-by-subtracting-equal-amounts
Easy
You are given a non-negative integer array nums. In one operation, you must: - Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums. - Subtract x from every positive element in nums. Return the minimum number of operations to make every element in nums equal to 0. Ex...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [1, 5, 0, 3, 5]) == 3\n assert candidate(nums = [0, 1, 0, 1, 0]) == 1\n assert candidate(nums = [1]) == 1\n assert c...
[ "[1,5,0,3,5]", "[0]" ]
[ "It is always best to set x as the smallest non-zero element in nums.", "Elements with the same value will always take the same number of operations to become 0. Contrarily, elements with different values will always take a different number of operations to become 0.", "The answer is the number of unique non-ze...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:50", "tests_total": 116, "tes...
typescript
{ "raw_signature": "function minimumOperations(nums: number[]): number {", "container": null, "callable": "minimumOperations", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
2,358
maximum-number-of-groups-entering-a-competition
Medium
You are given a positive integer array grades which represents the grades of students in a university. You would like to enter all these students into a competition in ordered non-empty groups, such that the ordering meets the following conditions: - The sum of the grades of students in the i^th group is less than the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grades = [10, 6, 12, 7, 3, 5]) == 3\n assert candidate(grades = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 4\n assert candidate(grades = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 4\n assert candidate(grades = [1]) == 1\n assert c...
[ "[10,6,12,7,3,5]", "[8,8]" ]
[ "Would it be easier to place the students into valid groups after sorting them based on their grades in ascending order?", "Notice that, after sorting, we can separate them into groups of sizes 1, 2, 3, and so on.", "If the last group is invalid, we can merge it with the previous group.", "This creates the ma...
{ "canonical_parameter_names": [ "grades" ], "leetcode_dataset_entry_point": "Solution().maximumGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:52", "tests_total": 84, "tests_...
typescript
{ "raw_signature": "function maximumGroups(grades: number[]): number {", "container": null, "callable": "maximumGroups", "parameters": [ { "name": "grades", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
2,359
find-closest-node-to-given-two-nodes
Medium
You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge. The graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from i, then edges[i] == -1. You...
{ "language": "python", "source": "def check(candidate):\n assert candidate(edges = [5, -1, 3, 4, 5, 6, -1, -1, 4, 3],node1 = 0,node2 = 0) == 0\n assert candidate(edges = [4, 3, 0, 5, 3, -1],node1 = 4,node2 = 0) == 4\n assert candidate(edges = [1, 2, 0, -1],node1 = 0,node2 = 2) == 0\n assert candidate(e...
[ "[2,2,3,-1]\n0\n1", "[1,2,-1]\n0\n2" ]
[ "How can you find the shortest distance from one node to all nodes in the graph?", "Use BFS to find the shortest distance from both node1 and node2 to all nodes in the graph. Then iterate over all nodes, and find the node with the minimum max distance." ]
{ "canonical_parameter_names": [ "edges", "node1", "node2" ], "leetcode_dataset_entry_point": "Solution().closestMeetingNode", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:55", ...
typescript
{ "raw_signature": "function closestMeetingNode(edges: number[], node1: number, node2: number): number {", "container": null, "callable": "closestMeetingNode", "parameters": [ { "name": "edges", "type": "number[]" }, { "name": "node1", "type": "number" }, { "nam...
2,360
longest-cycle-in-a-graph
Hard
You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge. The graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from node i, then edges[i] == -1....
{ "language": "python", "source": "def check(candidate):\n assert candidate(edges = [-1, 2, 0, 1, -1]) == -1\n assert candidate(edges = [1, 2, 0, 4, -1]) == 3\n assert candidate(edges = [5, 4, 5, 4, 5, 4]) == 2\n assert candidate(edges = [1, 0, -1, -1]) == 2\n assert candidate(edges = [1, 0, 0, 0, 1]...
[ "[3,3,4,2,3]", "[2,-1,3,1]" ]
[ "How many cycles can each node at most be part of?", "Each node can be part of at most one cycle. Start from each node and find the cycle that it is part of if there is any. Save the already visited nodes to not repeat visiting the same cycle multiple times." ]
{ "canonical_parameter_names": [ "edges" ], "leetcode_dataset_entry_point": "Solution().longestCycle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:58", "tests_total": 109, "tests_d...
typescript
{ "raw_signature": "function longestCycle(edges: number[]): number {", "container": null, "callable": "longestCycle", "parameters": [ { "name": "edges", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
2,363
merge-similar-items
Easy
You are given two 2D integer arrays, items1 and items2, representing two sets of items. Each array items has the following properties: - items[i] = [value_i, weight_i] where value_i represents the value and weight_i represents the weight of the i^th item. - The value of each item in items is unique. Return a 2D integ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(items1 = [[1, 3], [2, 2]],items2 = [[7, 1], [2, 2], [1, 4]]) == [(1, 7), (2, 4), (7, 1)]\n assert candidate(items1 = [[1, 1000]],items2 = [[2, 1000]]) == [(1, 1000), (2, 1000)]\n assert candidate(items1 = [[1, 1], [4, 5], [3, 8]],i...
[ "[[1,1],[4,5],[3,8]]\n[[3,1],[1,5]]", "[[1,1],[3,2],[2,3]]\n[[2,1],[3,2],[1,3]]", "[[1,3],[2,2]]\n[[7,1],[2,2],[1,4]]" ]
[ "Map the weights using the corresponding values as keys.", "Make sure your output is sorted in ascending order by value." ]
{ "canonical_parameter_names": [ "items1", "items2" ], "leetcode_dataset_entry_point": "Solution().mergeSimilarItems", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:03", "tests_tot...
typescript
{ "raw_signature": "function mergeSimilarItems(items1: number[][], items2: number[][]): number[][] {", "container": null, "callable": "mergeSimilarItems", "parameters": [ { "name": "items1", "type": "number[][]" }, { "name": "items2", "type": "number[][]" } ], "return...
2,364
count-number-of-bad-pairs
Medium
You are given a 0-indexed integer array nums. A pair of indices (i, j) is a bad pair if i < j and j - i != nums[j] - nums[i]. Return the total number of bad pairs in nums. Example 1: Input: nums = [4,1,3,3] Output: 5 Explanation: The pair (0, 1) is a bad pair since 1 - 0 != 1 - 4. The pair (0, 2) is a bad pair since...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 15\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4,...
[ "[4,1,3,3]", "[1,2,3,4,5]" ]
[ "Would it be easier to count the number of pairs that are not bad pairs?", "Notice that (j - i != nums[j] - nums[i]) is the same as (nums[i] - i != nums[j] - j).", "Keep a counter of nums[i] - i. To be efficient, use a HashMap." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countBadPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:05", "tests_total": 132, "tests_d...
typescript
{ "raw_signature": "function countBadPairs(nums: number[]): number {", "container": null, "callable": "countBadPairs", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
2,365
task-scheduler-ii
Medium
You are given a 0-indexed array of positive integers tasks, representing tasks that need to be completed in order, where tasks[i] represents the type of the i^th task. You are also given a positive integer space, which represents the minimum number of days that must pass after the completion of a task before another t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 10) == 10\n assert candidate(tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],space = 1) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5],space = 5) == 5\n assert candidate(tasks = [1, 1, 1...
[ "[1,2,1,2,3,1]\n3", "[5,8,8,5]\n2" ]
[ "Try taking breaks as late as possible, such that tasks are still spaced appropriately.", "Whenever considering whether to complete the next task, if it is not the first task of its type, check how many days ago the previous task was completed and add an appropriate number of breaks." ]
{ "canonical_parameter_names": [ "tasks", "space" ], "leetcode_dataset_entry_point": "Solution().taskSchedulerII", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:07", "tests_total":...
typescript
{ "raw_signature": "function taskSchedulerII(tasks: number[], space: number): number {", "container": null, "callable": "taskSchedulerII", "parameters": [ { "name": "tasks", "type": "number[]" }, { "name": "space", "type": "number" } ], "return_type": "number", "sig...
2,366
minimum-replacements-to-sort-the-array
Hard
You are given a 0-indexed integer array nums. In one operation you can replace any element of the array with any two elements that sum to it. - For example, consider nums = [5,6,7]. In one operation, we can replace nums[1] with 2 and 4 and convert nums to [5,2,4,7]. Return the minimum number of operations to make an ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1000000000]) == 0\n assert candidate(nums = [9, 7, 5, 3, 1]) == 20\n assert candidate(nums = [10, 5, 3]) == 5\n assert candidate(nums = [100, 75, 50]) == 3\n assert candidate(nums = [1, 3, 5, 7, 9]) == 0\n asser...
[ "[3,9,3]", "[1,2,3,4,5]" ]
[ "It is optimal to never make an operation to the last element of the array.", "You can iterate from the second last element to the first. If the current value is greater than the previous bound, we want to break it into pieces so that the smaller one is as large as possible but not larger than the previous one." ...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumReplacement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:10", "tests_total": 107, "te...
typescript
{ "raw_signature": "function minimumReplacement(nums: number[]): number {", "container": null, "callable": "minimumReplacement", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
2,367
number-of-arithmetic-triplets
Easy
You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met: - i < j < k, - nums[j] - nums[i] == diff, and - nums[k] - nums[j] == diff. Return the number of unique arithmetic triplets. Example 1: Inpu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13],diff = 2) == 5\n assert candidate(nums = [5, 10, 15, 20, 25, 30],diff = 5) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],diff = 4) == 6\n assert candidate(nums = [4, 5, 6, 7, 8...
[ "[0,1,4,6,7,10]\n3", "[4,5,6,7,8,9]\n2" ]
[ "Are the constraints small enough for brute force?", "We can use three loops, each iterating through the array to go through every possible triplet. Be sure to not count duplicates." ]
{ "canonical_parameter_names": [ "nums", "diff" ], "leetcode_dataset_entry_point": "Solution().arithmeticTriplets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:12", "tests_total"...
typescript
{ "raw_signature": "function arithmeticTriplets(nums: number[], diff: number): number {", "container": null, "callable": "arithmeticTriplets", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "diff", "type": "number" } ], "return_type": "number", "s...
2,368
reachable-nodes-with-restrictions
Medium
There is an undirected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given a 2D integer array edges of length n - 1 where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree. You are also given an integer array restricted which represents restricted nodes. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [2, 3], [2, 4], [4, 5]],restricted = [1, 4]) == 3\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]],restricted = [5, 7]) == 6\n assert candidate(n = 8,edges = [...
[ "7\n[[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]]\n[4,5]", "7\n[[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]]\n[4,2,1]" ]
[ "Can we find all the reachable nodes in a single traversal?", "Traverse the graph from node 0 while avoiding the nodes in restricted and do not revisit nodes that have been visited.", "Keep count of how many nodes are visited in total." ]
{ "canonical_parameter_names": [ "n", "edges", "restricted" ], "leetcode_dataset_entry_point": "Solution().reachableNodes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:15", "...
typescript
{ "raw_signature": "function reachableNodes(n: number, edges: number[][], restricted: number[]): number {", "container": null, "callable": "reachableNodes", "parameters": [ { "name": "n", "type": "number" }, { "name": "edges", "type": "number[][]" }, { "name": "...
2,369
check-if-there-is-a-valid-partition-for-the-array
Medium
You are given a 0-indexed integer array nums. You have to partition the array into one or more contiguous subarrays. We call a partition of the array valid if each of the obtained subarrays satisfies one of the following conditions: 1. The subarray consists of exactly 2, equal elements. For example, the subarray [2,2...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 4, 5]) == False\n assert candidate(nums = [2, 2, 2, 3, 3, 4, 4, 4]) == True\n assert candidate(nums = [2, 2, 3, 3, 4, 4]) == True\n assert candidate(nums = [1, 2, 3, 3, 3, 4, 5, 5]) == False\n assert candi...
[ "[4,4,4,5,6]", "[1,1,1,2]" ]
[ "How can you reduce the problem to checking if there is a valid partition for a smaller array?", "Use dynamic programming to reduce the problem until you have an empty array." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().validPartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:18", "tests_total": 134, "tests_...
typescript
{ "raw_signature": "function validPartition(nums: number[]): boolean {", "container": null, "callable": "validPartition", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
2,370
longest-ideal-subsequence
Medium
You are given a string s consisting of lowercase letters and an integer k. We call a string t ideal if the following conditions are satisfied: - t is a subsequence of the string s. - The absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k. Return the length of the l...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",k = 25) == 20\n assert candidate(s = \"a\",k = 0) == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 0) == 1\n assert candidate(s = \"abcd\",k = 3) == 4\n assert candidate(s = \"zyxwvu...
[ "\"acfgbd\"\n2", "\"abcd\"\n3" ]
[ "How can you calculate the longest ideal subsequence that ends at a specific index i?", "Can you calculate it for all positions i? How can you use previously calculated answers to calculate the answer for the next position?" ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().longestIdealString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:20", "tests_total": 85, ...
typescript
{ "raw_signature": "function longestIdealString(s: string, k: number): number {", "container": null, "callable": "longestIdealString", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source"...
2,373
largest-local-values-in-a-matrix
Easy
You are given an n x n integer matrix grid. Generate an integer matrix maxLocal of size (n - 2) x (n - 2) such that: - maxLocal[i][j] is equal to the largest value of the 3 x 3 matrix in grid centered around row i + 1 and column j + 1. In other words, we want to find the largest value in every contiguous 3 x 3 matri...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[5, 8, 4, 3], [3, 5, 9, 5], [7, 6, 7, 9], [4, 8, 5, 3]]) == [[9, 9], [9, 9]]\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 2, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == [[2, 2, 2], [2, 2, 2], [2, 2, 2]]...
[ "[[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]", "[[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]" ]
[ "Use nested loops to run through all possible 3 x 3 windows in the matrix.", "For each 3 x 3 window, iterate through the values to get the maximum value within the window." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().largestLocal", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:25", "tests_total": 56, "tests_dro...
typescript
{ "raw_signature": "function largestLocal(grid: number[][]): number[][] {", "container": null, "callable": "largestLocal", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
2,374
node-with-highest-edge-score
Medium
You are given a directed graph with n nodes labeled from 0 to n - 1, where each node has exactly one outgoing edge. The graph is represented by a given 0-indexed integer array edges of length n, where edges[i] indicates that there is a directed edge from node i to node edges[i]. The edge score of a node i is defined ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(edges = [2, 0, 0, 2]) == 0\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 0\n assert candidate(edges = [1, 0, 0, 0, 0, 7, 7, 5]) == 7\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 0]) == 0\n assert candidate...
[ "[1,0,0,0,0,7,7,5]", "[2,0,0,2]" ]
[ "Create an array arr where arr[i] is the edge score for node i.", "How does the edge score for node edges[i] change? It increases by i.", "The edge score may not fit within a standard 32-bit integer." ]
{ "canonical_parameter_names": [ "edges" ], "leetcode_dataset_entry_point": "Solution().edgeScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:27", "tests_total": 26, "tests_dropp...
typescript
{ "raw_signature": "function edgeScore(edges: number[]): number {", "container": null, "callable": "edgeScore", "parameters": [ { "name": "edges", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,375
construct-smallest-number-from-di-string
Medium
You are given a 0-indexed string pattern of length n consisting of the characters 'I' meaning increasing and 'D' meaning decreasing. A 0-indexed string num of length n + 1 is created using the following conditions: - num consists of the digits '1' to '9', where each digit is used at most once. - If pattern[i] == 'I',...
{ "language": "python", "source": "def check(candidate):\n assert candidate(pattern = \"DDD\") == \"4321\"\n assert candidate(pattern = \"IIIDIDDD\") == \"123549876\"\n assert candidate(pattern = \"ID\") == \"132\"\n assert candidate(pattern = \"IIDDD\") == \"126543\"\n assert candidate(pattern = \"D...
[ "\"IIIDIDDD\"", "\"DDD\"" ]
[ "With the constraints, could we generate every possible string?", "Yes we can. Now we just need to check if the string meets all the conditions." ]
{ "canonical_parameter_names": [ "pattern" ], "leetcode_dataset_entry_point": "Solution().smallestNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:30", "tests_total": 116, "tes...
typescript
{ "raw_signature": "function smallestNumber(pattern: string): string {", "container": null, "callable": "smallestNumber", "parameters": [ { "name": "pattern", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
2,376
count-special-integers
Hard
We call a positive integer special if all of its digits are distinct. Given a positive integer n, return the number of special integers that belong to the interval [1, n]. Example 1: Input: n = 20 Output: 19 Explanation: All the integers from 1 to 20, except 11, are special. Thus, there are 19 special integers. Exa...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 135) == 110\n assert candidate(n = 999) == 738\n assert candidate(n = 200) == 162\n assert candidate(n = 10000) == 5274\n assert candidate(n = 1234) == 803\n assert candidate(n = 2000) == 1242\n assert candidate(n =...
[ "20", "5", "135" ]
[ "Try to think of dynamic programming.", "Use the idea of digit dynamic programming to build the numbers, in addition to a bitmask that will tell which digits you have used so far on the number that you are building." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().countSpecialNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:32", "tests_total": 57, "tests...
typescript
{ "raw_signature": "function countSpecialNumbers(n: number): number {", "container": null, "callable": "countSpecialNumbers", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
2,379
minimum-recolors-to-get-k-consecutive-black-blocks
Easy
You are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the i^th block. The characters 'W' and 'B' denote the colors white and black, respectively. You are also given an integer k, which is the desired number of consecutive black blocks. In one operation, y...
{ "language": "python", "source": "def check(candidate):\n assert candidate(blocks = \"WWWW\",k = 2) == 2\n assert candidate(blocks = \"WBBBWWBBBW\",k = 3) == 0\n assert candidate(blocks = \"WBBWWBBWBW\",k = 7) == 3\n assert candidate(blocks = \"BBBBB\",k = 3) == 0\n assert candidate(blocks = \"BWBWB...
[ "\"WBBWWBBWBW\"\n7", "\"WBWBBBW\"\n2" ]
[ "Iterate through all possible consecutive substrings of k characters.", "Find the number of changes for each substring to make all blocks black, and return the minimum of these." ]
{ "canonical_parameter_names": [ "blocks", "k" ], "leetcode_dataset_entry_point": "Solution().minimumRecolors", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:37", "tests_total": 10...
typescript
{ "raw_signature": "function minimumRecolors(blocks: string, k: number): number {", "container": null, "callable": "minimumRecolors", "parameters": [ { "name": "blocks", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_sou...
2,380
time-needed-to-rearrange-a-binary-string
Medium
You are given a binary string s. In one second, all occurrences of "01" are simultaneously replaced with "10". This process repeats until no occurrences of "01" exist. Return the number of seconds needed to complete this process. Example 1: Input: s = "0110101" Output: 4 Explanation: After one second, s becomes "101...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == 0\n assert candidate(s = \"00110011\") == 5\n assert candidate(s = \"0000\") == 0\n assert candidate(s = \"111000\") == 0\n assert candidate(s = \"0010110\") == 4\n assert candidate(s = \"1001001\") == 4\n...
[ "\"0110101\"", "\"11100\"" ]
[ "Try replicating the steps from the problem statement.", "Perform the replacements simultaneously, and return the number of times the process repeats." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().secondsToRemoveOccurrences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:39", "tests_total": 127, ...
typescript
{ "raw_signature": "function secondsToRemoveOccurrences(s: string): number {", "container": null, "callable": "secondsToRemoveOccurrences", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetc...
2,381
shifting-letters-ii
Medium
You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [start_i, end_i, direction_i]. For every i, shift the characters in s from the index start_i to the index end_i (inclusive) forward if direction_i = 1, or shift the characters backward if direction_i = 0. Shifting a c...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"world\",shifts = [[0, 4, 0], [0, 4, 0], [0, 4, 0], [0, 4, 0]]) == \"sknhz\"\n assert candidate(s = \"abc\",shifts = [[0, 1, 0], [1, 2, 1], [0, 2, 1]]) == \"ace\"\n assert candidate(s = \"xyz\",shifts = [[0, 2, 0]]) == \"wxy\"...
[ "\"abc\"\n[[0,1,0],[1,2,1],[0,2,1]]", "\"dztz\"\n[[0,0,0],[1,1,1]]" ]
[ "Instead of shifting every character in each shift, could you keep track of which characters are shifted and by how much across all shifts?", "Try marking the start and ends of each shift, then perform a prefix sum of the shifts." ]
{ "canonical_parameter_names": [ "s", "shifts" ], "leetcode_dataset_entry_point": "Solution().shiftingLetters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:41", "tests_total": 94...
typescript
{ "raw_signature": "function shiftingLetters(s: string, shifts: number[][]): string {", "container": null, "callable": "shiftingLetters", "parameters": [ { "name": "s", "type": "string" }, { "name": "shifts", "type": "number[][]" } ], "return_type": "string", "signa...
2,382
maximum-segment-sum-after-removals
Hard
You are given two 0-indexed integer arrays nums and removeQueries, both of length n. For the i^th query, the element in nums at the index removeQueries[i] is removed, splitting nums into different segments. A segment is a contiguous sequence of positive integers in nums. A segment sum is the sum of every element in a ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 5, 6, 1],removeQueries = [0, 3, 2, 4, 1]) == [14, 7, 2, 2, 0]\n assert candidate(nums = [5, 1, 4, 3, 2],removeQueries = [2, 0, 4, 1, 3]) == [6, 5, 3, 3, 0]\n assert candidate(nums = [1000000000, 1000000000, 1000000000...
[ "[1,2,5,6,1]\n[0,3,2,4,1]", "[3,2,11,1]\n[3,2,1,0]" ]
[ "Use a sorted data structure to collect removal points and store the segments.", "Use a heap or priority queue to store segment sums and their corresponding boundaries.", "Make sure to remove invalid segments from the heap." ]
{ "canonical_parameter_names": [ "nums", "removeQueries" ], "leetcode_dataset_entry_point": "Solution().maximumSegmentSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:44", "test...
typescript
{ "raw_signature": "function maximumSegmentSum(nums: number[], removeQueries: number[]): number[] {", "container": null, "callable": "maximumSegmentSum", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "removeQueries", "type": "number[]" } ], "return...
2,383
minimum-hours-of-training-to-win-a-competition
Easy
You are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively. You are also given two 0-indexed integer arrays energy and experience, both of length n. You will face n opponents in order. The energy and experien...
{ "language": "python", "source": "def check(candidate):\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [50, 50],experience = [50, 50]) == 52\n assert candidate(initialEnergy = 5,initialExperience = 3,energy = [1, 4, 3, 2],experience = [2, 6, 3, 1]) == 8\n assert candidate(initialEne...
[ "5\n3\n[1,4,3,2]\n[2,6,3,1]", "2\n4\n[1]\n[3]" ]
[ "Find the minimum number of training hours needed for the energy and experience separately, and sum the results.", "Try to increase the energy and experience until you find how much is enough to win the competition." ]
{ "canonical_parameter_names": [ "initialEnergy", "initialExperience", "energy", "experience" ], "leetcode_dataset_entry_point": "Solution().minNumberOfHours", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", ...
typescript
{ "raw_signature": "function minNumberOfHours(initialEnergy: number, initialExperience: number, energy: number[], experience: number[]): number {", "container": null, "callable": "minNumberOfHours", "parameters": [ { "name": "initialEnergy", "type": "number" }, { "name": "initialEx...
2,384
largest-palindromic-number
Medium
You are given a string num consisting of digits only. Return the largest palindromic integer (in the form of a string) that can be formed using digits taken from num. It should not contain leading zeroes. Notes: - You do not need to use all the digits of num, but you must use at least one digit. - The digits can be ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = \"1111\") == \"1111\"\n assert candidate(num = \"00000\") == \"0\"\n assert candidate(num = \"10\") == \"1\"\n assert candidate(num = \"9\") == \"9\"\n assert candidate(num = \"1111111111\") == \"1111111111\"\n asser...
[ "\"444947137\"", "\"00009\"" ]
[ "In order to form a valid palindrome, other than the middle digit in an odd-length palindrome, every digit needs to exist on both sides.", "A longer palindrome implies a larger valued palindrome. For palindromes of the same length, the larger digits should occur first.", "We can count the occurrences of each di...
{ "canonical_parameter_names": [ "num" ], "leetcode_dataset_entry_point": "Solution().largestPalindromic", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:48", "tests_total": 50, "test...
typescript
{ "raw_signature": "function largestPalindromic(num: string): string {", "container": null, "callable": "largestPalindromic", "parameters": [ { "name": "num", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
2,386
find-the-k-sum-of-an-array
Hard
You are given an integer array nums and a positive integer k. You can choose any subsequence of the array and sum all of its elements together. We define the K-Sum of the array as the k^th largest subsequence sum that can be obtained (not necessarily distinct). Return the K-Sum of the array. A subsequence is an arra...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 100\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000],k = 7) == 0\n assert candidate(nums = [1000000000, -1000000000, 1000000000],k = 3) == 1000000000\n assert cand...
[ "[2,4,-2]\n5", "[1,-2,3,4,-10,12]\n16" ]
[ "Start from the largest sum possible, and keep finding the next largest sum until you reach the kth sum.", "Starting from a sum, what are the two next largest sums that you can obtain from it?" ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().kSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:53", "tests_total": 105, "tests_d...
typescript
{ "raw_signature": "function kSum(nums: number[], k: number): number {", "container": null, "callable": "kSum", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSn...
2,389
longest-subsequence-with-limited-sum
Easy
You are given an integer array nums of length n, and an integer array queries of length m. Return an array answer of length m where answer[i] is the maximum size of a subsequence that you can take from nums such that the sum of its elements is less than or equal to queries[i]. A subsequence is an array that can be de...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [1, 2, 3, 4, 5]) == [1, 1, 2, 2, 2]\n assert candidate(nums = [10, 20, 30],queries = [10, 25, 50, 70]) == [1, 1, 2, 3]\n assert candidate(nums = [10, 20, 30],queries = [5, 15, 25, 35]) == [0, 1, 1, ...
[ "[4,5,2,1]\n[3,10,21]", "[2,3,4,5]\n[1]" ]
[ "Solve each query independently.", "When solving a query, which elements of nums should you choose to make the subsequence as long as possible?", "Choose the smallest elements in nums that add up to a sum less than the query." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().answerQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:58", "tests_total": ...
typescript
{ "raw_signature": "function answerQueries(nums: number[], queries: number[]): number[] {", "container": null, "callable": "answerQueries", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "queries", "type": "number[]" } ], "return_type": "number[]", ...
2,390
removing-stars-from-a-string
Medium
You are given a string s, which contains stars *. In one operation, you can: - Choose a star in s. - Remove the closest non-star character to its left, as well as remove the star itself. Return the string after all stars have been removed. Note: - The input will be generated such that the operation is always possi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc*def*ghi*jkl*mno*pqr*stu*vwx*y*z\") == \"abdeghjkmnpqstvwz\"\n assert candidate(s = \"leet**cod*e\") == \"lecoe\"\n assert candidate(s = \"a*b*c*d*e*\") == \"\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == ...
[ "\"leet**cod*e\"", "\"erase*****\"" ]
[ "What data structure could we use to efficiently perform these removals?", "Use a stack to store the characters. Pop one character off the stack at each star. Otherwise, we push the character onto the stack." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().removeStars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:01", "tests_total": 65, "tests_dropped...
typescript
{ "raw_signature": "function removeStars(s: string): string {", "container": null, "callable": "removeStars", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,391
minimum-amount-of-time-to-collect-garbage
Medium
You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the i^th house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, paper and glass garbage respectively. Picking up one unit of any type of garbage takes 1 minute. You ar...
{ "language": "python", "source": "def check(candidate):\n assert candidate(garbage = ['M', 'P', 'G', 'M', 'P', 'G'],travel = [1, 2, 3, 4, 5]) == 37\n assert candidate(garbage = ['P', 'G', 'M', 'P'],travel = [1, 1, 1]) == 10\n assert candidate(garbage = ['GGG', 'PPP', 'MMM', 'GGG', 'PPP', 'MMM'],travel = [...
[ "[\"G\",\"P\",\"GP\",\"GG\"]\n[2,4,3]", "[\"MMM\",\"PGM\",\"GP\"]\n[3,10]" ]
[ "Where can we save time? By not visiting all the houses.", "For each type of garbage, find the house with the highest index that has at least 1 unit of this type of garbage." ]
{ "canonical_parameter_names": [ "garbage", "travel" ], "leetcode_dataset_entry_point": "Solution().garbageCollection", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:03", "tests_to...
typescript
{ "raw_signature": "function garbageCollection(garbage: string[], travel: number[]): number {", "container": null, "callable": "garbageCollection", "parameters": [ { "name": "garbage", "type": "string[]" }, { "name": "travel", "type": "number[]" } ], "return_type": "n...
2,392
build-a-matrix-with-conditions
Hard
You are given a positive integer k. You are also given: - a 2D integer array rowConditions of size n where rowConditions[i] = [above_i, below_i], and - a 2D integer array colConditions of size m where colConditions[i] = [left_i, right_i]. The two arrays contain integers from 1 to k. You have to build a k x k matrix ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(k = 5,rowConditions = [[1, 5], [2, 5], [3, 5], [4, 5]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5]]) == [[1, 0, 0, 0, 0], [0, 2, 0, 0, 0], [0, 0, 3, 0, 0], [0, 0, 0, 4, 0], [0, 0, 0, 0, 5]]\n assert candidate(k = 3,rowConditions =...
[ "3\n[[1,2],[3,2]]\n[[2,1],[3,2]]", "3\n[[1,2],[2,3],[3,1],[2,3]]\n[[2,1]]" ]
[ "Can you think of the problem in terms of graphs?", "What algorithm allows you to find the order of nodes in a graph?" ]
{ "canonical_parameter_names": [ "k", "rowConditions", "colConditions" ], "leetcode_dataset_entry_point": "Solution().buildMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:...
typescript
{ "raw_signature": "function buildMatrix(k: number, rowConditions: number[][], colConditions: number[][]): number[][] {", "container": null, "callable": "buildMatrix", "parameters": [ { "name": "k", "type": "number" }, { "name": "rowConditions", "type": "number[][]" }, ...
2,395
find-subarrays-with-equal-sum
Easy
Given a 0-indexed integer array nums, determine whether there exist two subarrays of length 2 with equal sum. Note that the two subarrays must begin at different indices. Return true if these subarrays exist, and false otherwise. A subarray is a contiguous non-empty sequence of elements within an array. Example 1: ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, 0, 1, -1, 0]) == True\n assert candidate(nums = [1, 1, 1, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(nums = [5, -1, 5, -1]) == True\n assert candidate(nums =...
[ "[4,2,4]", "[1,2,3,4,5]", "[0,0,0]" ]
[ "Use a counter to keep track of the subarray sums.", "Use a hashset to check if any two sums are equal." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:10", "tests_total": 119, "tests_d...
typescript
{ "raw_signature": "function findSubarrays(nums: number[]): boolean {", "container": null, "callable": "findSubarrays", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
2,396
strictly-palindromic-number
Medium
An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic. Given an integer n, return true if n is strictly palindromic and false otherwise. A string is palindromic if it reads the same forward and backward. Example ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 15) == False\n assert candidate(n = 4) == False\n assert candidate(n = 9) == False\n assert candidate(n = 6) == False\n assert candidate(n = 20) == False\n assert candidate(n = 100) == False\n assert candidate(n = 1...
[ "9", "4" ]
[ "Consider the representation of the given number in the base n - 2.", "The number n in base (n - 2) is always 12, which is not palindromic." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().isStrictlyPalindromic", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:13", "tests_total": 57, "tes...
typescript
{ "raw_signature": "function isStrictlyPalindromic(n: number): boolean {", "container": null, "callable": "isStrictlyPalindromic", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
2,397
maximum-rows-covered-by-columns
Medium
You are given an m x n binary matrix matrix and an integer numSelect. Your goal is to select exactly numSelect distinct columns from matrix such that you cover as many rows as possible. A row is considered covered if all the 1's in that row are also part of a column that you have selected. If a row does not have any ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],numSelect = 4) == 3\n assert candidate(matrix = [[1, 1], [0, 0], [1, 0], [0, 1]],numSelect = 1) == 2\n assert candidate(matrix = [[1, 1, 1], [0, 1, 1], [1, 0, 1]],numSelect = 1) =...
[ "[[0,0,0],[1,0,1],[0,1,1],[0,0,1]]\n2", "[[1],[0]]\n1" ]
[ "Try a brute-force approach.", "Iterate through all possible sets of exactly cols columns.", "For each valid set, check how many rows are covered, and return the maximum." ]
{ "canonical_parameter_names": [ "matrix", "numSelect" ], "leetcode_dataset_entry_point": "Solution().maximumRows", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:15", "tests_total"...
typescript
{ "raw_signature": "function maximumRows(matrix: number[][], numSelect: number): number {", "container": null, "callable": "maximumRows", "parameters": [ { "name": "matrix", "type": "number[][]" }, { "name": "numSelect", "type": "number" } ], "return_type": "number", ...
2,398
maximum-number-of-robots-within-budget
Hard
You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The i^th robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also given an integer budget. The total cost of running k chosen robots is equal to max(chargeTimes) + k * s...
{ "language": "python", "source": "def check(candidate):\n assert candidate(chargeTimes = [1, 1, 1, 1, 1],runningCosts = [100000, 100000, 100000, 100000, 100000],budget = 500000) == 2\n assert candidate(chargeTimes = [7, 7, 7, 7],runningCosts = [1, 1, 1, 1],budget = 20) == 3\n assert candidate(chargeTimes ...
[ "[3,6,1,3,4]\n[2,1,3,4,5]\n25", "[11,12,19]\n[10,8,7]\n19" ]
[ "Use binary search to convert the problem into checking if we can find a specific number of consecutive robots within the budget.", "Maintain a sliding window of the consecutive robots being considered.", "Use either a map, deque, or heap to find the maximum charge times in the window efficiently." ]
{ "canonical_parameter_names": [ "chargeTimes", "runningCosts", "budget" ], "leetcode_dataset_entry_point": "Solution().maximumRobots", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20...
typescript
{ "raw_signature": "function maximumRobots(chargeTimes: number[], runningCosts: number[], budget: number): number {", "container": null, "callable": "maximumRobots", "parameters": [ { "name": "chargeTimes", "type": "number[]" }, { "name": "runningCosts", "type": "number[]" ...
2,399
check-distances-between-same-letters
Easy
You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26. Each letter in the alphabet is numbered from 0 to 25 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, ... , 'z' -> 25). In a well-spaced...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrztuvwxyz\",distance = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(s = \"zz\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
[ "\"abaccb\"\n[1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]", "\"aa\"\n[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]" ]
[ "Create an integer array of size 26 to keep track of the first occurrence of each letter.", "The number of letters between indices i and j is j - i - 1." ]
{ "canonical_parameter_names": [ "s", "distance" ], "leetcode_dataset_entry_point": "Solution().checkDistances", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:19", "tests_total": 9...
typescript
{ "raw_signature": "function checkDistances(s: string, distance: number[]): boolean {", "container": null, "callable": "checkDistances", "parameters": [ { "name": "s", "type": "string" }, { "name": "distance", "type": "number[]" } ], "return_type": "boolean", "signa...
2,400
number-of-ways-to-reach-a-position-after-exactly-k-steps
Medium
You are given two positive integers startPos and endPos. Initially, you are standing at position startPos on an infinite number line. With one step, you can move either one position to the left, or one position to the right. Given a positive integer k, return the number of different ways to reach the position endPos s...
{ "language": "python", "source": "def check(candidate):\n assert candidate(startPos = 1,endPos = 2,k = 3) == 3\n assert candidate(startPos = 10,endPos = 1,k = 15) == 455\n assert candidate(startPos = 5,endPos = 5,k = 10) == 252\n assert candidate(startPos = 10,endPos = 1,k = 9) == 1\n assert candida...
[ "1\n2\n3", "2\n5\n10" ]
[ "How many steps to the left and to the right do you need to make exactly?", "Does the order of the steps matter?", "Use combinatorics to find the number of ways to order the steps." ]
{ "canonical_parameter_names": [ "startPos", "endPos", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:21", "tes...
typescript
{ "raw_signature": "function numberOfWays(startPos: number, endPos: number, k: number): number {", "container": null, "callable": "numberOfWays", "parameters": [ { "name": "startPos", "type": "number" }, { "name": "endPos", "type": "number" }, { "name": "k", ...
2,401
longest-nice-subarray
Medium
You are given an array nums consisting of positive integers. We call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0. Return the length of the longest nice subarray. A subarray is a contiguous part of an array. Note that subarrays of...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 1, 5, 11, 13]) == 1\n assert candidate(nums = [31, 1, 4, 32, 16]) == 4\n assert candidate(nums = [7, 11, 13, 14, 2, 5, 3]) == 2\n assert candidate(nums = [1, 2, 4, 8, 16]) == 5\n assert candidate(nums = [16, 17, 71...
[ "[1,3,8,48,10]", "[3,1,5,11,13]" ]
[ "What is the maximum possible length of a nice subarray?", "If two numbers have bitwise AND equal to zero, they do not have any common set bit. A number x <= 10^9 only has 30 bits, hence the length of the longest nice subarray cannot exceed 30." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().longestNiceSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:24", "tests_total": 115, "t...
typescript
{ "raw_signature": "function longestNiceSubarray(nums: number[]): number {", "container": null, "callable": "longestNiceSubarray", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
2,402
meeting-rooms-iii
Hard
You are given an integer n. There are n rooms numbered from 0 to n - 1. You are given a 2D integer array meetings where meetings[i] = [start_i, end_i] means that a meeting will be held during the half-closed time interval [start_i, end_i). All the values of start_i are unique. Meetings are allocated to rooms in the f...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,meetings = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == 0\n assert candidate(n = 5,meetings = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6]]) =...
[ "2\n[[0,10],[1,5],[2,7],[3,4]]", "3\n[[1,20],[2,10],[3,5],[4,9],[6,8]]" ]
[ "Sort meetings based on start times.", "Use two min heaps, the first one keeps track of the numbers of all the rooms that are free. The second heap keeps track of the end times of all the meetings that are happening and the room that they are in.", "Keep track of the number of times each room is used in an arra...
{ "canonical_parameter_names": [ "n", "meetings" ], "leetcode_dataset_entry_point": "Solution().mostBooked", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:27", "tests_total": 92, ...
typescript
{ "raw_signature": "function mostBooked(n: number, meetings: number[][]): number {", "container": null, "callable": "mostBooked", "parameters": [ { "name": "n", "type": "number" }, { "name": "meetings", "type": "number[][]" } ], "return_type": "number", "signature_s...
2,404
most-frequent-even-element
Easy
Given an integer array nums, return the most frequent even element. If there is a tie, return the smallest one. If there is no such element, return -1. Example 1: Input: nums = [0,1,2,2,4,4,1] Output: 2 Explanation: The even elements are 0, 2, and 4. Of these, 2 and 4 appear the most. We return the smallest one, whi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [29, 47, 21, 41, 13, 37, 25, 7]) == -1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == -1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4]) == 4\n assert candidate(nums = [8, 8, 8, 8, 8, 7, 7, 7, 7...
[ "[0,1,2,2,4,4,1]", "[4,4,4,9,2,4]", "[29,47,21,41,13,37,25,7]" ]
[ "Could you count the frequency of each even element in the array?", "Would a hashmap help?" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().mostFrequentEven", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:31", "tests_total": 110, "test...
typescript
{ "raw_signature": "function mostFrequentEven(nums: number[]): number {", "container": null, "callable": "mostFrequentEven", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
2,405
optimal-partition-of-string
Medium
Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once. Return the minimum number of substrings in such a partition. Note that each character should belong to exactly one substring in a p...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefg\") == 1\n assert candidate(s = \"abac\") == 2\n assert candidate(s = \"abcdabcdeabcdefabcdefg\") == 4\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 44\n assert candidate(s = \"ababa...
[ "\"abacaba\"", "\"ssssss\"" ]
[ "Try to come up with a greedy approach.", "From left to right, extend every substring in the partition as much as possible." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().partitionString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:34", "tests_total": 103, "tests_dr...
typescript
{ "raw_signature": "function partitionString(s: string): number {", "container": null, "callable": "partitionString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,406
divide-intervals-into-minimum-number-of-groups
Medium
You are given a 2D integer array intervals where intervals[i] = [left_i, right_i] represents the inclusive interval [left_i, right_i]. You have to divide the intervals into one or more groups such that each interval is in exactly one group, and no two intervals that are in the same group intersect each other. Return ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(intervals = [[1, 2], [3, 4], [5, 6], [7, 8]]) == 1\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 2\n assert candidate(intervals = [[1, 1000000]]) == 1\n assert candidate(intervals = [[5, 10], [6, 8], [1, 5]...
[ "[[5,10],[6,8],[1,5],[2,3],[1,10]]", "[[1,3],[5,6],[8,10],[11,13]]" ]
[ "Can you find a different way to describe the question?", "The minimum number of groups we need is equivalent to the maximum number of intervals that overlap at some point. How can you find that?" ]
{ "canonical_parameter_names": [ "intervals" ], "leetcode_dataset_entry_point": "Solution().minGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:36", "tests_total": 97, "tests_d...
typescript
{ "raw_signature": "function minGroups(intervals: number[][]): number {", "container": null, "callable": "minGroups", "parameters": [ { "name": "intervals", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
2,407
longest-increasing-subsequence-ii
Hard
You are given an integer array nums and an integer k. Find the longest subsequence of nums that meets the following requirements: - The subsequence is strictly increasing and - The difference between adjacent elements in the subsequence is at most k. Return the length of the longest subsequence that meets the requir...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18],k = 10) == 3\n assert candidate(nums = [5, 4, 3, 2, 1],k = 2) == 1\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18],k = 5) == 3\n assert candidate(nums = [7, 4, 5, 1, 8, 12, 4, 7],k = 5)...
[ "[4,2,1,4,3,4,5,8,15]\n3", "[7,4,5,1,8,12,4,7]\n5", "[1,5]\n1" ]
[ "We can use dynamic programming. Let dp[i][val] be the answer using only the first i + 1 elements, and the last element in the subsequence is equal to val.", "The only value that might change between dp[i - 1] and dp[i] are dp[i - 1][val] and dp[i][val].", "Try using dp[i - 1] and the fact that the second last ...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().lengthOfLIS", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:38", "tests_total": 110, "...
typescript
{ "raw_signature": "function lengthOfLIS(nums: number[], k: number): number {", "container": null, "callable": "lengthOfLIS", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "l...
2,409
count-days-spent-together
Easy
Alice and Bob are traveling to Rome for separate business meetings. You are given 4 strings arriveAlice, leaveAlice, arriveBob, and leaveBob. Alice will be in the city from the dates arriveAlice to leaveAlice (inclusive), while Bob will be in the city from the dates arriveBob to leaveBob (inclusive). Each will be a 5-...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arriveAlice = \"03-10\",leaveAlice = \"05-20\",arriveBob = \"04-01\",leaveBob = \"04-30\") == 30\n assert candidate(arriveAlice = \"06-15\",leaveAlice = \"06-20\",arriveBob = \"06-18\",leaveBob = \"06-25\") == 3\n assert candidate(...
[ "\"08-15\"\n\"08-18\"\n\"08-16\"\n\"08-19\"", "\"10-01\"\n\"10-31\"\n\"11-01\"\n\"12-31\"" ]
[ "For a given day, determine if Alice or Bob or both are in Rome.", "Brute force all 365 days for both Alice and Bob." ]
{ "canonical_parameter_names": [ "arriveAlice", "leaveAlice", "arriveBob", "leaveBob" ], "leetcode_dataset_entry_point": "Solution().countDaysTogether", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetche...
typescript
{ "raw_signature": "function countDaysTogether(arriveAlice: string, leaveAlice: string, arriveBob: string, leaveBob: string): number {", "container": null, "callable": "countDaysTogether", "parameters": [ { "name": "arriveAlice", "type": "string" }, { "name": "leaveAlice", "t...
2,410
maximum-matching-of-players-with-trainers
Medium
You are given a 0-indexed integer array players, where players[i] represents the ability of the i^th player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of the j^th trainer. The i^th player can match with the j^th trainer if the player's ability is less tha...
{ "language": "python", "source": "def check(candidate):\n assert candidate(players = [1, 2, 3],trainers = [10, 11, 12]) == 3\n assert candidate(players = [10, 20, 30],trainers = [1, 2, 3]) == 0\n assert candidate(players = [1, 2, 3, 4, 5],trainers = [5, 4, 3, 2, 1]) == 5\n assert candidate(players = [1...
[ "[4,7,9]\n[8,2,5,8]", "[1,1,1]\n[10]" ]
[ "Sort both the arrays.", "Construct the matching greedily." ]
{ "canonical_parameter_names": [ "players", "trainers" ], "leetcode_dataset_entry_point": "Solution().matchPlayersAndTrainers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:43", "...
typescript
{ "raw_signature": "function matchPlayersAndTrainers(players: number[], trainers: number[]): number {", "container": null, "callable": "matchPlayersAndTrainers", "parameters": [ { "name": "players", "type": "number[]" }, { "name": "trainers", "type": "number[]" } ], "...
2,411
smallest-subarrays-with-maximum-bitwise-or
Medium
You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclusive) that has the maximum possible bitwise OR. - In other words, let B_ij be the bitwise OR of the su...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035, 30517, 15258, 7629, 3814, 1907, 953, 476, 238, 119, 59, 29, 14, 7, 3, 1]) == [10, 9, 8, ...
[ "[1,0,2,1,3]", "[1,2]" ]
[ "Consider trying to solve the problem for each bit position separately.", "For each bit position, find the position of the next number that has a 1 in that position, if any.", "Take the maximum distance to such a number, including the current number.", "Iterate backwards to achieve a linear complexity." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().smallestSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:45", "tests_total": 102, "tes...
typescript
{ "raw_signature": "function smallestSubarrays(nums: number[]): number[] {", "container": null, "callable": "smallestSubarrays", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
2,412
minimum-money-required-before-transactions
Hard
You are given a 0-indexed 2D integer array transactions, where transactions[i] = [cost_i, cashback_i]. The array describes transactions, where each transaction must be completed exactly once in some order. At any given moment, you have a certain amount of money. In order to complete transaction i, money >= cost_i must...
{ "language": "python", "source": "def check(candidate):\n assert candidate(transactions = [[1, 2], [3, 4], [5, 6]]) == 5\n assert candidate(transactions = [[1, 0], [2, 0], [3, 0]]) == 6\n assert candidate(transactions = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 4\n assert candidate(transactions = [[0, 0], [...
[ "[[2,1],[5,0],[4,2]]", "[[3,0],[0,3]]" ]
[ "Split transactions that have cashback greater or equal to cost apart from transactions that have cashback less than cost. You will always earn money in the first scenario.", "For transactions that have cashback greater or equal to cost, sort them by cost in descending order.", "For transactions that have cashb...
{ "canonical_parameter_names": [ "transactions" ], "leetcode_dataset_entry_point": "Solution().minimumMoney", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:48", "tests_total": 109, "...
typescript
{ "raw_signature": "function minimumMoney(transactions: number[][]): number {", "container": null, "callable": "minimumMoney", "parameters": [ { "name": "transactions", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
2,413
smallest-even-multiple
Easy
Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n. Example 1: Input: n = 5 Output: 10 Explanation: The smallest multiple of both 5 and 2 is 10. Example 2: Input: n = 6 Output: 6 Explanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multipl...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 6\n assert candidate(n = 100) == 100\n assert candidate(n = 33) == 66\n assert candidate(n = 75) == 150\n assert candidate(n = 6) == 6\n assert candidate(n = 2) == 2\n assert candidate(n = 1) == 2\n assert ...
[ "5", "6" ]
[ "A guaranteed way to find a multiple of 2 and n is to multiply them together. When is this the answer, and when is there a smaller answer?", "There is a smaller answer when n is even." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().smallestEvenMultiple", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:50", "tests_total": 91, "test...
typescript
{ "raw_signature": "function smallestEvenMultiple(n: number): number {", "container": null, "callable": "smallestEvenMultiple", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
2,414
length-of-the-longest-alphabetical-continuous-substring
Medium
An alphabetical continuous string is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string "abcdefghijklmnopqrstuvwxyz". - For example, "abc" is an alphabetical continuous string, while "acb" and "za" are not. Given a string s consisting of lowercase letters onl...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 1\n assert candidate(s = \"abxyz\") == 3\n assert candidate(s = \"qrstuvwpqrstu\") == 7\n assert candidate(s = \"mnopqrstuvwxyzz\") == 14\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n ...
[ "\"abacaba\"", "\"abcde\"" ]
[ "What is the longest possible continuous substring?", "The size of the longest possible continuous substring is at most 26, so we can just brute force the answer." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().longestContinuousSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:53", "tests_total": 115, ...
typescript
{ "raw_signature": "function longestContinuousSubstring(s: string): number {", "container": null, "callable": "longestContinuousSubstring", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetc...
2,416
sum-of-prefix-scores-of-strings
Hard
You are given an array words of size n consisting of non-empty strings. We define the score of a string term as the number of strings words[i] such that term is a prefix of words[i]. - For example, if words = ["a", "ab", "abc", "cab"], then the score of "ab" is 2, since "ab" is a prefix of both "ab" and "abc". Retur...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['hello', 'hell', 'he', 'h']) == [12, 11, 7, 4]\n assert candidate(words = ['abc', 'ab', 'bc', 'b']) == [5, 4, 3, 2]\n assert candidate(words = ['a', 'b', 'c', 'd']) == [1, 1, 1, 1]\n assert candidate(words = ['aa', 'aaa...
[ "[\"abc\",\"ab\",\"bc\",\"b\"]", "[\"abcd\"]" ]
[ "What data structure will allow you to efficiently keep track of the score of each prefix?", "Use a Trie. Insert all the words into it, and keep a counter at each node that will tell you how many times we have visited each prefix." ]
{ "canonical_parameter_names": [ "words" ], "leetcode_dataset_entry_point": "Solution().sumPrefixScores", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:57", "tests_total": 96, "tests...
typescript
{ "raw_signature": "function sumPrefixScores(words: string[]): number[] {", "container": null, "callable": "sumPrefixScores", "parameters": [ { "name": "words", "type": "string[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
2,418
sort-the-people
Easy
You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n. For each index i, names[i] and heights[i] denote the name and height of the i^th person. Return names sorted in descending order by the people's heights. Example 1: Input: names = ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(names = ['Zoe', 'Lily', 'Rose'],heights = [150, 145, 155]) == ['Rose', 'Zoe', 'Lily']\n assert candidate(names = ['Qwen', 'Alibaba', 'Cloud'],heights = [200, 190, 180]) == ['Qwen', 'Alibaba', 'Cloud']\n assert candidate(names = ['A...
[ "[\"Mary\",\"John\",\"Emma\"]\n[180,165,170]", "[\"Alice\",\"Bob\",\"Bob\"]\n[155,185,150]" ]
[ "Find the tallest person and swap with the first person, then find the second tallest person and swap with the second person, etc. Repeat until you fix all n people." ]
{ "canonical_parameter_names": [ "names", "heights" ], "leetcode_dataset_entry_point": "Solution().sortPeople", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:02", "tests_total": 12...
typescript
{ "raw_signature": "function sortPeople(names: string[], heights: number[]): string[] {", "container": null, "callable": "sortPeople", "parameters": [ { "name": "names", "type": "string[]" }, { "name": "heights", "type": "number[]" } ], "return_type": "string[]", "s...
2,419
longest-subarray-with-maximum-bitwise-and
Medium
You are given an integer array nums of size n. Consider a non-empty subarray from nums that has the maximum possible bitwise AND. - In other words, let k be the maximum value of the bitwise AND of any subarray of nums. Then, only subarrays with a bitwise AND equal to k should be considered. Return the length of the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [8, 9, 10, 11, 12, 13, 14, 15, 16]) == 1\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953]) == 1\n assert candidate(nums = [8, 9, 10, 10, 10, 8]) == 3\n assert candidate(nu...
[ "[1,2,3,3,2,2]", "[1,2,3,4]" ]
[ "Notice that the bitwise AND of two different numbers will always be strictly less than the maximum of those two numbers.", "What does that tell us about the nature of the subarray that we should choose?" ]
{ "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:52:04", "tests_total": 42, "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...
2,420
find-all-good-indices
Medium
You are given a 0-indexed integer array nums of size n and a positive integer k. We call an index i in the range k <= i < n - k good if the following conditions are satisfied: - The k elements that are just before the index i are in non-increasing order. - The k elements that are just after the index i are in non-dec...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5],k = 3) == [7, 8, 9]\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1],k = 2) == []\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 4, 3, 2, 1],k = 3) == []\n assert candidate(nums = [...
[ "[2,1,1,1,3,4,1]\n2", "[2,1,1,2]\n2" ]
[ "Iterate over all indices i. How do you quickly check the two conditions?", "Precompute for each index whether the conditions are satisfied on the left and the right of the index. You can do that with two iterations, from left to right and right to left." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().goodIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:07", "tests_total": 101, "...
typescript
{ "raw_signature": "function goodIndices(nums: number[], k: number): number[] {", "container": null, "callable": "goodIndices", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number[]", "signature_source"...
2,421
number-of-good-paths
Hard
There is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the i^th node. You are also given a 2D integer array edges where edges[i] = [a_i, b_i] ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(vals = [2, 2, 2, 2, 2],edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 15\n assert candidate(vals = [1],edges = []) == 1\n assert candidate(vals = [1, 2, 3, 4, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 5\n assert candidate(va...
[ "[1,3,2,1,3]\n[[0,1],[0,2],[2,3],[2,4]]", "[1,1,2,2,3]\n[[0,1],[1,2],[2,3],[2,4]]", "[1]\n[]" ]
[ "Can you process nodes from smallest to largest value?", "Try to build the graph from nodes with the smallest value to the largest value.", "May union find help?" ]
{ "canonical_parameter_names": [ "vals", "edges" ], "leetcode_dataset_entry_point": "Solution().numberOfGoodPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:10", "tests_total"...
typescript
{ "raw_signature": "function numberOfGoodPaths(vals: number[], edges: number[][]): number {", "container": null, "callable": "numberOfGoodPaths", "parameters": [ { "name": "vals", "type": "number[]" }, { "name": "edges", "type": "number[][]" } ], "return_type": "numbe...
2,423
remove-letter-to-equalize-frequency
Easy
You are given a 0-indexed string word, consisting of lowercase English letters. You need to select one index and remove the letter at that index from word so that the frequency of every letter present in word is equal. Return true if it is possible to remove one letter so that the frequency of all letters in word are ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"aabbccd\") == True\n assert candidate(word = \"aaabbbccc\") == False\n assert candidate(word = \"zazaza\") == False\n assert candidate(word = \"aaaaabbbbbcccc\") == False\n assert candidate(word = \"zzzzzzzz\") == Tr...
[ "\"abcc\"", "\"aazz\"" ]
[ "Brute force all letters that could be removed.", "Use a frequency array of size 26." ]
{ "canonical_parameter_names": [ "word" ], "leetcode_dataset_entry_point": "Solution().equalFrequency", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:14", "tests_total": 74, "tests_d...
typescript
{ "raw_signature": "function equalFrequency(word: string): boolean {", "container": null, "callable": "equalFrequency", "parameters": [ { "name": "word", "type": "string" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
2,425
bitwise-xor-of-all-pairings
Medium
You are given two 0-indexed arrays, nums1 and nums2, consisting of non-negative integers. Let there be another array, nums3, which contains the bitwise XOR of all pairings of integers between nums1 and nums2 (every integer in nums1 is paired with every integer in nums2 exactly once). Return the bitwise XOR of all inte...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [8, 16, 24, 32],nums2 = [4, 8, 12, 16, 20]) == 32\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1]) == 11\n assert candidate(nums1 = [2, 1, 3],nums2 = [10, 2, 5, 0]) == 13\n assert candidate(nums1 =...
[ "[2,1,3]\n[10,2,5,0]", "[1,2]\n[3,4]" ]
[ "Think how the count of each individual integer affects the final answer.", "If the length of nums1 is m and the length of nums2 is n, then each number in nums1 is repeated n times and each number in nums2 is repeated m times." ]
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().xorAllNums", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:17", "tests_total": 102,...
typescript
{ "raw_signature": "function xorAllNums(nums1: number[], nums2: number[]): number {", "container": null, "callable": "xorAllNums", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" } ], "return_type": "number", "signature...
2,426
number-of-pairs-satisfying-inequality
Hard
You are given two 0-indexed integer arrays nums1 and nums2, each of size n, and an integer diff. Find the number of pairs (i, j) such that: - 0 <= i < j <= n - 1 and - nums1[i] - nums1[j] <= nums2[i] - nums2[j] + diff. Return the number of pairs that satisfy the conditions. Example 1: Input: nums1 = [3,2,5], nums2 ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [3, -1],nums2 = [-2, 2],diff = -1) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],diff = 0) == 10\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5],diff = 50) == 10\n assert...
[ "[3,2,5]\n[2,2,1]\n1", "[3,-1]\n[-2,2]\n-1" ]
[ "Try rearranging the equation.", "Once the equation is rearranged properly, think how a segment tree or a Fenwick tree can be used to solve the rearranged equation.", "Iterate through the array backwards." ]
{ "canonical_parameter_names": [ "nums1", "nums2", "diff" ], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:20", "tes...
typescript
{ "raw_signature": "function numberOfPairs(nums1: number[], nums2: number[], diff: number): number {", "container": null, "callable": "numberOfPairs", "parameters": [ { "name": "nums1", "type": "number[]" }, { "name": "nums2", "type": "number[]" }, { "name": "di...
2,427
number-of-common-factors
Easy
Given two positive integers a and b, return the number of common factors of a and b. An integer x is a common factor of a and b if x divides both a and b. Example 1: Input: a = 12, b = 6 Output: 4 Explanation: The common factors of 12 and 6 are 1, 2, 3, 6. Example 2: Input: a = 25, b = 30 Output: 2 Explanation: Th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(a = 7,b = 13) == 1\n assert candidate(a = 500,b = 500) == 12\n assert candidate(a = 42,b = 56) == 4\n assert candidate(a = 999,b = 1000) == 1\n assert candidate(a = 77,b = 14) == 2\n assert candidate(a = 98,b = 42) == 4\n ...
[ "12\n6", "25\n30" ]
[ "For each integer in range [1,1000], check if it’s divisible by both A and B." ]
{ "canonical_parameter_names": [ "a", "b" ], "leetcode_dataset_entry_point": "Solution().commonFactors", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:22", "tests_total": 107, "t...
typescript
{ "raw_signature": "function commonFactors(a: number, b: number): number {", "container": null, "callable": "commonFactors", "parameters": [ { "name": "a", "type": "number" }, { "name": "b", "type": "number" } ], "return_type": "number", "signature_source": "leetcod...
2,428
maximum-sum-of-an-hourglass
Medium
You are given an m x n integer matrix grid. We define an hourglass as a part of the matrix with the following form: Return the maximum sum of the elements of an hourglass. Note that an hourglass cannot be rotated and must be entirely contained within the matrix. Example 1: Input: grid = [[6,2,1,3],[4,2,1,5],[9,2,8...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25]]) == 133\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 1\n assert candidate(grid = [[1000000, 1000000, 10...
[ "[[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]]", "[[1,2,3],[4,5,6],[7,8,9]]" ]
[ "Each 3x3 submatrix has exactly one hourglass.", "Find the sum of each hourglass in the matrix and return the largest of these values." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().maxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:24", "tests_total": 65, "tests_dropped":...
typescript
{ "raw_signature": "function maxSum(grid: number[][]): number {", "container": null, "callable": "maxSum", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,429
minimize-xor
Medium
Given two positive integers num1 and num2, find the positive integer x such that: - x has the same number of set bits as num2, and - The value x XOR num1 is minimal. Note that XOR is the bitwise XOR operation. Return the integer x. The test cases are generated such that x is uniquely determined. The number of set b...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num1 = 1,num2 = 12) == 3\n assert candidate(num1 = 8,num2 = 3) == 9\n assert candidate(num1 = 29,num2 = 15) == 29\n assert candidate(num1 = 3,num2 = 5) == 3\n assert candidate(num1 = 7,num2 = 10) == 6\n assert candidate(nu...
[ "3\n5", "1\n12" ]
[ "To arrive at a small xor, try to turn off some bits from num1", "If there are still left bits to set, try to set them from the least significant bit" ]
{ "canonical_parameter_names": [ "num1", "num2" ], "leetcode_dataset_entry_point": "Solution().minimizeXor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:26", "tests_total": 85, ...
typescript
{ "raw_signature": "function minimizeXor(num1: number, num2: number): number {", "container": null, "callable": "minimizeXor", "parameters": [ { "name": "num1", "type": "number" }, { "name": "num2", "type": "number" } ], "return_type": "number", "signature_source": ...
2,430
maximum-deletions-on-a-string
Hard
You are given a string s consisting of only lowercase English letters. In one operation, you can: - Delete the entire string s, or - Delete the first i letters of s if the first i letters of s are equal to the following i letters in s, for any i in the range 1 <= i <= s.length / 2. For example, if s = "ababc", then i...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abababababababababababababababababababababababababababababababababababababababababababababababab\") == 48\n assert candidate(s = \"aaabaab\") == 4\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...
[ "\"abcabcdabc\"", "\"aaabaab\"", "\"aaaaa\"" ]
[ "We can use dynamic programming to find the answer. Create a 0-indexed dp array where dp[i] represents the maximum number of moves needed to remove the first i + 1 letters from s.", "What should we do if there is an i where it is impossible to remove the first i + 1 letters?", "Use a sentinel value such as -1 t...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().deleteString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:28", "tests_total": 103, "tests_dropp...
typescript
{ "raw_signature": "function deleteString(s: string): number {", "container": null, "callable": "deleteString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,432
the-employee-that-worked-on-the-longest-task
Easy
There are n employees, each with a unique id from 0 to n - 1. You are given a 2D integer array logs where logs[i] = [id_i, leaveTime_i] where: - id_i is the id of the employee that worked on the i^th task, and - leaveTime_i is the time at which the employee finished the i^th task. All the values leaveTime_i are uniqu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,logs = [[0, 1], [2, 2], [1, 3], [3, 4]]) == 0\n assert candidate(n = 2,logs = [[0, 10], [1, 20]]) == 0\n assert candidate(n = 6,logs = [[0, 2], [1, 6], [2, 10], [3, 14], [4, 18], [5, 22]]) == 1\n assert candidate(n = 5,log...
[ "10\n[[0,3],[2,5],[0,9],[1,15]]", "26\n[[1,1],[3,7],[2,12],[7,17]]", "2\n[[0,10],[1,20]]" ]
[ "Find the time of the longest task", "Store each employee’s longest task time in a hash table", "For employees that have the same longest task time, we only need the employee with the smallest ID" ]
{ "canonical_parameter_names": [ "n", "logs" ], "leetcode_dataset_entry_point": "Solution().hardestWorker", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:33", "tests_total": 99, ...
typescript
{ "raw_signature": "function hardestWorker(n: number, logs: number[][]): number {", "container": null, "callable": "hardestWorker", "parameters": [ { "name": "n", "type": "number" }, { "name": "logs", "type": "number[][]" } ], "return_type": "number", "signature_sou...
2,433
find-the-original-array-of-prefix-xor
Medium
You are given an integer array pref of size n. Find and return the array arr of size n that satisfies: - pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]. Note that ^ denotes the bitwise-xor operation. It can be proven that the answer is unique. Example 1: Input: pref = [5,2,0,3,1] Output: [5,7,2,3,2] Explanation: From th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(pref = [5, 2, 0, 3, 1]) == [5, 7, 2, 3, 2]\n assert candidate(pref = [0, 0, 0, 0, 0]) == [0, 0, 0, 0, 0]\n assert candidate(pref = [0, 1, 2, 3, 4]) == [0, 1, 3, 1, 7]\n assert candidate(pref = [10, 4, 6, 3, 5]) == [10, 14, 2, 5,...
[ "[5,2,0,3,1]", "[13]" ]
[ "Consider the following equation: x ^ a = b. How can you find x?", "Notice that arr[i] ^ pref[i-1] = pref[i]. This is the same as the previous equation." ]
{ "canonical_parameter_names": [ "pref" ], "leetcode_dataset_entry_point": "Solution().findArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:35", "tests_total": 98, "tests_droppe...
typescript
{ "raw_signature": "function findArray(pref: number[]): number[] {", "container": null, "callable": "findArray", "parameters": [ { "name": "pref", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,434
using-a-robot-to-print-the-lexicographically-smallest-string
Medium
You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty: - Remove the first character of a string s and give it to the robot. The robot will append this character to the string t. - Remove the last character of a string t and give ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbcc\") == \"aabbcc\"\n assert candidate(s = \"bdda\") == \"addb\"\n assert candidate(s = \"cba\") == \"abc\"\n assert candidate(s = \"bac\") == \"abc\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcd...
[ "\"zza\"", "\"bac\"", "\"bdda\"" ]
[ "If there are some character “a” ’ s in the string, they can be written on paper before anything else.", "Every character in the string before the last “a” should be written in reversed order.", "After the robot writes every “a” on paper, the same holds for other characters “b”, ”c”, …etc." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().robotWithString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:38", "tests_total": 61, "tests_dro...
typescript
{ "raw_signature": "function robotWithString(s: string): string {", "container": null, "callable": "robotWithString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,435
paths-in-matrix-whose-sum-is-divisible-by-k
Hard
You are given a 0-indexed m x n integer matrix grid and an integer k. You are currently at position (0, 0) and you want to reach position (m - 1, n - 1) moving only down or right. Return the number of paths where the sum of the elements on the path is divisible by k. Since the answer may be very large, return it modul...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[10, 10, 10], [10, 10, 10], [10, 10, 10]],k = 5) == 6\n assert candidate(grid = [[100, 100], [100, 100]],k = 5) == 2\n assert candidate(grid = [[1, 2, 3], [4, 5, 6]],k = 2) == 3\n assert candidate(grid = [[7, 3, 4, 9], [...
[ "[[5,2,4],[3,0,5],[0,7,2]]\n3", "[[0,0]]\n5", "[[7,3,4,9],[2,3,6,2],[2,3,7,0]]\n1" ]
[ "The actual numbers in grid do not matter. What matters are the remainders you get when you divide the numbers by k.", "We can use dynamic programming to solve this problem. What can we use as states?", "Let dp[i][j][value] represent the number of paths where the sum of the elements on the path has a remainder ...
{ "canonical_parameter_names": [ "grid", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:40", "tests_total": 74, ...
typescript
{ "raw_signature": "function numberOfPaths(grid: number[][], k: number): number {", "container": null, "callable": "numberOfPaths", "parameters": [ { "name": "grid", "type": "number[][]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_sou...
2,437
number-of-valid-clock-times
Easy
You are given a string of length 5 called time, representing the current time on a digital clock in the format "hh:mm". The earliest possible time is "00:00" and the latest possible time is "23:59". In the string time, the digits represented by the ? symbol are unknown, and must be replaced with a digit from 0 to 9. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(time = \"23:?0\") == 6\n assert candidate(time = \"23:5?\") == 10\n assert candidate(time = \"09:5?\") == 10\n assert candidate(time = \"23:?9\") == 6\n assert candidate(time = \"1?:?0\") == 60\n assert candidate(time = \"...
[ "\"?5:00\"", "\"0?:0?\"", "\"??:??\"" ]
[ "Brute force all possible clock times.", "Checking if a clock time is valid can be done with Regex." ]
{ "canonical_parameter_names": [ "time" ], "leetcode_dataset_entry_point": "Solution().countTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:44", "tests_total": 114, "tests_dropp...
typescript
{ "raw_signature": "function countTime(time: string): number {", "container": null, "callable": "countTime", "parameters": [ { "name": "time", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,438
range-product-queries-of-powers
Medium
Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in non-decreasing order, and there is only one way to form the array. You are also given a 0-indexed 2D integer array queries, where queries[i] = [left_i, right_i]....
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 10,queries = [[0, 0], [1, 1], [0, 2]]) == [2, 8, 16]\n assert candidate(n = 1023,queries = [[0, 9], [3, 5]]) == [371842544, 4096]\n assert candidate(n = 1023,queries = [[0, 9], [4, 5], [2, 8]]) == [371842544, 512, 359738130]\n ...
[ "15\n[[0,1],[2,2],[0,3]]", "2\n[[0,0]]" ]
[ "The powers array can be created using the binary representation of n.", "Once powers is formed, the products can be taken using brute force." ]
{ "canonical_parameter_names": [ "n", "queries" ], "leetcode_dataset_entry_point": "Solution().productQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:47", "tests_total": 90...
typescript
{ "raw_signature": "function productQueries(n: number, queries: number[][]): number[] {", "container": null, "callable": "productQueries", "parameters": [ { "name": "n", "type": "number" }, { "name": "queries", "type": "number[][]" } ], "return_type": "number[]", "s...
2,439
minimize-maximum-of-array
Medium
You are given a 0-indexed array nums comprising of n non-negative integers. In one operation, you must: - Choose an integer i such that 1 <= i < n and nums[i] > 0. - Decrease nums[i] by 1. - Increase nums[i - 1] by 1. Return the minimum possible value of the maximum integer of nums after performing any number of ope...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 9, 1, 9, 1]) == 5\n assert candidate(nums = [1, 1000000000]) == 500000001\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [9, 7, 5, 3, 1]...
[ "[3,7,1,6]", "[10,1]" ]
[ "Try a binary search approach.", "Perform a binary search over the minimum value that can be achieved for the maximum number of the array.", "In each binary search iteration, iterate through the array backwards, greedily decreasing the current element until it is within the limit." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimizeArrayValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:49", "tests_total": 114, "te...
typescript
{ "raw_signature": "function minimizeArrayValue(nums: number[]): number {", "container": null, "callable": "minimizeArrayValue", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
2,440
create-components-with-same-value
Hard
There is an undirected tree with n nodes labeled from 0 to n - 1. You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the i^th node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10],edges = [[0, 1], [1, 2], [2, 3]]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5]]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2]...
[ "[6,2,2,2,6]\n[[0,1],[1,2],[1,3],[3,4]]", "[2]\n[]" ]
[ "Consider all divisors of the sum of values." ]
{ "canonical_parameter_names": [ "nums", "edges" ], "leetcode_dataset_entry_point": "Solution().componentValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:51", "tests_total": 4...
typescript
{ "raw_signature": "function componentValue(nums: number[], edges: number[][]): number {", "container": null, "callable": "componentValue", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "edges", "type": "number[][]" } ], "return_type": "number", ...
2,441
largest-positive-integer-that-exists-with-its-negative
Easy
Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array. Return the positive integer k. If there is no such integer, return -1. Example 1: Input: nums = [-1,2,-3,3] Output: 3 Explanation: 3 is the only valid k we can find in the array. E...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, -4, -3, -2]) == 4\n assert candidate(nums = [1000, -1000, 500, -500, 250, -250, 125, -125]) == 1000\n assert candidate(nums = [5, 4, 3, 2, 1, -1]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, -5, -4, -3,...
[ "[-1,2,-3,3]", "[-1,10,6,7,-7,1]", "[-10,8,6,7,-2,-3]" ]
[ "What data structure can help you to determine if an element exists?", "Would a hash table help?" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findMaxK", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:54", "tests_total": 116, "tests_droppe...
typescript
{ "raw_signature": "function findMaxK(nums: number[]): number {", "container": null, "callable": "findMaxK", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,442
count-number-of-distinct-integers-after-reverse-operations
Medium
You are given an array nums consisting of positive integers. You have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers in nums. Return the number of distinct integers in the final array. Example 1: Input: nums = [1,13...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 2]) == 1\n assert candidate(nums = [123, 321, 111, 222]) == 4\n assert candidate(nums = [100, 200, 300, 400]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [9, 99, 99...
[ "[1,13,10,12,31]", "[2,2,2]" ]
[ "What data structure allows us to insert numbers and find the number of distinct numbers in it?", "Try using a set, insert all the numbers and their reverse into it, and return its size." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countDistinctIntegers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:56", "tests_total": 103, ...
typescript
{ "raw_signature": "function countDistinctIntegers(nums: number[]): number {", "container": null, "callable": "countDistinctIntegers", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetc...
2,443
sum-of-number-and-its-reverse
Medium
Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise. Example 1: Input: num = 443 Output: true Explanation: 172 + 271 = 443 so we return true. Example 2: Input: num = 63 Output: false Explanation: 63 cannot be expressed as t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = 443) == True\n assert candidate(num = 181) == True\n assert candidate(num = 99999) == False\n assert candidate(num = 1001) == True\n assert candidate(num = 0) == True\n assert candidate(num = 63) == False\n assert...
[ "443", "63", "181" ]
[ "The constraints are small enough that we can check every number.", "To reverse a number, first convert it to a string. Then, create a new string that is the reverse of the first one. Finally, convert the new string back into a number." ]
{ "canonical_parameter_names": [ "num" ], "leetcode_dataset_entry_point": "Solution().sumOfNumberAndReverse", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:58", "tests_total": 177, "...
typescript
{ "raw_signature": "function sumOfNumberAndReverse(num: number): boolean {", "container": null, "callable": "sumOfNumberAndReverse", "parameters": [ { "name": "num", "type": "number" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
2,444
count-subarrays-with-fixed-bounds
Hard
You are given an integer array nums and two integers minK and maxK. A fixed-bound subarray of nums is a subarray that satisfies the following conditions: - The minimum value in the subarray is equal to minK. - The maximum value in the subarray is equal to maxK. Return the number of fixed-bound subarrays. A subarray...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],minK = 3,maxK = 7) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],minK = 3,maxK = 7) == 1\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5],minK = 2,maxK = 4) == 4\n assert ca...
[ "[1,3,5,2,7,5]\n1\n5", "[1,1,1,1]\n1\n1" ]
[ "Can you solve the problem if all the numbers in the array were between minK and maxK inclusive?", "Think of the inclusion-exclusion principle.", "Divide the array into multiple subarrays such that each number in each subarray is between minK and maxK inclusive, solve the previous problem for each subarray, and...
{ "canonical_parameter_names": [ "nums", "minK", "maxK" ], "leetcode_dataset_entry_point": "Solution().countSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:00", "test...
typescript
{ "raw_signature": "function countSubarrays(nums: number[], minK: number, maxK: number): number {", "container": null, "callable": "countSubarrays", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "minK", "type": "number" }, { "name": "maxK", ...
2,446
determine-if-two-events-have-conflict
Easy
You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where: - event1 = [startTime_1, endTime_1] and - event2 = [startTime_2, endTime_2]. Event times are valid 24 hours format in the form of HH:MM. A conflict happens when two events have some non-em...
{ "language": "python", "source": "def check(candidate):\n assert candidate(event1 = ['10:00', '11:00'],event2 = ['14:00', '15:00']) == False\n assert candidate(event1 = ['00:00', '23:59'],event2 = ['12:00', '12:01']) == True\n assert candidate(event1 = ['00:00', '23:59'],event2 = ['12:00', '12:00']) == Tr...
[ "[\"01:15\",\"02:00\"]\n[\"02:00\",\"03:00\"]", "[\"01:00\",\"02:00\"]\n[\"01:20\",\"03:00\"]", "[\"10:00\",\"11:00\"]\n[\"14:00\",\"15:00\"]" ]
[ "Parse time format to some integer interval first", "How would you determine if two intervals overlap?" ]
{ "canonical_parameter_names": [ "event1", "event2" ], "leetcode_dataset_entry_point": "Solution().haveConflict", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:05", "tests_total": ...
typescript
{ "raw_signature": "function haveConflict(event1: string[], event2: string[]): boolean {", "container": null, "callable": "haveConflict", "parameters": [ { "name": "event1", "type": "string[]" }, { "name": "event2", "type": "string[]" } ], "return_type": "boolean", ...
2,447
number-of-subarrays-with-gcd-equal-to-k
Medium
Given an integer array nums and an integer k, return the number of subarrays of nums where the greatest common divisor of the subarray's elements is k. A subarray is a contiguous non-empty sequence of elements within an array. The greatest common divisor of an array is the largest integer that evenly divides all the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 11\n assert candidate(nums = [7, 14, 21, 28, 35],k = 7) == 11\n assert candidate(nums = [5, 10, 15, 20, 25],k = 5) == 11\n assert candidate(nums = [9, 3, 1, 2, 6, 3],k = 3) == 4\n assert...
[ "[9,3,1,2,6,3]\n3", "[4]\n7" ]
[ "The constraints on nums.length are small. It is possible to check every subarray.", "To calculate GCD, you can use a built-in function or the Euclidean Algorithm." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().subarrayGCD", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:07", "tests_total": 124, "...
typescript
{ "raw_signature": "function subarrayGCD(nums: number[], k: number): number {", "container": null, "callable": "subarrayGCD", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "l...
2,448
minimum-cost-to-make-array-equal
Hard
You are given two 0-indexed arrays nums and cost consisting each of n positive integers. You can do the following operation any number of times: - Increase or decrease any element of the array nums by 1. The cost of doing one operation on the i^th element is cost[i]. Return the minimum total cost such that all the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [6, 1, 3, 9, 3],cost = [2, 1, 2, 1, 2]) == 14\n assert candidate(nums = [1, 3, 5, 2],cost = [2, 3, 1, 14]) == 8\n assert candidate(nums = [2, 2, 2, 2, 2],cost = [4, 2, 8, 1, 3]) == 0\n assert candidate(nums = [6, 1, 9],co...
[ "[1,3,5,2]\n[2,3,1,14]", "[2,2,2,2,2]\n[4,2,8,1,3]" ]
[ "Changing the elements into one of the numbers already existing in the array nums is optimal.", "Try finding the cost of changing the array into each element, and return the minimum value." ]
{ "canonical_parameter_names": [ "nums", "cost" ], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:10", "tests_total": 109, "t...
typescript
{ "raw_signature": "function minCost(nums: number[], cost: number[]): number {", "container": null, "callable": "minCost", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "cost", "type": "number[]" } ], "return_type": "number", "signature_source": ...
2,449
minimum-number-of-operations-to-make-arrays-similar
Hard
You are given two positive integer arrays nums and target, of the same length. In one operation, you can choose any two distinct indices i and j where 0 <= i, j < nums.length and: - set nums[i] = nums[i] + 2 and - set nums[j] = nums[j] - 2. Two arrays are considered to be similar if the frequency of each element is ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 3, 3, 3],target = [1, 5, 1, 5]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1],target = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [3, 3, 3, 3],target = [5, 1, 5, 1]) == 2\n assert candidate(nums = [100000, 50000...
[ "[8,12,6]\n[2,14,10]", "[1,2,5]\n[4,1,3]", "[1,1,1,1,1]\n[1,1,1,1,1]" ]
[ "Solve for even and odd numbers separately.", "Greedily match smallest even element from nums to smallest even element from target, then similarly next smallest element and so on.", "Similarly, match odd elements too." ]
{ "canonical_parameter_names": [ "nums", "target" ], "leetcode_dataset_entry_point": "Solution().makeSimilar", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:12", "tests_total": 107...
typescript
{ "raw_signature": "function makeSimilar(nums: number[], target: number[]): number {", "container": null, "callable": "makeSimilar", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "target", "type": "number[]" } ], "return_type": "number", "signatu...
2,451
odd-string-difference
Easy
You are given an array of equal-length strings words. Assume that the length of each string is n. Each string words[i] can be converted into a difference integer array difference[i] of length n - 1 where difference[i][j] = words[i][j+1] - words[i][j] where 0 <= j <= n - 2. Note that the difference between two letters ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['adc', 'wzy', 'abc']) == \"abc\"\n assert candidate(words = ['zzz', 'zyx', 'zwy', 'zvx']) == \"zzz\"\n assert candidate(words = ['zzz', 'zyz', 'zxz', 'wyz']) == \"zzz\"\n assert candidate(words = ['aaa', 'bob', 'ccc', '...
[ "[\"adc\",\"wzy\",\"abc\"]", "[\"aaa\",\"bob\",\"ccc\",\"ddd\"]" ]
[ "Find the difference integer array for each string.", "Compare them to find the odd one out." ]
{ "canonical_parameter_names": [ "words" ], "leetcode_dataset_entry_point": "Solution().oddString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:17", "tests_total": 80, "tests_dropp...
typescript
{ "raw_signature": "function oddString(words: string[]): string {", "container": null, "callable": "oddString", "parameters": [ { "name": "words", "type": "string[]" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }