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,581 | count-number-of-possible-root-nodes | Hard | Alice has an undirected tree with n nodes labeled from 0 to n - 1. The tree is represented as 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.
Alice wants Bob to find the root of the tree. She allows Bob to make several guesses ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(edges = [[0, 1], [0, 2], [0, 3]],guesses = [[0, 1], [0, 2], [0, 3]],k = 2) == 4\n assert candidate(edges = [[0, 1], [0, 2]],guesses = [[0, 1]],k = 1) == 2\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [4, 2]],guesses = [[1, 3... | [
"[[0,1],[1,2],[1,3],[4,2]]\n[[1,3],[0,1],[1,0],[2,4]]\n3",
"[[0,1],[1,2],[2,3],[3,4]]\n[[1,0],[3,4],[2,1],[3,2]]\n1"
] | [
"How can we check if any node can be the root?",
"Can we use this information to check its neighboring nodes?",
"When we traverse from current node to a neighboring node, how will we update our answer?"
] | {
"canonical_parameter_names": [
"edges",
"guesses",
"k"
],
"leetcode_dataset_entry_point": "Solution().rootCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:57:58",
"tests_to... | typescript | {
"raw_signature": "function rootCount(edges: number[][], guesses: number[][], k: number): number {",
"container": null,
"callable": "rootCount",
"parameters": [
{
"name": "edges",
"type": "number[][]"
},
{
"name": "guesses",
"type": "number[][]"
},
{
"name": "k... |
2,582 | pass-the-pillow | Easy | There are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Once the pillow reaches the end of the line, the direction changes, and people continue passing the pillow... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 2,time = 5) == 2\n assert candidate(n = 10,time = 15) == 4\n assert candidate(n = 500,time = 750) == 249\n assert candidate(n = 2,time = 1) == 2\n assert candidate(n = 7,time = 20) == 5\n assert candidate(n = 8,time = ... | [
"4\n5",
"3\n2"
] | [
"Maintain two integer variables, direction and i, where direction denotes the current direction in which the pillow should pass, and i denotes an index of the person holding the pillow.",
"While time is positive, update the current index with the current direction. If the index reaches the end of the line, multip... | {
"canonical_parameter_names": [
"n",
"time"
],
"leetcode_dataset_entry_point": "Solution().passThePillow",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:01",
"tests_total": 94,
... | typescript | {
"raw_signature": "function passThePillow(n: number, time: number): number {",
"container": null,
"callable": "passThePillow",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "time",
"type": "number"
}
],
"return_type": "number",
"signature_source": "l... |
2,584 | split-the-array-to-make-coprime-products | Hard | You are given a 0-indexed integer array nums of length n.
A split at an index i where 0 <= i <= n - 2 is called valid if the product of the first i + 1 elements and the product of the remaining elements are coprime.
- For example, if nums = [2, 3, 3], then a split at the index i = 0 is valid because 2 and 9 are copri... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [60, 1, 2, 3]) == -1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == -1\n assert candidate(nums = [2, 3, 5, 7, 11, 13]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12]) == -1\n assert candidate(nums = ... | [
"[4,7,8,15,3,5]",
"[4,7,15,8,3,5]"
] | [
"Two numbers with GCD equal to 1 have no common prime divisor.",
"Find the prime factorization of the left and right sides and check if they share a prime divisor."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findValidSplit",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:06",
"tests_total": 107,
"tests_... | typescript | {
"raw_signature": "function findValidSplit(nums: number[]): number {",
"container": null,
"callable": "findValidSplit",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippe... |
2,585 | number-of-ways-to-earn-points | Hard | There is a test that has n types of questions. You are given an integer target and a 0-indexed 2D integer array types where types[i] = [count_i, marks_i] indicates that there are count_i questions of the i^th type, and each one of them is worth marks_i points.
Return the number of ways you can earn exactly target poin... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(target = 10,types = [[2, 5], [1, 3]]) == 1\n assert candidate(target = 1,types = [[1, 1]]) == 1\n assert candidate(target = 30,types = [[5, 10], [3, 5], [2, 15]]) == 5\n assert candidate(target = 750,types = [[50, 15], [50, 25],... | [
"6\n[[6,1],[3,2],[2,3]]",
"5\n[[50,1],[50,2],[50,5]]",
"18\n[[6,1],[3,2],[2,3]]"
] | [
"Use Dynamic Programming",
"Let ways[i][points] be the number of ways to score a given number of points after solving some questions of the first i types.",
"ways[i][points] is equal to the sum of ways[i-1][points - solved * marks[i] over 0 <= solved <= count_i"
] | {
"canonical_parameter_names": [
"target",
"types"
],
"leetcode_dataset_entry_point": "Solution().waysToReachTarget",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:08",
"tests_tota... | typescript | {
"raw_signature": "function waysToReachTarget(target: number, types: number[][]): number {",
"container": null,
"callable": "waysToReachTarget",
"parameters": [
{
"name": "target",
"type": "number"
},
{
"name": "types",
"type": "number[][]"
}
],
"return_type": "numbe... |
2,586 | count-the-number-of-vowel-strings-in-range | Easy | You are given a 0-indexed array of string words and two integers left and right.
A string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are 'a', 'e', 'i', 'o', and 'u'.
Return the number of vowel strings words[i] where i belongs to the inclusive ra... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['sky', 'fly', 'why'],left = 0,right = 2) == 0\n assert candidate(words = ['apple', 'banana', 'orange', 'umbrella'],left = 0,right = 3) == 3\n assert candidate(words = ['are', 'amy', 'u'],left = 0,right = 2) == 2\n asser... | [
"[\"are\",\"amy\",\"u\"]\n0\n2",
"[\"hey\",\"aeo\",\"mu\",\"ooo\",\"artro\"]\n1\n4"
] | [
"consider iterating over all strings from left to right and use an if condition to check if the first character and last character are vowels."
] | {
"canonical_parameter_names": [
"words",
"left",
"right"
],
"leetcode_dataset_entry_point": "Solution().vowelStrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:11",
"test... | typescript | {
"raw_signature": "function vowelStrings(words: string[], left: number, right: number): number {",
"container": null,
"callable": "vowelStrings",
"parameters": [
{
"name": "words",
"type": "string[]"
},
{
"name": "left",
"type": "number"
},
{
"name": "right",
... |
2,587 | rearrange-array-to-maximize-prefix-score | Medium | You are given a 0-indexed integer array nums. You can rearrange the elements of nums to any order (including the given order).
Let prefix be the array containing the prefix sums of nums after rearranging it. In other words, prefix[i] is the sum of the elements from 0 to i in nums after rearranging it. The score of num... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, -1, 3, 2, -4, 0, 2]) == 7\n assert candidate(nums = [-1]) == 0\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == 5\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [5, -2, 3, 1, -4, 7]) == 6\n ass... | [
"[2,-1,0,1,-3,3,-3]",
"[-2,-3,0]"
] | [
"The best order of the array is in decreasing order.",
"Sort the array in decreasing order and count the number of positive values in the prefix sum array."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:13",
"tests_total": 105,
"tests_droppe... | typescript | {
"raw_signature": "function maxScore(nums: number[]): number {",
"container": null,
"callable": "maxScore",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,588 | count-the-number-of-beautiful-subarrays | Medium | You are given a 0-indexed integer array nums. In one operation, you can:
- Choose two different indices i and j such that 0 <= i, j < nums.length.
- Choose a non-negative integer k such that the k^th bit (0-indexed) in the binary representation of nums[i] and nums[j] is 1.
- Subtract 2^k from nums[i] and nums[j].
A s... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 25\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953]) == 0\n assert candidate(nums = [1, 0, 1, 0, 1]) == 6\n assert candidate(nums = [2, ... | [
"[4,3,1,2,4]",
"[1,10,4]"
] | [
"A subarray is beautiful if its xor is equal to zero.",
"Compute the prefix xor for every index, then the xor of subarray [left, right] is equal to zero if prefix_xor[left] ^ perfix_xor[right] == 0",
"Iterate from left to right and maintain a hash table to count the number of indices equal to the current prefix... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().beautifulSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:16",
"tests_total": 121,
"te... | typescript | {
"raw_signature": "function beautifulSubarrays(nums: number[]): number {",
"container": null,
"callable": "beautifulSubarrays",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/co... |
2,589 | minimum-time-to-complete-all-tasks | Hard | There is a computer that can run an unlimited number of tasks at the same time. You are given a 2D integer array tasks where tasks[i] = [start_i, end_i, duration_i] indicates that the i^th task should run for a total of duration_i seconds (not necessarily continuous) within the inclusive time range [start_i, end_i].
Y... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(tasks = [[1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1]]) == 2\n assert candidate(tasks = [[1, 100, 50], [50, 150, 50], [100, 200, 50]]) == 99\n assert candidate(tasks = [[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1]]) == 5\n ... | [
"[[2,3,1],[4,5,1],[1,5,2]]",
"[[1,3,2],[2,5,3],[5,6,2]]"
] | [
"Sort the tasks in ascending order of end time",
"Since there are only up to 2000 time points to consider, you can check them one by one",
"It is always beneficial to run the task as late as possible so that later tasks can run simultaneously."
] | {
"canonical_parameter_names": [
"tasks"
],
"leetcode_dataset_entry_point": "Solution().findMinimumTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:18",
"tests_total": 112,
"test... | typescript | {
"raw_signature": "function findMinimumTime(tasks: number[][]): number {",
"container": null,
"callable": "findMinimumTime",
"parameters": [
{
"name": "tasks",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/co... |
2,591 | distribute-money-to-maximum-children | Easy | You are given an integer money denoting the amount of money (in dollars) that you have and another integer children denoting the number of children that you must distribute the money to.
You have to distribute the money according to the following rules:
- All money must be distributed.
- Everyone must receive at leas... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(money = 150,children = 15) == 14\n assert candidate(money = 100,children = 5) == 4\n assert candidate(money = 15,children = 3) == 1\n assert candidate(money = 31,children = 3) == 2\n assert candidate(money = 7,children = 2) =... | [
"20\n3",
"16\n2"
] | [
"Can we distribute the money according to the rules if we give 'k' children exactly 8 dollars?",
"Brute force to find the largest possible value of k, or return -1 if there doesn’t exist any such k."
] | {
"canonical_parameter_names": [
"money",
"children"
],
"leetcode_dataset_entry_point": "Solution().distMoney",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:20",
"tests_total": 47... | typescript | {
"raw_signature": "function distMoney(money: number, children: number): number {",
"container": null,
"callable": "distMoney",
"parameters": [
{
"name": "money",
"type": "number"
},
{
"name": "children",
"type": "number"
}
],
"return_type": "number",
"signature_sou... |
2,592 | maximize-greatness-of-an-array | Medium | You are given a 0-indexed integer array nums. You are allowed to permute nums into a new array perm of your choosing.
We define the greatness of nums be the number of indices 0 <= i < nums.length for which perm[i] > nums[i].
Return the maximum possible greatness you can achieve after permuting nums.
Example 1:
Inpu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 6\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5]) == 5\n assert candidate(nums = [1... | [
"[1,3,5,2,1,3,1]",
"[1,2,3,4]"
] | [
"Can we use sorting and two pointers here?",
"Assign every element the next bigger unused element as many times as possible."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maximizeGreatness",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:23",
"tests_total": 86,
"test... | typescript | {
"raw_signature": "function maximizeGreatness(nums: number[]): number {",
"container": null,
"callable": "maximizeGreatness",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/code... |
2,593 | find-score-of-an-array-after-marking-all-elements | Medium | You are given an array nums consisting of positive integers.
Starting with score = 0, apply the following algorithm:
- Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index.
- Add the value of the chosen integer to score.
- Mark the chosen element and i... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [1, 1000000]) == 1\n assert candidate(nums = [1000000, 1, 1000000, 1, 1000000]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 25\n assert candidat... | [
"[2,1,3,4,5,2]",
"[2,3,5,1,3,2]"
] | [
"Try simulating the process of marking the elements and their adjacent.",
"If there is an element that was already marked, then you skip it."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:25",
"tests_total": 112,
"tests_dropp... | typescript | {
"raw_signature": "function findScore(nums: number[]): number {",
"container": null,
"callable": "findScore",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,594 | minimum-time-to-repair-cars | Medium | You are given an integer array ranks representing the ranks of some mechanics. ranks_i is the rank of the i^th mechanic. A mechanic with a rank r can repair n cars in r * n^2 minutes.
You are also given an integer cars representing the total number of cars waiting in the garage to be repaired.
Return the minimum time... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(ranks = [1],cars = 1000000) == 1000000000000\n assert candidate(ranks = [10],cars = 100) == 100000\n assert candidate(ranks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cars = 20) == 25\n assert candidate(ranks = [5, 1, 8],cars = 6) == 16\... | [
"[4,2,3,1]\n10",
"[5,1,8]\n6"
] | [
"For a predefined fixed time, can all the cars be repaired?",
"Try using binary search on the answer."
] | {
"canonical_parameter_names": [
"ranks",
"cars"
],
"leetcode_dataset_entry_point": "Solution().repairCars",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:27",
"tests_total": 92,
... | typescript | {
"raw_signature": "function repairCars(ranks: number[], cars: number): number {",
"container": null,
"callable": "repairCars",
"parameters": [
{
"name": "ranks",
"type": "number[]"
},
{
"name": "cars",
"type": "number"
}
],
"return_type": "number",
"signature_sourc... |
2,595 | number-of-even-and-odd-bits | Easy | You are given a positive integer n.
Let even denote the number of even indices in the binary representation of n with value 1.
Let odd denote the number of odd indices in the binary representation of n with value 1.
Note that bits are indexed from right to left in the binary representation of a number.
Return the a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 8) == [0, 1]\n assert candidate(n = 3) == [1, 1]\n assert candidate(n = 1000) == [2, 4]\n assert candidate(n = 63) == [3, 3]\n assert candidate(n = 255) == [4, 4]\n assert candidate(n = 15) == [2, 2]\n assert candid... | [
"50",
"2"
] | [
"Maintain two integer variables, even and odd, to count the number of even and odd indices in the binary representation of integer n.",
"Divide n by 2 while n is positive, and if n modulo 2 is 1, add 1 to its corresponding variable."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().evenOddBit",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:30",
"tests_total": 62,
"tests_dropped"... | typescript | {
"raw_signature": "function evenOddBit(n: number): number[] {",
"container": null,
"callable": "evenOddBit",
"parameters": [
{
"name": "n",
"type": "number"
}
],
"return_type": "number[]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,596 | check-knight-tour-configuration | Medium | There is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the board exactly once.
You are given an n x n integer matrix grid consisting of distinct integers from the range [0, n * n - 1] where grid[row][col] indicates that the cell ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 5, 2], [6, 3, 1], [8, 7, 4]]) == False\n assert candidate(grid = [[0, 12, 3, 14, 5], [19, 2, 15, 4, 13], [6, 23, 8, 17, 16], [22, 11, 10, 9, 18], [7, 24, 21, 1, 20]]) == False\n assert candidate(grid = [[0, 5, 2], [3, 8... | [
"[[0,11,16,5,20],[17,4,19,10,15],[12,1,8,21,6],[3,18,23,14,9],[24,13,2,7,22]]",
"[[0,3,6],[5,8,1],[2,7,4]]"
] | [
"It is enough to check if each move of the knight is valid.",
"Try all cases of the knight's movements to check if a move is valid."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().checkValidGrid",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:32",
"tests_total": 54,
"tests_d... | typescript | {
"raw_signature": "function checkValidGrid(grid: number[][]): boolean {",
"container": null,
"callable": "checkValidGrid",
"parameters": [
{
"name": "grid",
"type": "number[][]"
}
],
"return_type": "boolean",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/code... |
2,597 | the-number-of-beautiful-subsets | Medium | You are given an array nums of positive integers and a positive integer k.
A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k.
Return the number of non-empty beautiful subsets of the array nums.
A subset of nums is an array that can be obtained by deleting some (... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90],k = 5) == 6764\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],k = 1) == 6764\n assert candidate(nums = [10, 2... | [
"[2,4,6]\n2",
"[1]\n1"
] | [
"Sort the array nums and create another array cnt of size nums[i].",
"Use backtracking to generate all the beautiful subsets. If cnt[nums[i] - k] is positive, then it is impossible to add nums[i] in the subset, and we just move to the next index. Otherwise, it is also possible to add nums[i] in the subset, in thi... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().beautifulSubsets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:34",
"tests_total": 74,... | typescript | {
"raw_signature": "function beautifulSubsets(nums: number[], k: number): number {",
"container": null,
"callable": "beautifulSubsets",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_s... |
2,598 | smallest-missing-non-negative-integer-after-operations | Medium | You are given a 0-indexed integer array nums and an integer value.
In one operation, you can add or subtract value from any element of nums.
- For example, if nums = [1,2,3] and value = 2, you can choose to subtract value from nums[0] to make nums = [-1,2,3].
The MEX (minimum excluded) of an array is the smallest mi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [0, 1, 2, 3, 4, 5],value = 1) == 6\n assert candidate(nums = [0, 0, 0, 0],value = 3) == 1\n assert candidate(nums = [10, 15, 20, 25, 30],value = 5) == 1\n assert candidate(nums = [-1, -2, -3, -4],value = 2) == 4\n asse... | [
"[1,-10,7,13,6,8]\n5",
"[1,-10,7,13,6,8]\n7"
] | [
"Think about using modular arithmetic.",
"if x = nums[i] (mod value), then we can make nums[i] equal to x after some number of operations",
"How does finding the frequency of (nums[i] mod value) help?"
] | {
"canonical_parameter_names": [
"nums",
"value"
],
"leetcode_dataset_entry_point": "Solution().findSmallestInteger",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:37",
"tests_tota... | typescript | {
"raw_signature": "function findSmallestInteger(nums: number[], value: number): number {",
"container": null,
"callable": "findSmallestInteger",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "value",
"type": "number"
}
],
"return_type": "number",
... |
2,600 | k-items-with-the-maximum-sum | Easy | There is a bag that consists of items, each item has a number 1, 0, or -1 written on it.
You are given four non-negative integers numOnes, numZeros, numNegOnes, and k.
The bag initially contains:
- numOnes items with 1s written on them.
- numZeroes items with 0s written on them.
- numNegOnes items with -1s written o... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(numOnes = 25,numZeros = 25,numNegOnes = 0,k = 50) == 25\n assert candidate(numOnes = 0,numZeros = 50,numNegOnes = 0,k = 10) == 0\n assert candidate(numOnes = 3,numZeros = 2,numNegOnes = 0,k = 2) == 2\n assert candidate(numOnes =... | [
"3\n2\n0\n2",
"3\n2\n0\n4"
] | [
"It is always optimal to take items with the number 1 written on them as much as possible.",
"If k > numOnes, after taking all items with the number 1, it is always optimal to take items with the number 0 written on them as much as possible.",
"If k > numOnes + numZeroes we are forced to take k - numOnes - numZ... | {
"canonical_parameter_names": [
"numOnes",
"numZeros",
"numNegOnes",
"k"
],
"leetcode_dataset_entry_point": "Solution().kItemsWithMaximumSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2... | typescript | {
"raw_signature": "function kItemsWithMaximumSum(numOnes: number, numZeros: number, numNegOnes: number, k: number): number {",
"container": null,
"callable": "kItemsWithMaximumSum",
"parameters": [
{
"name": "numOnes",
"type": "number"
},
{
"name": "numZeros",
"type": "numbe... |
2,601 | prime-subtraction-operation | Medium | You are given a 0-indexed integer array nums of length n.
You can perform the following operation as many times as you want:
- Pick an index i that you haven’t picked before, and pick a prime p strictly less than nums[i], then subtract p from nums[i].
Return true if you can make nums a strictly increasing array usin... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 9, 6, 10]) == True\n assert candidate(nums = [999, 998, 997, 996, 995]) == True\n assert candidate(nums = [5, 8, 3]) == False\n assert candidate(nums = [100, 99, 98, 97, 96]) == True\n assert candidate(nums = [2, 3... | [
"[4,9,6,10]",
"[6,8,11,12]",
"[5,8,3]"
] | [
"Think about if we have many primes to subtract from nums[i]. Which prime is more optimal?",
"The most optimal prime to subtract from nums[i] is the one that makes nums[i] the smallest as possible and greater than nums[i-1]."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().primeSubOperation",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:44",
"tests_total": 157,
"tes... | typescript | {
"raw_signature": "function primeSubOperation(nums: number[]): boolean {",
"container": null,
"callable": "primeSubOperation",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "boolean",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/co... |
2,602 | minimum-operations-to-make-all-array-elements-equal | Medium | You are given an array nums consisting of positive integers.
You are also given an integer array queries of size m. For the i^th query, you want to make all of the elements of nums equal to queries[i]. You can perform the following operation on the array any number of times:
- Increase or decrease an element of the a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1000000000],queries = [1000000000, 1, 999999999]) == [0, 999999999, 1]\n assert candidate(nums = [2, 9, 6, 3],queries = [10]) == [20]\n assert candidate(nums = [1, 1, 1, 1, 1],queries = [1, 2, 3]) == [0, 5, 10]\n assert ... | [
"[3,1,6,8]\n[1,5]",
"[2,9,6,3]\n[10]"
] | [
"For each query, you should decrease all elements greater than queries[i] and increase all elements less than queries[i].",
"The answer is the sum of absolute differences between queries[i] and every element of the array. How do you calculate that optimally?"
] | {
"canonical_parameter_names": [
"nums",
"queries"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:46",
"tests_total": ... | typescript | {
"raw_signature": "function minOperations(nums: number[], queries: number[]): number[] {",
"container": null,
"callable": "minOperations",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "queries",
"type": "number[]"
}
],
"return_type": "number[]",
... |
2,603 | collect-coins-in-a-tree | Hard | There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given an integer n and 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 array coins of size n where coins[i] can be... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(coins = [0, 0, 1, 0, 1, 0],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5]]) == 0\n assert candidate(coins = [0, 0, 0, 0, 0, 0, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 0\n assert candidate(coins = [1, 0, 0, ... | [
"[1,0,0,0,0,1]\n[[0,1],[1,2],[2,3],[3,4],[4,5]]",
"[0,0,0,1,1,0,0,1]\n[[0,1],[0,2],[1,3],[1,4],[2,5],[5,6],[5,7]]"
] | [
"All leaves that do not have a coin are redundant and can be deleted from the tree.",
"Remove the leaves that do not have coins on them, so that the resulting tree will have a coin on every leaf.",
"In the remaining tree, remove each leaf node and its parent from the tree. The remaining nodes in the tree are th... | {
"canonical_parameter_names": [
"coins",
"edges"
],
"leetcode_dataset_entry_point": "Solution().collectTheCoins",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:48",
"tests_total":... | typescript | {
"raw_signature": "function collectTheCoins(coins: number[], edges: number[][]): number {",
"container": null,
"callable": "collectTheCoins",
"parameters": [
{
"name": "coins",
"type": "number[]"
},
{
"name": "edges",
"type": "number[][]"
}
],
"return_type": "number"... |
2,605 | form-smallest-number-from-two-digit-arrays | Easy | Given two arrays of unique digits nums1 and nums2, return the smallest number that contains at least one digit from each array.
Example 1:
Input: nums1 = [4,1,3], nums2 = [5,7]
Output: 15
Explanation: The number 15 contains the digit 1 from nums1 and the digit 5 from nums2. It can be proven that 15 is the smallest nu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 4, 5]) == 3\n assert candidate(nums1 = [1, 2],nums2 = [3, 4]) == 13\n assert candidate(nums1 = [1, 9],nums2 = [2, 8]) == 12\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9]) == 16\n ... | [
"[4,1,3]\n[5,7]",
"[3,5,2,6]\n[3,1,7]"
] | [
"How many digits will the resulting number have at most?",
"The resulting number will have either one or two digits. Try to find when each case is possible."
] | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().minNumber",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:53",
"tests_total": 97,
... | typescript | {
"raw_signature": "function minNumber(nums1: number[], nums2: number[]): number {",
"container": null,
"callable": "minNumber",
"parameters": [
{
"name": "nums1",
"type": "number[]"
},
{
"name": "nums2",
"type": "number[]"
}
],
"return_type": "number",
"signature_s... |
2,606 | find-the-substring-with-maximum-cost | Medium | You are given a string s, a string chars of distinct characters and an integer array vals of the same length as chars.
The cost of the substring is the sum of the values of each character in the substring. The cost of an empty string is considered 0.
The value of the character is defined in the following way:
- If t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"programming\",chars = \"pg\",vals = [-1, -2]) == 99\n assert candidate(s = \"a\",chars = \"a\",vals = [-1]) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",chars = \"abcdefghijklmnopqrstuvwxyz\",vals = [-26, -25, -... | [
"\"adaa\"\n\"d\"\n[-1000]",
"\"abc\"\n\"abc\"\n[-1,-1,-1]"
] | [
"Create a new integer array where arr[i] denotes the value of character s[i].",
"We can use Kadane’s maximum subarray sum algorithm to find the maximum cost."
] | {
"canonical_parameter_names": [
"s",
"chars",
"vals"
],
"leetcode_dataset_entry_point": "Solution().maximumCostSubstring",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:55",
"... | typescript | {
"raw_signature": "function maximumCostSubstring(s: string, chars: string, vals: number[]): number {",
"container": null,
"callable": "maximumCostSubstring",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "chars",
"type": "string"
},
{
"name": "va... |
2,607 | make-k-subarray-sums-equal | Medium | You are given a 0-indexed integer array arr and an integer k. The array arr is circular. In other words, the first element of the array is the next element of the last element, and the last element of the array is the previous element of the first element.
You can do the following operation any number of times:
- Pic... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5],k = 1) == 6\n assert candidate(arr = [5, 5, 5, 5, 5],k = 2) == 0\n assert candidate(arr = [1, 4, 1, 3],k = 2) == 1\n assert candidate(arr = [10, 20, 30, 40, 50],k = 5) == 0\n assert candidate(arr = [5, 5... | [
"[1,4,1,3]\n2",
"[2,5,5,7]\n3"
] | [
"Think about gcd(n, k). How will it help to calculate the answer?",
"indices i and j are in the same group if gcd(n, k) mod i = gcd(n, k) mod j. Each group should have equal elements. Think about the minimum number of operations for each group",
"The minimum number of operations for each group equals the summat... | {
"canonical_parameter_names": [
"arr",
"k"
],
"leetcode_dataset_entry_point": "Solution().makeSubKSumEqual",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:58:58",
"tests_total": 102,... | typescript | {
"raw_signature": "function makeSubKSumEqual(arr: number[], k: number): number {",
"container": null,
"callable": "makeSubKSumEqual",
"parameters": [
{
"name": "arr",
"type": "number[]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_sou... |
2,608 | shortest-cycle-in-a-graph | Hard | There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D integer array edges, where edges[i] = [u_i, v_i] denotes an edge between vertex u_i and vertex v_i. Every vertex pair is connected by at most one edge, and no vertex has an... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5]]) == 4\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [0, 4]]) == 4\n assert candidate(n = 3,edges = [[0, 1], [1, 2], [2, 0]])... | [
"7\n[[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]]",
"4\n[[0,1],[0,2]]"
] | [
"How can BFS be used?",
"For each vertex u, calculate the length of the shortest cycle that contains vertex u using BFS"
] | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().findShortestCycle",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:00",
"tests_total": 6... | typescript | {
"raw_signature": "function findShortestCycle(n: number, edges: number[][]): number {",
"container": null,
"callable": "findShortestCycle",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "edges",
"type": "number[][]"
}
],
"return_type": "number",
"sig... |
2,609 | find-the-longest-balanced-substring-of-a-binary-string | Easy | You are given a binary string s consisting only of zeroes and ones.
A substring of s is considered balanced if all zeroes are before ones and the number of zeroes is equal to the number of ones inside the substring. Notice that the empty substring is considered a balanced substring.
Return the length of the longest b... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"000000111111\") == 12\n assert candidate(s = \"000111000111\") == 6\n assert candidate(s = \"000110\") == 4\n assert candidate(s = \"01\") == 2\n assert candidate(s = \"00111\") == 4\n assert candidate(s = \"00011001... | [
"\"01000111\"",
"\"00111\"",
"\"111\""
] | [
"Consider iterating over each subarray and checking if it’s balanced or not.",
"Among all balanced subarrays, the answer is the longest one of them."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().findTheLongestBalancedSubstring",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:02",
"tests_total": ... | typescript | {
"raw_signature": "function findTheLongestBalancedSubstring(s: string): number {",
"container": null,
"callable": "findTheLongestBalancedSubstring",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_sourc... |
2,610 | convert-an-array-into-a-2d-array-with-conditions | Medium | You are given an integer array nums. You need to create a 2D array from nums satisfying the following conditions:
- The 2D array should contain only the elements of the array nums.
- Each row in the 2D array contains distinct integers.
- The number of rows in the 2D array should be minimal.
Return the resulting array... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == [[1, 2, 3, 4], [2, 3, 4], [3, 4], [4]]\n assert candidate(nums = [1, 2, 3, 4]) == [[1, 2, 3, 4]]\n assert candidate(nums = [10, 1, 2, 9, 3, 8, 4, 7, 5, 6]) == [[10, 1, 2, 9, 3, 8, 4, 7, 5, ... | [
"[1,3,4,1,2,3,1]",
"[2,1,1]"
] | [
"Process the elements in the array one by one in any order and only create a new row in the matrix when we cannot put it into the existing rows",
"We can simply iterate over the existing rows of the matrix to see if we can place each element."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findMatrix",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:04",
"tests_total": 79,
"tests_dropp... | typescript | {
"raw_signature": "function findMatrix(nums: number[]): number[][] {",
"container": null,
"callable": "findMatrix",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number[][]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippe... |
2,611 | mice-and-cheese | Medium | There are two mice and n different types of cheese, each type of cheese should be eaten by exactly one mouse.
A point of the cheese with index i (0-indexed) is:
- reward1[i] if the first mouse eats it.
- reward2[i] if the second mouse eats it.
You are given a positive integer array reward1, a positive integer array ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(reward1 = [10, 20, 30, 40],reward2 = [40, 30, 20, 10],k = 3) == 130\n assert candidate(reward1 = [5, 4, 3, 2, 1],reward2 = [1, 2, 3, 4, 5],k = 3) == 21\n assert candidate(reward1 = [10, 20, 30],reward2 = [40, 50, 60],k = 0) == 150\... | [
"[1,1,3,4]\n[4,4,1,1]\n2",
"[1,1]\n[1,1]\n2"
] | [
"The intended solution uses greedy approach.",
"Imagine at first that the second mouse eats all the cheese, then we should choose k types of cheese with the maximum sum of - reward2[i] + reward1[i]."
] | {
"canonical_parameter_names": [
"reward1",
"reward2",
"k"
],
"leetcode_dataset_entry_point": "Solution().miceAndCheese",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:07",
"te... | typescript | {
"raw_signature": "function miceAndCheese(reward1: number[], reward2: number[], k: number): number {",
"container": null,
"callable": "miceAndCheese",
"parameters": [
{
"name": "reward1",
"type": "number[]"
},
{
"name": "reward2",
"type": "number[]"
},
{
"name"... |
2,614 | prime-in-diagonal | Easy | You are given a 0-indexed two-dimensional integer array nums.
Return the largest prime number that lies on at least one of the diagonals of nums. In case, no prime is present on any of the diagonals, return 0.
Note that:
- An integer is prime if it is greater than 1 and has no positive integer divisors other than 1 ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [[4, 6, 8], [10, 12, 14], [16, 18, 20]]) == 0\n assert candidate(nums = [[3, 1, 4], [1, 5, 9], [2, 6, 5]]) == 5\n assert candidate(nums = [[1, 4, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12], [13, 14, 15, 16]]) == 13\n assert can... | [
"[[1,2,3],[5,6,7],[9,10,11]]",
"[[1,2,3],[5,17,7],[9,11,10]]"
] | [
"Iterate over the diagonals of the matrix and check for each element.",
"Check if the element is prime or not in O(sqrt(n)) time."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().diagonalPrime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:11",
"tests_total": 73,
"tests_dr... | typescript | {
"raw_signature": "function diagonalPrime(nums: number[][]): number {",
"container": null,
"callable": "diagonalPrime",
"parameters": [
{
"name": "nums",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnip... |
2,615 | sum-of-distances | Medium | You are given a 0-indexed integer array nums.
There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] to be 0.
Return the array arr.
Example 1:
Input: nums = [1,3,1,1,2]
Output: [5,0,3,4,0]
Explanation:... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [0, 5, 3]) == [0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [1]) == [0]\n assert candidate(nums = [10, 10, 10, 10]) == [6, 4, 4, 6]\n as... | [
"[1,3,1,1,2]",
"[0,5,3]"
] | [
"Can we use the prefix sum here?",
"For each number x, collect all the indices where x occurs, and calculate the prefix sum of the array.",
"For each occurrence of x, the indices to the right will be regular subtraction while the indices to the left will be reversed subtraction."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().distance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:14",
"tests_total": 105,
"tests_droppe... | typescript | {
"raw_signature": "function distance(nums: number[]): number[] {",
"container": null,
"callable": "distance",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number[]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,616 | minimize-the-maximum-difference-of-pairs | Medium | You are given a 0-indexed integer array nums and an integer p. Find p pairs of indices of nums such that the maximum difference amongst all the pairs is minimized. Also, ensure no index appears more than once amongst the p pairs.
Note that for a pair of elements at the index i and j, the difference of this pair is |nu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 6, 8, 10],p = 2) == 2\n assert candidate(nums = [5, 3, 8, 4, 9, 1],p = 3) == 2\n assert candidate(nums = [5, 5, 5, 5, 5],p = 2) == 0\n assert candidate(nums = [7, 1, 3, 4, 2, 5],p = 0) == 0\n assert candidate(nu... | [
"[10,1,2,7,1,3]\n2",
"[4,2,1,2]\n1"
] | [
"To minimize the answer, the array should be sorted first.",
"Can we use binary search here?"
] | {
"canonical_parameter_names": [
"nums",
"p"
],
"leetcode_dataset_entry_point": "Solution().minimizeMax",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:16",
"tests_total": 106,
"... | typescript | {
"raw_signature": "function minimizeMax(nums: number[], p: number): number {",
"container": null,
"callable": "minimizeMax",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "p",
"type": "number"
}
],
"return_type": "number",
"signature_source": "l... |
2,617 | minimum-number-of-visited-cells-in-a-grid | Hard | You are given a 0-indexed m x n integer matrix grid. Your initial position is at the top-left cell (0, 0).
Starting from the cell (i, j), you can move to one of the following cells:
- Cells (i, k) with j < k <= grid[i][j] + j (rightward movement), or
- Cells (k, j) with i < k <= grid[i][j] + i (downward movement).
R... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[2, 0, 0], [1, 3, 1], [0, 1, 0]]) == 5\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == -1\n assert candidate(grid = [[3, 4, 2, 1], [4, 2, 3, 1], [2, 1, 0, 0], [2, 4, 0, 0]]) == 4\n ... | [
"[[3,4,2,1],[4,2,3,1],[2,1,0,0],[2,4,0,0]]",
"[[3,4,2,1],[4,2,1,1],[2,1,1,0],[3,4,1,0]]",
"[[2,1,0],[1,0,0]]"
] | [
"For each cell (i,j), it is critical to find out the minimum number of steps to reach (i,j), denoted dis[i][j], quickly, given the tight constraint.",
"Calculate dis[i][j] going left to right, top to bottom.",
"Suppose we want to calculate dis[i][j], keep track of a priority queue that stores (dis[i][k], i, k) ... | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().minimumVisitedCells",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:19",
"tests_total": 103,
"t... | typescript | {
"raw_signature": "function minimumVisitedCells(grid: number[][]): number {",
"container": null,
"callable": "minimumVisitedCells",
"parameters": [
{
"name": "grid",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetc... |
2,639 | find-the-width-of-columns-of-a-grid | Easy | You are given a 0-indexed m x n integer matrix grid. The width of a column is the maximum length of its integers.
- For example, if grid = [[-10], [3], [12]], the width of the only column is 3 since -10 is of length 3.
Return an integer array ans of size n where ans[i] is the width of the i^th column.
The length of ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[12345], [67890]]) == [5]\n assert candidate(grid = [[1], [22], [333]]) == [3]\n assert candidate(grid = [[1000], [-1000], [100], [-100], [10], [-10], [1], [-1]]) == [5]\n assert candidate(grid = [[-15, 1, 3], [15, 7, 12... | [
"[[1],[22],[333]]",
"[[-15,1,3],[15,7,12],[5,6,-2]]"
] | [
"You can find the length of a number by dividing it by 10 and then rounding it down again and again until this number becomes equal to 0. Add 1 if this number is negative.",
"Traverse the matrix column-wise to find the maximum length in each column."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().findColumnWidth",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:23",
"tests_total": 96,
"tests_... | typescript | {
"raw_signature": "function findColumnWidth(grid: number[][]): number[] {",
"container": null,
"callable": "findColumnWidth",
"parameters": [
{
"name": "grid",
"type": "number[][]"
}
],
"return_type": "number[]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/... |
2,640 | find-the-score-of-all-prefixes-of-an-array | Medium | We define the conversion array conver of an array arr as follows:
- conver[i] = arr[i] + max(arr[0..i]) where max(arr[0..i]) is the maximum value of arr[j] over 0 <= j <= i.
We also define the score of an array arr as the sum of the values of the conversion array of arr.
Given a 0-indexed integer array nums of lengt... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == [10, 19, 27, 34, 40]\n assert candidate(nums = [1]) == [2]\n assert candidate(nums = [1000000000]) == [2000000000]\n assert candidate(nums = [1, 1, 2, 4, 8, 16]) == [2, 4, 8, 16, 32, 64]\n assert ca... | [
"[2,3,7,5,10]",
"[1,1,2,4,8,16]"
] | [
"Keep track of the prefix maximum of the array",
"Establish a relationship between ans[i] and ans[i-1]",
"for 0 < i < n, ans[i] = ans[i-1]+conver[i]. In other words, array ans is the prefix sum array of the conversion array"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findPrefixScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:26",
"tests_total": 94,
"tests_... | typescript | {
"raw_signature": "function findPrefixScore(nums: number[]): number[] {",
"container": null,
"callable": "findPrefixScore",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number[]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/code... |
2,643 | row-with-maximum-ones | Easy | Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row.
In case there are multiple rows that have the maximum count of ones, the row with the smallest row number should be selected.
Return an array containing the index of the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mat = [[0, 1], [1, 0]]) == [0, 1]\n assert candidate(mat = [[1, 1, 1], [0, 1, 1], [1, 0, 0]]) == [0, 3]\n assert candidate(mat = [[1, 1, 1, 0], [0, 1, 1, 1], [1, 1, 1, 1], [0, 0, 1, 1]]) == [2, 4]\n assert candidate(mat = [[0, 0... | [
"[[0,1],[1,0]]",
"[[0,0,0],[0,1,1]]",
"[[0,0],[1,1],[0,0]]"
] | [
"Iterate through each row and keep the count of ones."
] | {
"canonical_parameter_names": [
"mat"
],
"leetcode_dataset_entry_point": "Solution().rowAndMaximumOnes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:30",
"tests_total": 71,
"tests... | typescript | {
"raw_signature": "function rowAndMaximumOnes(mat: number[][]): number[] {",
"container": null,
"callable": "rowAndMaximumOnes",
"parameters": [
{
"name": "mat",
"type": "number[][]"
}
],
"return_type": "number[]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcod... |
2,644 | find-the-maximum-divisibility-score | Easy | You are given two integer arrays nums and divisors.
The divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].
Return the integer divisors[i] with the maximum divisibility score. If multiple integers have the maximum score, return the smallest one.
Example 1:
Inp... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [20, 14, 21, 10],divisors = [10, 16, 20]) == 10\n assert candidate(nums = [7, 14, 28, 35],divisors = [7, 14, 28, 35]) == 7\n assert candidate(nums = [12, 24, 36, 48],divisors = [3, 6, 12, 24]) == 3\n assert candidate(nums... | [
"[2,9,15,50]\n[5,3,7,2]",
"[4,7,9,3,9]\n[5,2,3]",
"[20,14,21,10]\n[10,16,20]"
] | [
"Consider counting for each element in divisors the count of elements in nums divisible by it using bruteforce.",
"After counting for each divisor, take the one with the maximum count. In case of a tie, take the minimum one of them."
] | {
"canonical_parameter_names": [
"nums",
"divisors"
],
"leetcode_dataset_entry_point": "Solution().maxDivScore",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:33",
"tests_total": 1... | typescript | {
"raw_signature": "function maxDivScore(nums: number[], divisors: number[]): number {",
"container": null,
"callable": "maxDivScore",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "divisors",
"type": "number[]"
}
],
"return_type": "number",
"sig... |
2,645 | minimum-additions-to-make-valid-string | Medium | Given a string word to which you can insert letters "a", "b" or "c" anywhere and any number of times, return the minimum number of letters that must be inserted so that word becomes valid.
A string is called valid if it can be formed by concatenating the string "abc" several times.
Example 1:
Input: word = "b"
Outpu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(word = \"aab\") == 3\n assert candidate(word = \"abc\") == 0\n assert candidate(word = \"bacbac\") == 6\n assert candidate(word = \"aabbcc\") == 6\n assert candidate(word = \"acbac\") == 4\n assert candidate(word = \"aabab... | [
"\"b\"",
"\"aaa\"",
"\"abc\""
] | [
"Maintain a pointer on word and another pointer on string “abc”.",
"If the two characters that are being pointed to differ, Increment the answer and the pointer to the string “abc” by one."
] | {
"canonical_parameter_names": [
"word"
],
"leetcode_dataset_entry_point": "Solution().addMinimum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:35",
"tests_total": 108,
"tests_drop... | typescript | {
"raw_signature": "function addMinimum(word: string): number {",
"container": null,
"callable": "addMinimum",
"parameters": [
{
"name": "word",
"type": "string"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,646 | minimize-the-total-price-of-the-trips | Hard | There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and 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.
Each node has an associated price. You are given an integer arr... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3,edges = [[0, 1], [1, 2]],price = [10, 10, 10],trips = [[0, 2], [0, 1], [1, 2]]) == 50\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [1, 3], [3, 4]],price = [2, 4, 6, 8, 10],trips = [[0, 4], [1, 2]]) == 25\n assert candida... | [
"4\n[[0,1],[1,2],[1,3]]\n[2,2,10,6]\n[[0,3],[2,1],[2,3]]",
"2\n[[0,1]]\n[2,2]\n[[0,0]]"
] | [
"The final answer is the price[i] * freq[i], where freq[i] is the number of times node i was visited during the trip, and price[i] is the final price.",
"To find freq[i] we will use dfs or bfs for each trip and update every node on the path start and end.",
"Finally, to find the final price[i] we will use dynam... | {
"canonical_parameter_names": [
"n",
"edges",
"price",
"trips"
],
"leetcode_dataset_entry_point": "Solution().minimumTotalPrice",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:... | typescript | {
"raw_signature": "function minimumTotalPrice(n: number, edges: number[][], price: number[], trips: number[][]): number {",
"container": null,
"callable": "minimumTotalPrice",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "edges",
"type": "number[][]"
},
... |
2,651 | calculate-delayed-arrival-time | Easy | You are given a positive integer arrivalTime denoting the arrival time of a train in hours, and another positive integer delayedTime denoting the amount of delay in hours.
Return the time when the train will arrive at the station.
Note that the time in this problem is in 24-hours format.
Example 1:
Input: arrivalTi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arrivalTime = 5,delayedTime = 19) == 0\n assert candidate(arrivalTime = 8,delayedTime = 16) == 0\n assert candidate(arrivalTime = 13,delayedTime = 11) == 0\n assert candidate(arrivalTime = 15,delayedTime = 5) == 20\n assert c... | [
"15\n5",
"13\n11"
] | [
"Use the modulo operator to handle the case when the arrival time plus the delayed time goes beyond 24 hours.",
"If the arrival time plus the delayed time is greater than or equal to 24, you can also subtract 24 to get the time in the 24-hour format."
] | {
"canonical_parameter_names": [
"arrivalTime",
"delayedTime"
],
"leetcode_dataset_entry_point": "Solution().findDelayedArrivalTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:42... | typescript | {
"raw_signature": "function findDelayedArrivalTime(arrivalTime: number, delayedTime: number): number {",
"container": null,
"callable": "findDelayedArrivalTime",
"parameters": [
{
"name": "arrivalTime",
"type": "number"
},
{
"name": "delayedTime",
"type": "number"
}
],... |
2,652 | sum-multiples | Easy | Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7.
Return an integer denoting the sum of all numbers in the given range satisfying the constraint.
Example 1:
Input: n = 7
Output: 21
Explanation: Numbers in the range [1, 7] that are divisible by 3,... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 9) == 30\n assert candidate(n = 1) == 0\n assert candidate(n = 1000) == 272066\n assert candidate(n = 7) == 21\n assert candidate(n = 10) == 40\n assert candidate(n = 210) == 12075\n assert candidate(n = 666) == 121... | [
"7",
"10",
"9"
] | [
"Iterate through the range 1 to n and count numbers divisible by either 3, 5, or 7."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().sumOfMultiples",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:44",
"tests_total": 38,
"tests_drop... | typescript | {
"raw_signature": "function sumOfMultiples(n: number): number {",
"container": null,
"callable": "sumOfMultiples",
"parameters": [
{
"name": "n",
"type": "number"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,653 | sliding-subarray-beauty | Medium | Given an integer array nums containing n integers, find the beauty of each subarray of size k.
The beauty of a subarray is the x^th smallest integer in the subarray if it is negative, or 0 if there are fewer than x negative integers.
Return an integer array containing n - k + 1 integers, which denote the beauty of th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 6, 7, 8, 9],k = 3,x = 2) == [0, 0, 0]\n assert candidate(nums = [-1, -2, -3, -4, -5],k = 2,x = 2) == [-1, -2, -3, -4]\n assert candidate(nums = [1, -1, -3, -2, 3],k = 3,x = 2) == [-1, -2, -2]\n assert candidate(nums =... | [
"[1,-1,-3,-2,3]\n3\n2",
"[-1,-2,-3,-4,-5]\n2\n2",
"[-3,1,2,-3,0,-3]\n2\n1"
] | [
"Try to maintain the frequency of negative numbers in the current window of size k.",
"The x^th smallest negative integer can be gotten by iterating through the frequencies of the numbers in order."
] | {
"canonical_parameter_names": [
"nums",
"k",
"x"
],
"leetcode_dataset_entry_point": "Solution().getSubarrayBeauty",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:46",
"tests_t... | typescript | {
"raw_signature": "function getSubarrayBeauty(nums: number[], k: number, x: number): number[] {",
"container": null,
"callable": "getSubarrayBeauty",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
},
{
"name": "x",
... |
2,654 | minimum-number-of-operations-to-make-all-array-elements-equal-to-1 | Medium | You are given a 0-indexed array nums consisting of positive integers. You can do the following operation on the array any number of times:
- Select an index i such that 0 <= i < n - 1 and replace either of nums[i] or nums[i+1] with their gcd value.
Return the minimum number of operations to make all elements of nums ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 1]) == 3\n assert candidate(nums = [100, 200, 300, 400]) == -1\n assert candidate(nums = [1, 2, 2, 3]) == 3\n assert candidate(nums = [7, 21, 35, 49, 63]) == -1\n assert candidate(nums = [2, 4, 6, 8, 10, 12])... | [
"[2,6,3,4]",
"[2,10,6,14]"
] | [
"Note that if you have at least one occurrence of 1 in the array, then you can make all the other elements equal to 1 with one operation each.",
"Try finding the shortest subarray with a gcd equal to 1."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:49",
"tests_total": 157,
"tests_d... | typescript | {
"raw_signature": "function minOperations(nums: number[]): number {",
"container": null,
"callable": "minOperations",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets... |
2,656 | maximum-sum-with-exactly-k-elements | Easy | You are given a 0-indexed integer array nums and an integer k. Your task is to perform the following operation exactly k times in order to maximize your score:
1. Select an element m from nums.
2. Remove the selected element m from the array.
3. Add a new element with a value of m + 1 to the array.
4. Increase your sc... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 18\n assert candidate(nums = [5, 5, 5],k = 2) == 11\n assert candidate(nums = [1, 1, 1, 1],k = 4) == 10\n assert candidate(nums = [10, 20, 30],k = 1) == 30\n assert candidate(nums = [100],k = ... | [
"[1,2,3,4,5]\n3",
"[5,5,5]\n2"
] | [] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().maximizeSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:53",
"tests_total": 97,
"t... | typescript | {
"raw_signature": "function maximizeSum(nums: number[], k: number): number {",
"container": null,
"callable": "maximizeSum",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_source": "l... |
2,657 | find-the-prefix-common-array-of-two-arrays | Medium | You are given two 0-indexed integer permutations A and B of length n.
A prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A and B.
Return the prefix common array of A and B.
A sequence of n integers is called a permutation i... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(A = [1, 3, 2, 4],B = [3, 1, 2, 4]) == [0, 2, 3, 4]\n assert candidate(A = [1, 2, 3],B = [3, 2, 1]) == [0, 1, 3]\n assert candidate(A = [2, 3, 1],B = [3, 1, 2]) == [0, 1, 3]\n assert candidate(A = [5, 4, 3, 2, 1],B = [1, 2, 3, 4,... | [
"[1,3,2,4]\n[3,1,2,4]",
"[2,3,1]\n[3,1,2]"
] | [
"Consider keeping a frequency array that stores the count of occurrences of each number till index i.",
"If a number occurred two times, it means it occurred in both A and B since they’re both permutations so add one to the answer."
] | {
"canonical_parameter_names": [
"A",
"B"
],
"leetcode_dataset_entry_point": "Solution().findThePrefixCommonArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:56",
"tests_total"... | typescript | {
"raw_signature": "function findThePrefixCommonArray(A: number[], B: number[]): number[] {",
"container": null,
"callable": "findThePrefixCommonArray",
"parameters": [
{
"name": "A",
"type": "number[]"
},
{
"name": "B",
"type": "number[]"
}
],
"return_type": "number[... |
2,658 | maximum-number-of-fish-in-a-grid | Medium | You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents:
- A land cell if grid[r][c] = 0, or
- A water cell containing grid[r][c] fish, if grid[r][c] > 0.
A fisher can start at any water cell (r, c) and can do the following operations any number of times:
- Catch all the fish at cell (r, c), ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 1\n assert candidate(grid = [[1, 2, 3], [0, 0, 0], [4, 5, 6]]) == 15\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 45\n assert candidate(grid = [[10, 0, 0], [0, 0, 0... | [
"[[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]]",
"[[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]]"
] | [
"Run DFS from each non-zero cell.",
"Each time you pick a cell to start from, add up the number of fish contained in the cells you visit."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().findMaxFish",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:59:58",
"tests_total": 105,
"tests_dro... | typescript | {
"raw_signature": "function findMaxFish(grid: number[][]): number {",
"container": null,
"callable": "findMaxFish",
"parameters": [
{
"name": "grid",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets... |
2,659 | make-array-empty | Hard | You are given an integer array nums containing distinct numbers, and you can perform the following operations until the array is empty:
- If the first element has the smallest value, remove it
- Otherwise, put the first element at the end of the array.
Return an integer denoting the number of operations it takes to m... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 55\n assert candidate(nums = [-3, -1, -2, -4]) == 8\n assert candidate(nums = [10, 20, -10, 0]) == 6\n assert candidate(nums = [0, 10, -10, 5, -5]) == 9\n assert candidate(... | [
"[3,4,-1]",
"[1,2,4,3]",
"[1,2,3]"
] | [
"Understand the order in which the indices are removed from the array.",
"We don’t really need to delete or move the elements, only the array length matters.",
"Upon removing an index, decide how many steps it takes to move to the next one.",
"Use a data structure to speed up the calculation."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countOperationsToEmptyArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:00",
"tests_total": 2... | typescript | {
"raw_signature": "function countOperationsToEmptyArray(nums: number[]): number {",
"container": null,
"callable": "countOperationsToEmptyArray",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_sou... |
2,660 | determine-the-winner-of-a-bowling-game | Easy | You are given two 0-indexed integer arrays player1 and player2, representing the number of pins that player 1 and player 2 hit in a bowling game, respectively.
The bowling game consists of n turns, and the number of pins in each turn is exactly 10.
Assume a player hits x_i pins in the i^th turn. The value of the i^th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(player1 = [5, 5, 5, 5, 5],player2 = [5, 5, 5, 5, 5]) == 0\n assert candidate(player1 = [2, 3],player2 = [4, 1]) == 0\n assert candidate(player1 = [5, 10, 3, 2],player2 = [6, 5, 7, 3]) == 1\n assert candidate(player1 = [5, 5, 5, ... | [
"[5,10,3,2]\n[6,5,7,3]",
"[3,5,7,6]\n[8,10,10,2]",
"[2,3]\n[4,1]",
"[1,1,1,10,10,10,10]\n[10,10,10,10,1,1,1]"
] | [
"Think about simulating the process to calculate the answer.",
"Iterate over each element and check the previous two elements. See if one of them is 10 and can affect the score."
] | {
"canonical_parameter_names": [
"player1",
"player2"
],
"leetcode_dataset_entry_point": "Solution().isWinner",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:03",
"tests_total": 93... | typescript | {
"raw_signature": "function isWinner(player1: number[], player2: number[]): number {",
"container": null,
"callable": "isWinner",
"parameters": [
{
"name": "player1",
"type": "number[]"
},
{
"name": "player2",
"type": "number[]"
}
],
"return_type": "number",
"signa... |
2,661 | first-completely-painted-row-or-column | Medium | You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n].
Go through each index i in arr starting from index 0 and paint the cell in mat containing the integer arr[i].
Return the smallest index i at which either a row or a column w... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [15, 13, 14, 12, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 1],mat = [[13, 14, 15], [10, 11, 12], [7, 8, 9], [4, 5, 6], [1, 2, 3]]) == 2\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9... | [
"[1,3,4,2]\n[[1,4],[2,3]]",
"[2,8,7,4,1,3,5,6,9]\n[[3,2,5],[1,4,6],[8,7,9]]"
] | [
"Can we use a frequency array?",
"Pre-process the positions of the values in the matrix.",
"Traverse the array and increment the corresponding row and column frequency using the pre-processed positions.",
"If the row frequency becomes equal to the number of columns, or vice-versa return the current index."
] | {
"canonical_parameter_names": [
"arr",
"mat"
],
"leetcode_dataset_entry_point": "Solution().firstCompleteIndex",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:05",
"tests_total": ... | typescript | {
"raw_signature": "function firstCompleteIndex(arr: number[], mat: number[][]): number {",
"container": null,
"callable": "firstCompleteIndex",
"parameters": [
{
"name": "arr",
"type": "number[]"
},
{
"name": "mat",
"type": "number[][]"
}
],
"return_type": "number",
... |
2,662 | minimum-cost-of-a-path-with-special-roads | Medium | You are given an array start where start = [startX, startY] represents your initial position (startX, startY) in a 2D space. You are also given the array target where target = [targetX, targetY] represents your target position (targetX, targetY).
The cost of going from a position (x1, y1) to any other position in the ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(start = [3, 2],target = [5, 7],specialRoads = [[5, 7, 3, 2, 1], [3, 2, 3, 4, 4], [3, 3, 5, 5, 5], [3, 4, 5, 6, 6]]) == 7\n assert candidate(start = [1, 1],target = [4, 5],specialRoads = [[1, 2, 3, 3, 2], [3, 4, 4, 5, 1]]) == 5\n as... | [
"[1,1]\n[4,5]\n[[1,2,3,3,2],[3,4,4,5,1]]",
"[3,2]\n[5,7]\n[[5,7,3,2,1],[3,2,3,4,4],[3,3,5,5,5],[3,4,5,6,6]]",
"[1,1]\n[10,4]\n[[4,2,1,1,3],[1,2,7,4,4],[10,3,6,1,2],[6,1,1,2,3]]"
] | [
"It can be proven that it is optimal to go only to the positions that are either the start or the end of a special road or the target position.",
"Consider all positions given to you as nodes in a graph, and the edges of the graph are the special roads.",
"Now the problem is equivalent to finding the shortest p... | {
"canonical_parameter_names": [
"start",
"target",
"specialRoads"
],
"leetcode_dataset_entry_point": "Solution().minimumCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:08",... | typescript | {
"raw_signature": "function minimumCost(start: number[], target: number[], specialRoads: number[][]): number {",
"container": null,
"callable": "minimumCost",
"parameters": [
{
"name": "start",
"type": "number[]"
},
{
"name": "target",
"type": "number[]"
},
{
"... |
2,663 | lexicographically-smallest-beautiful-string | Hard | A string is beautiful if:
- It consists of the first k letters of the English lowercase alphabet.
- It does not contain any substring of length 2 or more which is a palindrome.
You are given a beautiful string s of length n and a positive integer k.
Return the lexicographically smallest string of length n, which is ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcd\",k = 5) == \"abce\"\n assert candidate(s = \"aabbcc\",k = 6) == \"aabbcd\"\n assert candidate(s = \"zyx\",k = 26) == \"\"\n assert candidate(s = \"abcz\",k = 26) == \"abda\"\n assert candidate(s = \"aaa\",k = 4) =... | [
"\"abcz\"\n26",
"\"dc\"\n4"
] | [
"If the string does not contain any palindromic substrings of lengths 2 and 3, then the string does not contain any palindromic substrings at all.",
"Iterate from right to left and if it is possible to increase character at index i without creating any palindromic substrings of lengths 2 and 3, then increase it."... | {
"canonical_parameter_names": [
"s",
"k"
],
"leetcode_dataset_entry_point": "Solution().smallestBeautifulString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:10",
"tests_total":... | typescript | {
"raw_signature": "function smallestBeautifulString(s: string, k: number): string {",
"container": null,
"callable": "smallestBeautifulString",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "string",
"signatu... |
2,670 | find-the-distinct-difference-array | Easy | You are given a 0-indexed array nums of length n.
The distinct difference array of nums is an array diff of length n such that diff[i] is equal to the number of distinct elements in the suffix nums[i + 1, ..., n - 1] subtracted from the number of distinct elements in the prefix nums[0, ..., i].
Return the distinct di... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == [-3, -1, 1, 3, 5]\n assert candidate(nums = [10, 20, 10, 20, 10]) == [-1, 0, 0, 1, 2]\n assert candidate(nums = [1, 1, 2, 2, 3]) == [-2, -1, 0, 1, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, ... | [
"[1,2,3,4,5]",
"[3,2,3,4,2]"
] | [
"Which data structure will help you maintain distinct elements?",
"Iterate over all possible prefix sizes. Then, use a nested loop to add the elements of the prefix to a set, and another nested loop to add the elements of the suffix to another set."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().distinctDifferenceArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:15",
"tests_total": 107,
... | typescript | {
"raw_signature": "function distinctDifferenceArray(nums: number[]): number[] {",
"container": null,
"callable": "distinctDifferenceArray",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number[]",
"signature_source": "leetcode/codeSnippets",
"type_source"... |
2,672 | number-of-adjacent-elements-with-the-same-color | Medium | You are given an integer n representing an array colors of length n where all elements are set to 0's meaning uncolored. You are also given a 2D integer array queries where queries[i] = [index_i, color_i]. For the i^th query:
- Set colors[index_i] to color_i.
- Count the number of adjacent pairs in colors which have t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 3,queries = [[0, 2], [1, 2], [2, 2]]) == [0, 1, 2]\n assert candidate(n = 1,queries = [[0, 100000]]) == [0]\n assert candidate(n = 10,queries = [[5, 3], [6, 3], [5, 3], [4, 3], [3, 3], [2, 3], [1, 3], [0, 3], [8, 3], [9, 3]]) =... | [
"4\n[[0,2],[1,2],[3,1],[1,1],[2,1]]",
"1\n[[0,100000]]"
] | [
"Since at each query, only one element is being recolored, we just need to focus on its neighbors.",
"If an element that is changed on the i-th query had the same color as its right element answer decreases by 1. Similarly contributes its left element too.",
"After changing the color, if the element has the sam... | {
"canonical_parameter_names": [
"n",
"queries"
],
"leetcode_dataset_entry_point": "Solution().colorTheArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:18",
"tests_total": 74,... | typescript | {
"raw_signature": "function colorTheArray(n: number, queries: number[][]): number[] {",
"container": null,
"callable": "colorTheArray",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "queries",
"type": "number[][]"
}
],
"return_type": "number[]",
"sig... |
2,673 | make-costs-of-paths-equal-in-a-binary-tree | Medium | You are given an integer n representing the number of nodes in a perfect binary tree consisting of nodes numbered from 1 to n. The root of the tree is node 1 and each node i in the tree has two children where the left child is the node 2 * i and the right child is 2 * i + 1.
Each node in the tree also has a cost repre... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 31,cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(n = 7,cost = [1, 5, 2, 2, 3, 3, 1]) == 6\n assert candidate(n = 31,cost = [1, 2, 3, 4, 5, 6, 7, 8,... | [
"7\n[1,5,2,2,3,3,1]",
"3\n[5,3,3]"
] | [
"The path from the root to a leaf that has the maximum cost should not be modified.",
"The optimal way is to increase all other paths to make their costs equal to the path with maximum cost."
] | {
"canonical_parameter_names": [
"n",
"cost"
],
"leetcode_dataset_entry_point": "Solution().minIncrements",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:21",
"tests_total": 50,
... | typescript | {
"raw_signature": "function minIncrements(n: number, cost: number[]): number {",
"container": null,
"callable": "minIncrements",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "cost",
"type": "number[]"
}
],
"return_type": "number",
"signature_source"... |
2,678 | number-of-senior-citizens | Easy | You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that:
- The first ten characters consist of the phone number of passengers.
- The next character denotes the gender of the person.
- The fol... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(details = ['0000000000M5500', '1111111111F5999', '2222222222O6100']) == 1\n assert candidate(details = ['1234567890M5999', '0987654321F6000']) == 0\n assert candidate(details = ['1111111111M5999', '2222222222F6000', '3333333333M600... | [
"[\"7868190130M7522\",\"5303914400F9211\",\"9273338290F4010\"]",
"[\"1313579440F2036\",\"2921522980M5644\"]"
] | [
"Convert the value at index 11 and 12 to a numerical value.",
"The age of the person at index i is equal to details[i][11]*10+details[i][12]."
] | {
"canonical_parameter_names": [
"details"
],
"leetcode_dataset_entry_point": "Solution().countSeniors",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:23",
"tests_total": 78,
"tests_... | typescript | {
"raw_signature": "function countSeniors(details: string[]): number {",
"container": null,
"callable": "countSeniors",
"parameters": [
{
"name": "details",
"type": "string[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnip... |
2,679 | sum-in-a-matrix | Medium | You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty:
1. From each row in the matrix, select the largest number and remove it. In the case of a tie, it does not matter which number is chosen.
2. Identify the highest number amongst ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [[1]]) == 1\n assert candidate(nums = [[5, 4, 3], [1, 2, 3], [3, 2, 1]]) == 12\n assert candidate(nums = [[5, 3, 1], [4, 2, 1], [3, 2, 1]]) == 9\n assert candidate(nums = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0\n asser... | [
"[[7,2,1],[6,4,2],[6,5,3],[3,2,1]]",
"[[1]]"
] | [
"Sort the numbers in each row in decreasing order.",
"The answer is the summation of the max number in every column after sorting the rows."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().matrixSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:25",
"tests_total": 103,
"tests_dropp... | typescript | {
"raw_signature": "function matrixSum(nums: number[][]): number {",
"container": null,
"callable": "matrixSum",
"parameters": [
{
"name": "nums",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,680 | maximum-or | Medium | You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2.
Return the maximum possible value of nums[0] | nums[1] | ... | nums[n - 1] that can be obtained after applying the operation on nums at most k times.
Note that a | b denotes the ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 31\n assert candidate(nums = [1, 2, 4, 8, 16],k = 3) == 143\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 8) == 256554748416\n assert candidate(nums = [3, 5, ... | [
"[12,9]\n1",
"[8,1,2]\n2"
] | [
"The optimal solution should apply all the k operations on a single number.",
"Calculate the prefix or and the suffix or and perform k operations over each element, and maximize the answer."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().maximumOr",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:28",
"tests_total": 114,
"te... | typescript | {
"raw_signature": "function maximumOr(nums: number[], k: number): number {",
"container": null,
"callable": "maximumOr",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number",
"signature_source": "leetc... |
2,681 | power-of-heroes | Hard | You are given a 0-indexed integer array nums representing the strength of some heroes. The power of a group of heroes is defined as follows:
- Let i_0, i_1, ... ,i_k be the indices of the heroes in a group. Then, the power of this group is max(nums[i_0], nums[i_1], ... ,nums[i_k])^2 * min(nums[i_0], nums[i_1], ... ,nu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [3, 5, 7, 2]) == 1627\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1000000000]) == 999999664\n assert candidate(nums = [3, 2, 5, 6]) == 1253\n assert candidate(nums = [3, 5, 2, 8]) == 2081\n assert... | [
"[2,1,4]",
"[1,1,1]"
] | [
"Try something with sorting the array.",
"For a pair of array elements nums[i] and nums[j] (i < j), the power would be nums[i]*nums[j]^2 regardless of how many elements in between are included.",
"The number of subsets with the above as power will correspond to 2^(j-i-1).",
"Try collecting the terms for nums[... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().sumOfPower",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:30",
"tests_total": 93,
"tests_dropp... | typescript | {
"raw_signature": "function sumOfPower(nums: number[]): number {",
"container": null,
"callable": "sumOfPower",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,682 | find-the-losers-of-the-circular-game | Easy | There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the i^th friend brings you to the (i+1)^th friend for 1 <= i < n, and moving clockwise from the n^th friend brings you to the 1^st friend.
The rules of ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 10,k = 5) == [2, 3, 4, 5, 7, 8, 9, 10]\n assert candidate(n = 4,k = 4) == [2, 3, 4]\n assert candidate(n = 5,k = 2) == [4, 5]\n assert candidate(n = 7,k = 3) == [2, 6, 7]\n assert candidate(n = 6,k = 1) == [3, 5, 6]\n ... | [
"5\n2",
"4\n4"
] | [
"Simulate the whole game until a player receives the ball for the second time."
] | {
"canonical_parameter_names": [
"n",
"k"
],
"leetcode_dataset_entry_point": "Solution().circularGameLosers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:32",
"tests_total": 73,
... | typescript | {
"raw_signature": "function circularGameLosers(n: number, k: number): number[] {",
"container": null,
"callable": "circularGameLosers",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "k",
"type": "number"
}
],
"return_type": "number[]",
"signature_sou... |
2,683 | neighboring-bitwise-xor | Medium | A 0-indexed array derived with length n is derived by computing the bitwise XOR (⊕) of adjacent values in a binary array original of length n.
Specifically, for each index i in the range [0, n - 1]:
- If i = n - 1, then derived[i] = original[i] ⊕ original[0].
- Otherwise, derived[i] = original[i] ⊕ original[i + 1].
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(derived = [0, 0, 0]) == True\n assert candidate(derived = [0, 0, 1, 1]) == True\n assert candidate(derived = [0, 1, 1, 0, 1]) == False\n assert candidate(derived = [1, 0, 1, 0]) == True\n assert candidate(derived = [0, 1, 0, ... | [
"[1,1,0]",
"[1,1]",
"[1,0]"
] | [
"Understand that from the original element, we are using each element twice to construct the derived array",
"The xor-sum of the derived array should be 0 since there is always a duplicate occurrence of each element."
] | {
"canonical_parameter_names": [
"derived"
],
"leetcode_dataset_entry_point": "Solution().doesValidArrayExist",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:35",
"tests_total": 91,
... | typescript | {
"raw_signature": "function doesValidArrayExist(derived: number[]): boolean {",
"container": null,
"callable": "doesValidArrayExist",
"parameters": [
{
"name": "derived",
"type": "number[]"
}
],
"return_type": "boolean",
"signature_source": "leetcode/codeSnippets",
"type_source": "l... |
2,684 | maximum-number-of-moves-in-a-grid | Medium | You are given a 0-indexed m x n matrix grid consisting of positive integers.
You can start at any cell in the first column of the matrix, and traverse the grid in the following way:
- From a cell (row, col), you can move to any of the cells: (row - 1, col + 1), (row, col + 1) and (row + 1, col + 1) such that the valu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 3, 5, 7], [2, 4, 6, 8], [1, 3, 5, 7]]) == 3\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == 2\n assert candidate(grid = [[10, 15, 20], [5, 9, 12], [7, 8, 10]]) == 2\n assert candidate(grid = [[5, 3, 2... | [
"[[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]]",
"[[3,2,4],[2,1,9],[1,1,7]]"
] | [
"Consider using dynamic programming to find the maximum number of moves that can be made from each cell.",
"The final answer will be the maximum value in cells of the first column."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().maxMoves",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:38",
"tests_total": 81,
"tests_dropped... | typescript | {
"raw_signature": "function maxMoves(grid: number[][]): number {",
"container": null,
"callable": "maxMoves",
"parameters": [
{
"name": "grid",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,685 | count-the-number-of-complete-components | Medium | You are given an integer n. There is an undirected graph with n vertices, 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 vertices a_i and b_i.
Return the number of complete connected components of the graph.
A connec... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 2,edges = [[0, 1]]) == 1\n assert candidate(n = 1,edges = []) == 1\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [0, 2], [2, 4], [1, 3]]) == 0\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1,... | [
"6\n[[0,1],[0,2],[1,2],[3,4]]",
"6\n[[0,1],[0,2],[1,2],[3,4],[3,5]]"
] | [
"Find the connected components of an undirected graph using depth-first search (DFS) or breadth-first search (BFS).",
"For each connected component, count the number of nodes and edges in the component.",
"A connected component is complete if and only if the number of edges in the component is equal to m*(m-1)/... | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().countCompleteComponents",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:40",
"tests_tot... | typescript | {
"raw_signature": "function countCompleteComponents(n: number, edges: number[][]): number {",
"container": null,
"callable": "countCompleteComponents",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "edges",
"type": "number[][]"
}
],
"return_type": "num... |
2,696 | minimum-string-length-after-removing-substrings | Easy | You are given a string s consisting only of uppercase English letters.
You can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings "AB" or "CD" from s.
Return the minimum possible length of the resulting string that you can obtain.
Note that the string... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"ABCDBA\") == 2\n assert candidate(s = \"CDCDCD\") == 0\n assert candidate(s = \"ABABAB\") == 0\n assert candidate(s = \"ACBBD\") == 5\n assert candidate(s = \"ABFCACDB\") == 2\n assert candidate(s = \"AAAA\") == 4\n ... | [
"\"ABFCACDB\"",
"\"ACBBD\""
] | [
"Can we use brute force to solve the problem?",
"Repeatedly traverse the string to find and remove the substrings “AB” and “CD” until no more occurrences exist.",
"Can the solution be optimized using a stack?"
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().minLength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:42",
"tests_total": 153,
"tests_dropped"... | typescript | {
"raw_signature": "function minLength(s: string): number {",
"container": null,
"callable": "minLength",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,697 | lexicographically-smallest-palindrome | Easy | You are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a character in s with another lowercase English letter.
Your task is to make s a palindrome with the minimum number of operations possible. If there are multiple palindro... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcba\") == \"abcba\"\n assert candidate(s = \"madam\") == \"madam\"\n assert candidate(s = \"abac\") == \"aaaa\"\n assert candidate(s = \"aabbaa\") == \"aabbaa\"\n assert candidate(s = \"abcdcba\") == \"abcdcba\"\n ... | [
"\"egcfe\"",
"\"abcd\"",
"\"seven\""
] | [
"We can make any string a palindrome, by simply making any character at index i equal to the character at index length - i - 1 (using 0-based indexing).",
"To make it lexicographically smallest we can change the character with maximum ASCII value to the one with minimum ASCII value."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().makeSmallestPalindrome",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:44",
"tests_total": 216,
"t... | typescript | {
"raw_signature": "function makeSmallestPalindrome(s: string): string {",
"container": null,
"callable": "makeSmallestPalindrome",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/code... |
2,698 | find-the-punishment-number-of-an-integer | Medium | Given a positive integer n, return the punishment number of n.
The punishment number of n is defined as the sum of the squares of all integers i such that:
- 1 <= i <= n
- The decimal representation of i * i can be partitioned into contiguous substrings such that the sum of the integer values of these substrings equa... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 700) == 1660140\n assert candidate(n = 800) == 3353149\n assert candidate(n = 100) == 41334\n assert candidate(n = 600) == 772866\n assert candidate(n = 37) == 1478\n assert candidate(n = 200) == 41334\n assert cand... | [
"10",
"37"
] | [
"Can we generate all possible partitions of a number?",
"Use a recursive algorithm that splits the number into two parts, generates all possible partitions of each part recursively, and then combines them in all possible ways."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().punishmentNumber",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:47",
"tests_total": 21,
"tests_dr... | typescript | {
"raw_signature": "function punishmentNumber(n: number): number {",
"container": null,
"callable": "punishmentNumber",
"parameters": [
{
"name": "n",
"type": "number"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,699 | modify-graph-edge-weights | Hard | You are given an undirected weighted connected graph containing n nodes labeled from 0 to n - 1, and an integer array edges where edges[i] = [a_i, b_i, w_i] indicates that there is an edge between nodes a_i and b_i with weight w_i.
Some edges have a weight of -1 (w_i = -1), while others have a positive weight (w_i > 0... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ... | [
"5\n[[4,1,-1],[2,0,-1],[0,3,-1],[4,3,-1]]\n0\n1\n5",
"3\n[[0,1,-1],[0,2,5]]\n0\n2\n6",
"4\n[[1,0,4],[1,2,3],[2,3,5],[0,3,-1]]\n0\n2\n6"
] | [
"Firstly, check that it’s actually possible to make the shortest path from source to destination equal to the target.",
"If the shortest path from source to destination without the edges to be modified, is less than the target, then it is not possible.",
"If the shortest path from source to destination includin... | {
"canonical_parameter_names": [
"n",
"edges",
"source",
"destination",
"target"
],
"leetcode_dataset_entry_point": "Solution().modifiedGraphEdges",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetche... | typescript | {
"raw_signature": "function modifiedGraphEdges(n: number, edges: number[][], source: number, destination: number, target: number): number[][] {",
"container": null,
"callable": "modifiedGraphEdges",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "edges",
"type"... |
2,706 | buy-two-chocolates | Easy | You are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which represents your initial amount of money.
You must buy exactly two chocolates in such a way that you still have some non-negative leftover money. You would like to minimize th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(prices = [99, 1],money = 100) == 0\n assert candidate(prices = [5, 4, 3, 2, 1],money = 10) == 7\n assert candidate(prices = [1, 1, 1, 1],money = 2) == 0\n assert candidate(prices = [1, 1],money = 3) == 1\n assert candidate(pr... | [
"[1,2,2]\n3",
"[3,2,3]\n3"
] | [
"Sort the array and check if the money is more than or equal to the sum of the two cheapest elements."
] | {
"canonical_parameter_names": [
"prices",
"money"
],
"leetcode_dataset_entry_point": "Solution().buyChoco",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:54",
"tests_total": 111,
... | typescript | {
"raw_signature": "function buyChoco(prices: number[], money: number): number {",
"container": null,
"callable": "buyChoco",
"parameters": [
{
"name": "prices",
"type": "number[]"
},
{
"name": "money",
"type": "number"
}
],
"return_type": "number",
"signature_sourc... |
2,707 | extra-characters-in-a-string | Medium | You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra characters in s which are not present in any of the substrings.
Return the minimum number of extra characte... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abc\",dictionary = ['a', 'b', 'c']) == 0\n assert candidate(s = \"sayhelloworld\",dictionary = ['hello', 'world']) == 3\n assert candidate(s = \"abc\",dictionary = ['d', 'e']) == 3\n assert candidate(s = \"abcabcabc\",dict... | [
"\"leetscode\"\n[\"leet\",\"code\",\"leetcode\"]",
"\"sayhelloworld\"\n[\"hello\",\"world\"]"
] | [
"Can we use Dynamic Programming here?",
"Define DP[i] as the min extra character if breaking up s[0:i] optimally."
] | {
"canonical_parameter_names": [
"s",
"dictionary"
],
"leetcode_dataset_entry_point": "Solution().minExtraChar",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:56",
"tests_total": 9... | typescript | {
"raw_signature": "function minExtraChar(s: string, dictionary: string[]): number {",
"container": null,
"callable": "minExtraChar",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "dictionary",
"type": "string[]"
}
],
"return_type": "number",
"signatu... |
2,708 | maximum-strength-of-a-group | Medium | You are given a 0-indexed integer array nums representing the score of students in an exam. The teacher would like to form one non-empty group of students with maximal strength, where the strength of a group of students of indices i_0, i_1, i_2, ... , i_k is defined as nums[i_0] * nums[i_1] * nums[i_2] * ... * nums[i_k... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == 36\n assert candidate(nums = [-9]) == -9\n assert candidate(nums = [0, 0, 0, 1, -1]) == 1\n assert candidate(nums = [-4, -5, -4]) == 20\n assert candidate(nums = [0, 2, 3, 4]) == 24\n asser... | [
"[3,-1,-5,2,5,-9]",
"[-4,-5,-4]"
] | [
"Try to generate all pairs of subsets and check which group provides maximal strength.",
"It can also be solved in O(NlogN) by sorting the array and using all positive integers.",
"Use negative integers only in pairs such that their product becomes positive."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxStrength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:00:59",
"tests_total": 123,
"tests_dro... | typescript | {
"raw_signature": "function maxStrength(nums: number[]): number {",
"container": null,
"callable": "maxStrength",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,709 | greatest-common-divisor-traversal | Hard | You are given a 0-indexed integer array nums, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != j, if and only if gcd(nums[i], nums[j]) > 1, where gcd is the greatest common divisor.
Your task is to determine if for every pair of indices i and j in nums, where i < ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 3, 6]) == True\n assert candidate(nums = [100, 200, 300, 400]) == True\n assert candidate(nums = [1, 1, 1]) == False\n assert candidate(nums = [1, 1, 1, 1]) == False\n assert candidate(nums = [7, 14, 21, 35]) == Tr... | [
"[2,3,6]",
"[3,9,5]",
"[4,3,12,8]"
] | [
"Create a (prime) factor-numbers list for all the indices.",
"Add an edge between the neighbors of the (prime) factor-numbers list. The order of the numbers doesn’t matter. We only need edges between 2 neighbors instead of edges for all pairs.",
"The problem is now similar to checking if all the numbers (nodes ... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().canTraverseAllPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:01",
"tests_total": 134,
"t... | typescript | {
"raw_signature": "function canTraverseAllPairs(nums: number[]): boolean {",
"container": null,
"callable": "canTraverseAllPairs",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "boolean",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcod... |
2,710 | remove-trailing-zeros-from-a-string | Easy | Given a positive integer num represented as a string, return the integer num without trailing zeros as a string.
Example 1:
Input: num = "51230100"
Output: "512301"
Explanation: Integer "51230100" has 2 trailing zeros, we remove them and return integer "512301".
Example 2:
Input: num = "123"
Output: "123"
Explanati... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = \"10\") == \"1\"\n assert candidate(num = \"100100\") == \"1001\"\n assert candidate(num = \"1111111111\") == \"1111111111\"\n assert candidate(num = \"1000\") == \"1\"\n assert candidate(num = \"1\") == \"1\"\n asse... | [
"\"51230100\"",
"\"123\""
] | [
"Find the last non-zero digit in num."
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().removeTrailingZeros",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:03",
"tests_total": 24,
"tes... | typescript | {
"raw_signature": "function removeTrailingZeros(num: string): string {",
"container": null,
"callable": "removeTrailingZeros",
"parameters": [
{
"name": "num",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSn... |
2,711 | difference-of-number-of-distinct-values-on-diagonals | Medium | Given a 2D grid of size m x n, you should find the matrix answer of size m x n.
The cell answer[r][c] is calculated by looking at the diagonal values of the cell grid[r][c]:
- Let leftAbove[r][c] be the number of distinct values on the diagonal to the left and above the cell grid[r][c] not including the cell grid[r][... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == [[1, 1, 0], [1, 0, 1], [0, 1, 1]]\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert... | [
"[[1,2,3],[3,1,5],[3,2,1]]",
"[[1]]"
] | [
"Use the set to count the number of distinct elements on diagonals."
] | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().differenceOfDistinctValues",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:06",
"tests_total": 91... | typescript | {
"raw_signature": "function differenceOfDistinctValues(grid: number[][]): number[][] {",
"container": null,
"callable": "differenceOfDistinctValues",
"parameters": [
{
"name": "grid",
"type": "number[][]"
}
],
"return_type": "number[][]",
"signature_source": "leetcode/codeSnippets",
... |
2,712 | minimum-cost-to-make-all-characters-equal | Medium | You are given a 0-indexed binary string s of length n on which you can apply two types of operations:
- Choose an index i and invert all characters from index 0 to index i (both inclusive), with a cost of i + 1
- Choose an index i and invert all characters from index i to index n - 1 (both inclusive), with a cost of n... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"100100100\") == 13\n assert candidate(s = \"00000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"110011\") == 4\n assert candidate(s = \"11110000\") == 4\n assert candidate(s = \"100010001... | [
"\"0011\"",
"\"010101\""
] | [
"For every index i, calculate the number of operations required to make the prefix [0, i - 1] equal to the character at index i, denoted prefix[i].",
"For every index i, calculate the number of operations required to make the suffix [i + 1, n - 1] equal to the character at index i, denoted suffix[i].",
"The fin... | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().minimumCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:08",
"tests_total": 162,
"tests_droppe... | typescript | {
"raw_signature": "function minimumCost(s: string): number {",
"container": null,
"callable": "minimumCost",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,713 | maximum-strictly-increasing-cells-in-a-matrix | Hard | Given a 1-indexed m x n integer matrix mat, you can select any cell in the matrix as your starting cell.
From the starting cell, you can move to any other cell in the same row or column, but only if the value of the destination cell is strictly greater than the value of the current cell. You can repeat this process as... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mat = [[10, 20, 30], [15, 25, 35], [20, 30, 40]]) == 5\n assert candidate(mat = [[1]]) == 1\n assert candidate(mat = [[-100000, 100000], [-100000, 100000]]) == 2\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]... | [
"[[3,1],[3,4]]",
"[[1,1],[1,1]]",
"[[3,1,6],[-9,5,7]]"
] | [
"We can try to build the answer in a bottom-up fashion, starting from the smallest values and increasing to the larger values.",
"Going through the values in sorted order, we can store the maximum path we have seen so far for a row/column.",
"When we are at a cell, we check its row and column to find out the be... | {
"canonical_parameter_names": [
"mat"
],
"leetcode_dataset_entry_point": "Solution().maxIncreasingCells",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:11",
"tests_total": 106,
"tes... | typescript | {
"raw_signature": "function maxIncreasingCells(mat: number[][]): number {",
"container": null,
"callable": "maxIncreasingCells",
"parameters": [
{
"name": "mat",
"type": "number[][]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/... |
2,716 | minimize-string-length | Easy | Given a string s, you have two types of operation:
1. Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the left of i (if exists).
2. Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the right... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aaabc\") == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"abacabadabacaba\") == 4\n assert candidate(s = \"abcabcabc\") == 3\n assert candi... | [
"\"aaabc\"",
"\"cbbd\"",
"\"baadccab\""
] | [
"The minimized string will not contain duplicate characters.",
"The minimized string will contain all distinct characters of the original string."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().minimizedStringLength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:15",
"tests_total": 112,
"te... | typescript | {
"raw_signature": "function minimizedStringLength(s: string): number {",
"container": null,
"callable": "minimizedStringLength",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSn... |
2,717 | semi-ordered-permutation | Easy | You are given a 0-indexed permutation of n integers nums.
A permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want until you make nums a semi-ordered permutation:
- Pick two adjacent elements in nums, then swap them.
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 7\n assert candidate(nums = [2, 4, 1, 3]) == 3\n assert candidate(nums = [3, 5, 4, 1, 2]) == 5\n assert candidate(nums = [3, 1, 2, 5, 4]) == 2\n assert candidate(nums = [1, 5, 4, 3, 2]) == 3\n as... | [
"[2,1,4,3]",
"[2,4,1,3]",
"[1,3,4,2,5]"
] | [
"Find the index of elements 1 and n.",
"Let x be the position of 1 and y be the position of n. the answer is x + (n-y-1) if x < y and x + (n-y-1) - 1 if x > y."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().semiOrderedPermutation",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:17",
"tests_total": 99,
... | typescript | {
"raw_signature": "function semiOrderedPermutation(nums: number[]): number {",
"container": null,
"callable": "semiOrderedPermutation",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "lee... |
2,718 | sum-of-matrix-after-queries | Medium | You are given an integer n and a 0-indexed 2D array queries where queries[i] = [type_i, index_i, val_i].
Initially, there is a 0-indexed n x n matrix filled with 0's. For each query, you must apply one of the following changes:
- if type_i == 0, set the values in the row with index_i to val_i, overwriting any previou... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 2,queries = [[0, 0, 1], [1, 0, 2], [0, 1, 3], [1, 1, 4]]) == 13\n assert candidate(n = 5,queries = [[0, 1, 10], [1, 2, 5], [0, 4, 7], [1, 0, 3]]) == 93\n assert candidate(n = 4,queries = [[1, 3, 2], [0, 1, 5], [1, 0, 3], [0, 2,... | [
"3\n[[0,0,1],[1,2,2],[0,2,3],[1,0,4]]",
"3\n[[0,0,4],[0,1,2],[1,0,1],[0,2,3],[1,2,1]]"
] | [
"Process queries in reversed order, as the latest queries represent the most recent changes in the matrix.",
"Once you encounter an operation on some row/column, no further operations will affect the values in this row/column. Keep track of seen rows and columns with a set.",
"When operating on an unseen row/co... | {
"canonical_parameter_names": [
"n",
"queries"
],
"leetcode_dataset_entry_point": "Solution().matrixSumQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:20",
"tests_total": ... | typescript | {
"raw_signature": "function matrixSumQueries(n: number, queries: number[][]): number {",
"container": null,
"callable": "matrixSumQueries",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "queries",
"type": "number[][]"
}
],
"return_type": "number",
"s... |
2,719 | count-of-integers | Hard | You are given two numeric strings num1 and num2 and two integers max_sum and min_sum. We denote an integer x to be good if:
- num1 <= x <= num2
- min_sum <= digit_sum(x) <= max_sum.
Return the number of good integers. Since the answer may be large, return it modulo 10^9 + 7.
Note that digit_sum(x) denotes the sum of... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num1 = \"1\",num2 = \"5\",min_sum = 1,max_sum = 5) == 5\n assert candidate(num1 = \"1\",num2 = \"1000000000000000000000000000000\",min_sum = 300,max_sum = 400) == 0\n assert candidate(num1 = \"999999999999999999999999999999\",num2 ... | [
"\"1\"\n\"12\"\n1\n8",
"\"1\"\n\"5\"\n1\n5"
] | [
"Let f(n, l, r) denotes the number of integers from 1 to n with the sum of digits between l and r.",
"The answer is f(num2, min_sum, max_sum) - f(num1-1, min_sum, max_sum).",
"You can calculate f(n, l, r) using digit dp."
] | {
"canonical_parameter_names": [
"num1",
"num2",
"min_sum",
"max_sum"
],
"leetcode_dataset_entry_point": "Solution().count",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:22"... | typescript | {
"raw_signature": "function count(num1: string, num2: string, min_sum: number, max_sum: number): number {",
"container": null,
"callable": "count",
"parameters": [
{
"name": "num1",
"type": "string"
},
{
"name": "num2",
"type": "string"
},
{
"name": "min_sum",
... |
2,729 | check-if-the-number-is-fascinating | Easy | You are given an integer n that consists of exactly 3 digits.
We call the number n fascinating if, after the following modification, the resulting number contains all the digits from 1 to 9 exactly once and does not contain any 0's:
- Concatenate n with the numbers 2 * n and 3 * n.
Return true if n is fascinating, o... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 933) == False\n assert candidate(n = 147) == False\n assert candidate(n = 576) == False\n assert candidate(n = 789) == False\n assert candidate(n = 579) == False\n assert candidate(n = 273) == True\n assert candidat... | [
"192",
"100"
] | [
"Consider changing the number to the way it is described in the statement.",
"Check if the resulting number contains all the digits from 1 to 9 exactly once."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().isFascinating",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:25",
"tests_total": 60,
"tests_dropp... | typescript | {
"raw_signature": "function isFascinating(n: number): boolean {",
"container": null,
"callable": "isFascinating",
"parameters": [
{
"name": "n",
"type": "number"
}
],
"return_type": "boolean",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,730 | find-the-longest-semi-repetitive-substring | Medium | You are given a digit string s that consists of digits from 0 to 9.
A string is called semi-repetitive if there is at most one adjacent pair of the same digit. For example, "0010", "002020", "0123", "2002", and "54944" are semi-repetitive while the following are not: "00101022" (adjacent same digit pairs are 00 and 22... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"1111\") == 2\n assert candidate(s = \"9876543210\") == 10\n assert candidate(s = \"111222333\") == 3\n assert candidate(s = \"88888888888\") == 2\n assert candidate(s = \"87878787878787878\") == 17\n assert candidate... | [
"\"52233\"",
"\"5494\"",
"\"1111111\""
] | [
"Since n is small, we can just check every substring, and if the substring is semi-repetitive, maximize the answer with its length."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().longestSemiRepetitiveSubstring",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:27",
"tests_total": 1... | typescript | {
"raw_signature": "function longestSemiRepetitiveSubstring(s: string): number {",
"container": null,
"callable": "longestSemiRepetitiveSubstring",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source"... |
2,731 | movement-of-robots | Medium | Some robots are standing on an infinite number line with their initial coordinates given by a 0-indexed integer array nums and will start moving once given the command to move. The robots will move a unit distance each second.
You are given a string s denoting the direction in which robots will move on command. 'L' me... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [-1, 2, -3, 4],s = \"RLRL\",d = 5) == 24\n assert candidate(nums = [-5, 1, 4],s = \"RLR\",d = 4) == 22\n assert candidate(nums = [-5, -1, 0, 3, 7],s = \"RLLLR\",d = 5) == 82\n assert candidate(nums = [-10, -20, -30],s = \... | [
"[-2,0,2]\n\"RLL\"\n3",
"[1,0]\n\"RL\"\n2"
] | [
"Observe that if you ignore collisions, the resultant positions of robots after d seconds would be the same.",
"After d seconds, sort the ending positions and use prefix sum to calculate the distance sum."
] | {
"canonical_parameter_names": [
"nums",
"s",
"d"
],
"leetcode_dataset_entry_point": "Solution().sumDistance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:29",
"tests_total":... | typescript | {
"raw_signature": "function sumDistance(nums: number[], s: string, d: number): number {",
"container": null,
"callable": "sumDistance",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "s",
"type": "string"
},
{
"name": "d",
"type": "numb... |
2,732 | find-a-good-subset-of-the-matrix | Hard | You are given a 0-indexed m x n binary matrix grid.
Let us call a non-empty subset of rows good if the sum of each column of the subset is at most half of the length of the subset.
More formally, if the length of the chosen subset of rows is k, then the sum of each column should be at most floor(k / 2).
Return an in... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 1, 0]]) == [2, 3]\n assert candidate(grid = [[0, 0, 0, 0], [1, 0, 0, 1], [0, 1, 1, 0]]) == [0]\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [1, 0, 0]]) == [0]\n assert candidate(g... | [
"[[0,1,1,0],[0,0,0,1],[1,1,1,1]]",
"[[0]]",
"[[1,1,1],[1,1,1]]"
] | [
"It can be proven, that if there exists a good subset of rows then there exists a good subset of rows with the size of either 1 or 2.",
"To check if there exists a good subset of rows of size 1, we check if there exists a row containing only zeros, if it does, we return its index as a good subset.",
"To check i... | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().goodSubsetofBinaryMatrix",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:32",
"tests_total": 86,
... | typescript | {
"raw_signature": "function goodSubsetofBinaryMatrix(grid: number[][]): number[] {",
"container": null,
"callable": "goodSubsetofBinaryMatrix",
"parameters": [
{
"name": "grid",
"type": "number[][]"
}
],
"return_type": "number[]",
"signature_source": "leetcode/codeSnippets",
"type_s... |
2,733 | neither-minimum-nor-maximum | Easy | Given an integer array nums containing distinct positive integers, find and return any number from the array that is neither the minimum nor the maximum value in the array, or -1 if there is no such number.
Return the selected integer.
Example 1:
Input: nums = [3,2,1,4]
Output: 2
Explanation: In this example, the mi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1]) == -1\n assert candidate(nums = [1, 3, 2]) == 2\n assert candidate(nums = [9, 5, 6]) == 6\n assert candidate(nums = [9, 11, 10]) == 10\n assert candidate(nums = [1, 2]) == -1\n assert candidate(nums = [7, 8, 9]... | [
"[3,2,1,4]",
"[1,2]",
"[2,1,3]"
] | [
"Find any value in the array that is not the minimum or the maximum value."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findNonMinOrMax",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:34",
"tests_total": 94,
"tests_... | typescript | {
"raw_signature": "function findNonMinOrMax(nums: number[]): number {",
"container": null,
"callable": "findNonMinOrMax",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnip... |
2,734 | lexicographically-smallest-string-after-substring-operation | Medium | Given a string s consisting of lowercase English letters. Perform the following operation:
- Select any non-empty substring then replace every letter of the substring with the preceding letter of the English alphabet. For example, 'b' is converted to 'a', and 'a' is converted to 'z'.
Return the lexicographically smal... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abz\") == \"aay\"\n assert candidate(s = \"azazaz\") == \"ayazaz\"\n assert candidate(s = \"zzzz\") == \"yyyy\"\n assert candidate(s = \"azaza\") == \"ayaza\"\n assert candidate(s = \"acbbc\") == \"abaab\"\n assert c... | [
"\"cbabc\"",
"\"aa\"",
"\"acbbc\"",
"\"leetcode\""
] | [
"When a character is replaced by the one that comes before it on the alphabet, it makes the string lexicographically smaller, except for ‘a'.",
"Find the leftmost substring that doesn’t contain the character 'a' and change all characters in it."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().smallestString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:36",
"tests_total": 102,
"tests_dro... | typescript | {
"raw_signature": "function smallestString(s: string): string {",
"container": null,
"callable": "smallestString",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,735 | collecting-chocolates | Medium | You are given a 0-indexed integer array nums of size n representing the cost of collecting different chocolates. The cost of collecting the chocolate at the index i is nums[i]. Each chocolate is of a different type, and initially, the chocolate at the index i is of i^th type.
In one operation, you can do the following... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],x = 10) == 90\n assert candidate(nums = [10, 20, 30, 40],x = 10) == 70\n assert candidate(nums = [1, 1, 1, 1, 1],x = 1) == 5\n assert candidate(nums = [7, 7, 7, 7, 7, 7],x = 2) == 42\n assert candi... | [
"[20,1,15]\n5",
"[1,2,3]\n4"
] | [
"How many maximum rotations will be needed?",
"The array will be rotated for a max of N times, so try all possibilities as N = 1000."
] | {
"canonical_parameter_names": [
"nums",
"x"
],
"leetcode_dataset_entry_point": "Solution().minCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:39",
"tests_total": 100,
"test... | typescript | {
"raw_signature": "function minCost(nums: number[], x: number): number {",
"container": null,
"callable": "minCost",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "x",
"type": "number"
}
],
"return_type": "number",
"signature_source": "leetcode/... |
2,736 | maximum-sum-queries | Hard | You are given two 0-indexed integer arrays nums1 and nums2, each of length n, and a 1-indexed 2D array queries where queries[i] = [x_i, y_i].
For the i^th query, find the maximum value of nums1[j] + nums2[j] among all indices j (0 <= j < n), where nums1[j] >= x_i and nums2[j] >= y_i, or -1 if there is no j satisfying ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [4, 3, 1, 2],nums2 = [2, 4, 9, 5],queries = [[4, 1], [1, 3], [2, 5]]) == [6, 10, 7]\n assert candidate(nums1 = [2, 1],nums2 = [2, 3],queries = [[3, 3]]) == [-1]\n assert candidate(nums1 = [3, 2, 5],nums2 = [2, 3, 4],queries... | [
"[4,3,1,2]\n[2,4,9,5]\n[[4,1],[1,3],[2,5]]",
"[3,2,5]\n[2,3,4]\n[[4,4],[3,2],[1,1]]",
"[2,1]\n[2,3]\n[[3,3]]"
] | [
"Sort (x, y) tuples and queries by x-coordinate descending. Don’t forget to index queries before sorting so that you can answer them in the correct order.",
"Before answering a query (min_x, min_y), add all (x, y) pairs with x >= min_x to some data structure.",
"Use a monotone descending map to store (y, x + y)... | {
"canonical_parameter_names": [
"nums1",
"nums2",
"queries"
],
"leetcode_dataset_entry_point": "Solution().maximumSumQueries",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:41",... | typescript | {
"raw_signature": "function maximumSumQueries(nums1: number[], nums2: number[], queries: number[][]): number[] {",
"container": null,
"callable": "maximumSumQueries",
"parameters": [
{
"name": "nums1",
"type": "number[]"
},
{
"name": "nums2",
"type": "number[]"
},
{
... |
2,739 | total-distance-traveled | Easy | A truck has two fuel tanks. You are given two integers, mainTank representing the fuel present in the main tank in liters and additionalTank representing the fuel present in the additional tank in liters.
The truck has a mileage of 10 km per liter. Whenever 5 liters of fuel get used up in the main tank, if the additio... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mainTank = 100,additionalTank = 100) == 1240\n assert candidate(mainTank = 5,additionalTank = 10) == 60\n assert candidate(mainTank = 7,additionalTank = 3) == 80\n assert candidate(mainTank = 1,additionalTank = 2) == 10\n ass... | [
"5\n10",
"1\n2"
] | [
"Avoid calculations in decimal to prevent precision errors."
] | {
"canonical_parameter_names": [
"mainTank",
"additionalTank"
],
"leetcode_dataset_entry_point": "Solution().distanceTraveled",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:46",
"... | typescript | {
"raw_signature": "function distanceTraveled(mainTank: number, additionalTank: number): number {",
"container": null,
"callable": "distanceTraveled",
"parameters": [
{
"name": "mainTank",
"type": "number"
},
{
"name": "additionalTank",
"type": "number"
}
],
"return_t... |
2,740 | find-the-value-of-the-partition | Medium | You are given a positive integer array nums.
Partition nums into two arrays, nums1 and nums2, such that:
- Each element of the array nums belongs to either the array nums1 or the array nums2.
- Both arrays are non-empty.
- The value of the partition is minimized.
The value of the partition is |max(nums1) - min(nums2... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1000000000]) == 999999999\n assert candidate(nums = [5, 1, 3, 2, 4]) == 1\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [2, 2, 2, 2, 2]) == 0\n assert candidate(nums = [5, 1, 3, 19... | [
"[1,3,2,4]",
"[100,1,10]"
] | [
"Sort the array.",
"The answer is min(nums[i+1] - nums[i]) for all i in the range [0, n-2]."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findValueOfPartition",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:48",
"tests_total": 106,
"... | typescript | {
"raw_signature": "function findValueOfPartition(nums: number[]): number {",
"container": null,
"callable": "findValueOfPartition",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcod... |
2,741 | special-permutations | Medium | You are given a 0-indexed integer array nums containing n distinct positive integers. A permutation of nums is called special if:
- For all indexes 0 <= i < n - 1, either nums[i] % nums[i+1] == 0 or nums[i+1] % nums[i] == 0.
Return the total number of special permutations. As the answer could be large, return it modu... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [31, 62, 93, 124, 155]) == 0\n assert candidate(nums = [2, 3, 6]) == 2\n assert candidate(nums = [17, 34, 51, 68, 85]) == 0\n assert candidate(nums = [7, 14, 28, 56, 112]) == 120\n assert candidate(nums = [1, 2, 3, 4, ... | [
"[2,3,6]",
"[1,4,3]"
] | [
"Can we solve this problem using DP with bit masking?",
"You just need two states in DP which are last_ind in the permutation and the mask of numbers already used."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().specialPerm",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:51",
"tests_total": 99,
"tests_drop... | typescript | {
"raw_signature": "function specialPerm(nums: number[]): number {",
"container": null,
"callable": "specialPerm",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,742 | painting-the-walls | Hard | You are given two 0-indexed integer arrays, cost and time, of size n representing the costs and the time taken to paint n different walls respectively. There are two painters available:
- A paid painter that paints the i^th wall in time[i] units of time and takes cost[i] units of money.
- A free painter that paints an... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(cost = [4, 4, 4, 4],time = [4, 4, 4, 4]) == 4\n assert candidate(cost = [5, 8, 4, 3],time = [2, 3, 1, 2]) == 7\n assert candidate(cost = [10, 20, 30, 40],time = [5, 4, 3, 2]) == 10\n assert candidate(cost = [10, 20, 30, 40, 50],... | [
"[1,2,3,2]\n[1,2,3,2]",
"[2,3,4,2]\n[1,1,1,1]"
] | [
"Can we break the problem down into smaller subproblems and use DP?",
"If you pay for wall i, it contributes cost[i] and effectively covers time[i] + 1 walls: the paid wall itself plus up to time[i] walls that the free painter can paint while the paid painter works.",
"Use DP over the number of walls covered, c... | {
"canonical_parameter_names": [
"cost",
"time"
],
"leetcode_dataset_entry_point": "Solution().paintWalls",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:53",
"tests_total": 93,
... | typescript | {
"raw_signature": "function paintWalls(cost: number[], time: number[]): number {",
"container": null,
"callable": "paintWalls",
"parameters": [
{
"name": "cost",
"type": "number[]"
},
{
"name": "time",
"type": "number[]"
}
],
"return_type": "number",
"signature_sou... |
2,744 | find-maximum-number-of-string-pairs | Easy | You are given a 0-indexed array words consisting of distinct strings.
The string words[i] can be paired with the string words[j] if:
- The string words[i] is equal to the reversed string of words[j].
- 0 <= i < j < words.length.
Return the maximum number of pairs that can be formed from the array words.
Note that e... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji']) == 5\n assert candidate(words = ['mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts']) == 4\n assert candidate(words = ['uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'ab', 'ba'... | [
"[\"cd\",\"ac\",\"dc\",\"ca\",\"zz\"]",
"[\"ab\",\"ba\",\"cc\"]",
"[\"aa\",\"ab\"]"
] | [
"Notice that array words consist of distinct strings.",
"Iterate over all indices (i, j) and check if they can be paired."
] | {
"canonical_parameter_names": [
"words"
],
"leetcode_dataset_entry_point": "Solution().maximumNumberOfStringPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:01:57",
"tests_total": 6... | typescript | {
"raw_signature": "function maximumNumberOfStringPairs(words: string[]): number {",
"container": null,
"callable": "maximumNumberOfStringPairs",
"parameters": [
{
"name": "words",
"type": "string[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_sou... |
2,745 | construct-the-longest-new-string | Medium | You are given three integers x, y, and z.
You have x strings equal to "AA", y strings equal to "BB", and z strings equal to "AB". You want to choose some (possibly all or none) of these strings and concatenate them in some order to form a new string. This new string must not contain "AAA" or "BBB" as a substring.
Ret... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(x = 1,y = 10,z = 10) == 26\n assert candidate(x = 50,y = 50,z = 50) == 300\n assert candidate(x = 10,y = 1,z = 10) == 26\n assert candidate(x = 20,y = 10,z = 5) == 52\n assert candidate(x = 10,y = 10,z = 1) == 42\n assert ... | [
"2\n5\n1",
"3\n2\n2"
] | [
"It can be proved that ALL “AB”s can be used in the optimal solution. (1) If the final string starts with 'A', we can put all unused “AB”s at the very beginning. (2) If the final string starts with 'B' (meaning) it starts with “BB”, we can put all unused “AB”s after the 2nd 'B'.",
"Using “AB” doesn’t increase the... | {
"canonical_parameter_names": [
"x",
"y",
"z"
],
"leetcode_dataset_entry_point": "Solution().longestString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:02:00",
"tests_total": ... | typescript | {
"raw_signature": "function longestString(x: number, y: number, z: number): number {",
"container": null,
"callable": "longestString",
"parameters": [
{
"name": "x",
"type": "number"
},
{
"name": "y",
"type": "number"
},
{
"name": "z",
"type": "number"
... |
2,746 | decremental-string-concatenation | Medium | You are given a 0-indexed array words containing n strings.
Let's define a join operation join(x, y) between two strings x and y as concatenating them into xy. However, if the last character of x is equal to the first character of y, one of them is deleted.
For example join("ab", "ba") = "aba" and join("ab", "cde") =... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['abcd', 'de', 'efg', 'gh']) == 8\n assert candidate(words = ['abcd', 'dcba', 'abdc', 'cdab']) == 13\n assert candidate(words = ['x', 'y', 'z', 'x', 'y', 'z']) == 4\n assert candidate(words = ['ab', 'bc', 'cd', 'da']) ==... | [
"[\"aa\",\"ab\",\"bc\"]",
"[\"ab\",\"b\"]",
"[\"aaa\",\"c\",\"aba\"]"
] | [
"Use dynamic programming with memoization.",
"Notice that the first and last characters of a string are sufficient to determine the length of its concatenation with any other string.",
"Define dp[i][first][last] as the shortest concatenation length of the first i words starting with a character first and ending... | {
"canonical_parameter_names": [
"words"
],
"leetcode_dataset_entry_point": "Solution().minimizeConcatenatedLength",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:02:02",
"tests_total": 8... | typescript | {
"raw_signature": "function minimizeConcatenatedLength(words: string[]): number {",
"container": null,
"callable": "minimizeConcatenatedLength",
"parameters": [
{
"name": "words",
"type": "string[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_sou... |
2,747 | count-zero-request-servers | Medium | You are given an integer n denoting the total number of servers and a 2D 0-indexed integer array logs, where logs[i] = [server_id, time] denotes that the server with id server_id received a request at time time.
You are also given an integer x and a 0-indexed integer array queries.
Return a 0-indexed integer array ar... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 1,logs = [[1, 1]],x = 1,queries = [2]) == [0]\n assert candidate(n = 10,logs = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],x = 10,queries = [20, 50, 80, 110]) == [8, 8, 8, 9]\n a... | [
"3\n[[1,3],[2,6],[1,5]]\n5\n[10,11]",
"3\n[[2,4],[2,1],[1,2],[3,1]]\n2\n[3,4]"
] | [
"Can we use sorting and two-pointer approach here?",
"Sort the queries array and logs array based on time in increasing order.",
"For every window of size x, use sliding window and two-pointer approach to find the answer to the queries."
] | {
"canonical_parameter_names": [
"n",
"logs",
"x",
"queries"
],
"leetcode_dataset_entry_point": "Solution().countServers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:02:05",
... | typescript | {
"raw_signature": "function countServers(n: number, logs: number[][], x: number, queries: number[]): number[] {",
"container": null,
"callable": "countServers",
"parameters": [
{
"name": "n",
"type": "number"
},
{
"name": "logs",
"type": "number[][]"
},
{
"name... |
2,748 | number-of-beautiful-pairs | Easy | You are given a 0-indexed integer array nums. A pair of indices i, j where 0 <= i < j < nums.length is called beautiful if the first digit of nums[i] and the last digit of nums[j] are coprime.
Return the total number of beautiful pairs in nums.
Two integers x and y are coprime if there is no integer greater than 1 th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [34, 23, 12, 45, 56]) == 5\n assert candidate(nums = [33, 14, 25, 78]) == 5\n assert candidate(nums = [123, 456, 789, 101, 202]) == 9\n assert candidate(nums = [13, 31, 17, 71]) == 6\n assert candidate(nums = [111, 222... | [
"[2,5,1,4]",
"[11,21,12]"
] | [
"Since nums.length is small, you can find all pairs of indices and check if each pair is beautiful.",
"Use integer to string conversion to get the first and last digit of each number."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countBeautifulPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:02:07",
"tests_total": 102,
"t... | typescript | {
"raw_signature": "function countBeautifulPairs(nums: number[]): number {",
"container": null,
"callable": "countBeautifulPairs",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/... |
2,749 | minimum-operations-to-make-the-integer-zero | Medium | You are given two integers num1 and num2.
In one operation, you can choose integer i in the range [0, 60] and subtract 2^i + num2 from num1.
Return the integer denoting the minimum number of operations needed to make num1 equal to 0.
If it is impossible to make num1 equal to 0, return -1.
Example 1:
Input: num1 = ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num1 = 8,num2 = 2) == 2\n assert candidate(num1 = 8,num2 = -1) == 2\n assert candidate(num1 = 7,num2 = -3) == 3\n assert candidate(num1 = 1,num2 = 0) == 1\n assert candidate(num1 = 15,num2 = -3) == 3\n assert candidate(num... | [
"3\n-2",
"5\n7"
] | [
"If we want to make integer n equal to 0 by only subtracting powers of 2 from n, in how many operations can we achieve it?",
"We need at least - the number of bits in the binary representation of n, and at most - n.",
"Notice that, if it is possible to make num1 equal to 0, then we need at most 60 operations.",... | {
"canonical_parameter_names": [
"num1",
"num2"
],
"leetcode_dataset_entry_point": "Solution().makeTheIntegerZero",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:02:09",
"tests_total"... | typescript | {
"raw_signature": "function makeTheIntegerZero(num1: number, num2: number): number {",
"container": null,
"callable": "makeTheIntegerZero",
"parameters": [
{
"name": "num1",
"type": "number"
},
{
"name": "num2",
"type": "number"
}
],
"return_type": "number",
"signa... |
2,750 | ways-to-split-array-into-good-subarrays | Medium | You are given a binary array nums.
A subarray of an array is good if it contains exactly one element with the value 1.
Return an integer denoting the number of ways to split the array nums into good subarrays. As the number may be too large, return it modulo 10^9 + 7.
A subarray is a contiguous non-empty sequence of... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [0, 1, 0, 0, 1]) == 3\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 1]) == 8\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1]) == 9\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 1, 0, 0... | [
"[0,1,0,0,1]",
"[0,1,0]"
] | [
"If the array consists of only 0s answer is 0.",
"In the final split, exactly one separation point exists between two consecutive 1s.",
"In how many ways can separation points be put?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().numberOfGoodSubarraySplits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:02:12",
"tests_total": 87... | typescript | {
"raw_signature": "function numberOfGoodSubarraySplits(nums: number[]): number {",
"container": null,
"callable": "numberOfGoodSubarraySplits",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_sourc... |
2,751 | robot-collisions | Hard | There are n 1-indexed robots, each having a position on a line, health, and movement direction.
You are given 0-indexed integer arrays positions, healths, and a string directions (directions[i] is either 'L' for left or 'R' for right). All integers in positions are unique.
All robots start moving on the line simultan... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(positions = [2, 4, 6, 8, 10],healths = [30, 25, 20, 15, 10],directions = \"LLRRR\") == [30, 25, 20, 15, 10]\n assert candidate(positions = [2, 4, 6, 8],healths = [1, 2, 3, 4],directions = \"LLLL\") == [1, 2, 3, 4]\n assert candidat... | [
"[5,4,3,2,1]\n[2,17,9,15,10]\n\"RRRRR\"",
"[3,5,2,6]\n[10,10,15,12]\n\"RLRL\"",
"[1,2,5,6]\n[10,10,11,11]\n\"RLRL\""
] | [
"Process the robots in the order of their positions to ensure that we process the collisions correctly.",
"To optimize the solution, use a stack to keep track of the surviving robots as we iterate through the positions.",
"Instead of simulating each collision, check the current robot against the top of the stac... | {
"canonical_parameter_names": [
"positions",
"healths",
"directions"
],
"leetcode_dataset_entry_point": "Solution().survivedRobotsHealths",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-... | typescript | {
"raw_signature": "function survivedRobotsHealths(positions: number[], healths: number[], directions: string): number[] {",
"container": null,
"callable": "survivedRobotsHealths",
"parameters": [
{
"name": "positions",
"type": "number[]"
},
{
"name": "healths",
"type": "numb... |
2,760 | longest-even-odd-subarray-with-threshold | Easy | You are given a 0-indexed integer array nums and an integer threshold.
Find the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following conditions:
- nums[l] % 2 == 0
- For all indices i in the range [l, r - 1], nums[i] % 2 != nums[i + ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 10) == 9\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1],threshold = 2) == 10\n assert candidate(nums = [2, 3, 4, 5],threshold = 4) == 3\n assert candidate(nums = [6, 1... | [
"[3,2,5,4]\n5",
"[1,2]\n2",
"[2,3,4,5]\n4"
] | [
"Brute force all the possible subarrays and find the longest that satisfies the conditions."
] | {
"canonical_parameter_names": [
"nums",
"threshold"
],
"leetcode_dataset_entry_point": "Solution().longestAlternatingSubarray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:02:17",
... | typescript | {
"raw_signature": "function longestAlternatingSubarray(nums: number[], threshold: number): number {",
"container": null,
"callable": "longestAlternatingSubarray",
"parameters": [
{
"name": "nums",
"type": "number[]"
},
{
"name": "threshold",
"type": "number"
}
],
"re... |
2,761 | prime-pairs-with-target-sum | Medium | You are given an integer n. We say that two integers x and y form a prime number pair if:
- 1 <= x <= y <= n
- x + y == n
- x and y are prime numbers
Return the 2D sorted list of prime number pairs [x_i, y_i]. The list should be sorted in increasing order of x_i. If there are no prime number pairs at all, return an e... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 11) == []\n assert candidate(n = 20) == [[3, 17], [7, 13]]\n assert candidate(n = 2) == []\n assert candidate(n = 10) == [[3, 7], [5, 5]]\n assert candidate(n = 3) == []\n assert candidate(n = 29) == []\n assert can... | [
"10",
"2"
] | [
"Pre-compute all the prime numbers in the range [1, n] using a sieve, and store them in a data structure where they can be accessed in O(1) time.",
"For x in the range [2, n/2], we can use the pre-computed list of prime numbers to check if both x and n - x are primes. If they are, we add them to the result."
] | {
"canonical_parameter_names": [
"n"
],
"leetcode_dataset_entry_point": "Solution().findPrimePairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:02:19",
"tests_total": 52,
"tests_drop... | typescript | {
"raw_signature": "function findPrimePairs(n: number): number[][] {",
"container": null,
"callable": "findPrimePairs",
"parameters": [
{
"name": "n",
"type": "number"
}
],
"return_type": "number[][]",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets... |
2,762 | continuous-subarrays | Medium | You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:
- Let i, i + 1, ..., jbe the indices in the subarray. Then, for each pair of indices i <= i_1, i_2 <= j, 0 <= |nums[i_1] - nums[i_2]| <= 2.
Return the total number of continuous subarrays.
A subarray is a contiguous non-empty s... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 4, 2, 4]) == 8\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 4]) == 27\n assert candidate(nums = [9, 7, 5, 3, 1]) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 27\n assert candidate(nums = [9, 8... | [
"[5,4,2,4]",
"[1,2,3]"
] | [
"Try using the sliding window technique.",
"Use a set or map to keep track of the maximum and minimum of subarrays."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().continuousSubarrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:02:22",
"tests_total": 234,
"t... | typescript | {
"raw_signature": "function continuousSubarrays(nums: number[]): number {",
"container": null,
"callable": "continuousSubarrays",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/... |
2,763 | sum-of-imbalance-numbers-of-all-subarrays | Hard | The imbalance number of a 0-indexed integer array arr of length n is defined as the number of indices in sarr = sorted(arr) such that:
- 0 <= i < n - 1, and
- sarr[i+1] - sarr[i] > 1
Here, sorted(arr) is the function that returns the sorted version of arr.
Given a 0-indexed integer array nums, return the sum of imba... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [2, 3, 1, 4]) == 3\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 8\n assert candidate(nums = [1, 2, 2, 3, ... | [
"[2,3,1,4]",
"[1,3,3,3,5]"
] | [
"Iterate over all subarrays in a nested fashion. Namely, for each left endpoint, start from nums[left] and add elements nums[left + 1], nums[left + 2], etc.",
"To keep track of the imbalance value, maintain a set of added elements.",
"Increment the imbalance value whenever a new number is not adjacent (+/- 1) t... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().sumImbalanceNumbers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T21:02:24",
"tests_total": 181,
"t... | typescript | {
"raw_signature": "function sumImbalanceNumbers(nums: number[]): number {",
"container": null,
"callable": "sumImbalanceNumbers",
"parameters": [
{
"name": "nums",
"type": "number[]"
}
],
"return_type": "number",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.