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,070 | most-beautiful-item-for-each-query | Medium | You are given a 2D integer array items where items[i] = [price_i, beauty_i] denotes the price and beauty of an item respectively.
You are also given a 0-indexed integer array queries. For each queries[j], you want to determine the maximum beauty of an item whose price is less than or equal to queries[j]. If no such it... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(items = [[10, 1000]],queries = [5]) == [0]\n assert candidate(items = [[100, 5], [50, 4], [200, 3], [150, 2], [300, 1]],queries = [50, 100, 150, 200, 250, 300]) == [4, 5, 5, 5, 5, 5]\n assert candidate(items = [[1, 5], [2, 9], [3, ... | [
"[[1,2],[3,2],[2,4],[5,6],[3,5]]\n[1,2,3,4,5,6]",
"[[1,2],[1,2],[1,3],[1,4]]\n[1]",
"[[10,1000]]\n[5]"
] | [
"Can we process the queries in a smart order to avoid repeatedly checking the same items?",
"How can we use the answer to a query for other queries?"
] | {
"canonical_parameter_names": [
"items",
"queries"
],
"leetcode_dataset_entry_point": "Solution().maximumBeauty",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:05",
"tests_total":... | cpp | {
"raw_signature": "vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {",
"container": "Solution",
"callable": "maximumBeauty",
"parameters": [
{
"name": "items",
"type": "vector<vector<int>>&"
},
{
"name": "queries",
"type": "vector<int>&"
}
]... |
2,071 | maximum-number-of-tasks-you-can-assign | Hard | You have n tasks and m workers. Each task has a strength requirement stored in a 0-indexed integer array tasks, with the i^th task requiring tasks[i] strength to complete. The strength of each worker is stored in a 0-indexed integer array workers, with the j^th worker having workers[j] strength. Each worker can only be... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(tasks = [100, 200, 300],workers = [50, 150, 250, 350],pills = 2,strength = 100) == 3\n assert candidate(tasks = [10, 20, 30],workers = [30, 40, 50],pills = 0,strength = 10) == 3\n assert candidate(tasks = [10, 15, 30],workers = [0,... | [
"[3,2,1]\n[0,3,3]\n1\n1",
"[5,4]\n[0,0,0]\n1\n5",
"[10,15,30]\n[0,10,10,10,10]\n3\n10"
] | [
"Is it possible to assign the first k smallest tasks to the workers?",
"How can you efficiently try every k?"
] | {
"canonical_parameter_names": [
"tasks",
"workers",
"pills",
"strength"
],
"leetcode_dataset_entry_point": "Solution().maxTaskAssign",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-3... | cpp | {
"raw_signature": "int maxTaskAssign(vector<int>& tasks, vector<int>& workers, int pills, int strength) {",
"container": "Solution",
"callable": "maxTaskAssign",
"parameters": [
{
"name": "tasks",
"type": "vector<int>&"
},
{
"name": "workers",
"type": "vector<int>&"
},
... |
2,073 | time-needed-to-buy-tickets | Easy | There are n people in a line queuing to buy tickets, where the 0^th person is at the front of the line and the (n - 1)^th person is at the back of the line.
You are given a 0-indexed integer array tickets of length n where the number of tickets that the i^th person would like to buy is tickets[i].
Each person takes e... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(tickets = [5, 1, 1, 1],k = 0) == 8\n assert candidate(tickets = [4, 3, 2, 1],k = 1) == 9\n assert candidate(tickets = [100, 100, 100],k = 1) == 299\n assert candidate(tickets = [1],k = 0) == 1\n assert candidate(tickets = [10... | [
"[2,3,2]\n2",
"[5,1,1,1]\n0"
] | [
"Loop through the line of people and decrement the number of tickets for each to buy one at a time as if simulating the line moving forward. Keep track of how many tickets have been sold up until person k has no more tickets to buy.",
"Remember that those who have no more tickets to buy will leave the line."
] | {
"canonical_parameter_names": [
"tickets",
"k"
],
"leetcode_dataset_entry_point": "Solution().timeRequiredToBuy",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:10",
"tests_total":... | cpp | {
"raw_signature": "int timeRequiredToBuy(vector<int>& tickets, int k) {",
"container": "Solution",
"callable": "timeRequiredToBuy",
"parameters": [
{
"name": "tickets",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_sou... |
2,075 | decode-the-slanted-ciphertext | Medium | A string originalText is encoded using a slanted transposition cipher to a string encodedText with the help of a matrix having a fixed number of rows rows.
originalText is placed first in a top-left to bottom-right manner.
The blue cells are filled first, followed by the red cells, then the yellow cells, and so on, u... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(encodedText = \"a\",rows = 1) == \"a\"\n assert candidate(encodedText = \"abcd efg hijk\",rows = 3) == \"aeibfjcgd\"\n assert candidate(encodedText = \"a b c d\",rows = 2) == \"a c b\"\n assert candidate(encodedText = ... | [
"\"ch ie pr\"\n3",
"\"iveo eed l te olc\"\n4",
"\"coding\"\n1"
] | [
"How can you use rows and encodedText to find the number of columns of the matrix?",
"Once you have the number of rows and columns, you can create the matrix and place encodedText in it. How should you place it in the matrix?",
"How should you traverse the matrix to \"decode\" originalText?"
] | {
"canonical_parameter_names": [
"encodedText",
"rows"
],
"leetcode_dataset_entry_point": "Solution().decodeCiphertext",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:15",
"tests_t... | cpp | {
"raw_signature": "string decodeCiphertext(string encodedText, int rows) {",
"container": "Solution",
"callable": "decodeCiphertext",
"parameters": [
{
"name": "encodedText",
"type": "string"
},
{
"name": "rows",
"type": "int"
}
],
"return_type": "string",
"signatu... |
2,076 | process-restricted-friend-requests | Hard | You are given an integer n indicating the number of people in a network. Each person is labeled from 0 to n - 1.
You are also given a 0-indexed 2D integer array restrictions, where restrictions[i] = [x_i, y_i] means that person x_i and person y_i cannot become friends, either directly or indirectly through other peopl... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,restrictions = [[0, 2], [1, 3]],requests = [[0, 1], [2, 3], [0, 3]]) == [True, True, False]\n assert candidate(n = 4,restrictions = [],requests = [[0, 1], [1, 2], [2, 3], [3, 0]]) == [True, True, True, True]\n assert candidat... | [
"3\n[[0,1]]\n[[0,2],[2,1]]",
"3\n[[0,1]]\n[[1,2],[0,2]]",
"5\n[[0,1],[1,2],[2,3]]\n[[0,4],[1,2],[3,1],[3,4]]"
] | [
"For each request, we could loop through all restrictions. Can you think of doing a check-in close to O(1)?",
"Could you use Union Find?"
] | {
"canonical_parameter_names": [
"n",
"restrictions",
"requests"
],
"leetcode_dataset_entry_point": "Solution().friendRequests",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:17"... | cpp | {
"raw_signature": "vector<bool> friendRequests(int n, vector<vector<int>>& restrictions, vector<vector<int>>& requests) {",
"container": "Solution",
"callable": "friendRequests",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "restrictions",
"type": "vector<vector... |
2,078 | two-furthest-houses-with-different-colors | Easy | There are n houses evenly lined up on the street, and each house is beautifully painted. You are given a 0-indexed integer array colors of length n, where colors[i] represents the color of the i^th house.
Return the maximum distance between two houses with different colors.
The distance between the i^th and j^th hous... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(colors = [10, 20, 10, 10, 10]) == 3\n assert candidate(colors = [10, 20, 30, 40, 50]) == 4\n assert candidate(colors = [100, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 9\n assert candidate(colors = [3, 1, 3, 3, 3]) == 3\n assert candidat... | [
"[1,1,1,6,1,1,1]",
"[1,8,3,8,3]",
"[0,1]"
] | [
"The constraints are small. Can you try the combination of every two houses?",
"Greedily, the maximum distance will come from either the pair of the leftmost house and possibly some house on the right with a different color, or the pair of the rightmost house and possibly some house on the left with a different c... | {
"canonical_parameter_names": [
"colors"
],
"leetcode_dataset_entry_point": "Solution().maxDistance",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:22",
"tests_total": 90,
"tests_dr... | cpp | {
"raw_signature": "int maxDistance(vector<int>& colors) {",
"container": "Solution",
"callable": "maxDistance",
"parameters": [
{
"name": "colors",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,079 | watering-plants | Medium | You want to water n plants in your garden with a watering can. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the i^th plant is located at x = i. There is a river at x = -1 that you can refill your watering can at.
Each plant needs a specific amount of water. You will water t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(plants = [1000000],capacity = 1000000) == 1\n assert candidate(plants = [3, 2, 4, 2, 1],capacity = 6) == 17\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacity = 1) == 100\n assert candidate(plants = [5, 5, 5, 5,... | [
"[2,2,3,3]\n5",
"[1,1,1,4,2,3]\n4",
"[7,7,7,7,7,7,7]\n8"
] | [
"Simulate the process.",
"Return to refill the container once you meet a plant that needs more water than you have."
] | {
"canonical_parameter_names": [
"plants",
"capacity"
],
"leetcode_dataset_entry_point": "Solution().wateringPlants",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:24",
"tests_tota... | cpp | {
"raw_signature": "int wateringPlants(vector<int>& plants, int capacity) {",
"container": "Solution",
"callable": "wateringPlants",
"parameters": [
{
"name": "plants",
"type": "vector<int>&"
},
{
"name": "capacity",
"type": "int"
}
],
"return_type": "int",
"signatu... |
2,081 | sum-of-k-mirror-numbers | Hard | A k-mirror number is a positive integer without leading zeros that reads the same both forward and backward in base-10 as well as in base-k.
- For example, 9 is a 2-mirror number. The representation of 9 in base-10 and base-2 are 9 and 1001 respectively, which read the same both forward and backward.
- On the contrary... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(k = 2,n = 1) == 1\n assert candidate(k = 5,n = 8) == 638\n assert candidate(k = 8,n = 15) == 5818\n assert candidate(k = 9,n = 5) == 15\n assert candidate(k = 9,n = 6) == 21\n assert candidate(k = 8,n = 9) == 158\n asse... | [
"2\n5",
"3\n7",
"7\n17"
] | [
"Since we need to reduce search space, instead of checking if every number is a palindrome in base-10, can we try to \"generate\" the palindromic numbers?",
"If you are provided with a d digit number, how can you generate a palindrome with 2*d or 2*d - 1 digit?",
"Try brute-forcing and checking if the palindrom... | {
"canonical_parameter_names": [
"k",
"n"
],
"leetcode_dataset_entry_point": "Solution().kMirror",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:26",
"tests_total": 59,
"tests_dr... | cpp | {
"raw_signature": "long long kMirror(int k, int n) {",
"container": "Solution",
"callable": "kMirror",
"parameters": [
{
"name": "k",
"type": "int"
},
{
"name": "n",
"type": "int"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type... |
2,085 | count-common-words-with-one-occurrence | Easy | Given two string arrays words1 and words2, return the number of strings that appear exactly once in each of the two arrays.
Example 1:
Input: words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"]
Output: 2
Explanation:
- "leetcode" appears exactly once in each of the two arrays. We coun... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words1 = ['one'],words2 = ['two']) == 0\n assert candidate(words1 = ['unique'],words2 = ['unique']) == 1\n assert candidate(words1 = ['b', 'bb', 'bbb'],words2 = ['a', 'aa', 'aaa']) == 0\n assert candidate(words1 = ['distinct'],w... | [
"[\"leetcode\",\"is\",\"amazing\",\"as\",\"is\"]\n[\"amazing\",\"leetcode\",\"is\"]",
"[\"b\",\"bb\",\"bbb\"]\n[\"a\",\"aa\",\"aaa\"]",
"[\"a\",\"ab\"]\n[\"a\",\"a\",\"a\",\"ab\"]"
] | [
"Could you try every word?",
"Could you use a hash map to achieve a good complexity?"
] | {
"canonical_parameter_names": [
"words1",
"words2"
],
"leetcode_dataset_entry_point": "Solution().countWords",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:31",
"tests_total": 10... | cpp | {
"raw_signature": "int countWords(vector<string>& words1, vector<string>& words2) {",
"container": "Solution",
"callable": "countWords",
"parameters": [
{
"name": "words1",
"type": "vector<string>&"
},
{
"name": "words2",
"type": "vector<string>&"
}
],
"return_type":... |
2,086 | minimum-number-of-food-buckets-to-feed-the-hamsters | Medium | You are given a 0-indexed string hamsters where hamsters[i] is either:
- 'H' indicating that there is a hamster at index i, or
- '.' indicating that index i is empty.
You will add some number of food buckets at the empty indices in order to feed the hamsters. A hamster can be fed if there is at least one food bucket ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(hamsters = \"H\") == -1\n assert candidate(hamsters = \"H.H.H.H.H.H\") == 3\n assert candidate(hamsters = \"HH.H.H.H.H.H.H.H.H.H.H.H.H.H\") == -1\n assert candidate(hamsters = \"H.H.H.H.H.H.H.H.H.H\") == 5\n assert candidate(... | [
"\"H..H\"",
"\".H.H.\"",
"\".HHH.\""
] | [
"When is it impossible to feed all the hamsters?",
"When one or more hamsters do not have an empty space adjacent to it.",
"Assuming all previous hamsters are fed. If there is a hamster at index i and you are able to place a bucket at index i - 1 or i + 1, where should you put it?",
"It is always better to pl... | {
"canonical_parameter_names": [
"hamsters"
],
"leetcode_dataset_entry_point": "Solution().minimumBuckets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:33",
"tests_total": 91,
"tes... | cpp | {
"raw_signature": "int minimumBuckets(string hamsters) {",
"container": "Solution",
"callable": "minimumBuckets",
"parameters": [
{
"name": "hamsters",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,087 | minimum-cost-homecoming-of-a-robot-in-a-grid | Medium | There is an m x n grid, where (0, 0) is the top-left cell and (m - 1, n - 1) is the bottom-right cell. You are given an integer array startPos where startPos = [start_row, start_col] indicates that initially, a robot is at the cell (start_row, start_col). You are also given an integer array homePos where homePos = [hom... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(startPos = [2, 2],homePos = [0, 0],rowCosts = [1, 10, 1],colCosts = [1, 10, 1]) == 22\n assert candidate(startPos = [3, 3],homePos = [0, 0],rowCosts = [10, 20, 30, 40],colCosts = [5, 15, 25, 35]) == 105\n assert candidate(startPos ... | [
"[1,0]\n[2,3]\n[5,4,3]\n[8,2,6,7]",
"[0,0]\n[0,0]\n[5]\n[26]"
] | [
"Irrespective of what path the robot takes, it will have to traverse all the rows between startRow and homeRow and all the columns between startCol and homeCol.",
"Hence, making any other move other than traversing the required rows and columns will potentially incur more cost which can be avoided."
] | {
"canonical_parameter_names": [
"startPos",
"homePos",
"rowCosts",
"colCosts"
],
"leetcode_dataset_entry_point": "Solution().minCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-3... | cpp | {
"raw_signature": "int minCost(vector<int>& startPos, vector<int>& homePos, vector<int>& rowCosts, vector<int>& colCosts) {",
"container": "Solution",
"callable": "minCost",
"parameters": [
{
"name": "startPos",
"type": "vector<int>&"
},
{
"name": "homePos",
"type": "vector<... |
2,088 | count-fertile-pyramids-in-a-land | Hard | A farmer has a rectangular grid of land with m rows and n columns that can be divided into unit cells. Each cell is either fertile (represented by a 1) or barren (represented by a 0). All cells outside the grid are considered barren.
A pyramidal plot of land can be defined as a set of cells with the following criteria... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 0\n assert candidate(grid = [[0, 1, 1, 0], [1, 1, 1, 1]]) == 2\n assert candidate(grid = [[1, 1, 0, 1, 1], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]) == 5\n ... | [
"[[0,1,1,0],[1,1,1,1]]",
"[[1,1,1],[1,1,1]]",
"[[1,1,1,1,0],[1,1,1,1,1],[1,1,1,1,1],[0,1,0,0,1]]"
] | [
"Think about how dynamic programming can help solve the problem.",
"For any fixed cell (r, c), can you calculate the maximum height of the pyramid for which it is the apex? Let us denote this value as dp[r][c].",
"How will the values at dp[r+1][c-1] and dp[r+1][c+1] help in determining the value at dp[r][c]?",
... | {
"canonical_parameter_names": [
"grid"
],
"leetcode_dataset_entry_point": "Solution().countPyramids",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:38",
"tests_total": 74,
"tests_dr... | cpp | {
"raw_signature": "int countPyramids(vector<vector<int>>& grid) {",
"container": "Solution",
"callable": "countPyramids",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
2,089 | find-target-indices-after-sorting-array | Easy | You are given a 0-indexed integer array nums and a target element target.
A target index is an index i such that nums[i] == target.
Return a list of the target indices of nums after sorting nums in non-decreasing order. If there are no target indices, return an empty list. The returned list must be sorted in increasi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [100, 99, 98, 97, 96],target = 98) == [2]\n assert candidate(nums = [10, 20, 30, 40, 50],target = 50) == [4]\n assert candidate(nums = [7, 7, 7, 7, 7],target = 8) == []\n assert candidate(nums = [10, 20, 30, 40, 50],targe... | [
"[1,2,5,2,3]\n2",
"[1,2,5,2,3]\n3",
"[1,2,5,2,3]\n5"
] | [
"Try \"sorting\" the array first.",
"Now find all indices in the array whose values are equal to target."
] | {
"canonical_parameter_names": [
"nums",
"target"
],
"leetcode_dataset_entry_point": "Solution().targetIndices",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:40",
"tests_total": 1... | cpp | {
"raw_signature": "vector<int> targetIndices(vector<int>& nums, int target) {",
"container": "Solution",
"callable": "targetIndices",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "target",
"type": "int"
}
],
"return_type": "vector<int>",
"s... |
2,090 | k-radius-subarray-averages | Medium | You are given a 0-indexed array nums of n integers, and an integer k.
The k-radius average for a subarray of nums centered at some index i with the radius k is the average of all elements in nums between the indices i - k and i + k (inclusive). If there are less than k elements before or after the index i, then the k-... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == [-1, -1, 3, 4, 5, 6, 7, 8, -1, -1]\n assert candidate(nums = [0, 0, 0, 0, 0],k = 2) == [-1, -1, 0, -1, -1]\n assert candidate(nums = [100000],k = 0) == [100000]\n assert candidate... | [
"[7,4,3,9,1,8,5,2,6]\n3",
"[100000]\n0",
"[8]\n100000"
] | [
"To calculate the average of a subarray, you need the sum and the K. K is already given. How could you quickly calculate the sum of a subarray?",
"Use the Prefix Sums method to calculate the subarray sums.",
"It is possible that the sum of all the elements does not fit in a 32-bit integer type. Be sure to use a... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().getAverages",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:42",
"tests_total": 94,
"t... | cpp | {
"raw_signature": "vector<int> getAverages(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "getAverages",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "vector<int>",
"signature_sourc... |
2,091 | removing-minimum-and-maximum-from-array | Medium | You are given a 0-indexed array of distinct integers nums.
There is an element in nums that has the lowest value and an element that has the highest value. We call them the minimum and maximum respectively. Your goal is to remove both these elements from the array.
A deletion is defined as either removing an element ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [2, 10, 7, 5, 4, 1, 8, 6]) == 5\n assert candidate(nums = [100000, -100000, 50000, -50000]) == 2\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [100000, -100000, 50000, -5... | [
"[2,10,7,5,4,1,8,6]",
"[0,-4,19,1,8,-2,-3,5]",
"[101]"
] | [
"There can only be three scenarios for deletions such that both minimum and maximum elements are removed:",
"Scenario 1: Both elements are removed by only deleting from the front.",
"Scenario 2: Both elements are removed by only deleting from the back.",
"Scenario 3: Delete from the front to remove one of the... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minimumDeletions",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:45",
"tests_total": 102,
"test... | cpp | {
"raw_signature": "int minimumDeletions(vector<int>& nums) {",
"container": "Solution",
"callable": "minimumDeletions",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
2,092 | find-all-people-with-secret | Hard | You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [x_i, y_i, time_i] indicates that person x_i and person y_i have a meeting at time_i. A person may attend multiple meetings at the same time. Finally, you are g... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ... | [
"6\n[[1,2,5],[2,3,8],[1,5,10]]\n1",
"4\n[[3,1,3],[1,2,2],[0,3,3]]\n3",
"5\n[[3,4,2],[1,2,1],[2,3,1]]\n1"
] | [
"Could you model all the meetings happening at the same time as a graph?",
"What data structure can you use to efficiently share the secret?",
"You can use the union-find data structure to quickly determine who knows the secret and share the secret."
] | {
"canonical_parameter_names": [
"n",
"meetings",
"firstPerson"
],
"leetcode_dataset_entry_point": "Solution().findAllPeople",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:48",
... | cpp | {
"raw_signature": "vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {",
"container": "Solution",
"callable": "findAllPeople",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "meetings",
"type": "vector<vector<int>>&"
},
{
... |
2,094 | finding-3-digit-even-numbers | Easy | You are given an integer array digits, where each element is a digit. The array may contain duplicates.
You need to find all the unique integers that follow the given requirements:
- The integer consists of the concatenation of three elements from digits in any arbitrary order.
- The integer does not have leading zer... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(digits = [1, 1, 1, 1, 1, 1]) == []\n assert candidate(digits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == []\n assert candidate(digits = [2, 4, 6, 8, 0]) == [204, 206, 208, 240, 246, 248, 260, 264, 268, 280, 284, 286, 402, 406, 408, 420, 4... | [
"[2,1,3,0]",
"[2,2,8,8,2]",
"[3,7,5]"
] | [
"The range of possible answers includes all even numbers between 100 and 999 inclusive. Could you check each possible answer to see if it could be formed from the digits in the array?"
] | {
"canonical_parameter_names": [
"digits"
],
"leetcode_dataset_entry_point": "Solution().findEvenNumbers",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:40:53",
"tests_total": 91,
"test... | cpp | {
"raw_signature": "vector<int> findEvenNumbers(vector<int>& digits) {",
"container": "Solution",
"callable": "findEvenNumbers",
"parameters": [
{
"name": "digits",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
2,097 | valid-arrangement-of-pairs | Hard | You are given a 0-indexed 2D integer array pairs where pairs[i] = [start_i, end_i]. An arrangement of pairs is valid if for every index i where 1 <= i < pairs.length, we have end_{i-1} == start_i.
Return any valid arrangement of pairs.
Note: The inputs will be generated such that there exists a valid arrangement of p... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(pairs = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [[0, 1], [1, 2], [2, 3], [3, 4]]\n assert candidate(pairs = [[0, 1], [1, 2], [2, 3], [3, 0]]) == [[0, 1], [1, 2], [2, 3], [3, 0]]\n assert candidate(pairs = [[1, 2], [1, 3], [2, 1]]) == ... | [
"[[5,1],[4,5],[11,9],[9,4]]",
"[[1,3],[3,2],[2,1]]",
"[[1,2],[1,3],[2,1]]"
] | [
"Could you convert this into a graph problem?",
"Consider the pairs as edges and each number as a node.",
"We have to find an Eulerian path of this graph. Hierholzer’s algorithm can be used."
] | {
"canonical_parameter_names": [
"pairs"
],
"leetcode_dataset_entry_point": "Solution().validArrangement",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:00",
"tests_total": 79,
"test... | cpp | {
"raw_signature": "vector<vector<int>> validArrangement(vector<vector<int>>& pairs) {",
"container": "Solution",
"callable": "validArrangement",
"parameters": [
{
"name": "pairs",
"type": "vector<vector<int>>&"
}
],
"return_type": "vector<vector<int>>",
"signature_source": "leetcode/c... |
2,099 | find-subsequence-of-length-k-with-the-largest-sum | Easy | You are given an integer array nums and an integer k. You want to find a subsequence of nums of length k that has the largest sum.
Return any such subsequence as an integer array of length k.
A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 3, 1, 2, 4],k = 5) == [5, 3, 1, 2, 4]\n assert candidate(nums = [10, 10, 10, 10, 10],k = 3) == [10, 10, 10]\n assert candidate(nums = [0, 0, 0, 0],k = 2) == [0, 0]\n assert candidate(nums = [-1, -2, 3, 4],k = 3) == [-... | [
"[2,1,3,3]\n2",
"[-1,-2,3,4]\n3",
"[3,4,3,3]\n2"
] | [
"From a greedy perspective, what k elements should you pick?",
"Could you sort the array while maintaining the index?"
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxSubsequence",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:05",
"tests_total": 99,
... | cpp | {
"raw_signature": "vector<int> maxSubsequence(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "maxSubsequence",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "vector<int>",
"signature... |
2,100 | find-good-days-to-rob-the-bank | Medium | You and a gang of thieves are planning on robbing a bank. You are given a 0-indexed integer array security, where security[i] is the number of guards on duty on the i^th day. The days are numbered starting from 0. You are also given an integer time.
The i^th day is a good day to rob the bank if:
- There are at least ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(security = [3, 3, 5, 5, 5, 5, 2, 2, 2, 3],time = 2) == [6, 7]\n assert candidate(security = [1, 1, 1, 1, 1],time = 0) == [0, 1, 2, 3, 4]\n assert candidate(security = [1, 2, 2, 3, 3, 4, 5, 5, 6, 6],time = 1) == [2, 4, 7]\n asser... | [
"[5,3,3,3,5,6,2]\n2",
"[1,1,1,1,1]\n0",
"[1,2,3,4,5,6]\n2"
] | [
"The trivial solution is to check the time days before and after each day. There are a lot of repeated operations using this solution. How could we optimize this solution?",
"We can use precomputation to make the solution faster.",
"Use an array to store the number of days before the i^th day that is non-increa... | {
"canonical_parameter_names": [
"security",
"time"
],
"leetcode_dataset_entry_point": "Solution().goodDaysToRobBank",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:07",
"tests_tot... | cpp | {
"raw_signature": "vector<int> goodDaysToRobBank(vector<int>& security, int time) {",
"container": "Solution",
"callable": "goodDaysToRobBank",
"parameters": [
{
"name": "security",
"type": "vector<int>&"
},
{
"name": "time",
"type": "int"
}
],
"return_type": "vector... |
2,101 | detonate-the-maximum-bombs | Medium | You are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the center as the location of the bomb.
The bombs are represented by a 0-indexed 2D integer array bombs where bombs[i] = [x_i, y_i, r_i]. x_i and y_i denote the X-coordinat... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(bombs = [[10, 10, 5], [15, 15, 5], [20, 20, 5]]) == 1\n assert candidate(bombs = [[1, 1, 5], [2, 2, 5], [3, 3, 5], [4, 4, 5]]) == 4\n assert candidate(bombs = [[1, 1, 1], [2, 2, 1], [3, 3, 1]]) == 1\n assert candidate(bombs = [[... | [
"[[2,1,3],[6,1,4]]",
"[[1,1,5],[10,10,5]]",
"[[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]]"
] | [
"How can we model the relationship between different bombs? Can \"graphs\" help us?",
"Bombs are nodes and are connected to other bombs in their range by directed edges.",
"If we know which bombs will be affected when any bomb is detonated, how can we find the total number of bombs that will be detonated if we ... | {
"canonical_parameter_names": [
"bombs"
],
"leetcode_dataset_entry_point": "Solution().maximumDetonation",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:09",
"tests_total": 115,
"te... | cpp | {
"raw_signature": "int maximumDetonation(vector<vector<int>>& bombs) {",
"container": "Solution",
"callable": "maximumDetonation",
"parameters": [
{
"name": "bombs",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source":... |
2,103 | rings-and-rods | Easy | There are n rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from 0 to 9.
You are given a string rings of length 2n that describes the n rings that are placed onto the rods. Every two characters in rings forms a color-position pair that is used to describe each ring ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2\") == 3\n assert candidate(rings = \"R9G9B9R9G9B9R9G9B9\") == 1\n assert candidate(rings = \"G4\") == 0\n assert candidate(rings = \"R0G0R0G0R0G0\") == 0\n assert candidate(rings = \"G0G1G2G3G4G5G... | [
"\"B0B6G0R6R0R6G9\"",
"\"B0R0G0R9R0B0G0\"",
"\"G4\""
] | [
"For every rod, look through ‘rings’ to see if the rod contains all colors.",
"Create 3 booleans, 1 for each color, to store if that color is present for the current rod. If all 3 are true after looking through the string, then the rod contains all the colors."
] | {
"canonical_parameter_names": [
"rings"
],
"leetcode_dataset_entry_point": "Solution().countPoints",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:12",
"tests_total": 99,
"tests_dro... | cpp | {
"raw_signature": "int countPoints(string rings) {",
"container": "Solution",
"callable": "countPoints",
"parameters": [
{
"name": "rings",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,104 | sum-of-subarray-ranges | Medium | You are given an integer array nums. The range of a subarray of nums is the difference between the largest and smallest element in the subarray.
Return the sum of all subarray ranges of nums.
A subarray is a contiguous non-empty sequence of elements within an array.
Example 1:
Input: nums = [1,2,3]
Output: 4
Explan... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [-1, -2, -3, -4]) == 10\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 165\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 165\n assert candidat... | [
"[1,2,3]",
"[1,3,3]",
"[4,-2,-3,4,1]"
] | [
"Can you get the max/min of a certain subarray by using the max/min of a smaller subarray within it?",
"Notice that the max of the subarray from index i to j is equal to max of (max of the subarray from index i to j-1) and nums[j]."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().subArrayRanges",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:14",
"tests_total": 127,
"tests_... | cpp | {
"raw_signature": "long long subArrayRanges(vector<int>& nums) {",
"container": "Solution",
"callable": "subArrayRanges",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
2,105 | watering-plants-ii | Medium | Alice and Bob want to water n plants in their garden. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the i^th plant is located at x = i.
Each plant needs a specific amount of water. Alice and Bob have a watering can each, initially full. They water the plants in the following... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(plants = [5],capacityA = 10,capacityB = 8) == 0\n assert candidate(plants = [1000000, 1000000, 1000000],capacityA = 1000000,capacityB = 1000000) == 1\n assert candidate(plants = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],capacityA = 15,capaci... | [
"[2,2,3,3]\n5\n5",
"[2,2,3,3]\n3\n4",
"[5]\n10\n8"
] | [
"Try \"simulating\" the process.",
"Since watering each plant takes the same amount of time, where will Alice and Bob meet if they start watering the plants simultaneously? How can you use this to optimize your solution?",
"What will you do when both Alice and Bob have to water the same plant?"
] | {
"canonical_parameter_names": [
"plants",
"capacityA",
"capacityB"
],
"leetcode_dataset_entry_point": "Solution().minimumRefill",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:1... | cpp | {
"raw_signature": "int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {",
"container": "Solution",
"callable": "minimumRefill",
"parameters": [
{
"name": "plants",
"type": "vector<int>&"
},
{
"name": "capacityA",
"type": "int"
},
{
"name": "ca... |
2,106 | maximum-fruits-harvested-after-at-most-k-steps | Hard | Fruits are available at some positions on an infinite x-axis. You are given a 2D integer array fruits where fruits[i] = [position_i, amount_i] depicts amount_i fruits at the position position_i. fruits is already sorted by position_i in ascending order, and each position_i is unique.
You are also given an integer star... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(fruits = [[0, 9], [4, 1], [5, 7], [6, 2], [7, 4], [10, 9]],startPos = 5,k = 4) == 14\n assert candidate(fruits = [[1, 100], [50, 100], [100, 100]],startPos = 75,k = 25) == 100\n assert candidate(fruits = [[100000, 10000]],startPos ... | [
"[[2,8],[6,3],[8,6]]\n5\n4",
"[[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]]\n5\n4",
"[[0,3],[6,4],[8,5]]\n3\n2"
] | [
"Does an optimal path have very few patterns? For example, could a path that goes left, turns and goes right, then turns again and goes left be any better than a path that simply goes left, turns, and goes right?",
"The optimal path turns at most once. That is, the optimal path is one of these: to go left only; t... | {
"canonical_parameter_names": [
"fruits",
"startPos",
"k"
],
"leetcode_dataset_entry_point": "Solution().maxTotalFruits",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:19",
"t... | cpp | {
"raw_signature": "int maxTotalFruits(vector<vector<int>>& fruits, int startPos, int k) {",
"container": "Solution",
"callable": "maxTotalFruits",
"parameters": [
{
"name": "fruits",
"type": "vector<vector<int>>&"
},
{
"name": "startPos",
"type": "int"
},
{
"na... |
2,108 | find-first-palindromic-string-in-the-array | Easy | Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string "".
A string is palindromic if it reads the same forward and backward.
Example 1:
Input: words = ["abc","car","ada","racecar","cool"]
Output: "ada"
Explanation: The first string that ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['hello', 'world', 'python', 'madam']) == \"madam\"\n assert candidate(words = ['hello', 'world', 'python']) == \"\"\n assert candidate(words = ['abba', 'abcba', 'abcdedcba', 'nonpalindrome']) == \"abba\"\n assert candid... | [
"[\"abc\",\"car\",\"ada\",\"racecar\",\"cool\"]",
"[\"notapalindrome\",\"racecar\"]",
"[\"def\",\"ghi\"]"
] | [
"Iterate through the elements in order. As soon as the current element is a palindrome, return it.",
"To check if an element is a palindrome, can you reverse the string?"
] | {
"canonical_parameter_names": [
"words"
],
"leetcode_dataset_entry_point": "Solution().firstPalindrome",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:23",
"tests_total": 104,
"test... | cpp | {
"raw_signature": "string firstPalindrome(vector<string>& words) {",
"container": "Solution",
"callable": "firstPalindrome",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
2,109 | adding-spaces-to-a-string | Medium | You are given a 0-indexed string s and a 0-indexed integer array spaces that describes the indices in the original string where spaces will be added. Each space should be inserted before the character at the given index.
- For example, given s = "EnjoyYourCoffee" and spaces = [5, 9], we place spaces before 'Y' and 'C'... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"spacing\",spaces = [0, 1, 2, 3, 4, 5, 6]) == \" s p a c i n g\"\n assert candidate(s = \"icodeinpython\",spaces = [1, 5, 7, 9]) == \"i code in py thon\"\n assert candidate(s = \"A\",spaces = [0]) == \" A\"\n assert candida... | [
"\"LeetcodeHelpsMeLearn\"\n[8,13,15]",
"\"icodeinpython\"\n[1,5,7,9]",
"\"spacing\"\n[0,1,2,3,4,5,6]"
] | [
"Create a new string, initially empty, as the modified string. Iterate through the original string and append each character of the original string to the new string. However, each time you reach a character that requires a space before it, append a space before appending the character.",
"Since the array of indi... | {
"canonical_parameter_names": [
"s",
"spaces"
],
"leetcode_dataset_entry_point": "Solution().addSpaces",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:26",
"tests_total": 127,
"... | cpp | {
"raw_signature": "string addSpaces(string s, vector<int>& spaces) {",
"container": "Solution",
"callable": "addSpaces",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "spaces",
"type": "vector<int>&"
}
],
"return_type": "string",
"signature_source": ... |
2,110 | number-of-smooth-descent-periods-of-a-stock | Medium | You are given an integer array prices representing the daily price history of a stock, where prices[i] is the stock price on the i^th day.
A smooth descent period of a stock consists of one or more contiguous days such that the price on each day is lower than the price on the preceding day by exactly 1. The first day ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(prices = [10, 9, 4, 3, 2, 1]) == 13\n assert candidate(prices = [3, 3, 3, 3, 3]) == 5\n assert candidate(prices = [100000, 99999, 99998, 99997, 99996, 99995]) ==... | [
"[3,2,1,4]",
"[8,6,7,7]",
"[1]"
] | [
"Any array is a series of adjacent longest possible smooth descent periods. For example, [5,3,2,1,7,6] is [5] + [3,2,1] + [7,6].",
"Think of a 2-pointer approach to traverse the array and find each longest possible period.",
"Suppose you found the longest possible period with a length of k. How many periods are... | {
"canonical_parameter_names": [
"prices"
],
"leetcode_dataset_entry_point": "Solution().getDescentPeriods",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:29",
"tests_total": 116,
"t... | cpp | {
"raw_signature": "long long getDescentPeriods(vector<int>& prices) {",
"container": "Solution",
"callable": "getDescentPeriods",
"parameters": [
{
"name": "prices",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
2,111 | minimum-operations-to-make-the-array-k-increasing | Hard | You are given a 0-indexed array arr consisting of n positive integers, and a positive integer k.
The array arr is called K-increasing if arr[i-k] <= arr[i] holds for every index i, where k <= i <= n-1.
- For example, arr = [4, 1, 5, 2, 6, 2] is K-increasing for k = 2 because:
- arr[0] <= arr[2] (4 <= 5)
- arr[1] ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [2, 2, 2, 2, 2],k = 1) == 0\n assert candidate(arr = [4, 1, 5, 2, 6, 2],k = 3) == 2\n assert candidate(arr = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 1) == 0\n assert candidate(arr = [6, 5, 4, 3, 2, 1],k = 2) == 4\n assert ca... | [
"[5,4,3,2,1]\n1",
"[4,1,5,2,6,2]\n2",
"[4,1,5,2,6,2]\n3"
] | [
"Can we divide the array into non-overlapping subsequences and simplify the problem?",
"In the final array, arr[i-k] ≤ arr[i] should hold. We can use this to divide the array into at most k non-overlapping sequences, where arr[i] will belong to the (i%k)th sequence.",
"Now our problem boils down to performing t... | {
"canonical_parameter_names": [
"arr",
"k"
],
"leetcode_dataset_entry_point": "Solution().kIncreasing",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:31",
"tests_total": 133,
"t... | cpp | {
"raw_signature": "int kIncreasing(vector<int>& arr, int k) {",
"container": "Solution",
"callable": "kIncreasing",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/code... |
2,114 | maximum-number-of-words-found-in-sentences | Easy | A sentence is a list of words that are separated by a single space with no leading or trailing spaces.
You are given an array of strings sentences, where each sentences[i] represents a single sentence.
Return the maximum number of words that appear in a single sentence.
Example 1:
Input: sentences = ["alice and bob... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(sentences = ['short', 'tiny', 'minuscule']) == 1\n assert candidate(sentences = ['one']) == 1\n assert candidate(sentences = ['alice and bob love leetcode', 'i think so too', 'this is great thanks very much']) == 6\n assert cand... | [
"[\"alice and bob love leetcode\",\"i think so too\",\"this is great thanks very much\"]",
"[\"please wait\",\"continue to fight\",\"continue to win\"]"
] | [
"Process each sentence separately and count the number of words by looking for the number of space characters in the sentence and adding it by 1."
] | {
"canonical_parameter_names": [
"sentences"
],
"leetcode_dataset_entry_point": "Solution().mostWordsFound",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:36",
"tests_total": 78,
"te... | cpp | {
"raw_signature": "int mostWordsFound(vector<string>& sentences) {",
"container": "Solution",
"callable": "mostWordsFound",
"parameters": [
{
"name": "sentences",
"type": "vector<string>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
2,115 | find-all-possible-recipes-from-given-supplies | Medium | You have information about n different recipes. You are given a string array recipes and a 2D string array ingredients. The i^th recipe has the name recipes[i], and you can create it if you have all the needed ingredients from ingredients[i]. A recipe can also be an ingredient for other recipes, i.e., ingredients[i] ma... | {
"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 ... | [
"[\"bread\"]\n[[\"yeast\",\"flour\"]]\n[\"yeast\",\"flour\",\"corn\"]",
"[\"bread\",\"sandwich\"]\n[[\"yeast\",\"flour\"],[\"bread\",\"meat\"]]\n[\"yeast\",\"flour\",\"meat\"]",
"[\"bread\",\"sandwich\",\"burger\"]\n[[\"yeast\",\"flour\"],[\"bread\",\"meat\"],[\"sandwich\",\"meat\",\"bread\"]]\n[\"yeast\",\"flo... | [
"Can we use a data structure to quickly query whether we have a certain ingredient?",
"Once we verify that we can make a recipe, we can add it to our ingredient data structure. We can then check if we can make more recipes as a result of this."
] | {
"canonical_parameter_names": [
"recipes",
"ingredients",
"supplies"
],
"leetcode_dataset_entry_point": "Solution().findAllRecipes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:4... | cpp | {
"raw_signature": "vector<string> findAllRecipes(vector<string>& recipes, vector<vector<string>>& ingredients, vector<string>& supplies) {",
"container": "Solution",
"callable": "findAllRecipes",
"parameters": [
{
"name": "recipes",
"type": "vector<string>&"
},
{
"name": "ingredie... |
2,116 | check-if-a-parentheses-string-can-be-valid | Medium | A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true:
- It is ().
- It can be written as AB (A concatenated with B), where A and B are valid parentheses strings.
- It can be written as (A), where A is a valid parentheses string.
You are give... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"(((())(((())\",locked = \"111111010111\") == True\n assert candidate(s = \"()))()\",locked = \"010100\") == True\n assert candidate(s = \"()()\",locked = \"0000\") == True\n assert candidate(s = \")\",locked = \"0\") == Fa... | [
"\"))()))\"\n\"010100\"",
"\"()()\"\n\"0000\"",
"\")\"\n\"0\"",
"\"(((())(((())\"\n\"111111010111\""
] | [
"Can an odd length string ever be valid?",
"From left to right, if a locked ')' is encountered, it must be balanced with either a locked '(' or an unlocked index on its left. If neither exist, what conclusion can be drawn? If both exist, which one is more preferable to use?",
"After the above, we may have locke... | {
"canonical_parameter_names": [
"s",
"locked"
],
"leetcode_dataset_entry_point": "Solution().canBeValid",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:41",
"tests_total": 81,
"... | cpp | {
"raw_signature": "bool canBeValid(string s, string locked) {",
"container": "Solution",
"callable": "canBeValid",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "locked",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/code... |
2,117 | abbreviating-the-product-of-a-range | Hard | You are given two positive integers left and right with left <= right. Calculate the product of all integers in the inclusive range [left, right].
Since the product may be very large, you will abbreviate it following these steps:
1. Count all trailing zeros in the product and remove them. Let us denote this count as ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(left = 100,right = 105) == \"1158727752e3\"\n assert candidate(left = 1,right = 10000) == \"28462...79008e2499\"\n assert candidate(left = 10,right = 20) == \"6704425728e3\"\n assert candidate(left = 371,right = 375) == \"721985... | [
"1\n4",
"2\n11",
"371\n375"
] | [
"Calculating the number of trailing zeros, the last five digits, and the first five digits can all be done separately.",
"Use a prime factorization property to find the number of trailing zeros. Use modulo to find the last 5 digits. Use a logarithm property to find the first 5 digits.",
"The number of trailing ... | {
"canonical_parameter_names": [
"left",
"right"
],
"leetcode_dataset_entry_point": "Solution().abbreviateProduct",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:43",
"tests_total"... | cpp | {
"raw_signature": "string abbreviateProduct(int left, int right) {",
"container": "Solution",
"callable": "abbreviateProduct",
"parameters": [
{
"name": "left",
"type": "int"
},
{
"name": "right",
"type": "int"
}
],
"return_type": "string",
"signature_source": "lee... |
2,119 | a-number-after-a-double-reversal | Easy | Reversing an integer means to reverse all its digits.
- For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained.
Given an integer num, reverse num to get reversed1, then reverse reversed1 to get reversed2. Return true if reversed2 equals num. Otherwise return false.
Ex... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = 1001) == True\n assert candidate(num = 1000000) == False\n assert candidate(num = 999999) == True\n assert candidate(num = 1200) == False\n assert candidate(num = 0) == True\n assert candidate(num = 1800) == False\n ... | [
"526",
"1800",
"0"
] | [
"Other than the number 0 itself, any number that ends with 0 would lose some digits permanently when reversed."
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().isSameAfterReversals",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:45",
"tests_total": 66,
"te... | cpp | {
"raw_signature": "bool isSameAfterReversals(int num) {",
"container": "Solution",
"callable": "isSameAfterReversals",
"parameters": [
{
"name": "num",
"type": "int"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,120 | execution-of-all-suffix-instructions-staying-in-a-grid | Medium | There is an n x n grid, with the top-left cell at (0, 0) and the bottom-right cell at (n - 1, n - 1). You are given the integer n and an integer array startPos where startPos = [start_row, start_col] indicates that a robot is initially at cell (start_row, start_col).
You are also given a 0-indexed string s of length m... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 1,startPos = [0, 0],s = \"LRUD\") == [0, 0, 0, 0]\n assert candidate(n = 4,startPos = [2, 2],s = \"DDDD\") == [1, 1, 1, 1]\n assert candidate(n = 5,startPos = [2, 2],s = \"LUDDRL\") == [6, 5, 4, 3, 2, 1]\n assert candidate(n... | [
"3\n[0,1]\n\"RRDDLU\"",
"2\n[1,1]\n\"LURD\"",
"1\n[0,0]\n\"LRUD\""
] | [
"The constraints are not very large. Can we simulate the execution by starting from each index of s?",
"Before any of the stopping conditions is met, stop the simulation for that index and set the answer for that index."
] | {
"canonical_parameter_names": [
"n",
"startPos",
"s"
],
"leetcode_dataset_entry_point": "Solution().executeInstructions",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:48",
"t... | cpp | {
"raw_signature": "vector<int> executeInstructions(int n, vector<int>& startPos, string s) {",
"container": "Solution",
"callable": "executeInstructions",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "startPos",
"type": "vector<int>&"
},
{
"name": ... |
2,121 | intervals-between-identical-elements | Medium | You are given a 0-indexed array of n integers arr.
The interval between two elements in arr is defined as the absolute difference between their indices. More formally, the interval between arr[i] and arr[j] is |i - j|.
Return an array intervals of length n where intervals[i] is the sum of intervals between arr[i] and... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(arr = [100000, 1, 100000, 2, 100000, 3, 100000, 4, 100000, 5]) == [20, 0, 14, 0, 12, 0, 14, 0, 20, 0]\n assert candidate(arr = [5, 4, 3, 2, 1]) == [0, 0, 0, 0, 0]\n assert candidate(arr = [1, 3, 2, 3, 1, 4, 2, 3, 1, 4, 2]) == [12, ... | [
"[2,1,3,1,2,3,3]",
"[10,5,10,10]"
] | [
"For each unique value found in the array, store a sorted list of indices of elements that have this value in the array.",
"One way of doing this is to use a HashMap that maps the values to their list of indices. Update this mapping as you iterate through the array.",
"Process each list of indices separately an... | {
"canonical_parameter_names": [
"arr"
],
"leetcode_dataset_entry_point": "Solution().getDistances",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:50",
"tests_total": 89,
"tests_drop... | cpp | {
"raw_signature": "vector<long long> getDistances(vector<int>& arr) {",
"container": "Solution",
"callable": "getDistances",
"parameters": [
{
"name": "arr",
"type": "vector<int>&"
}
],
"return_type": "vector<long long>",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
2,122 | recover-the-original-array | Hard | Alice had a 0-indexed array arr consisting of n positive integers. She chose an arbitrary positive integer k and created two new 0-indexed integer arrays lower and higher in the following manner:
1. lower[i] = arr[i] - k, for every index i where 0 <= i < n
2. higher[i] = arr[i] + k, for every index i where 0 <= i < n
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [3, 1, 5, 7, 9, 11]) == [2, 6, 10]\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == [15, 35, 55]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == [2, 3, 6, 7]\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == [... | [
"[2,10,6,4,8,12]",
"[1,1,3,3]",
"[5,435]"
] | [
"If we fix the value of k, how can we check if an original array exists for the fixed k?",
"The smallest value of nums is obtained by subtracting k from the smallest value of the original array. How can we use this to reduce the search space for finding a valid k?",
"You can compute every possible k by using th... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().recoverArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:52",
"tests_total": 111,
"tests_dr... | cpp | {
"raw_signature": "vector<int> recoverArray(vector<int>& nums) {",
"container": "Solution",
"callable": "recoverArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
2,124 | check-if-all-as-appears-before-all-bs | Easy | Given a string s consisting of only the characters 'a' and 'b', return true if every 'a' appears before every 'b' in the string. Otherwise, return false.
Example 1:
Input: s = "aaabbb"
Output: true
Explanation:
The 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5.
Hence, every 'a' appears be... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"b\") == True\n assert candidate(s = \"aaaaabbbbb\") == True\n assert candidate(s = \"bbb\") == True\n assert candidate(s = \"ab\") == True\n assert candidate(s = \"aabbaa\") == False\n assert candidate(s = \"ba\") ==... | [
"\"aaabbb\"",
"\"abab\"",
"\"bbb\""
] | [
"You can check the opposite: check if there is a ‘b’ before an ‘a’. Then, negate and return that answer.",
"s should not have any occurrences of “ba” as a substring."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().checkString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:41:57",
"tests_total": 152,
"tests_droppe... | cpp | {
"raw_signature": "bool checkString(string s) {",
"container": "Solution",
"callable": "checkString",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,125 | number-of-laser-beams-in-a-bank | Medium | Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array bank representing the floor plan of the bank, which is an m x n 2D matrix. bank[i] represents the i^th row, consisting of '0's and '1's. '0' means the cell is empty, while'1' means the cell has a security device.
The... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(bank = ['00000', '00000', '00000', '00000']) == 0\n assert candidate(bank = ['001', '000', '101', '000', '110']) == 6\n assert candidate(bank = ['111', '000', '111']) == 9\n assert candidate(bank = ['0000', '0000', '0000', '0000... | [
"[\"011001\",\"000000\",\"010100\",\"001000\"]",
"[\"000\",\"111\",\"000\"]"
] | [
"What is the commonality between security devices on the same row?",
"Each device on the same row has the same number of beams pointing towards the devices on the next row with devices.",
"If you were given an integer array where each element is the number of security devices on each row, can you solve it?",
... | {
"canonical_parameter_names": [
"bank"
],
"leetcode_dataset_entry_point": "Solution().numberOfBeams",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:00",
"tests_total": 117,
"tests_d... | cpp | {
"raw_signature": "int numberOfBeams(vector<string>& bank) {",
"container": "Solution",
"callable": "numberOfBeams",
"parameters": [
{
"name": "bank",
"type": "vector<string>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
2,126 | destroying-asteroids | Medium | You are given an integer mass, which represents the original mass of a planet. You are further given an integer array asteroids, where asteroids[i] is the mass of the i^th asteroid.
You can arrange for the planet to collide with the asteroids in any arbitrary order. If the mass of the planet is greater than or equal t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mass = 1,asteroids = [100000]) == False\n assert candidate(mass = 1,asteroids = [1, 2, 3, 4, 5]) == True\n assert candidate(mass = 5,asteroids = [4, 9, 23, 4]) == False\n assert candidate(mass = 10,asteroids = [10, 10, 10, 10, 1... | [
"10\n[3,9,19,5,21]",
"5\n[4,9,23,4]"
] | [
"Choosing the asteroid to collide with can be done greedily.",
"If an asteroid will destroy the planet, then every bigger asteroid will also destroy the planet.",
"You only need to check the smallest asteroid at each collision. If it will destroy the planet, then every other asteroid will also destroy the plane... | {
"canonical_parameter_names": [
"mass",
"asteroids"
],
"leetcode_dataset_entry_point": "Solution().asteroidsDestroyed",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:02",
"tests_t... | cpp | {
"raw_signature": "bool asteroidsDestroyed(int mass, vector<int>& asteroids) {",
"container": "Solution",
"callable": "asteroidsDestroyed",
"parameters": [
{
"name": "mass",
"type": "int"
},
{
"name": "asteroids",
"type": "vector<int>&"
}
],
"return_type": "bool",
... |
2,127 | maximum-employees-to-be-invited-to-a-meeting | Hard | A company is organizing a meeting and has a list of n employees, waiting to be invited. They have arranged for a large circular table, capable of seating any number of employees.
The employees are numbered from 0 to n - 1. Each employee has a favorite person and they will attend the meeting only if they can sit next t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(favorite = [1, 0, 0, 2]) == 4\n assert candidate(favorite = [5, 4, 3, 2, 1, 0]) == 6\n assert candidate(favorite = [2, 0, 1, 4, 5, 3]) == 3\n assert candidate(favorite = [5, 4, 0, 2, 0, 1]) == 4\n assert candidate(favorite = ... | [
"[2,2,1,2]",
"[1,2,0]",
"[3,0,1,4,1]"
] | [
"From the given array favorite, create a graph where for every index i, there is a directed edge from favorite[i] to i. The graph will be a combination of cycles and chains of acyclic edges. Now, what are the ways in which we can choose employees to sit at the table?",
"The first way by which we can choose employ... | {
"canonical_parameter_names": [
"favorite"
],
"leetcode_dataset_entry_point": "Solution().maximumInvitations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:04",
"tests_total": 127,
... | cpp | {
"raw_signature": "int maximumInvitations(vector<int>& favorite) {",
"container": "Solution",
"callable": "maximumInvitations",
"parameters": [
{
"name": "favorite",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
2,129 | capitalize-the-title | Easy | You are given a string title consisting of one or more words separated by a single space, where each word consists of English letters. Capitalize the string by changing the capitalization of each word such that:
- If the length of the word is 1 or 2 letters, change all letters to lowercase.
- Otherwise, change the fir... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(title = \"ai and ml\") == \"ai And ml\"\n assert candidate(title = \"First leTTeR of EACH Word\") == \"First Letter of Each Word\"\n assert candidate(title = \"tHis iS a tEsT\") == \"This is a Test\"\n assert candidate(title = \... | [
"\"capiTalIze tHe titLe\"",
"\"First leTTeR of EACH Word\"",
"\"i lOve leetcode\""
] | [
"Firstly, try to find all the words present in the string.",
"On the basis of each word's lengths, simulate the process explained in Problem."
] | {
"canonical_parameter_names": [
"title"
],
"leetcode_dataset_entry_point": "Solution().capitalizeTitle",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:09",
"tests_total": 137,
"test... | cpp | {
"raw_signature": "string capitalizeTitle(string title) {",
"container": "Solution",
"callable": "capitalizeTitle",
"parameters": [
{
"name": "title",
"type": "string"
}
],
"return_type": "string",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,131 | longest-palindrome-by-concatenating-two-letter-words | Medium | You are given an array of strings words. Each element of words consists of two lowercase English letters.
Create the longest possible palindrome by selecting some elements from words and concatenating them in any order. Each element can be selected at most once.
Return the length of the longest palindrome that you ca... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['xy', 'yx', 'xy', 'yx', 'xy', 'yx']) == 12\n assert candidate(words = ['aa', 'bb', 'cc', 'dd', 'ee']) == 2\n assert candidate(words = ['ab', 'ba', 'xy', 'yx', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz']) == 22\n assert ca... | [
"[\"lc\",\"cl\",\"gg\"]",
"[\"ab\",\"ty\",\"yt\",\"lc\",\"cl\",\"ab\"]",
"[\"cc\",\"ll\",\"xx\"]"
] | [
"A palindrome must be mirrored over the center. Suppose we have a palindrome. If we prepend the word \"ab\" on the left, what must we append on the right to keep it a palindrome?",
"We must append \"ba\" on the right. The number of times we can do this is the minimum of (occurrences of \"ab\") and (occurrences of... | {
"canonical_parameter_names": [
"words"
],
"leetcode_dataset_entry_point": "Solution().longestPalindrome",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:13",
"tests_total": 52,
"tes... | cpp | {
"raw_signature": "int longestPalindrome(vector<string>& words) {",
"container": "Solution",
"callable": "longestPalindrome",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
2,132 | stamping-the-grid | Hard | You are given an m x n binary matrix grid where each cell is either 0 (empty) or 1 (occupied).
You are then given stamps of size stampHeight x stampWidth. We want to fit the stamps such that they follow the given restrictions and requirements:
1. Cover all the empty cells.
2. Do not cover any of the occupied cells.
3... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],stampHeight = 2,stampWidth = 2) == True\n assert candidate(grid = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],stampHeight = 2,stampWidth = 2) == False\n a... | [
"[[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0]]\n4\n3",
"[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]\n2\n2"
] | [
"Can we use prefix sums here?"
] | {
"canonical_parameter_names": [
"grid",
"stampHeight",
"stampWidth"
],
"leetcode_dataset_entry_point": "Solution().possibleToStamp",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:4... | cpp | {
"raw_signature": "bool possibleToStamp(vector<vector<int>>& grid, int stampHeight, int stampWidth) {",
"container": "Solution",
"callable": "possibleToStamp",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
},
{
"name": "stampHeight",
"type": "int"
},
... |
2,133 | check-if-every-row-and-column-contains-all-numbers | Easy | An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive).
Given an n x n integer matrix matrix, return true if the matrix is valid. Otherwise, return false.
Example 1:
Input: matrix = [[1,2,3],[3,1,2],[2,3,1]]
Output: true
Explanation: In this case, n = 3, and every ro... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(matrix = [[1, 2, 3, 4], [2, 3, 4, 1], [3, 4, 1, 2], [4, 1, 2, 3]]) == True\n assert candidate(matrix = [[4, 3, 2, 1], [1, 4, 3, 2], [2, 1, 4, 3], [3, 2, 1, 4]]) == True\n assert candidate(matrix = [[5, 5, 5, 5, 5], [5, 5, 5, 5, 5],... | [
"[[1,2,3],[3,1,2],[2,3,1]]",
"[[1,1,1],[1,2,3],[1,2,3]]"
] | [
"Use for loops to check each row for every number from 1 to n. Similarly, do the same for each column.",
"For each check, you can keep a set of the unique elements in the checked row/col. By the end of the check, the size of the set should be n."
] | {
"canonical_parameter_names": [
"matrix"
],
"leetcode_dataset_entry_point": "Solution().checkValid",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:18",
"tests_total": 57,
"tests_dro... | cpp | {
"raw_signature": "bool checkValid(vector<vector<int>>& matrix) {",
"container": "Solution",
"callable": "checkValid",
"parameters": [
{
"name": "matrix",
"type": "vector<vector<int>>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
2,134 | minimum-swaps-to-group-all-1s-together-ii | Medium | A swap is defined as taking two distinct positions in an array and swapping the values in them.
A circular array is defined as an array where we consider the first element and the last element to be adjacent.
Given a binary circular array nums, return the minimum number of swaps required to group all 1's present in t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 0, 0, 0, 1, 1, 1, 0, 0, 1]) == 2\n assert candidate(nums = [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0]) == 2\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1]) == 0\n assert candidate(nums = [0, 1, 0, 1, 1, 0, 0]) ... | [
"[0,1,0,1,1,0,0]",
"[0,1,1,1,0,0,1,1,0]",
"[1,1,0,0,1]"
] | [
"Notice that the number of 1’s to be grouped together is fixed. It is the number of 1's the whole array has.",
"Call this number total. We should then check for every subarray of size total (possibly wrapped around), how many swaps are required to have the subarray be all 1’s.",
"The number of swaps required is... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minSwaps",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:20",
"tests_total": 117,
"tests_droppe... | cpp | {
"raw_signature": "int minSwaps(vector<int>& nums) {",
"container": "Solution",
"callable": "minSwaps",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,135 | count-words-obtained-after-adding-a-letter | Medium | You are given two 0-indexed arrays of strings startWords and targetWords. Each string consists of lowercase English letters only.
For each string in targetWords, check if it is possible to choose a string from startWords and perform a conversion operation on it to be equal to that from targetWords.
The conversion ope... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(startWords = ['ant', 'act', 'tack'],targetWords = ['tack', 'act', 'acti']) == 2\n assert candidate(startWords = ['ab', 'a'],targetWords = ['abc', 'abcd']) == 1\n assert candidate(startWords = ['pqrst', 'vwxyz', 'abcdef'],targetWord... | [
"[\"ant\",\"act\",\"tack\"]\n[\"tack\",\"act\",\"acti\"]",
"[\"ab\",\"a\"]\n[\"abc\",\"abcd\"]"
] | [
"Which data structure can be used to efficiently check if a string exists in startWords?",
"After appending a letter, all letters of a string can be rearranged in any possible way. How can we use this to reduce our search space while checking if a string in targetWords can be obtained from a string in startWords?... | {
"canonical_parameter_names": [
"startWords",
"targetWords"
],
"leetcode_dataset_entry_point": "Solution().wordCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:23",
"tests_to... | cpp | {
"raw_signature": "int wordCount(vector<string>& startWords, vector<string>& targetWords) {",
"container": "Solution",
"callable": "wordCount",
"parameters": [
{
"name": "startWords",
"type": "vector<string>&"
},
{
"name": "targetWords",
"type": "vector<string>&"
}
],
... |
2,136 | earliest-possible-day-of-full-bloom | Hard | You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each:
- plantTime[i] is the number of full days it takes you to plant the i^th s... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(plantTime = [1],growTime = [1]) == 2\n assert candidate(plantTime = [2, 2, 2],growTime = [3, 3, 3]) == 9\n assert candidate(plantTime = [2, 2, 2],growTime = [3, 2, 1]) == 7\n assert candidate(plantTime = [10000, 10000],growTime ... | [
"[1,4,3]\n[2,3,1]",
"[1,2,3,2]\n[2,1,2,1]",
"[1]\n[1]"
] | [
"List the planting like the diagram above shows, where a row represents the timeline of a seed. A row i is above another row j if the last day planting seed i is ahead of the last day for seed j. Does it have any advantage to spend some days to plant seed j before completely planting seed i?",
"No. It does not he... | {
"canonical_parameter_names": [
"plantTime",
"growTime"
],
"leetcode_dataset_entry_point": "Solution().earliestFullBloom",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:26",
"test... | cpp | {
"raw_signature": "int earliestFullBloom(vector<int>& plantTime, vector<int>& growTime) {",
"container": "Solution",
"callable": "earliestFullBloom",
"parameters": [
{
"name": "plantTime",
"type": "vector<int>&"
},
{
"name": "growTime",
"type": "vector<int>&"
}
],
"r... |
2,138 | divide-a-string-into-groups-of-size-k | Easy | A string s can be partitioned into groups of size k using the following procedure:
- The first group consists of the first k characters of the string, the second group consists of the next k characters of the string, and so on. Each element can be a part of exactly one group.
- For the last group, if the string does n... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcdefghij\",k = 3,fill = \"x\") == ['abc', 'def', 'ghi', 'jxx']\n assert candidate(s = \"abcdefg\",k = 2,fill = \"z\") == ['ab', 'cd', 'ef', 'gz']\n assert candidate(s = \"abcdefghi\",k = 3,fill = \"x\") == ['abc', 'def', 'g... | [
"\"abcdefghi\"\n3\n\"x\"",
"\"abcdefghij\"\n3\n\"x\""
] | [
"Using the length of the string and k, can you count the number of groups the string can be divided into?",
"Try completing each group using characters from the string. If there aren’t enough characters for the last group, use the fill character to complete the group."
] | {
"canonical_parameter_names": [
"s",
"k",
"fill"
],
"leetcode_dataset_entry_point": "Solution().divideString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:30",
"tests_total"... | cpp | {
"raw_signature": "vector<string> divideString(string s, int k, char fill) {",
"container": "Solution",
"callable": "divideString",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "k",
"type": "int"
},
{
"name": "fill",
"type": "char"
}
... |
2,139 | minimum-moves-to-reach-target-score | Medium | You are playing a game with integers. You start with the integer 1 and you want to reach the integer target.
In one move, you can either:
- Increment the current integer by one (i.e., x = x + 1).
- Double the current integer (i.e., x = 2 * x).
You can use the increment operation any number of times, however, you can... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(target = 2,maxDoubles = 1) == 1\n assert candidate(target = 6,maxDoubles = 0) == 5\n assert candidate(target = 1000000000,maxDoubles = 100) == 41\n assert candidate(target = 8,maxDoubles = 3) == 3\n assert candidate(target = ... | [
"5\n0",
"19\n2",
"10\n4"
] | [
"Solve the opposite problem: start at the given score and move to 1.",
"It is better to use the move of the second type once we can to lose more scores fast."
] | {
"canonical_parameter_names": [
"target",
"maxDoubles"
],
"leetcode_dataset_entry_point": "Solution().minMoves",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:32",
"tests_total": ... | cpp | {
"raw_signature": "int minMoves(int target, int maxDoubles) {",
"container": "Solution",
"callable": "minMoves",
"parameters": [
{
"name": "target",
"type": "int"
},
{
"name": "maxDoubles",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/code... |
2,140 | solving-questions-with-brainpower | Medium | You are given a 0-indexed 2D integer array questions where questions[i] = [points_i, brainpower_i].
The array describes the questions of an exam, where you have to process the questions in order (i.e., starting from question 0) and make a decision whether to solve or skip each question. Solving question i will earn yo... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(questions = [[5, 10], [10, 5], [15, 1]]) == 15\n assert candidate(questions = [[10, 1], [10, 1], [10, 1], [10, 1], [10, 1]]) == 30\n assert candidate(questions = [[5, 1], [2, 2], [3, 3], [1, 1], [4, 4]]) == 9\n assert candidate(... | [
"[[3,2],[4,3],[4,4],[2,5]]",
"[[1,1],[2,2],[3,3],[4,4],[5,5]]"
] | [
"For each question, we can either solve it or skip it. How can we use Dynamic Programming to decide the most optimal option for each problem?",
"We store for each question the maximum points we can earn if we started the exam on that question.",
"If we skip a question, then the answer for it will be the same as... | {
"canonical_parameter_names": [
"questions"
],
"leetcode_dataset_entry_point": "Solution().mostPoints",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:35",
"tests_total": 108,
"tests... | cpp | {
"raw_signature": "long long mostPoints(vector<vector<int>>& questions) {",
"container": "Solution",
"callable": "mostPoints",
"parameters": [
{
"name": "questions",
"type": "vector<vector<int>>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_so... |
2,141 | maximum-running-time-of-n-computers | Hard | You have n computers. You are given the integer n and a 0-indexed integer array batteries where the i^th battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously using the given batteries.
Initially, you can insert at most one battery into each computer. After t... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 5,batteries = [1, 2, 3, 4, 5]) == 1\n assert candidate(n = 4,batteries = [10, 10, 3, 5]) == 3\n assert candidate(n = 2,batteries = [1000000000, 1000000000]) == 1000000000\n assert candidate(n = 2,batteries = [9, 4, 10]) == 1... | [
"2\n[3,3,3]",
"2\n[1,1,1,1]"
] | [
"For a given running time, can you determine if it is possible to run all n computers simultaneously?",
"Try to use Binary Search to find the maximal running time"
] | {
"canonical_parameter_names": [
"n",
"batteries"
],
"leetcode_dataset_entry_point": "Solution().maxRunTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:37",
"tests_total": 114,... | cpp | {
"raw_signature": "long long maxRunTime(int n, vector<int>& batteries) {",
"container": "Solution",
"callable": "maxRunTime",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "batteries",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_s... |
2,144 | minimum-cost-of-buying-candies-with-discount | Easy | A shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free.
The customer can choose any candy to take away for free as long as the cost of the chosen candy is less than or equal to the minimum cost of the two candies bought.
- For example, if there are 4 candies with co... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(cost = [100]) == 100\n assert candidate(cost = [1, 1, 1, 1, 1, 1]) == 4\n assert candidate(cost = [10, 20, 30, 40, 50]) == 120\n assert candidate(cost = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 663\n assert candidate(cost... | [
"[1,2,3]",
"[6,5,7,9,2,2]",
"[5,5]"
] | [
"If we consider costs from high to low, what is the maximum cost of a single candy that we can get for free?",
"How can we generalize this approach to maximize the costs of the candies we get for free?",
"Can “sorting” the array help us find the minimum cost?"
] | {
"canonical_parameter_names": [
"cost"
],
"leetcode_dataset_entry_point": "Solution().minimumCost",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:41",
"tests_total": 96,
"tests_drop... | cpp | {
"raw_signature": "int minimumCost(vector<int>& cost) {",
"container": "Solution",
"callable": "minimumCost",
"parameters": [
{
"name": "cost",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,145 | count-the-hidden-sequences | Medium | You are given a 0-indexed array of n integers differences, which describes the differences between each pair of consecutive integers of a hidden sequence of length (n + 1). More formally, call the hidden sequence hidden, then we have that differences[i] = hidden[i + 1] - hidden[i].
You are further given two integers l... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(differences = [0, 0, 0],lower = 1,upper = 1) == 1\n assert candidate(differences = [5, -5, 5, -5],lower = -10,upper = 10) == 16\n assert candidate(differences = [3, -4, 5, 1, -2],lower = -4,upper = 5) == 4\n assert candidate(dif... | [
"[1,-3,4]\n1\n6",
"[3,-4,5,1,-2]\n-4\n5",
"[4,-7,2]\n3\n6"
] | [
"Fix the first element of the hidden sequence to any value x and ignore the given bounds. Notice that we can then determine all the other elements of the sequence by using the differences array.",
"We will also be able to determine the difference between the minimum and maximum elements of the sequence. Notice th... | {
"canonical_parameter_names": [
"differences",
"lower",
"upper"
],
"leetcode_dataset_entry_point": "Solution().numberOfArrays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:44"... | cpp | {
"raw_signature": "int numberOfArrays(vector<int>& differences, int lower, int upper) {",
"container": "Solution",
"callable": "numberOfArrays",
"parameters": [
{
"name": "differences",
"type": "vector<int>&"
},
{
"name": "lower",
"type": "int"
},
{
"name": "up... |
2,146 | k-highest-ranked-items-within-a-price-range | Medium | You are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop. The integers in the grid represent the following:
- 0 represents a wall that you cannot pass through.
- 1 represents an empty cell that you can freely move to and from.
- All other positive integers represent th... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [0, 0, 1], [2, 3, 4]],pricing = [2, 3],start = [0, 0],k = 3) == [[2, 1], [2, 0]]\n assert candidate(grid = [[1, 2, 0, 1], [1, 3, 3, 1], [0, 2, 5, 1]],pricing = [2, 3],start = [2, 3],k = 2) == [[2, 1], [1, 2]]\n a... | [
"[[1,2,0,1],[1,3,0,1],[0,2,5,1]]\n[2,5]\n[0,0]\n3",
"[[1,2,0,1],[1,3,3,1],[0,2,5,1]]\n[2,3]\n[2,3]\n2",
"[[1,1,1],[0,0,1],[2,3,4]]\n[2,3]\n[0,0]\n3"
] | [
"Could you determine the rank of every item efficiently?",
"We can perform a breadth-first search from the starting position and know the length of the shortest path from start to every item.",
"Sort all the items according to the conditions listed in the problem, and return the first k (or all if less than k e... | {
"canonical_parameter_names": [
"grid",
"pricing",
"start",
"k"
],
"leetcode_dataset_entry_point": "Solution().highestRankedKItems",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T... | cpp | {
"raw_signature": "vector<vector<int>> highestRankedKItems(vector<vector<int>>& grid, vector<int>& pricing, vector<int>& start, int k) {",
"container": "Solution",
"callable": "highestRankedKItems",
"parameters": [
{
"name": "grid",
"type": "vector<vector<int>>&"
},
{
"name": "pri... |
2,147 | number-of-ways-to-divide-a-long-corridor | Hard | Along a long library corridor, there is a line of seats and decorative plants. You are given a 0-indexed string corridor of length n consisting of letters 'S' and 'P' where each 'S' represents a seat and each 'P' represents a plant.
One room divider has already been installed to the left of index 0, and another to the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(corridor = \"PPPPSSPPPPSSPPPP\") == 5\n assert candidate(corridor = \"SSSSSSSSSS\") == 1\n assert candidate(corridor = \"SPSPSPSP\") == 2\n assert candidate(corridor = \"SSSPPSS\") == 0\n assert candidate(corridor = \"PSSPSPS... | [
"\"SSPPSPS\"",
"\"PPSPSP\"",
"\"S\""
] | [
"Divide the corridor into segments. Each segment has two seats, starts precisely with one seat, and ends precisely with the other seat.",
"How many dividers can you install between two adjacent segments? You must install precisely one. Otherwise, you would have created a section with not exactly two seats.",
"I... | {
"canonical_parameter_names": [
"corridor"
],
"leetcode_dataset_entry_point": "Solution().numberOfWays",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:49",
"tests_total": 145,
"test... | cpp | {
"raw_signature": "int numberOfWays(string corridor) {",
"container": "Solution",
"callable": "numberOfWays",
"parameters": [
{
"name": "corridor",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,148 | count-elements-with-strictly-smaller-and-greater-elements | Easy | Given an integer array nums, return the number of elements that have both a strictly smaller and a strictly greater element appear in nums.
Example 1:
Input: nums = [11,7,2,15]
Output: 2
Explanation: The element 7 has the element 2 strictly smaller than it and the element 11 strictly greater than it.
Element 11 has e... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 4\n assert candidate(nums = [-100000, 100000]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 8\n assert candidate(nums = [100000, -100000, 0, 1, 2]) == 3\n assert candi... | [
"[11,7,2,15]",
"[-3,3,3,90]"
] | [
"All the elements in the array should be counted except for the minimum and maximum elements.",
"If the array has n elements, the answer will be n - count(min(nums)) - count(max(nums))",
"This formula will not work in case the array has all the elements equal, why?"
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().countElements",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:51",
"tests_total": 120,
"tests_d... | cpp | {
"raw_signature": "int countElements(vector<int>& nums) {",
"container": "Solution",
"callable": "countElements",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,149 | rearrange-array-elements-by-sign | Medium | You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers.
You should return the array of nums such that the array follows the given conditions:
1. Every consecutive pair of integers have opposite signs.
2. For all integers with the same sign, the orde... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 2, -3, -1, 5, -6]) == [4, -3, 2, -1, 5, -6]\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == [1, -1, 2, -2, 3, -3]\n assert candidate(nums = [4, -3, 2, -5, 6, -7]) == [4, -3, 2, -5, 6, -7]\n assert candidate(nums =... | [
"[3,1,-2,-5,2,-4]",
"[-1,1]"
] | [
"Divide the array into two parts- one comprising of only positive integers and the other of negative integers.",
"Merge the two parts to get the resultant array."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().rearrangeArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:53",
"tests_total": 99,
"tests_d... | cpp | {
"raw_signature": "vector<int> rearrangeArray(vector<int>& nums) {",
"container": "Solution",
"callable": "rearrangeArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetco... |
2,150 | find-all-lonely-numbers-in-the-array | Medium | You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.
Return all lonely numbers in nums. You may return the answer in any order.
Example 1:
Input: nums = [10,6,5,8]
Output: [10,8]
Explanation:
- 10 is a lonely number s... | {
"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 ... | [
"[10,6,5,8]",
"[1,3,5,3]"
] | [
"For a given element x, how can you quickly check if x - 1 and x + 1 are present in the array without reiterating through the entire array?",
"Use a set or a hash map."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().findLonely",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:55",
"tests_total": 148,
"tests_drop... | cpp | {
"raw_signature": "vector<int> findLonely(vector<int>& nums) {",
"container": "Solution",
"callable": "findLonely",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeS... |
2,151 | maximum-good-people-based-on-statements | Hard | There are two types of persons:
- The good person: The person who always tells the truth.
- The bad person: The person who might tell the truth and might lie.
You are given a 0-indexed 2D integer array statements of size n x n that represents the statements made by n people about each other. More specifically, statem... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(statements = [[2, 1, 2], [1, 2, 2], [2, 0, 2]]) == 2\n assert candidate(statements = [[2, 1, 0, 2], [1, 2, 2, 0], [0, 2, 2, 1], [2, 0, 1, 2]]) == 2\n assert candidate(statements = [[2, 2], [2, 2]]) == 2\n assert candidate(statem... | [
"[[2,1,2],[1,2,2],[2,0,2]]",
"[[2,0],[0,2]]"
] | [
"You should test every possible assignment of good and bad people, using a bitmask.",
"In each bitmask, if the person i is good, then his statements should be consistent with the bitmask in order for the assignment to be valid.",
"If the assignment is valid, count how many people are good and keep track of the ... | {
"canonical_parameter_names": [
"statements"
],
"leetcode_dataset_entry_point": "Solution().maximumGood",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:42:58",
"tests_total": 75,
"test... | cpp | {
"raw_signature": "int maximumGood(vector<vector<int>>& statements) {",
"container": "Solution",
"callable": "maximumGood",
"parameters": [
{
"name": "statements",
"type": "vector<vector<int>>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "... |
2,154 | keep-multiplying-found-values-by-two | Easy | You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.
You then do the following steps:
1. If original is found in nums, multiply it by two (i.e., set original = 2 * original).
2. Otherwise, stop the process.
3. Repeat this proc... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],original = 5) == 5\n assert candidate(nums = [1000, 500, 250, 125, 625],original = 5) == 5\n assert candidate(nums = [3, 6, 9, 12, 15],original = 3) == 24\n assert candidate(nums = [1, 2, 4, 8],origin... | [
"[5,3,6,1,12]\n3",
"[2,7,9]\n4"
] | [
"Repeatedly iterate through the array and check if the current value of original is in the array.",
"If original is not found, stop and return its current value.",
"Otherwise, multiply original by 2 and repeat the process.",
"Use set data structure to check the existence faster."
] | {
"canonical_parameter_names": [
"nums",
"original"
],
"leetcode_dataset_entry_point": "Solution().findFinalValue",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:02",
"tests_total"... | cpp | {
"raw_signature": "int findFinalValue(vector<int>& nums, int original) {",
"container": "Solution",
"callable": "findFinalValue",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "original",
"type": "int"
}
],
"return_type": "int",
"signature_s... |
2,155 | all-divisions-with-the-highest-score-of-a-binary-array | Medium | You are given a 0-indexed binary array nums of length n. nums can be divided at index i (where 0 <= i <= n) into two arrays (possibly empty) nums_left and nums_right:
- nums_left has all the elements of nums between index 0 and i - 1 (inclusive), while nums_right has all the elements of nums between index i and n - 1 ... | {
"language": "python",
"source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ... | [
"[0,0,1,0]",
"[0,0,0]",
"[1,1]"
] | [
"When you iterate the array, maintain the number of zeros and ones on the left side. Can you quickly calculate the number of ones on the right side?",
"The number of ones on the right side equals the number of ones in the whole array minus the number of ones on the left side.",
"Alternatively, you can quickly c... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().maxScoreIndices",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:05",
"tests_total": 98,
"tests_... | cpp | {
"raw_signature": "vector<int> maxScoreIndices(vector<int>& nums) {",
"container": "Solution",
"callable": "maxScoreIndices",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leet... |
2,156 | find-substring-with-given-hash-value | Hard | The hash of a 0-indexed string s of length k, given integers p and m, is computed using the following function:
- hash(s, p, m) = (val(s[0]) * p^0 + val(s[1]) * p^1 + ... + val(s[k-1]) * p^{k-1}) mod m.
Where val(s[i]) represents the index of s[i] in the alphabet from val('a') = 1 to val('z') = 26.
You are given a s... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abracadabra\",power = 5,modulo = 11,k = 3,hashValue = 4) == \"dab\"\n assert candidate(s = \"leetcode\",power = 7,modulo = 20,k = 2,hashValue = 0) == \"ee\"\n assert candidate(s = \"fbxzaad\",power = 31,modulo = 100,k = 3,has... | [
"\"leetcode\"\n7\n20\n2\n0",
"\"fbxzaad\"\n31\n100\n3\n32"
] | [
"How can we update the hash value efficiently while iterating instead of recalculating it each time?",
"Use the rolling hash method."
] | {
"canonical_parameter_names": [
"s",
"power",
"modulo",
"k",
"hashValue"
],
"leetcode_dataset_entry_point": "Solution().subStrHash",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09... | cpp | {
"raw_signature": "string subStrHash(string s, int power, int modulo, int k, int hashValue) {",
"container": "Solution",
"callable": "subStrHash",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "power",
"type": "int"
},
{
"name": "modulo",
"... |
2,157 | groups-of-strings | Hard | You are given a 0-indexed array of strings words. Each string consists of lowercase English letters only. No letter occurs more than once in any string of words.
Two strings s1 and s2 are said to be connected if the set of letters of s2 can be obtained from the set of letters of s1 by any one of the following operatio... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['abc', 'bcd', 'ace', 'bce']) == [1, 4]\n assert candidate(words = ['abcd', 'ac', 'ab', 'abc', 'a']) == [1, 5]\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abde', 'acde', 'bcde', 'abcde']) == [1, 7]\n assert cand... | [
"[\"a\",\"b\",\"ab\",\"cde\"]",
"[\"a\",\"ab\",\"abc\"]"
] | [
"Can we build a graph from words, where there exists an edge between nodes i and j if words[i] and words[j] are connected?",
"The problem now boils down to finding the total number of components and the size of the largest component in the graph.",
"How can we use bit masking to reduce the search space while ad... | {
"canonical_parameter_names": [
"words"
],
"leetcode_dataset_entry_point": "Solution().groupStrings",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:10",
"tests_total": 70,
"tests_dr... | cpp | {
"raw_signature": "vector<int> groupStrings(vector<string>& words) {",
"container": "Solution",
"callable": "groupStrings",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "le... |
2,160 | minimum-sum-of-four-digit-number-after-splitting-digits | Easy | You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits found in num must be used.
- For example, given num = 2932, you have the following digits: two 2's, one ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = 8765) == 125\n assert candidate(num = 2309) == 32\n assert candidate(num = 5678) == 125\n assert candidate(num = 1098) == 27\n assert candidate(num = 1111) == 22\n assert candidate(num = 3333) == 66\n assert candi... | [
"2932",
"4009"
] | [
"Notice that the most optimal way to obtain the minimum possible sum using 4 digits is by summing up two 2-digit numbers.",
"We can use the two smallest digits out of the four as the digits found in the tens place respectively.",
"Similarly, we use the final 2 larger digits as the digits found in the ones place... | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().minimumSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:14",
"tests_total": 83,
"tests_droppe... | cpp | {
"raw_signature": "int minimumSum(int num) {",
"container": "Solution",
"callable": "minimumSum",
"parameters": [
{
"name": "num",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,161 | partition-array-according-to-given-pivot | Medium | You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:
- Every element less than pivot appears before every element greater than pivot.
- Every element equal to pivot appears in between the elements less than and greater than pivot.
- The rel... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [0, 0, 1, 1, 0, 1, 0, 1, 0, 0],pivot = 0) == [0, 0, 0, 0, 0, 0, 1, 1, 1, 1]\n assert candidate(nums = [1, 1, 1, 1, 1],pivot = 1) == [1, 1, 1, 1, 1]\n assert candidate(nums = [0, 0, 1, 1, 0, 1, 0, 1, 0, 0],pivot = 1) == [0, 0... | [
"[9,12,5,10,14,3,10]\n10",
"[-3,4,3,2]\n2"
] | [
"Could you put the elements smaller than the pivot and greater than the pivot in a separate list as in the sequence that they occur?",
"With the separate lists generated, could you then generate the result?"
] | {
"canonical_parameter_names": [
"nums",
"pivot"
],
"leetcode_dataset_entry_point": "Solution().pivotArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:17",
"tests_total": 105,
... | cpp | {
"raw_signature": "vector<int> pivotArray(vector<int>& nums, int pivot) {",
"container": "Solution",
"callable": "pivotArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "pivot",
"type": "int"
}
],
"return_type": "vector<int>",
"signature... |
2,162 | minimum-cost-to-set-cooking-time | Medium | A generic microwave supports cooking times for:
- at least 1 second.
- at most 99 minutes and 99 seconds.
To set the cooking time, you push at most four digits. The microwave normalizes what you push as four digits by prepending zeroes. It interprets the first two digits as the minutes and the last two digits as the ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(startAt = 1,moveCost = 2,pushCost = 1,targetSeconds = 600) == 6\n assert candidate(startAt = 0,moveCost = 1,pushCost = 2,targetSeconds = 76) == 6\n assert candidate(startAt = 2,moveCost = 2,pushCost = 3,targetSeconds = 599) == 15\n... | [
"1\n2\n1\n600",
"0\n1\n2\n76"
] | [
"Define a separate function Cost(mm, ss) where 0 <= mm <= 99 and 0 <= ss <= 99. This function should calculate the cost of setting the cooking time to mm minutes and ss seconds",
"The range of the minutes is small (i.e., [0, 99]), how can you use that?",
"For every mm in [0, 99], calculate the needed ss to make... | {
"canonical_parameter_names": [
"startAt",
"moveCost",
"pushCost",
"targetSeconds"
],
"leetcode_dataset_entry_point": "Solution().minCostSetTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at"... | cpp | {
"raw_signature": "int minCostSetTime(int startAt, int moveCost, int pushCost, int targetSeconds) {",
"container": "Solution",
"callable": "minCostSetTime",
"parameters": [
{
"name": "startAt",
"type": "int"
},
{
"name": "moveCost",
"type": "int"
},
{
"name": "... |
2,163 | minimum-difference-in-sums-after-removal-of-elements | Hard | You are given a 0-indexed integer array nums consisting of 3 * n elements.
You are allowed to remove any subsequence of elements of size exactly n from nums. The remaining 2 * n elements will be divided into two equal parts:
- The first n elements belonging to the first part and their sum is sum_first.
- The next n e... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == -80\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == -180\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2]) == 0\n ... | [
"[3,1,2]",
"[7,9,5,8,1,3]"
] | [
"The lowest possible difference can be obtained when the sum of the first n elements in the resultant array is minimum, and the sum of the next n elements is maximum.",
"For every index i, think about how you can find the minimum possible sum of n elements with indices lesser or equal to i, if possible.",
"Simi... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minimumDifference",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:22",
"tests_total": 117,
"tes... | cpp | {
"raw_signature": "long long minimumDifference(vector<int>& nums) {",
"container": "Solution",
"callable": "minimumDifference",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leet... |
2,164 | sort-even-and-odd-indices-independently | Easy | You are given a 0-indexed integer array nums. Rearrange the values of nums according to the following rules:
1. Sort the values at odd indices of nums in non-increasing order.
- For example, if nums = [4,1,2,3] before this step, it becomes [4,3,2,1] after. The values at odd indices 1 and 3 are sorted in non-increasi... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1]) == [1]\n assert candidate(nums = [100, 99, 98, 97, 96, 95]) == [96, 99, 98, 97, 100, 95]\n assert candidate(nums = [1, 3, 2, 2, 3, 1]) == [1, 3, 2, 2, 3, 1]\n assert candidate(nums = [1, 9, 3, 7, 5, 6, 2, 8, 4]) == [... | [
"[4,1,2,3]",
"[2,1]"
] | [
"Try to separate the elements at odd indices from the elements at even indices.",
"Sort the two groups of elements individually.",
"Combine them to form the resultant array."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().sortEvenOdd",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:24",
"tests_total": 107,
"tests_dro... | cpp | {
"raw_signature": "vector<int> sortEvenOdd(vector<int>& nums) {",
"container": "Solution",
"callable": "sortEvenOdd",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/cod... |
2,165 | smallest-value-of-the-rearranged-number | Medium | You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.
Return the rearranged number with minimal value.
Note that the sign of the number does not change after rearranging the digits.
Example 1:
Input: num = 310
Output: 103
Explanation: T... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = 2020) == 2002\n assert candidate(num = 10) == 10\n assert candidate(num = -10000000000) == -10000000000\n assert candidate(num = 10000000000) == 10000000000\n assert candidate(num = 10001) == 10001\n assert candidate... | [
"310",
"-7605"
] | [
"For positive numbers, the leading digit should be the smallest nonzero digit. Then the remaining digits follow in ascending order.",
"For negative numbers, the digits should be arranged in descending order."
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().smallestNumber",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:26",
"tests_total": 121,
"tests_d... | cpp | {
"raw_signature": "long long smallestNumber(long long num) {",
"container": "Solution",
"callable": "smallestNumber",
"parameters": [
{
"name": "num",
"type": "long long"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnipp... |
2,167 | minimum-time-to-remove-all-cars-containing-illegal-goods | Hard | You are given a 0-indexed binary string s which represents a sequence of train cars. s[i] = '0' denotes that the i^th car does not contain illegal goods and s[i] = '1' denotes that the i^th car does contain illegal goods.
As the train conductor, you would like to get rid of all the cars containing illegal goods. You c... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"100100100100\") == 7\n assert candidate(s = \"110110110110110110110110110110110110110110110110\") == 47\n assert candidate(s = \"1100101\") == 5\n assert candidate(s = \"1001001001\") == 6\n assert candidate(s = \"11111... | [
"\"1100101\"",
"\"0010\""
] | [
"Build an array withoutFirst where withoutFirst[i] stores the minimum time to remove all the cars containing illegal goods from the ‘suffix’ of the sequence starting from the ith car without using any type 1 operations.",
"Next, build an array onlyFirst where onlyFirst[i] stores the minimum time to remove all the... | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().minimumTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:28",
"tests_total": 101,
"tests_droppe... | cpp | {
"raw_signature": "int minimumTime(string s) {",
"container": "Solution",
"callable": "minimumTime",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,169 | count-operations-to-obtain-zero | Easy | You are given two non-negative integers num1 and num2.
In one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.
- For example, if num1 = 5 and num2 = 4, subtract num2 from num1, thus obtaining num1 = 1 and num2 = 4. However, if num1 = 4 and num2 = 5, after one operation,... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num1 = 0,num2 = 5) == 0\n assert candidate(num1 = 100,num2 = 1) == 100\n assert candidate(num1 = 123,num2 = 456) == 12\n assert candidate(num1 = 8,num2 = 12) == 3\n assert candidate(num1 = 1,num2 = 1) == 1\n assert candida... | [
"2\n3",
"10\n10"
] | [
"Try simulating the process until either of the two integers is zero.",
"Count the number of operations done."
] | {
"canonical_parameter_names": [
"num1",
"num2"
],
"leetcode_dataset_entry_point": "Solution().countOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:33",
"tests_total": 7... | cpp | {
"raw_signature": "int countOperations(int num1, int num2) {",
"container": "Solution",
"callable": "countOperations",
"parameters": [
{
"name": "num1",
"type": "int"
},
{
"name": "num2",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSn... |
2,170 | minimum-operations-to-make-the-array-alternating | Medium | You are given a 0-indexed array nums consisting of n positive integers.
The array nums is called alternating if:
- nums[i - 2] == nums[i], where 2 <= i <= n - 1.
- nums[i - 1] != nums[i], where 1 <= i <= n - 1.
In one operation, you can choose an index i and change nums[i] into any positive integer.
Return the mini... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == 4\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5]) == 0\n assert candidate(nums = [2, 2, 2, 2, 2, 1]) == 2\n assert candidate(nums = [1, 3, 1, 3, 2, 3, 1, 3, 1, 3]) == 1\n asser... | [
"[3,1,3,2,4,3]",
"[1,2,2,2,2]"
] | [
"Count the frequency of each element in odd positions in the array. Do the same for elements in even positions.",
"To minimize the number of operations we need to maximize the number of elements we keep from the original array.",
"What are the possible combinations of elements we can choose from odd indices and... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().minimumOperations",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:35",
"tests_total": 135,
"tes... | cpp | {
"raw_signature": "int minimumOperations(vector<int>& nums) {",
"container": "Solution",
"callable": "minimumOperations",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSni... |
2,171 | removing-minimum-number-of-magic-beans | Medium | You are given an array of positive integers beans, where each integer represents the number of magic beans found in a particular magic bag.
Remove any number of beans (possibly none) from each bag such that the number of beans in each remaining non-empty bag (still containing at least one bean) is equal. Once a bean h... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(beans = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(beans = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 25\n assert candidate(beans = [4, 1, 6, 5]) == 4\n assert candidate(beans = [5, 5, 5, 5]) == 0\n assert candidate(bea... | [
"[4,1,6,5]",
"[2,10,3,2]"
] | [
"Notice that if we choose to make x bags of beans empty, we should choose the x bags with the least amount of beans.",
"Notice that if the minimum number of beans in a non-empty bag is m, then the best way to make all bags have an equal amount of beans is to reduce all the bags to have m beans.",
"Can we iterat... | {
"canonical_parameter_names": [
"beans"
],
"leetcode_dataset_entry_point": "Solution().minimumRemoval",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:38",
"tests_total": 107,
"tests... | cpp | {
"raw_signature": "long long minimumRemoval(vector<int>& beans) {",
"container": "Solution",
"callable": "minimumRemoval",
"parameters": [
{
"name": "beans",
"type": "vector<int>&"
}
],
"return_type": "long long",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode... |
2,172 | maximum-and-sum-of-array | Hard | You are given an integer array nums of length n and an integer numSlots such that 2 * numSlots >= n. There are numSlots slots numbered from 1 to numSlots.
You have to place all n integers into the slots such that each slot contains at most two numbers. The AND sum of a given placement is the sum of the bitwise AND of ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 1, 1],numSlots = 2) == 2\n assert candidate(nums = [1, 2, 3],numSlots = 2) == 5\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15],numSlots = 8) == 52\n assert candidate(nums = [15, 15, 15],numSlots = 2) == 5\... | [
"[1,2,3,4,5,6]\n3",
"[1,3,10,4,7,1]\n9"
] | [
"Can you think of a dynamic programming solution to this problem?",
"Can you use a bitmask to represent the state of the slots?"
] | {
"canonical_parameter_names": [
"nums",
"numSlots"
],
"leetcode_dataset_entry_point": "Solution().maximumANDSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:40",
"tests_total":... | cpp | {
"raw_signature": "int maximumANDSum(vector<int>& nums, int numSlots) {",
"container": "Solution",
"callable": "maximumANDSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "numSlots",
"type": "int"
}
],
"return_type": "int",
"signature_sou... |
2,176 | count-equal-and-divisible-pairs-in-an-array | Easy | Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) where 0 <= i < j < n, such that nums[i] == nums[j] and (i * j) is divisible by k.
Example 1:
Input: nums = [3,1,2,2,2,1,3], k = 2
Output: 4
Explanation:
There are 4 pairs that meet all the requirements:
- nums[0] == n... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 0\n assert candidate(nums = [6, 6, 6, 6],k = 2) == 5\n assert candidate(nums = [3, 1, 2, 2, 2, 1, 3],k = 2) == 4\n assert... | [
"[3,1,2,2,2,1,3]\n2",
"[1,2,3,4]\n1"
] | [
"For every possible pair of indices (i, j) where i < j, check if it satisfies the given conditions."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().countPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:45",
"tests_total": 89,
"te... | cpp | {
"raw_signature": "int countPairs(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "countPairs",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/code... |
2,177 | find-three-consecutive-integers-that-sum-to-a-given-number | Medium | Given an integer num, return three consecutive integers (as a sorted array) that sum to num. If num cannot be expressed as the sum of three consecutive integers, return an empty array.
Example 1:
Input: num = 33
Output: [10,11,12]
Explanation: 33 can be expressed as 10 + 11 + 12 = 33.
10, 11, 12 are 3 consecutive int... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = 9) == [2, 3, 4]\n assert candidate(num = 1000000000001) == []\n assert candidate(num = 0) == [-1, 0, 1]\n assert candidate(num = 4) == []\n assert candidate(num = 33) == [10, 11, 12]\n assert candidate(num = 10000000... | [
"33",
"4"
] | [
"Notice that if a solution exists, we can represent them as x-1, x, x+1. What does this tell us about the number?",
"Notice the sum of the numbers will be 3x. Can you solve for x?"
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().sumOfThree",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:47",
"tests_total": 52,
"tests_droppe... | cpp | {
"raw_signature": "vector<long long> sumOfThree(long long num) {",
"container": "Solution",
"callable": "sumOfThree",
"parameters": [
{
"name": "num",
"type": "long long"
}
],
"return_type": "vector<long long>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/c... |
2,178 | maximum-split-of-positive-even-integers | Medium | You are given an integer finalSum. Split it into a sum of a maximum number of unique positive even integers.
- For example, given finalSum = 12, the following splits are valid (unique positive even integers summing up to finalSum): (12), (2 + 10), (2 + 4 + 6), and (4 + 8). Among them, (2 + 4 + 6) contains the maximum ... | {
"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 ... | [
"12",
"7",
"28"
] | [
"First, check if finalSum is divisible by 2. If it isn’t, then we cannot split it into even integers.",
"Let k be the number of elements in our split. As we want the maximum number of elements, we should try to use the first k - 1 even elements to grow our sum as slowly as possible.",
"Thus, we find the maximum... | {
"canonical_parameter_names": [
"finalSum"
],
"leetcode_dataset_entry_point": "Solution().maximumEvenSplit",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:49",
"tests_total": 50,
"t... | cpp | {
"raw_signature": "vector<long long> maximumEvenSplit(long long finalSum) {",
"container": "Solution",
"callable": "maximumEvenSplit",
"parameters": [
{
"name": "finalSum",
"type": "long long"
}
],
"return_type": "vector<long long>",
"signature_source": "leetcode/codeSnippets",
"typ... |
2,179 | count-good-triplets-in-an-array | Hard | You are given two 0-indexed arrays nums1 and nums2 of length n, both of which are permutations of [0, 1, ..., n - 1].
A good triplet is a set of 3 distinct values which are present in increasing order by position both in nums1 and nums2. In other words, if we consider pos1_v as the index of the value v in nums1 and po... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 0]) == 0\n assert candidate(nums1 = [0, 1, 2, 3],nums2 = [3, 2, 1, 0]) == 0\n assert candidate(nums1 = [1, 0, 3, 2],nums2 = [2, 3, 0, 1]) == 0\n assert candidate(nums1 = [2, 0, ... | [
"[2,0,1,3]\n[0,1,2,3]",
"[4,0,1,3,2]\n[4,1,0,2,3]"
] | [
"For every value y, how can you find the number of values x (0 ≤ x, y ≤ n - 1) such that x appears before y in both of the arrays?",
"Similarly, for every value y, try finding the number of values z (0 ≤ y, z ≤ n - 1) such that z appears after y in both of the arrays.",
"Now, for every value y, count the number... | {
"canonical_parameter_names": [
"nums1",
"nums2"
],
"leetcode_dataset_entry_point": "Solution().goodTriplets",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:51",
"tests_total": 10... | cpp | {
"raw_signature": "long long goodTriplets(vector<int>& nums1, vector<int>& nums2) {",
"container": "Solution",
"callable": "goodTriplets",
"parameters": [
{
"name": "nums1",
"type": "vector<int>&"
},
{
"name": "nums2",
"type": "vector<int>&"
}
],
"return_type": "long... |
2,180 | count-integers-with-even-digit-sum | Easy | Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even.
The digit sum of a positive integer is the sum of all its digits.
Example 1:
Input: num = 4
Output: 2
Explanation:
The only integers less than or equal to 4 whose digit sums are even are 2 and 4.... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(num = 30) == 14\n assert candidate(num = 10) == 4\n assert candidate(num = 999) == 499\n assert candidate(num = 500) == 249\n assert candidate(num = 4) == 2\n assert candidate(num = 2) == 1\n assert candidate(num = 1) =... | [
"4",
"30"
] | [
"Iterate through all integers from 1 to num.",
"For any integer, extract the individual digits to compute their sum and check if it is even."
] | {
"canonical_parameter_names": [
"num"
],
"leetcode_dataset_entry_point": "Solution().countEven",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:54",
"tests_total": 34,
"tests_dropped... | cpp | {
"raw_signature": "int countEven(int num) {",
"container": "Solution",
"callable": "countEven",
"parameters": [
{
"name": "num",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,182 | construct-string-with-repeat-limit | Medium | You are given a string s and an integer repeatLimit. Construct a new string repeatLimitedString using the characters of s such that no letter appears more than repeatLimit times in a row. You do not have to use all characters from s.
Return the lexicographically largest repeatLimitedString possible.
A string a is lex... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aabbccddeeff\",repeatLimit = 1) == \"fefedcdcbaba\"\n assert candidate(s = \"aabbccddeeff\",repeatLimit = 3) == \"ffeeddccbbaa\"\n assert candidate(s = \"cczazcc\",repeatLimit = 3) == \"zzcccac\"\n assert candidate(s = \"z... | [
"\"cczazcc\"\n3",
"\"aababab\"\n2"
] | [
"Start constructing the string in descending order of characters.",
"When repeatLimit is reached, pick the next largest character."
] | {
"canonical_parameter_names": [
"s",
"repeatLimit"
],
"leetcode_dataset_entry_point": "Solution().repeatLimitedString",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:43:59",
"tests_t... | cpp | {
"raw_signature": "string repeatLimitedString(string s, int repeatLimit) {",
"container": "Solution",
"callable": "repeatLimitedString",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "repeatLimit",
"type": "int"
}
],
"return_type": "string",
"signatu... |
2,183 | count-array-pairs-divisible-by-k | Hard | Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) such that:
- 0 <= i < j <= n - 1 and
- nums[i] * nums[j] is divisible by k.
Example 1:
Input: nums = [1,2,3,4,5], k = 2
Output: 7
Explanation:
The 7 pairs of indices whose corresponding products are divisible by 2 ar... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7],k = 7) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 10\n assert candidate(nums = [5, 5, 5, 5],k = 5) == 6\n assert candidate(nums = [1, 2, 3, 4, 5],k = 2) == 7\n assert candidate(nums... | [
"[1,2,3,4,5]\n2",
"[1,2,3,4]\n5"
] | [
"For any element in the array, what is the smallest number it should be multiplied with such that the product is divisible by k?",
"The smallest number which should be multiplied with nums[i] so that the product is divisible by k is k / gcd(k, nums[i]). Now think about how you can store and update the count of su... | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().countPairs",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:01",
"tests_total": 102,
"t... | cpp | {
"raw_signature": "long long countPairs(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "countPairs",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "long long",
"signature_source": "l... |
2,185 | counting-words-with-a-given-prefix | Easy | You are given an array of strings words and a string pref.
Return the number of strings in words that contain pref as a prefix.
A prefix of a string s is any leading contiguous substring of s.
Example 1:
Input: words = ["pay","attention","practice","attend"], pref = "at"
Output: 2
Explanation: The 2 strings that co... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(words = ['test', 'testing', 'tested', 'testing'],pref = \"test\") == 4\n assert candidate(words = ['abc', 'bcd', 'cde'],pref = \"a\") == 1\n assert candidate(words = ['hello', 'world', 'helium', 'helper'],pref = \"hel\") == 3\n ... | [
"[\"pay\",\"attention\",\"practice\",\"attend\"]\n\"at\"",
"[\"leetcode\",\"win\",\"loops\",\"success\"]\n\"code\""
] | [
"Go through each word in words and increment the answer if pref is a prefix of the word."
] | {
"canonical_parameter_names": [
"words",
"pref"
],
"leetcode_dataset_entry_point": "Solution().prefixCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:06",
"tests_total": 153,... | cpp | {
"raw_signature": "int prefixCount(vector<string>& words, string pref) {",
"container": "Solution",
"callable": "prefixCount",
"parameters": [
{
"name": "words",
"type": "vector<string>&"
},
{
"name": "pref",
"type": "string"
}
],
"return_type": "int",
"signature_s... |
2,186 | minimum-number-of-steps-to-make-two-strings-anagram-ii | Medium | You are given two strings s and t. In one step, you can append any character to either s or t.
Return the minimum number of steps to make s and t anagrams of each other.
An anagram of a string is a string that contains the same characters with a different (or the same) ordering.
Example 1:
Input: s = "leetcode", t ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"aaaa\",t = \"bbbb\") == 8\n assert candidate(s = \"aabbcc\",t = \"abc\") == 3\n assert candidate(s = \"anagram\",t = \"nagaram\") == 0\n assert candidate(s = \"rat\",t = \"car\") == 2\n assert candidate(s = \"xyz\",t = ... | [
"\"leetcode\"\n\"coats\"",
"\"night\"\n\"thing\""
] | [
"Notice that for anagrams, the order of the letters is irrelevant.",
"For each letter, we can count its frequency in s and t.",
"For each letter, its contribution to the answer is the absolute difference between its frequency in s and t."
] | {
"canonical_parameter_names": [
"s",
"t"
],
"leetcode_dataset_entry_point": "Solution().minSteps",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:09",
"tests_total": 110,
"tests_... | cpp | {
"raw_signature": "int minSteps(string s, string t) {",
"container": "Solution",
"callable": "minSteps",
"parameters": [
{
"name": "s",
"type": "string"
},
{
"name": "t",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"ty... |
2,187 | minimum-time-to-complete-trips | Medium | You are given an array time where time[i] denotes the time taken by the i^th bus to complete one trip.
Each bus can make multiple trips successively; that is, the next trip can start immediately after completing the current trip. Also, each bus operates independently; that is, the trips of one bus do not influence the... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(time = [1, 2, 3],totalTrips = 5) == 3\n assert candidate(time = [10000000],totalTrips = 10000000) == 100000000000000\n assert candidate(time = [10, 20, 30],totalTrips = 100) == 550\n assert candidate(time = [1, 1, 1, 1, 1],total... | [
"[1,2,3]\n5",
"[2]\n1"
] | [
"For a given amount of time, how can we count the total number of trips completed by all buses within that time?",
"Consider using binary search."
] | {
"canonical_parameter_names": [
"time",
"totalTrips"
],
"leetcode_dataset_entry_point": "Solution().minimumTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:12",
"tests_total":... | cpp | {
"raw_signature": "long long minimumTime(vector<int>& time, int totalTrips) {",
"container": "Solution",
"callable": "minimumTime",
"parameters": [
{
"name": "time",
"type": "vector<int>&"
},
{
"name": "totalTrips",
"type": "int"
}
],
"return_type": "long long",
"s... |
2,188 | minimum-time-to-finish-the-race | Hard | You are given a 0-indexed 2D integer array tires where tires[i] = [f_i, r_i] indicates that the i^th tire can finish its x^th successive lap in f_i * r_i^(x-1) seconds.
- For example, if f_i = 3 and r_i = 2, then the tire would finish its 1^st lap in 3 seconds, its 2^nd lap in 3 * 2 = 6 seconds, its 3^rd lap in 3 * 2^... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(tires = [[2, 3], [3, 4]],changeTime = 5,numLaps = 4) == 21\n assert candidate(tires = [[5, 2], [3, 3]],changeTime = 4,numLaps = 3) == 17\n assert candidate(tires = [[5, 5], [3, 3]],changeTime = 10,numLaps = 6) == 56\n assert can... | [
"[[2,3],[3,4]]\n5\n4",
"[[1,10],[2,2],[3,4]]\n6\n5"
] | [
"What is the maximum number of times we would want to go around the track without changing tires?",
"Can we precompute the minimum time to go around the track x times without changing tires?",
"Can we use dynamic programming to solve this efficiently using the precomputed values?"
] | {
"canonical_parameter_names": [
"tires",
"changeTime",
"numLaps"
],
"leetcode_dataset_entry_point": "Solution().minimumFinishTime",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44... | cpp | {
"raw_signature": "int minimumFinishTime(vector<vector<int>>& tires, int changeTime, int numLaps) {",
"container": "Solution",
"callable": "minimumFinishTime",
"parameters": [
{
"name": "tires",
"type": "vector<vector<int>>&"
},
{
"name": "changeTime",
"type": "int"
},
... |
2,190 | most-frequent-number-following-key-in-an-array | Easy | You are given a 0-indexed integer array nums. You are also given an integer key, which is present in nums.
For every unique integer target in nums, count the number of times target immediately follows an occurrence of key in nums. In other words, count the number of indices i such that:
- 0 <= i <= nums.length - 2,
-... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],key = 1) == 2\n assert candidate(nums = [1, 2, 2, 3, 2, 1, 2, 4],key = 2) == 2\n assert candidate(nums = [3, 1, 3, 1, 3, 1, 3, 1, 3, 2],key = 1) == 3\n assert candidate(nums = [10, 20, 20, 1... | [
"[1,100,200,1,100]\n1",
"[2,2,2,2,3]\n2"
] | [
"Count the number of times each target value follows the key in the array.",
"Choose the target with the maximum count and return it."
] | {
"canonical_parameter_names": [
"nums",
"key"
],
"leetcode_dataset_entry_point": "Solution().mostFrequent",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:19",
"tests_total": 103,
... | cpp | {
"raw_signature": "int mostFrequent(vector<int>& nums, int key) {",
"container": "Solution",
"callable": "mostFrequent",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "key",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetc... |
2,191 | sort-the-jumbled-numbers | Medium | You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.
The mapped value of an integer is the new integer obtained by replacing each occurrence of digit i in the integer with mapping[i] for ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(mapping = [5, 8, 9, 2, 1, 6, 7, 0, 3, 4],nums = [345, 123, 678]) == [345, 678, 123]\n assert candidate(mapping = [0, 9, 1, 8, 2, 7, 3, 6, 4, 5],nums = [10, 100, 1000, 10000]) == [10, 100, 1000, 10000]\n assert candidate(mapping = [... | [
"[8,9,4,0,2,1,3,5,7,6]\n[991,338,38]",
"[0,1,2,3,4,5,6,7,8,9]\n[789,456,123]"
] | [
"Map the original numbers to new numbers by the mapping rule and sort the new numbers.",
"To maintain the same relative order for equal mapped values, use the index in the original input array as a tiebreaker."
] | {
"canonical_parameter_names": [
"mapping",
"nums"
],
"leetcode_dataset_entry_point": "Solution().sortJumbled",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:21",
"tests_total": 11... | cpp | {
"raw_signature": "vector<int> sortJumbled(vector<int>& mapping, vector<int>& nums) {",
"container": "Solution",
"callable": "sortJumbled",
"parameters": [
{
"name": "mapping",
"type": "vector<int>&"
},
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "ve... |
2,192 | all-ancestors-of-a-node-in-a-directed-acyclic-graph | Medium | You are given a positive integer n representing the number of nodes of a Directed Acyclic Graph (DAG). The nodes are numbered from 0 to n - 1 (inclusive).
You are also given a 2D integer array edges, where edges[i] = [from_i, to_i] denotes that there is a unidirectional edge from from_i to to_i in the graph.
Return a... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 2], [2, 3], [1, 3], [4, 5]]) == [[], [], [0], [0, 1, 2], [], [4]]\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [2, 3]]) == [[], [0], [0, 1], [0, 1, 2]]\n assert candidate(n = 8,edges = [[0, 3], [0, 4], [1, 3... | [
"8\n[[0,3],[0,4],[1,3],[2,4],[2,7],[3,5],[3,6],[3,7],[4,6]]",
"5\n[[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]"
] | [
"Consider how reversing each edge of the graph can help us.",
"How can performing BFS/DFS on the reversed graph help us find the ancestors of every node?"
] | {
"canonical_parameter_names": [
"n",
"edges"
],
"leetcode_dataset_entry_point": "Solution().getAncestors",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:24",
"tests_total": 63,
... | cpp | {
"raw_signature": "vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {",
"container": "Solution",
"callable": "getAncestors",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
}
],
"return_type": "vect... |
2,193 | minimum-number-of-moves-to-make-palindrome | Hard | You are given a string s consisting only of lowercase English letters.
In one move, you can select any two adjacent characters of s and swap them.
Return the minimum number of moves needed to make s a palindrome.
Note that the input will be generated such that s can always be converted to a palindrome.
Example 1:
... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"abcba\") == 0\n assert candidate(s = \"letelt\") == 2\n assert candidate(s = \"abcdcba\") == 0\n assert candidate(s = \"aabbaa\") == 0\n assert candidate(s = \"abcdedcba\") == 0\n assert candidate(s = \"mamad\") == 3... | [
"\"aabb\"",
"\"letelt\""
] | [
"Consider a greedy strategy.",
"Let’s start by making the leftmost and rightmost characters match with some number of swaps.",
"If we figure out how to do that using the minimum number of swaps, then we can delete the leftmost and rightmost characters and solve the problem recursively."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().minMovesToMakePalindrome",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:26",
"tests_total": 105,
... | cpp | {
"raw_signature": "int minMovesToMakePalindrome(string s) {",
"container": "Solution",
"callable": "minMovesToMakePalindrome",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippet... |
2,194 | cells-in-a-range-on-an-excel-sheet | Easy | A cell (r, c) of an excel sheet is represented as a string "<col><row>" where:
- <col> denotes the column number c of the cell. It is represented by alphabetical letters.
- For example, the 1^st column is denoted by 'A', the 2^nd by 'B', the 3^rd by 'C', and so on.
- <row> is the row number r of the cell. The r^th r... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(s = \"D4:H6\") == ['D4', 'D5', 'D6', 'E4', 'E5', 'E6', 'F4', 'F5', 'F6', 'G4', 'G5', 'G6', 'H4', 'H5', 'H6']\n assert candidate(s = \"K1:L2\") == ['K1', 'K2', 'L1', 'L2']\n assert candidate(s = \"A1:F1\") == ['A1', 'B1', 'C1', 'D1'... | [
"\"K1:L2\"",
"\"A1:F1\""
] | [
"From the given string, find the corresponding rows and columns.",
"Iterate through the columns in ascending order and for each column, iterate through the rows in ascending order to obtain the required cells in sorted order."
] | {
"canonical_parameter_names": [
"s"
],
"leetcode_dataset_entry_point": "Solution().cellsInRange",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:28",
"tests_total": 175,
"tests_dropp... | cpp | {
"raw_signature": "vector<string> cellsInRange(string s) {",
"container": "Solution",
"callable": "cellsInRange",
"parameters": [
{
"name": "s",
"type": "string"
}
],
"return_type": "vector<string>",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"... |
2,195 | append-k-integers-with-minimal-sum | Medium | You are given an integer array nums and an integer k. Append k unique positive integers that do not appear in nums to nums such that the resulting total sum is minimum.
Return the sum of the k integers appended to nums.
Example 1:
Input: nums = [1,4,25,10,25], k = 2
Output: 5
Explanation: The two unique positive int... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 21\n assert candidate(nums = [1, 4, 25, 10, 25],k = 2) == 5\n assert candidate(nums = [1000000000],k = 100000) == 5000050000\n assert candidate(nums = [1000000000],k = 1) == 1\n assert candida... | [
"[1,4,25,10,25]\n2",
"[5,6]\n6"
] | [
"The k smallest numbers that do not appear in nums will result in the minimum sum.",
"Recall that the sum of the first n positive numbers is equal to n * (n+1) / 2.",
"Initialize the answer as the sum of 1 to k. Then, adjust the answer depending on the values in nums."
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().minimalKSum",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:30",
"tests_total": 111,
"... | cpp | {
"raw_signature": "long long minimalKSum(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "minimalKSum",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "long long",
"signature_source": ... |
2,197 | replace-non-coprime-numbers-in-array | Hard | You are given an array of integers nums. Perform the following steps:
1. Find any two adjacent numbers in nums that are non-coprime.
2. If no such numbers are found, stop the process.
3. Otherwise, delete the two numbers and replace them with their LCM (Least Common Multiple).
4. Repeat this process as long as you kee... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 6, 8, 10, 12]) == [120]\n assert candidate(nums = [100000, 100000, 100000, 100000]) == [100000]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [... | [
"[6,4,3,2,7,6,2]",
"[2,2,1,1,3,3,3]"
] | [
"Notice that the order of merging two numbers into their LCM does not matter so we can greedily merge elements to its left if possible.",
"If a new value is formed, we should recursively check if it can be merged with the value to its left.",
"To simulate the merge efficiently, we can maintain a stack that stor... | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().replaceNonCoprimes",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:36",
"tests_total": 134,
"te... | cpp | {
"raw_signature": "vector<int> replaceNonCoprimes(vector<int>& nums) {",
"container": "Solution",
"callable": "replaceNonCoprimes",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "vector<int>",
"signature_source": "leetcode/codeSnippets",
"type_source":... |
2,200 | find-all-k-distant-indices-in-an-array | Easy | You are given a 0-indexed integer array nums and two integers key and k. A k-distant index is an index i of nums for which there exists at least one index j such that |i - j| <= k and nums[j] == key.
Return a list of all k-distant indices sorted in increasing order.
Example 1:
Input: nums = [3,4,9,1,3,9,5], key = 9,... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [5, 1, 4, 1, 5],key = 5,k = 2) == [0, 1, 2, 3, 4]\n assert candidate(nums = [1, 1, 1, 1, 1, 1],key = 1,k = 3) == [0, 1, 2, 3, 4, 5]\n assert candidate(nums = [1, 3, 5, 7, 9],key = 3,k = 2) == [0, 1, 2, 3]\n assert candida... | [
"[3,4,9,1,3,9,5]\n9\n1",
"[2,2,2,2,2]\n2\n2"
] | [
"For every occurrence of key in nums, find all indices within distance k from it.",
"Use a hash table to remove duplicate indices."
] | {
"canonical_parameter_names": [
"nums",
"key",
"k"
],
"leetcode_dataset_entry_point": "Solution().findKDistantIndices",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:40",
"tes... | cpp | {
"raw_signature": "vector<int> findKDistantIndices(vector<int>& nums, int key, int k) {",
"container": "Solution",
"callable": "findKDistantIndices",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "key",
"type": "int"
},
{
"name": "k",
... |
2,201 | count-artifacts-that-can-be-extracted | Medium | There is an n x n 0-indexed grid with some artifacts buried in it. You are given the integer n and a 0-indexed 2D integer array artifacts describing the positions of the rectangular artifacts where artifacts[i] = [r1_i, c1_i, r2_i, c2_i] denotes that the i^th artifact is buried in the subgrid where:
- (r1_i, c1_i) is ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 4,artifacts = [[0, 0, 0, 0], [1, 1, 2, 2], [3, 3, 3, 3]],dig = [[0, 0], [1, 1], [2, 2], [3, 3]]) == 2\n assert candidate(n = 5,artifacts = [[0, 0, 0, 1], [1, 1, 2, 2], [3, 3, 4, 4]],dig = [[0, 0], [0, 1], [1, 1], [1, 2], [2, 1], [... | [
"2\n[[0,0,0,0],[0,1,1,1]]\n[[0,0],[0,1]]",
"2\n[[0,0,0,0],[0,1,1,1]]\n[[0,0],[0,1],[1,1]]"
] | [
"Check if each coordinate of each artifact has been excavated. How can we do this quickly without iterating over the dig array every time?",
"Consider marking all excavated cells in a 2D boolean array."
] | {
"canonical_parameter_names": [
"n",
"artifacts",
"dig"
],
"leetcode_dataset_entry_point": "Solution().digArtifacts",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:43",
"tests... | cpp | {
"raw_signature": "int digArtifacts(int n, vector<vector<int>>& artifacts, vector<vector<int>>& dig) {",
"container": "Solution",
"callable": "digArtifacts",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "artifacts",
"type": "vector<vector<int>>&"
},
{
... |
2,202 | maximize-the-topmost-element-after-k-moves | Medium | You are given a 0-indexed integer array nums representing the contents of a pile, where nums[0] is the topmost element of the pile.
In one move, you can perform either of the following:
- If the pile is not empty, remove the topmost element of the pile.
- If there are one or more removed elements, add any one of them... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7],k = 2) == 7\n assert candidate(nums = [9, 8, 7, 6, 5],k = 5) == 9\n assert candidate(nums = [10],k = 2) == 10\n assert candidate(nums = [8, 6, 4, 2, 0],k = 7) == 8\n assert candidate(nums = [7, 7, 7, 7,... | [
"[5,2,2,4,0,6]\n4",
"[2]\n1"
] | [
"For each index i, how can we check if nums[i] can be present at the top of the pile or not after k moves?",
"For which conditions will we end up with an empty pile?"
] | {
"canonical_parameter_names": [
"nums",
"k"
],
"leetcode_dataset_entry_point": "Solution().maximumTop",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:45",
"tests_total": 148,
"t... | cpp | {
"raw_signature": "int maximumTop(vector<int>& nums, int k) {",
"container": "Solution",
"callable": "maximumTop",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
},
{
"name": "k",
"type": "int"
}
],
"return_type": "int",
"signature_source": "leetcode/code... |
2,203 | minimum-weighted-subgraph-with-the-required-paths | Hard | You are given an integer n denoting the number of nodes of a weighted directed graph. The nodes are numbered from 0 to n - 1.
You are also given a 2D integer array edges where edges[i] = [from_i, to_i, weight_i] denotes that there exists a directed edge from from_i to to_i with weight weight_i.
Lastly, you are given ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 2, 2], [0, 5, 6], [1, 0, 3], [1, 4, 5], [2, 1, 1], [2, 3, 3], [2, 3, 4], [3, 4, 2], [4, 5, 1]],src1 = 0,src2 = 1,dest = 5) == 9\n assert candidate(n = 6,edges = [[1, 2, 2], [1, 3, 1], [2, 4, 5], [3, 4, 3], [4, 5, 2]... | [
"6\n[[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]]\n0\n1\n5",
"3\n[[0,1,1],[2,1,1]]\n0\n1\n2"
] | [
"Consider what the paths from src1 to dest and src2 to dest would look like in the optimal solution.",
"It can be shown that in an optimal solution, the two paths from src1 and src2 will coincide at one node, and the remaining part to dest will be the same for both paths. Now consider how to find the node where t... | {
"canonical_parameter_names": [
"n",
"edges",
"src1",
"src2",
"dest"
],
"leetcode_dataset_entry_point": "Solution().minimumWeight",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-... | cpp | {
"raw_signature": "long long minimumWeight(int n, vector<vector<int>>& edges, int src1, int src2, int dest) {",
"container": "Solution",
"callable": "minimumWeight",
"parameters": [
{
"name": "n",
"type": "int"
},
{
"name": "edges",
"type": "vector<vector<int>>&"
},
... |
2,206 | divide-array-into-equal-pairs | Easy | You are given an integer array nums consisting of 2 * n integers.
You need to divide nums into n pairs such that:
- Each element belongs to exactly one pair.
- The elements present in a pair are equal.
Return true if nums can be divided into n pairs, otherwise return false.
Example 1:
Input: nums = [3,2,3,2,2,2]
O... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4]) == True\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2]) == True\n assert candidate(nums = [1, 2, 1, 3, 2, 3]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == True\n assert c... | [
"[3,2,3,2,2,2]",
"[1,2,3,4]"
] | [
"For any number x in the range [1, 500], count the number of elements in nums whose values are equal to x.",
"The elements with equal value can be divided completely into pairs if and only if their count is even."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().divideArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:52",
"tests_total": 91,
"tests_drop... | cpp | {
"raw_signature": "bool divideArray(vector<int>& nums) {",
"container": "Solution",
"callable": "divideArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "bool",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
2,207 | maximize-number-of-subsequences-in-a-string | Medium | You are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters.
You can add either pattern[0] or pattern[1] anywhere in text exactly once. Note that the character can be added even at the beginning or at the end of text.
Return the maxim... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(text = \"bbbb\",pattern = \"bb\") == 10\n assert candidate(text = \"aaaaa\",pattern = \"aa\") == 15\n assert candidate(text = \"zzzz\",pattern = \"zz\") == 10\n assert candidate(text = \"abdcdbc\",pattern = \"ac\") == 4\n ass... | [
"\"abdcdbc\"\n\"ac\"",
"\"aabb\"\n\"ab\""
] | [
"Find the optimal position to add pattern[0] so that the number of subsequences is maximized. Similarly, find the optimal position to add pattern[1].",
"For each of the above cases, count the number of times the pattern occurs as a subsequence in text. The larger count is the required answer."
] | {
"canonical_parameter_names": [
"text",
"pattern"
],
"leetcode_dataset_entry_point": "Solution().maximumSubsequenceCount",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:55",
"test... | cpp | {
"raw_signature": "long long maximumSubsequenceCount(string text, string pattern) {",
"container": "Solution",
"callable": "maximumSubsequenceCount",
"parameters": [
{
"name": "text",
"type": "string"
},
{
"name": "pattern",
"type": "string"
}
],
"return_type": "long... |
2,208 | minimum-operations-to-halve-array-sum | Medium | You are given an array nums of positive integers. In one operation, you can choose any number from nums and reduce it to exactly half the number. (Note that you may choose this reduced number in future operations.)
Return the minimum number of operations to reduce the sum of nums by at least half.
Example 1:
Input: ... | {
"language": "python",
"source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [100, 100, 100, 100]) == 4\n assert candidate(nums = [3, 8, 20]) == 3\n assert candidate(nums = [10000000... | [
"[5,19,8,1]",
"[3,8,20]"
] | [
"It is always optimal to halve the largest element.",
"What data structure allows for an efficient query of the maximum element?",
"Use a heap or priority queue to maintain the current elements."
] | {
"canonical_parameter_names": [
"nums"
],
"leetcode_dataset_entry_point": "Solution().halveArray",
"problem_source": "newfacade/LeetCodeDataset",
"description_source": "leetcode.com",
"interface_source": "leetcode/codeSnippets",
"fetched_at": "2026-09-30T20:44:57",
"tests_total": 81,
"tests_dropp... | cpp | {
"raw_signature": "int halveArray(vector<int>& nums) {",
"container": "Solution",
"callable": "halveArray",
"parameters": [
{
"name": "nums",
"type": "vector<int>&"
}
],
"return_type": "int",
"signature_source": "leetcode/codeSnippets",
"type_source": "leetcode/codeSnippets"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.