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,209
minimum-white-tiles-after-covering-with-carpets
Hard
You are given a 0-indexed binary string floor, which represents the colors of tiles on a floor: - floor[i] = '0' denotes that the i^th tile of the floor is colored black. - On the other hand, floor[i] = '1' denotes that the i^th tile of the floor is colored white. You are also given numCarpets and carpetLen. You have...
{ "language": "python", "source": "def check(candidate):\n assert candidate(floor = \"111100001111\",numCarpets = 4,carpetLen = 4) == 0\n assert candidate(floor = \"110011\",numCarpets = 3,carpetLen = 2) == 0\n assert candidate(floor = \"11111\",numCarpets = 2,carpetLen = 3) == 0\n assert candidate(floo...
[ "\"10110101\"\n2\n2", "\"11111\"\n2\n3" ]
[ "Can you think of a DP solution?", "Let DP[i][j] denote the minimum number of white tiles still visible from indices i to floor.length-1 after covering with at most j carpets.", "The transition will be whether to put down the carpet at position i (if possible), or not." ]
{ "canonical_parameter_names": [ "floor", "numCarpets", "carpetLen" ], "leetcode_dataset_entry_point": "Solution().minimumWhiteTiles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:...
cpp
{ "raw_signature": "int minimumWhiteTiles(string floor, int numCarpets, int carpetLen) {", "container": "Solution", "callable": "minimumWhiteTiles", "parameters": [ { "name": "floor", "type": "string" }, { "name": "numCarpets", "type": "int" }, { "name": "carpet...
2,210
count-hills-and-valleys-in-an-array
Easy
You are given a 0-indexed integer array nums. An index i is part of a hill in nums if the closest non-equal neighbors of i are smaller than nums[i]. Similarly, an index i is part of a valley in nums if the closest non-equal neighbors of i are larger than nums[i]. Adjacent indices i and j are part of the same hill or va...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 0\n assert candidate(nums = [100, 99, 100, 98, 99, 100]) == 3\n assert candidate(nums =...
[ "[2,4,1,1,6,5]", "[6,6,5,5,4,1]" ]
[ "For each index, could you find the closest non-equal neighbors?", "Ensure that adjacent indices that are part of the same hill or valley are not double-counted." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countHillValley", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:01", "tests_total": 154, "tests...
cpp
{ "raw_signature": "int countHillValley(vector<int>& nums) {", "container": "Solution", "callable": "countHillValley", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
2,211
count-collisions-on-a-road
Medium
There are n cars on an infinitely long road. The cars are numbered from 0 to n - 1 from left to right and each car is present at a unique point. You are given a 0-indexed string directions of length n. directions[i] can be either 'L', 'R', or 'S' denoting whether the i^th car is moving towards the left, towards the ri...
{ "language": "python", "source": "def check(candidate):\n assert candidate(directions = \"SSRLSL\") == 3\n assert candidate(directions = \"LRLRLR\") == 4\n assert candidate(directions = \"RRRR\") == 0\n assert candidate(directions = \"LRRSLRLR\") == 5\n assert candidate(directions = \"LSRL\") == 2\n...
[ "\"RLRSLL\"", "\"LLRR\"" ]
[ "In what circumstances does a moving car not collide with another car?", "If we disregard the moving cars that do not collide with another car, what does each moving car contribute to the answer?", "Will stationary cars contribute towards the answer?" ]
{ "canonical_parameter_names": [ "directions" ], "leetcode_dataset_entry_point": "Solution().countCollisions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:04", "tests_total": 177, ...
cpp
{ "raw_signature": "int countCollisions(string directions) {", "container": "Solution", "callable": "countCollisions", "parameters": [ { "name": "directions", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
2,212
maximum-points-in-an-archery-competition
Medium
Alice and Bob are opponents in an archery competition. The competition has set the following rules: 1. Alice first shoots numArrows arrows and then Bob shoots numArrows arrows. 2. The points are then calculated as follows: 1. The target has integer scoring sections ranging from 0 to 11 inclusive. 2. For each secti...
{ "language": "python", "source": "def check(candidate):\n assert candidate(numArrows = 100000,aliceArrows = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == [9991, 0, 0, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001]\n assert candidate(numArrows = 5,ali...
[ "9\n[1,1,0,1,0,0,2,1,0,1,2,0]", "3\n[0,0,1,0,0,0,0,0,0,0,0,2]" ]
[ "To obtain points for some certain section x, what is the minimum number of arrows Bob must shoot?", "Given the small number of sections, can we brute force which sections Bob wants to win?", "For every set of sections Bob wants to win, check if we have the required amount of arrows. If we do, it is a valid sel...
{ "canonical_parameter_names": [ "numArrows", "aliceArrows" ], "leetcode_dataset_entry_point": "Solution().maximumBobPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:06", "te...
cpp
{ "raw_signature": "vector<int> maximumBobPoints(int numArrows, vector<int>& aliceArrows) {", "container": "Solution", "callable": "maximumBobPoints", "parameters": [ { "name": "numArrows", "type": "int" }, { "name": "aliceArrows", "type": "vector<int>&" } ], "return_...
2,213
longest-substring-of-one-repeating-character
Hard
You are given a 0-indexed string s. You are also given a 0-indexed string queryCharacters of length k and a 0-indexed array of integer indices queryIndices of length k, both of which are used to describe k queries. The i^th query updates the character in s at index queryIndices[i] to the character queryCharacters[i]. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcde\",queryCharacters = \"aaaaa\",queryIndices = [0, 1, 2, 3, 4]) == [1, 2, 3, 4, 5]\n assert candidate(s = \"abyzz\",queryCharacters = \"aa\",queryIndices = [2, 1]) == [2, 3]\n assert candidate(s = \"abcde\",queryCharacter...
[ "\"babacc\"\n\"bcb\"\n[1,3,3]", "\"abyzz\"\n\"aa\"\n[2,1]" ]
[ "Use a segment tree to perform fast point updates and range queries.", "We need each segment tree node to store the length of the longest substring of that segment consisting of only 1 repeating character.", "We will also have each segment tree node store the leftmost and rightmost character of the segment, the...
{ "canonical_parameter_names": [ "s", "queryCharacters", "queryIndices" ], "leetcode_dataset_entry_point": "Solution().longestRepeating", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T...
cpp
{ "raw_signature": "vector<int> longestRepeating(string s, string queryCharacters, vector<int>& queryIndices) {", "container": "Solution", "callable": "longestRepeating", "parameters": [ { "name": "s", "type": "string" }, { "name": "queryCharacters", "type": "string" }, ...
2,215
find-the-difference-of-two-arrays
Easy
Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where: - answer[0] is a list of all distinct integers in nums1 which are not present in nums2. - answer[1] is a list of all distinct integers in nums2 which are not present in nums1. Note that the integers in the lists may be returned ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [0, -1, -2],nums2 = [1, -1, 2]) == [[0, -2], [1, 2]]\n assert candidate(nums1 = [5, 7, 8],nums2 = [9, 10, 5]) == [[8, 7], [9, 10]]\n assert candidate(nums1 = [10, 20, 30],nums2 = [5, 15, 25, 35]) == [[10, 20, 30], [25, 35, ...
[ "[1,2,3]\n[2,4,6]", "[1,2,3,3]\n[1,1,2,2]" ]
[ "For each integer in nums1, check if it exists in nums2.", "Do the same for each integer in nums2." ]
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().findDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:13", "tests_total": ...
cpp
{ "raw_signature": "vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {", "container": "Solution", "callable": "findDifference", "parameters": [ { "name": "nums1", "type": "vector<int>&" }, { "name": "nums2", "type": "vector<int>&" } ], "retur...
2,216
minimum-deletions-to-make-array-beautiful
Medium
You are given a 0-indexed integer array nums. The array nums is beautiful if: - nums.length is even. - nums[i] != nums[i + 1] for all i % 2 == 0. Note that an empty array is considered beautiful. You can delete any number of elements from nums. When you delete an element, all the elements to the right of the deleted...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000]) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 2\n assert candidate(nums = [100000, 100000, 99999, 99999, 99998, 99998]) == 2\n ...
[ "[1,1,2,3,5]", "[1,1,2,2,3,3]" ]
[ "Delete as many adjacent equal elements as necessary.", "If the length of nums is odd after the entire process, delete the last element." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minDeletion", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:15", "tests_total": 125, "tests_dro...
cpp
{ "raw_signature": "int minDeletion(vector<int>& nums) {", "container": "Solution", "callable": "minDeletion", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,217
find-palindrome-with-fixed-length
Medium
Given an integer array queries and a positive integer intLength, return an array answer where answer[i] is either the queries[i]^th smallest positive palindrome of length intLength or -1 if no such palindrome exists. A palindrome is a number that reads the same backwards and forwards. Palindromes cannot have leading z...
{ "language": "python", "source": "def check(candidate):\n assert candidate(queries = [10, 20, 30],intLength = 2) == [-1, -1, -1]\n assert candidate(queries = [1, 3, 5, 7, 9],intLength = 5) == [10001, 10201, 10401, 10601, 10801]\n assert candidate(queries = [50000],intLength = 15) == [100499999994001]\n ...
[ "[1,2,3,4,5,90]\n3", "[2,4,6]\n4" ]
[ "For any value of queries[i] and intLength, how can you check if there exists at least queries[i] palindromes of length intLength?", "Since a palindrome reads the same forwards and backwards, consider how you can efficiently find the first half (ceil(intLength/2) digits) of the palindrome." ]
{ "canonical_parameter_names": [ "queries", "intLength" ], "leetcode_dataset_entry_point": "Solution().kthPalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:18", "tests_tot...
cpp
{ "raw_signature": "vector<long long> kthPalindrome(vector<int>& queries, int intLength) {", "container": "Solution", "callable": "kthPalindrome", "parameters": [ { "name": "queries", "type": "vector<int>&" }, { "name": "intLength", "type": "int" } ], "return_type": "...
2,218
maximum-value-of-k-coins-from-piles
Hard
There are n piles of coins on a table. Each pile consists of a positive number of coins of assorted denominations. In one move, you can choose any coin on top of any pile, remove it, and add it to your wallet. Given a list piles, where piles[i] is a list of integers denoting the composition of the i^th pile from top ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(piles = [[30, 10], [50, 20, 10]],k = 3) == 100\n assert candidate(piles = [[1, 2], [3, 4], [5, 6]],k = 5) == 19\n assert candidate(piles = [[10, 20], [5, 5, 5, 5], [1, 1, 1, 1, 1]],k = 5) == 45\n assert candidate(piles = [[1, 2,...
[ "[[1,100,3],[7,8,9]]\n2", "[[100],[100],[100],[100],[100],[100],[1,1,1,1,1,1,700]]\n7" ]
[ "For each pile i, what will be the total value of coins we can collect if we choose the first j coins?", "How can we use dynamic programming to combine the results from different piles to find the most optimal answer?" ]
{ "canonical_parameter_names": [ "piles", "k" ], "leetcode_dataset_entry_point": "Solution().maxValueOfCoins", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:20", "tests_total": 96,...
cpp
{ "raw_signature": "int maxValueOfCoins(vector<vector<int>>& piles, int k) {", "container": "Solution", "callable": "maxValueOfCoins", "parameters": [ { "name": "piles", "type": "vector<vector<int>>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signa...
2,220
minimum-bit-flips-to-convert-number
Easy
A bit flip of a number x is choosing a bit in the binary representation of x and flipping it from either 0 to 1 or 1 to 0. - For example, for x = 7, the binary representation is 111 and we may choose any bit (including any leading zeros not shown) and flip it. We can flip the first bit from the right to get 110, flip ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(start = 123456789,goal = 987654321) == 15\n assert candidate(start = 5,goal = 2) == 3\n assert candidate(start = 1000000000,goal = 500000000) == 14\n assert candidate(start = 8,goal = 15) == 3\n assert candidate(start = 15,go...
[ "10\n7", "3\n4" ]
[ "If the value of a bit in start and goal differ, then we need to flip that bit.", "Consider using the XOR operation to determine which bits need a bit flip." ]
{ "canonical_parameter_names": [ "start", "goal" ], "leetcode_dataset_entry_point": "Solution().minBitFlips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:25", "tests_total": 85, ...
cpp
{ "raw_signature": "int minBitFlips(int start, int goal) {", "container": "Solution", "callable": "minBitFlips", "parameters": [ { "name": "start", "type": "int" }, { "name": "goal", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets...
2,221
find-triangular-sum-of-an-array
Medium
You are given a 0-indexed integer array nums, where nums[i] is a digit between 0 and 9 (inclusive). The triangular sum of nums is the value of the only element present in nums after the following process terminates: 1. Let nums comprise of n elements. If n == 1, end the process. Otherwise, create a new 0-indexed inte...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 6\n assert candidate(nums = [4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2]) == 3\n assert candidate(nums = [1, 2, 3...
[ "[1,2,3,4,5]", "[5]" ]
[ "Try simulating the entire process.", "To reduce space, use a temporary array to update nums in every step instead of creating a new array at each step." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().triangularSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:27", "tests_total": 96, "tests_dr...
cpp
{ "raw_signature": "int triangularSum(vector<int>& nums) {", "container": "Solution", "callable": "triangularSum", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,222
number-of-ways-to-select-buildings
Medium
You are given a 0-indexed binary string s which represents the types of buildings along a street where: - s[i] = '0' denotes that the i^th building is an office and - s[i] = '1' denotes that the i^th building is a restaurant. As a city official, you would like to select 3 buildings for random inspection. However, to ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"100100100\") == 24\n assert candidate(s = \"101010101\") == 30\n assert candidate(s = \"000111000\") == 27\n assert candidate(s = \"111\") == 0\n assert candidate(s = \"0000000001\") == 0\n assert candidate(s = \"010...
[ "\"001101\"", "\"11100\"" ]
[ "There are only 2 valid patterns: ‘101’ and ‘010’. Think about how we can construct these 2 patterns from smaller patterns.", "Count the number of subsequences of the form ‘01’ or ‘10’ first. Let n01[i] be the number of ‘01’ subsequences that exist in the prefix of s up to the ith building. How can you compute n0...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().numberOfWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:29", "tests_total": 162, "tests_dropp...
cpp
{ "raw_signature": "long long numberOfWays(string s) {", "container": "Solution", "callable": "numberOfWays", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,223
sum-of-scores-of-built-strings
Hard
You are building a string s of length n one character at a time, prepending each new character to the front of the string. The strings are labeled from 1 to n, where the string with length i is labeled s_i. - For example, for s = "abaca", s_1 == "a", s_2 == "ca", s_3 == "aca", etc. The score of s_i is the length of t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"xyzxyzxyz\") == 18\n assert candidate(s = \"abcabcabc\") == 18\n assert candidate(s = \"aabbcc\") == 7\n assert candidate(s = \"abacabadabacaba\") == 32\n assert candidate(s = \"zzzzz\") == 15\n assert candidate(s = ...
[ "\"babab\"", "\"azbazbzaz\"" ]
[ "Each s_i is a suffix of the string s, so consider algorithms that can determine the longest prefix that is also a suffix.", "Could you use the Z array from the Z algorithm to find the score of each s_i?" ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().sumScores", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:32", "tests_total": 123, "tests_dropped"...
cpp
{ "raw_signature": "long long sumScores(string s) {", "container": "Solution", "callable": "sumScores", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,224
minimum-number-of-operations-to-convert-time
Easy
You are given two strings current and correct representing two 24-hour times. 24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59. In one operation you can increase the time current by 1, 5, 15, or 60 minutes. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(current = \"01:59\",correct = \"02:00\") == 1\n assert candidate(current = \"00:01\",correct = \"00:02\") == 1\n assert candidate(current = \"02:30\",correct = \"04:35\") == 3\n assert candidate(current = \"12:00\",correct = \"1...
[ "\"02:30\"\n\"04:35\"", "\"11:00\"\n\"11:01\"" ]
[ "Convert the times to minutes.", "Use the operation with the biggest value possible at each step." ]
{ "canonical_parameter_names": [ "current", "correct" ], "leetcode_dataset_entry_point": "Solution().convertTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:34", "tests_total":...
cpp
{ "raw_signature": "int convertTime(string current, string correct) {", "container": "Solution", "callable": "convertTime", "parameters": [ { "name": "current", "type": "string" }, { "name": "correct", "type": "string" } ], "return_type": "int", "signature_source": ...
2,225
find-players-with-zero-or-one-losses
Medium
You are given an integer array matches where matches[i] = [winner_i, loser_i] indicates that the player winner_i defeated player loser_i in a match. Return a list answer of size 2 where: - answer[0] is a list of all players that have not lost any matches. - answer[1] is a list of all players that have lost exactly on...
{ "language": "python", "source": "def check(candidate):\n assert candidate(matches = [[1, 2]]) == [[1], [2]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]) == [[], [1, 2, 3, 4, 5]]\n assert candidate(matches = [[100, 200], [200, 300], [100, 300], [400, 500]]) == [[100, 400], [200, ...
[ "[[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]", "[[2,3],[1,3],[5,4],[6,4]]" ]
[ "Count the number of times a player loses while iterating through the matches." ]
{ "canonical_parameter_names": [ "matches" ], "leetcode_dataset_entry_point": "Solution().findWinners", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:36", "tests_total": 69, "tests_d...
cpp
{ "raw_signature": "vector<vector<int>> findWinners(vector<vector<int>>& matches) {", "container": "Solution", "callable": "findWinners", "parameters": [ { "name": "matches", "type": "vector<vector<int>>&" } ], "return_type": "vector<vector<int>>", "signature_source": "leetcode/codeSni...
2,226
maximum-candies-allocated-to-k-children
Medium
You are given a 0-indexed integer array candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together. You are also given an integer k. You should allocate piles of candies to k children such that each chi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(candies = [10000000, 10000000, 10000000],k = 10000000) == 2\n assert candidate(candies = [7, 14, 10, 7],k = 3) == 7\n assert candidate(candies = [5, 8, 6],k = 3) == 5\n assert candidate(candies = [3, 9, 7],k = 6) == 3\n asser...
[ "[5,8,6]\n3", "[2,5]\n11" ]
[ "For a fixed number of candies c, how can you check if each child can get c candies?", "Use binary search to find the maximum c as the answer." ]
{ "canonical_parameter_names": [ "candies", "k" ], "leetcode_dataset_entry_point": "Solution().maximumCandies", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:39", "tests_total": 82...
cpp
{ "raw_signature": "int maximumCandies(vector<int>& candies, long long k) {", "container": "Solution", "callable": "maximumCandies", "parameters": [ { "name": "candies", "type": "vector<int>&" }, { "name": "k", "type": "long long" } ], "return_type": "int", "signatu...
2,231
largest-number-after-digit-swaps-by-parity
Easy
You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits). Return the largest possible value of num after any number of swaps. Example 1: Input: num = 1234 Output: 3412 Explanation: Swap the digit 3 with the digit 1, this results in ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = 24680) == 86420\n assert candidate(num = 987654321) == 987654321\n assert candidate(num = 13524687) == 75386421\n assert candidate(num = 1000000) == 1000000\n assert candidate(num = 2222) == 2222\n assert candidate(n...
[ "1234", "65875" ]
[ "The bigger digit should appear first (more to the left) because it contributes more to the value of the number.", "Get all the even digits, as well as odd digits. Sort them separately.", "Reconstruct the number by giving the earlier digits the highest available digit of the same parity." ]
{ "canonical_parameter_names": [ "num" ], "leetcode_dataset_entry_point": "Solution().largestInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:43", "tests_total": 78, "tests_dr...
cpp
{ "raw_signature": "int largestInteger(int num) {", "container": "Solution", "callable": "largestInteger", "parameters": [ { "name": "num", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,232
minimize-result-by-adding-parentheses-to-expression
Medium
You are given a 0-indexed string expression of the form "<num1>+<num2>" where <num1> and <num2> represent positive integers. Add a pair of parentheses to expression such that after the addition of parentheses, expression is a valid mathematical expression and evaluates to the smallest possible value. The left parenthe...
{ "language": "python", "source": "def check(candidate):\n assert candidate(expression = \"56+78\") == \"(56+78)\"\n assert candidate(expression = \"5+6\") == \"(5+6)\"\n assert candidate(expression = \"3+8\") == \"(3+8)\"\n assert candidate(expression = \"111+222\") == \"1(11+22)2\"\n assert candida...
[ "\"247+38\"", "\"12+34\"", "\"999+999\"" ]
[ "The maximum length of expression is very low. We can try every possible spot to place the parentheses.", "Every possibility of expression is of the form a * (b + c) * d where a, b, c, d represent integers. Note the edge cases where a and/or d do not exist, in which case use 1 instead of them." ]
{ "canonical_parameter_names": [ "expression" ], "leetcode_dataset_entry_point": "Solution().minimizeResult", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:46", "tests_total": 134, "...
cpp
{ "raw_signature": "string minimizeResult(string expression) {", "container": "Solution", "callable": "minimizeResult", "parameters": [ { "name": "expression", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
2,233
maximum-product-after-k-increments
Medium
You are given an array of non-negative integers nums and an integer k. In one operation, you may choose any element from nums and increment it by 1. Return the maximum product of nums after at most k operations. Since the answer may be very large, return it modulo 10^9 + 7. Note that you should maximize the product be...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 7776\n assert candidate(nums = [1, 2, 3, 4],k = 3) == 108\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 94500000\n assert candidate(nums = [0, 4],k = 5) == 20\n assert c...
[ "[0,4]\n5", "[6,3,3,2]\n2" ]
[ "If you can increment only once, which number should you increment?", "We should always prioritize the smallest number. What kind of data structure could we use?", "Use a min heap to hold all the numbers. Each time we do an operation, replace the top of the heap x by x + 1." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maximumProduct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:48", "tests_total": 101, ...
cpp
{ "raw_signature": "int maximumProduct(vector<int>& nums, int k) {", "container": "Solution", "callable": "maximumProduct", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetc...
2,234
maximum-total-beauty-of-the-gardens
Hard
Alice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens. You are given a 0-indexed integer array flowers of size n, where flowers[i] is the number of flowers already planted in the i^th garden. Flowers that are already planted cannot be removed. You are then giv...
{ "language": "python", "source": "def check(candidate):\n assert candidate(flowers = [10, 20, 30, 40, 50],newFlowers = 100,target = 25,full = 5,partial = 2) == 68\n assert candidate(flowers = [1, 1, 1, 1],newFlowers = 15,target = 3,full = 5,partial = 3) == 21\n assert candidate(flowers = [5, 5, 5, 5],newF...
[ "[1,3,1,1]\n7\n6\n12\n1", "[2,4,5,3]\n10\n5\n2\n6" ]
[ "Say we choose k gardens to be complete, is there an optimal way of choosing which gardens to plant more flowers to achieve this?", "For a given k, we should greedily fill-up the k gardens with the most flowers planted already. This gives us the most remaining flowers to fill up the other gardens.", "After sort...
{ "canonical_parameter_names": [ "flowers", "newFlowers", "target", "full", "partial" ], "leetcode_dataset_entry_point": "Solution().maximumBeauty", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetche...
cpp
{ "raw_signature": "long long maximumBeauty(vector<int>& flowers, long long newFlowers, int target, int full, int partial) {", "container": "Solution", "callable": "maximumBeauty", "parameters": [ { "name": "flowers", "type": "vector<int>&" }, { "name": "newFlowers", "type": ...
2,235
add-two-integers
Easy
Given two integers num1 and num2, return the sum of the two integers. Example 1: Input: num1 = 12, num2 = 5 Output: 17 Explanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned. Example 2: Input: num1 = -10, num2 = 4 Output: -6 Explanation: num1 + num2 = -6, so -6 is returned. Constraints...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num1 = 100,num2 = -100) == 0\n assert candidate(num1 = -10,num2 = 4) == -6\n assert candidate(num1 = 25,num2 = 25) == 50\n assert candidate(num1 = -50,num2 = 50) == 0\n assert candidate(num1 = 99,num2 = 1) == 100\n assert ...
[ "12\n5", "-10\n4" ]
[]
{ "canonical_parameter_names": [ "num1", "num2" ], "leetcode_dataset_entry_point": "Solution().sum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:53", "tests_total": 59, "tests_...
cpp
{ "raw_signature": "int sum(int num1, int num2) {", "container": "Solution", "callable": "sum", "parameters": [ { "name": "num1", "type": "int" }, { "name": "num2", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source"...
2,239
find-closest-number-to-zero
Easy
Given an integer array nums of size n, return the number with the value closest to 0 in nums. If there are multiple answers, return the number with the largest value. Example 1: Input: nums = [-4,-2,1,4,8] Output: 1 Explanation: The distance from -4 to 0 is |-4| = 4. The distance from -2 to 0 is |-2| = 2. The distanc...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, -3, 2, -2, 1, -1]) == 1\n assert candidate(nums = [100000, -100000, 50000, -50000]) == 50000\n assert candidate(nums = [100000, -100000, 50000, -50000]) == 50000\n assert candidate(nums = [7, -10, 4, 3, -20, 2]) == 2\...
[ "[-4,-2,1,4,8]", "[2,-1,1]" ]
[ "Keep track of the number closest to 0 as you iterate through the array.", "Ensure that if multiple numbers are closest to 0, you store the one with the largest value." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findClosestNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:59", "tests_total": 128, "tes...
cpp
{ "raw_signature": "int findClosestNumber(vector<int>& nums) {", "container": "Solution", "callable": "findClosestNumber", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
2,240
number-of-ways-to-buy-pens-and-pencils
Medium
You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to buy multiple quantities (or none) of each kind of writing utensil. Return the number of distinct ways...
{ "language": "python", "source": "def check(candidate):\n assert candidate(total = 20,cost1 = 10,cost2 = 5) == 9\n assert candidate(total = 1000,cost1 = 1,cost2 = 1) == 501501\n assert candidate(total = 5,cost1 = 10,cost2 = 10) == 1\n assert candidate(total = 5,cost1 = 10,cost2 = 10) == 1\n assert c...
[ "20\n10\n5", "5\n10\n10" ]
[ "Fix the number of pencils purchased and calculate the number of ways to buy pens.", "Sum up the number of ways to buy pens for each amount of pencils purchased to get the answer." ]
{ "canonical_parameter_names": [ "total", "cost1", "cost2" ], "leetcode_dataset_entry_point": "Solution().waysToBuyPensPencils", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:01"...
cpp
{ "raw_signature": "long long waysToBuyPensPencils(int total, int cost1, int cost2) {", "container": "Solution", "callable": "waysToBuyPensPencils", "parameters": [ { "name": "total", "type": "int" }, { "name": "cost1", "type": "int" }, { "name": "cost2", ...
2,242
maximum-score-of-a-node-sequence
Hard
There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 0-indexed integer array scores of length n where scores[i] denotes the score of node i. You are also given a 2D integer array edges where edges[i] = [a_i, b_i] denotes that there exists an undirected edge connecting nodes a_i and b_i....
{ "language": "python", "source": "def check(candidate):\n assert candidate(scores = [5, 2, 9, 8, 4],edges = [[0, 1], [1, 2], [2, 3], [0, 2], [1, 3], [2, 4]]) == 24\n assert candidate(scores = [1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 4\n assert candidate...
[ "[5,2,9,8,4]\n[[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]", "[9,20,6,4,11,12]\n[[0,3],[5,3],[2,4],[1,3]]" ]
[ "For every node sequence of length 4, there are 3 relevant edges. How can we consider valid triplets of edges?", "Fix the middle 2 nodes connected by an edge in the node sequence. Can you determine the other 2 nodes that will give the highest possible score?", "The other 2 nodes must each be connected to one of...
{ "canonical_parameter_names": [ "scores", "edges" ], "leetcode_dataset_entry_point": "Solution().maximumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:04", "tests_total": 8...
cpp
{ "raw_signature": "int maximumScore(vector<int>& scores, vector<vector<int>>& edges) {", "container": "Solution", "callable": "maximumScore", "parameters": [ { "name": "scores", "type": "vector<int>&" }, { "name": "edges", "type": "vector<vector<int>>&" } ], "return_...
2,243
calculate-digit-sum-of-a-string
Easy
You are given a string s consisting of digits and an integer k. A round can be completed if the length of s is greater than k. In one round, do the following: 1. Divide s into consecutive groups of size k such that the first k characters are in the first group, the next k characters are in the second group, and so on...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"00000000\",k = 3) == \"000\"\n assert candidate(s = \"111\",k = 5) == \"111\"\n assert candidate(s = \"987654321\",k = 2) == \"36\"\n assert candidate(s = \"11111222223\",k = 3) == \"135\"\n assert candidate(s = \"98765...
[ "\"11111222223\"\n3", "\"00000000\"\n3" ]
[ "Try simulating the entire process to find the final answer." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().digitSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:06", "tests_total": 109, "tests_...
cpp
{ "raw_signature": "string digitSum(string s, int k) {", "container": "Solution", "callable": "digitSum", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "int" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "ty...
2,244
minimum-rounds-to-complete-all-tasks
Medium
You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level. Return the minimum rounds required to complete all the tasks, or -1 if it is not possible to complete all the tasks. Example 1: In...
{ "language": "python", "source": "def check(candidate):\n assert candidate(tasks = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 5\n assert candidate(tasks = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 5\n assert candidate(tasks = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 7\n ...
[ "[2,2,3,3,2,4,4,4,4,4]", "[2,3,3]" ]
[ "Which data structure can you use to store the number of tasks of each difficulty level?", "For any particular difficulty level, what can be the optimal strategy to complete the tasks using minimum rounds?", "When can we not complete all tasks of a difficulty level?" ]
{ "canonical_parameter_names": [ "tasks" ], "leetcode_dataset_entry_point": "Solution().minimumRounds", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:09", "tests_total": 58, "tests_d...
cpp
{ "raw_signature": "int minimumRounds(vector<int>& tasks) {", "container": "Solution", "callable": "minimumRounds", "parameters": [ { "name": "tasks", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
2,245
maximum-trailing-zeros-in-a-cornered-path
Medium
You are given a 2D integer array grid of size m x n, where each cell contains a positive integer. A cornered path is defined as a set of adjacent cells with at most one turn. More specifically, the path should exclusively move either horizontally or vertically up to the turn (if there is one), without returning to a p...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]) == 0\n assert candidate(grid = [[5, 10, 15], [20, 25, 30], [35, 40, 45]]) == 5\n assert candidate(grid = [[2, 4, 6, 8], [10, 20, 30, 40], [50, 60, 70, 80]]) == 6\n assert candid...
[ "[[23,17,15,3,20],[8,1,20,27,11],[9,4,6,2,21],[40,9,1,10,6],[22,7,4,5,3]]", "[[4,3,2],[7,6,1],[8,8,8]]" ]
[ "What actually tells us the trailing zeros of the product of a path?", "It is the sum of the exponents of 2 and sum of the exponents of 5 of the prime factorizations of the numbers on that path. The smaller of the two is the answer for that path.", "We can then treat each cell as the elbow point and calculate t...
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().maxTrailingZeros", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:11", "tests_total": 84, "tests...
cpp
{ "raw_signature": "int maxTrailingZeros(vector<vector<int>>& grid) {", "container": "Solution", "callable": "maxTrailingZeros", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "le...
2,246
longest-path-with-different-adjacent-characters
Hard
You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1. You are also given a string s ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(parent = [-1, 0, 0, 2, 2, 2],s = \"abbccc\") == 4\n assert candidate(parent = [-1, 0, 0, 0],s = \"aabc\") == 3\n assert candidate(parent = [-1, 0, 0, 1, 1, 2],s = \"abacbe\") == 3\n assert candidate(parent = [-1, 0, 1, 2, 3, 4, ...
[ "[-1,0,0,1,1,2]\n\"abacbe\"", "[-1,0,0,0]\n\"aabc\"" ]
[ "Do a DFS from the root. At each node, calculate the longest path we can make from two branches of that subtree.", "To do that, we need to find the length of the longest path from each of the node’s children." ]
{ "canonical_parameter_names": [ "parent", "s" ], "leetcode_dataset_entry_point": "Solution().longestPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:14", "tests_total": 49, ...
cpp
{ "raw_signature": "int longestPath(vector<int>& parent, string s) {", "container": "Solution", "callable": "longestPath", "parameters": [ { "name": "parent", "type": "vector<int>&" }, { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "l...
2,248
intersection-of-multiple-arrays
Easy
Given a 2D integer array nums where nums[i] is a non-empty array of distinct positive integers, return the list of integers that are present in each array of nums sorted in ascending order. Example 1: Input: nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]] Output: [3,4] Explanation: The only integers present in each of nums[...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [[10, 20, 30], [20, 30, 40], [30, 40, 50], [30, 60, 70]]) == [30]\n assert candidate(nums = [[3, 1, 2, 4, 5], [1, 2, 3, 4], [3, 4, 5, 6]]) == [3, 4]\n assert candidate(nums = [[10, 20, 30], [20, 30, 40], [30, 40, 50]]) == [3...
[ "[[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]", "[[1,2,3],[4,5,6]]" ]
[ "Keep a count of the number of times each integer occurs in nums.", "Since all integers of nums[i] are distinct, if an integer is present in each array, its count will be equal to the total number of arrays." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().intersection", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:18", "tests_total": 93, "tests_dro...
cpp
{ "raw_signature": "vector<int> intersection(vector<vector<int>>& nums) {", "container": "Solution", "callable": "intersection", "parameters": [ { "name": "nums", "type": "vector<vector<int>>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_sour...
2,249
count-lattice-points-inside-a-circle
Medium
Given a 2D integer array circles where circles[i] = [x_i, y_i, r_i] represents the center (x_i, y_i) and radius r_i of the i^th circle drawn on a grid, return the number of lattice points that are present inside at least one circle. Note: - A lattice point is a point with integer coordinates. - Points that lie on the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(circles = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]) == 33\n assert candidate(circles = [[10, 10, 5], [15, 15, 5], [20, 20, 5], [25, 25, 5]]) == 276\n assert candidate(circles = [[2, 2, 1]]) == 5\n assert candidate(circles = [[10, 10, 5...
[ "[[2,2,1]]", "[[2,2,2],[3,4,1]]" ]
[ "For each circle, how can you check whether or not a lattice point lies inside it?", "Since you need to reduce the search space, consider the minimum and maximum possible values of the coordinates of a lattice point contained in any circle." ]
{ "canonical_parameter_names": [ "circles" ], "leetcode_dataset_entry_point": "Solution().countLatticePoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:21", "tests_total": 114, ...
cpp
{ "raw_signature": "int countLatticePoints(vector<vector<int>>& circles) {", "container": "Solution", "callable": "countLatticePoints", "parameters": [ { "name": "circles", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_so...
2,250
count-number-of-rectangles-containing-each-point
Medium
You are given a 2D integer array rectangles where rectangles[i] = [l_i, h_i] indicates that i^th rectangle has a length of l_i and a height of h_i. You are also given a 2D integer array points where points[j] = [x_j, y_j] is a point with coordinates (x_j, y_j). The i^th rectangle has its bottom-left corner point at th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(rectangles = [[1, 2], [2, 3], [2, 5]],points = [[2, 1], [1, 4]]) == [2, 1]\n assert candidate(rectangles = [[10, 100], [9, 99], [8, 98], [7, 97]],points = [[10, 100], [9, 99], [8, 98], [7, 97]]) == [1, 2, 3, 4]\n assert candidate(r...
[ "[[1,2],[2,3],[2,5]]\n[[2,1],[1,4]]", "[[1,1],[2,2],[3,3]]\n[[1,3],[1,1]]" ]
[ "The heights of the rectangles and the y-coordinates of the points are only at most 100, so for each point, we can iterate over the possible heights of the rectangles that contain a given point.", "For a given point and height, can we efficiently count how many rectangles with that height contain our point?", "...
{ "canonical_parameter_names": [ "rectangles", "points" ], "leetcode_dataset_entry_point": "Solution().countRectangles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:23", "tests_t...
cpp
{ "raw_signature": "vector<int> countRectangles(vector<vector<int>>& rectangles, vector<vector<int>>& points) {", "container": "Solution", "callable": "countRectangles", "parameters": [ { "name": "rectangles", "type": "vector<vector<int>>&" }, { "name": "points", "type": "vec...
2,251
number-of-flowers-in-full-bloom
Hard
You are given a 0-indexed 2D integer array flowers, where flowers[i] = [start_i, end_i] means the i^th flower will be in full bloom from start_i to end_i (inclusive). You are also given a 0-indexed integer array people of size n, where people[i] is the time that the i^th person will arrive to see the flowers. Return a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(flowers = [[1, 10], [3, 3]],people = [3, 3, 2]) == [2, 2, 1]\n assert candidate(flowers = [[1, 100]],people = [50, 100, 150]) == [1, 1, 0]\n assert candidate(flowers = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],people = [1, 2, 3, 4,...
[ "[[1,6],[3,7],[9,12],[4,13]]\n[2,3,7,11]", "[[1,10],[3,3]]\n[3,3,2]" ]
[ "Notice that for any given time t, the number of flowers blooming at time t is equal to the number of flowers that have started blooming minus the number of flowers that have already stopped blooming.", "We can obtain these values efficiently using binary search.", "We can store the starting times in sorted ord...
{ "canonical_parameter_names": [ "flowers", "people" ], "leetcode_dataset_entry_point": "Solution().fullBloomFlowers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:26", "tests_tot...
cpp
{ "raw_signature": "vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {", "container": "Solution", "callable": "fullBloomFlowers", "parameters": [ { "name": "flowers", "type": "vector<vector<int>>&" }, { "name": "people", "type": "vector<int>&" ...
2,255
count-prefixes-of-a-given-string
Easy
You are given a string array words and a string s, where words[i] and s comprise only of lowercase English letters. Return the number of strings in words that are a prefix of s. A prefix of a string is a substring that occurs at the beginning of the string. A substring is a contiguous sequence of characters within a ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['hello', 'hell', 'he', 'h'],s = \"hello\") == 4\n assert candidate(words = ['short'],s = \"shorter\") == 1\n assert candidate(words = ['same', 'same'],s = \"same\") == 2\n assert candidate(words = ['hello'],s = \"h\") =...
[ "[\"a\",\"b\",\"c\",\"ab\",\"bc\",\"abc\"]\n\"abc\"", "[\"a\",\"a\"]\n\"aa\"" ]
[ "For each string in words, check if it is a prefix of s. If true, increment the answer by 1." ]
{ "canonical_parameter_names": [ "words", "s" ], "leetcode_dataset_entry_point": "Solution().countPrefixes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:28", "tests_total": 146, ...
cpp
{ "raw_signature": "int countPrefixes(vector<string>& words, string s) {", "container": "Solution", "callable": "countPrefixes", "parameters": [ { "name": "words", "type": "vector<string>&" }, { "name": "s", "type": "string" } ], "return_type": "int", "signature_sou...
2,256
minimum-average-difference
Medium
You are given a 0-indexed integer array nums of length n. The average difference of the index i is the absolute difference between the average of the first i + 1 elements of nums and the average of the last n - i - 1 elements. Both averages should be rounded down to the nearest integer. Return the index with the mini...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [100000, 0, 100000, 0, 100000, 0, 100000, 0, 100000, 0]) == 1\n assert candidate(nums = [100000, 0, 0, 0, 0, 0...
[ "[2,5,3,9,5,3]", "[0]" ]
[ "How can we use precalculation to efficiently calculate the average difference at an index?", "Create a prefix and/or suffix sum array." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minimumAverageDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:30", "tests_total": 94, ...
cpp
{ "raw_signature": "int minimumAverageDifference(vector<int>& nums) {", "container": "Solution", "callable": "minimumAverageDifference", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "le...
2,257
count-unguarded-cells-in-the-grid
Medium
You are given two integers m and n representing a 0-indexed m x n grid. You are also given two 2D integer arrays guards and walls where guards[i] = [row_i, col_i] and walls[j] = [row_j, col_j] represent the positions of the i^th guard and j^th wall respectively. A guard can see every cell in the four cardinal directio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(m = 4,n = 6,guards = [[0, 0], [1, 1], [2, 3]],walls = [[0, 1], [2, 2], [1, 4]]) == 7\n assert candidate(m = 3,n = 3,guards = [[1, 1]],walls = [[0, 1], [1, 0], [2, 1], [1, 2]]) == 4\n assert candidate(m = 5,n = 5,guards = [[2, 2]],w...
[ "4\n6\n[[0,0],[1,1],[2,3]]\n[[0,1],[2,2],[1,4]]", "3\n3\n[[1,1]]\n[[0,1],[1,0],[2,1],[1,2]]" ]
[ "Create a 2D array to represent the grid. Can you mark the tiles that can be seen by a guard?", "Iterate over the guards, and for each of the 4 directions, advance the current tile and mark the tile. When should you stop advancing?" ]
{ "canonical_parameter_names": [ "m", "n", "guards", "walls" ], "leetcode_dataset_entry_point": "Solution().countUnguarded", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:33"...
cpp
{ "raw_signature": "int countUnguarded(int m, int n, vector<vector<int>>& guards, vector<vector<int>>& walls) {", "container": "Solution", "callable": "countUnguarded", "parameters": [ { "name": "m", "type": "int" }, { "name": "n", "type": "int" }, { "name": "gu...
2,258
escape-the-spreading-fire
Hard
You are given a 0-indexed 2D integer array grid of size m x n which represents a field. Each cell has one of three values: - 0 represents grass, - 1 represents fire, - 2 represents a wall that you and fire cannot pass through. You are situated in the top-left cell, (0, 0), and you want to travel to the safehouse at t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 2, 0], [0, 2, 0, 0]]) == -1\n assert candidate(grid = [[0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 1, 0, 0, 0], [0, 0, 0, 2...
[ "[[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]]", "[[0,0,0,0],[0,1,2,0],[0,2,0,0]]", "[[0,0,0],[2,2,0],[1,2,0]]" ]
[ "For some tile (x, y), how can we determine when, if ever, the fire will reach it?", "We can use multi-source BFS to find the earliest time the fire will reach each cell.", "Then, starting with a given t minutes of staying in the initial position, we can check if there is a safe path to the safehouse using the ...
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().maximumMinutes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:35", "tests_total": 85, "tests_d...
cpp
{ "raw_signature": "int maximumMinutes(vector<vector<int>>& grid) {", "container": "Solution", "callable": "maximumMinutes", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
2,259
remove-digit-from-number-to-maximize-result
Easy
You are given a string number representing a positive integer and a character digit. Return the resulting string after removing exactly one occurrence of digit from number such that the value of the resulting string in decimal form is maximized. The test cases are generated such that digit occurs at least once in numb...
{ "language": "python", "source": "def check(candidate):\n assert candidate(number = \"222333\",digit = \"2\") == \"22333\"\n assert candidate(number = \"99999\",digit = \"9\") == \"9999\"\n assert candidate(number = \"999\",digit = \"9\") == \"99\"\n assert candidate(number = \"551\",digit = \"5\") == ...
[ "\"123\"\n\"3\"", "\"1231\"\n\"1\"", "\"551\"\n\"5\"" ]
[ "The maximum length of number is really small.", "Iterate through the digits of number and every time we see digit, try removing it.", "To remove a character at index i, concatenate the substring from index 0 to i - 1 and the substring from index i + 1 to number.length - 1." ]
{ "canonical_parameter_names": [ "number", "digit" ], "leetcode_dataset_entry_point": "Solution().removeDigit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:37", "tests_total": 12...
cpp
{ "raw_signature": "string removeDigit(string number, char digit) {", "container": "Solution", "callable": "removeDigit", "parameters": [ { "name": "number", "type": "string" }, { "name": "digit", "type": "char" } ], "return_type": "string", "signature_source": "lee...
2,260
minimum-consecutive-cards-to-pick-up
Medium
You are given an integer array cards where cards[i] represents the value of the i^th card. A pair of cards are matching if the cards have the same value. Return the minimum number of consecutive cards you have to pick up to have a pair of matching cards among the picked cards. If it is impossible to have matching card...
{ "language": "python", "source": "def check(candidate):\n assert candidate(cards = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 11\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1]) == 21\n assert candidate(cards = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n asse...
[ "[3,4,2,3,4,7]", "[1,0,5,3]" ]
[ "Iterate through the cards and store the location of the last occurrence of each number.", "What data structure could you use to get the last occurrence of a number in O(1) or O(log n)?" ]
{ "canonical_parameter_names": [ "cards" ], "leetcode_dataset_entry_point": "Solution().minimumCardPickup", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:39", "tests_total": 109, "te...
cpp
{ "raw_signature": "int minimumCardPickup(vector<int>& cards) {", "container": "Solution", "callable": "minimumCardPickup", "parameters": [ { "name": "cards", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeS...
2,261
k-divisible-elements-subarrays
Medium
Given an integer array nums and two integers k and p, return the number of distinct subarrays, which have at most k elements that are divisible by p. Two arrays nums1 and nums2 are said to be distinct if: - They are of different lengths, or - There exists at least one index i where nums1[i] != nums2[i]. A subarray i...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 1, 2, 1],k = 1,p = 2) == 5\n assert candidate(nums = [19, 23, 29, 31, 37],k = 3,p = 5) == 15\n assert candidate(nums = [1, 2, 1, 2],k = 1,p = 2) == 5\n assert candidate(nums = [13, 26, 39, 52, 65],k = 2,p = 13) == ...
[ "[2,3,3,2,2]\n2\n2", "[1,2,3,4]\n4\n1" ]
[ "Enumerate all subarrays and find the ones that satisfy all the conditions.", "Use any suitable method to hash the subarrays to avoid duplicates." ]
{ "canonical_parameter_names": [ "nums", "k", "p" ], "leetcode_dataset_entry_point": "Solution().countDistinct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:41", "tests_total...
cpp
{ "raw_signature": "int countDistinct(vector<int>& nums, int k, int p) {", "container": "Solution", "callable": "countDistinct", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" }, { "name": "p", "type": "int" } ...
2,262
total-appeal-of-a-string
Hard
The appeal of a string is the number of distinct characters found in the string. - For example, the appeal of "abbca" is 3 because it has 3 distinct characters: 'a', 'b', and 'c'. Given a string s, return the total appeal of all of its substrings. A substring is a contiguous sequence of characters within a string. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 3276\n assert candidate(s = \"zzzaaa\") == 30\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"abacabadabacaba\") == 357\n assert candidate(s = \"abcabcabc\") == 109\n asse...
[ "\"abbca\"", "\"code\"" ]
[ "Consider the set of substrings that end at a certain index i. Then, consider a specific alphabetic character. How do you count the number of substrings ending at index i that contain that character?", "The number of substrings that contain the alphabetic character is equivalent to 1 plus the index of the last oc...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().appealSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:44", "tests_total": 69, "tests_dropped":...
cpp
{ "raw_signature": "long long appealSum(string s) {", "container": "Solution", "callable": "appealSum", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,264
largest-3-same-digit-number-in-string
Easy
You are given a string num representing a large integer. An integer is good if it meets the following conditions: - It is a substring of num with length 3. - It consists of only one unique digit. Return the maximum good integer as a string or an empty string "" if no such integer exists. Note: - A substring is a co...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = \"999888777666555444333222111000\") == \"999\"\n assert candidate(num = \"000\") == \"000\"\n assert candidate(num = \"42352338\") == \"\"\n assert candidate(num = \"9876543210\") == \"\"\n assert candidate(num = \"5554...
[ "\"6777133339\"", "\"2300019\"", "\"42352338\"" ]
[ "We can sequentially check if “999”, “888”, “777”, … , “000” exists in num in that order. The first to be found is the maximum good integer.", "If we cannot find any of the above integers, we return an empty string “”." ]
{ "canonical_parameter_names": [ "num" ], "leetcode_dataset_entry_point": "Solution().largestGoodInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:48", "tests_total": 133, "tes...
cpp
{ "raw_signature": "string largestGoodInteger(string num) {", "container": "Solution", "callable": "largestGoodInteger", "parameters": [ { "name": "num", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
2,266
count-number-of-texts
Medium
Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below. In order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of the letter in the key. - For example, to add the letter 's', Alice has to press '7' four times. Simil...
{ "language": "python", "source": "def check(candidate):\n assert candidate(pressedKeys = \"99999999\") == 108\n assert candidate(pressedKeys = \"3333\") == 7\n assert candidate(pressedKeys = \"33\") == 2\n assert candidate(pressedKeys = \"4444\") == 7\n assert candidate(pressedKeys = \"555555\") == ...
[ "\"22233\"", "\"222222222222222222222222222222222222\"" ]
[ "For a substring consisting of the same digit, how can we count the number of texts it could have originally represented?", "How can dynamic programming help us calculate the required answer?" ]
{ "canonical_parameter_names": [ "pressedKeys" ], "leetcode_dataset_entry_point": "Solution().countTexts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:52", "tests_total": 38, "test...
cpp
{ "raw_signature": "int countTexts(string pressedKeys) {", "container": "Solution", "callable": "countTexts", "parameters": [ { "name": "pressedKeys", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,267
check-if-there-is-a-valid-parentheses-string-path
Hard
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(grid = [['(', '(', '('], [')', '(', ')'], ['(', '(', ')'], ['(', '(', ')']]) == True\n assert candidate(grid = [[')', ')'], ['(', '(']]) == False\n assert candidate(grid = [[')', '('], ['(', '(']]) == False\n assert candidate(gr...
[ "[[\"(\",\"(\",\"(\"],[\")\",\"(\",\")\"],[\"(\",\"(\",\")\"],[\"(\",\"(\",\")\"]]", "[[\")\",\")\"],[\"(\",\"(\"]]" ]
[ "What observations can you make about the number of open brackets and close brackets for any prefix of a valid bracket sequence?", "The number of open brackets must always be greater than or equal to the number of close brackets.", "Could you use dynamic programming?" ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().hasValidPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:55", "tests_total": 54, "tests_dro...
cpp
{ "raw_signature": "bool hasValidPath(vector<vector<char>>& grid) {", "container": "Solution", "callable": "hasValidPath", "parameters": [ { "name": "grid", "type": "vector<vector<char>>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetco...
2,269
find-the-k-beauty-of-a-number
Easy
The k-beauty of an integer num is defined as the number of substrings of num when it is read as a string that meet the following conditions: - It has a length of k. - It is a divisor of num. Given integers num and k, return the k-beauty of num. Note: - Leading zeros are allowed. - 0 is not a divisor of any value. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = 100000,k = 2) == 1\n assert candidate(num = 240,k = 2) == 2\n assert candidate(num = 1111,k = 2) == 3\n assert candidate(num = 430043,k = 2) == 2\n assert candidate(num = 99999,k = 5) == 1\n assert candidate(num = 12...
[ "240\n2", "430043\n2" ]
[ "We should check all the substrings of num with a length of k and see if it is a divisor of num.", "We can more easily obtain the substrings by converting num into a string and converting back to an integer to check for divisibility." ]
{ "canonical_parameter_names": [ "num", "k" ], "leetcode_dataset_entry_point": "Solution().divisorSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:59", "tests_total": 90,...
cpp
{ "raw_signature": "int divisorSubstrings(int num, int k) {", "container": "Solution", "callable": "divisorSubstrings", "parameters": [ { "name": "num", "type": "int" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippe...
2,270
number-of-ways-to-split-array
Medium
You are given a 0-indexed integer array nums of length n. nums contains a valid split at index i if the following are true: - The sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - 1 elements. - There is at least one element to the right of i. That is, 0 <= i < n - 1. Return the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [-100000, -100000, -100000, -100000, -100000]) == 2\n assert candidate(nums = [1, -1, 1, -1, 1]) == 2\n assert candidate(nums = [100, -50, 50, -25, 25]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3...
[ "[10,4,-8,7]", "[2,3,1,0]" ]
[ "For any index i, how can we find the sum of the first (i+1) elements from the sum of the first i elements?", "If the total sum of the array is known, how can we check if the sum of the first (i+1) elements greater than or equal to the remaining elements?" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().waysToSplitArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:02", "tests_total": 105, "test...
cpp
{ "raw_signature": "int waysToSplitArray(vector<int>& nums) {", "container": "Solution", "callable": "waysToSplitArray", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnipp...
2,271
maximum-white-tiles-covered-by-a-carpet
Medium
You are given a 2D integer array tiles where tiles[i] = [l_i, r_i] represents that every tile j in the range l_i <= j <= r_i is colored white. You are also given an integer carpetLen, the length of a single carpet that can be placed anywhere. Return the maximum number of white tiles that can be covered by the carpet....
{ "language": "python", "source": "def check(candidate):\n assert candidate(tiles = [[1, 1000000000]],carpetLen = 1000000000) == 1000000000\n assert candidate(tiles = [[1, 10], [11, 20], [21, 30]],carpetLen = 15) == 15\n assert candidate(tiles = [[1, 2], [4, 5], [7, 8], [10, 11]],carpetLen = 3) == 2\n a...
[ "[[1,5],[10,11],[12,18],[20,25],[30,32]]\n10", "[[10,11],[1,1]]\n2" ]
[ "Think about the potential placements of the carpet in an optimal solution.", "Can we use Prefix Sum and Binary Search to determine how many tiles are covered for a given placement?" ]
{ "canonical_parameter_names": [ "tiles", "carpetLen" ], "leetcode_dataset_entry_point": "Solution().maximumWhiteTiles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:04", "tests_t...
cpp
{ "raw_signature": "int maximumWhiteTiles(vector<vector<int>>& tiles, int carpetLen) {", "container": "Solution", "callable": "maximumWhiteTiles", "parameters": [ { "name": "tiles", "type": "vector<vector<int>>&" }, { "name": "carpetLen", "type": "int" } ], "return_ty...
2,272
substring-with-largest-variance
Hard
The variance of a string is defined as the largest difference between the number of occurrences of any 2 characters present in the string. Note the two characters may or may not be the same. Given a string s consisting of lowercase English letters only, return the largest variance possible among all substrings of s. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzy\") == 5\n assert candidate(s = \"zyzzyzyzy\") == 2\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(s = \"abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 1\n assert candid...
[ "\"aababbb\"", "\"abcde\"" ]
[ "Think about how to solve the problem if the string had only two distinct characters.", "If we replace all occurrences of the first character by +1 and those of the second character by -1, can we efficiently calculate the largest possible variance of a string with only two distinct characters?", "Now, try findi...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().largestVariance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:07", "tests_total": 25, "tests_dro...
cpp
{ "raw_signature": "int largestVariance(string s) {", "container": "Solution", "callable": "largestVariance", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,273
find-resultant-array-after-removing-anagrams
Easy
You are given a 0-indexed string array words, where words[i] consists of lowercase English letters. In one operation, select any index i such that 0 < i < words.length and words[i - 1] and words[i] are anagrams, and delete words[i] from words. Keep performing this operation as long as you can select an index that sati...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['abc', 'cab', 'bca', 'xyz', 'zyx', 'yxz']) == ['abc', 'xyz']\n assert candidate(words = ['abc', 'cba', 'bca', 'xyz', 'zyx']) == ['abc', 'xyz']\n assert candidate(words = ['unique', 'words', 'here', 'now']) == ['unique', 'w...
[ "[\"abba\",\"baba\",\"bbaa\",\"cd\",\"cd\"]", "[\"a\",\"b\",\"c\",\"d\",\"e\"]" ]
[ "Instead of removing each repeating anagram, try to find all the strings in words which will not be present in the final answer.", "For every index i, find the largest index j < i such that words[j] will be present in the final answer.", "Check if words[i] and words[j] are anagrams. If they are, then it can be ...
{ "canonical_parameter_names": [ "words" ], "leetcode_dataset_entry_point": "Solution().removeAnagrams", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:09", "tests_total": 86, "tests_...
cpp
{ "raw_signature": "vector<string> removeAnagrams(vector<string>& words) {", "container": "Solution", "callable": "removeAnagrams", "parameters": [ { "name": "words", "type": "vector<string>&" } ], "return_type": "vector<string>", "signature_source": "leetcode/codeSnippets", "type_so...
2,274
maximum-consecutive-floors-without-special-floors
Medium
Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be special floors, used for relaxation only. You are given two integers bottom and top, which denote that Alice has rented all the floors from bottom to top (inclusive). You are also given th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(bottom = 3,top = 7,special = [3, 4, 5, 6, 7]) == 0\n assert candidate(bottom = 1,top = 1,special = [1]) == 0\n assert candidate(bottom = 1,top = 10,special = [3, 5, 7, 9]) == 2\n assert candidate(bottom = 6,top = 8,special = [7,...
[ "2\n9\n[4,6]", "6\n8\n[7,6,8]" ]
[ "Say we have a pair of special floors (x, y) with no other special floors in between. There are x - y - 1 consecutive floors in between them without a special floor.", "Say there are n special floors. After sorting special, we have answer = max(answer, special[i] – special[i – 1] – 1) for all 0 < i < n.", "Howe...
{ "canonical_parameter_names": [ "bottom", "top", "special" ], "leetcode_dataset_entry_point": "Solution().maxConsecutive", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:12", "...
cpp
{ "raw_signature": "int maxConsecutive(int bottom, int top, vector<int>& special) {", "container": "Solution", "callable": "maxConsecutive", "parameters": [ { "name": "bottom", "type": "int" }, { "name": "top", "type": "int" }, { "name": "special", "type":...
2,275
largest-combination-with-bitwise-and-greater-than-zero
Medium
The bitwise AND of an array nums is the bitwise AND of all integers in nums. - For example, for nums = [1, 5, 3], the bitwise AND is equal to 1 & 5 & 3 = 1. - Also, for nums = [7], the bitwise AND is 7. You are given an array of positive integers candidates. Compute the bitwise AND for all possible combinations of el...
{ "language": "python", "source": "def check(candidate):\n assert candidate(candidates = [16, 17, 71, 62, 12, 24, 14]) == 4\n assert candidate(candidates = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 16\n assert candidate(candidates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert ca...
[ "[16,17,71,62,12,24,14]", "[8,8]" ]
[ "For the bitwise AND to be greater than zero, at least one bit should be 1 for every number in the combination.", "The candidates are 24 bits long, so for every bit position, we can calculate the size of the largest combination such that the bitwise AND will have a 1 at that bit position." ]
{ "canonical_parameter_names": [ "candidates" ], "leetcode_dataset_entry_point": "Solution().largestCombination", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:14", "tests_total": 92, ...
cpp
{ "raw_signature": "int largestCombination(vector<int>& candidates) {", "container": "Solution", "callable": "largestCombination", "parameters": [ { "name": "candidates", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "le...
2,278
percentage-of-letter-in-string
Easy
Given a string s and a character letter, return the percentage of characters in s that equal letter rounded down to the nearest whole percent. Example 1: Input: s = "foobar", letter = "o" Output: 33 Explanation: The percentage of characters in s that equal the letter 'o' is 2 / 6 * 100% = 33% when rounded down, so we...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"jjjj\",letter = \"k\") == 0\n assert candidate(s = \"foobar\",letter = \"o\") == 33\n assert candidate(s = \"mississippi\",letter = \"i\") == 36\n assert candidate(s = \"python\",letter = \"y\") == 16\n assert candidate...
[ "\"foobar\"\n\"o\"", "\"jjjj\"\n\"k\"" ]
[ "Can we count the number of occurrences of letter in s?", "Recall that the percentage is calculated as (occurrences / total) * 100." ]
{ "canonical_parameter_names": [ "s", "letter" ], "leetcode_dataset_entry_point": "Solution().percentageLetter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:19", "tests_total": 1...
cpp
{ "raw_signature": "int percentageLetter(string s, char letter) {", "container": "Solution", "callable": "percentageLetter", "parameters": [ { "name": "s", "type": "string" }, { "name": "letter", "type": "char" } ], "return_type": "int", "signature_source": "leetcod...
2,279
maximum-bags-with-full-capacity-of-rocks
Medium
You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The i^th bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also given an integer additionalRocks, the number of additional rocks you can place in any of the bags. Return the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(capacity = [2, 3, 4, 5],rocks = [1, 2, 4, 4],additionalRocks = 2) == 3\n assert candidate(capacity = [1, 2, 3],rocks = [0, 0, 0],additionalRocks = 5) == 2\n assert candidate(capacity = [3, 2, 1],rocks = [0, 0, 0],additionalRocks = ...
[ "[2,3,4,5]\n[1,2,4,4]\n2", "[10,2,2]\n[2,2,0]\n100" ]
[ "Which bag should you fill completely first?", "Can you think of a greedy solution?" ]
{ "canonical_parameter_names": [ "capacity", "rocks", "additionalRocks" ], "leetcode_dataset_entry_point": "Solution().maximumBags", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47...
cpp
{ "raw_signature": "int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {", "container": "Solution", "callable": "maximumBags", "parameters": [ { "name": "capacity", "type": "vector<int>&" }, { "name": "rocks", "type": "vector<int>&" }, { ...
2,280
minimum-lines-to-represent-a-line-chart
Medium
You are given a 2D integer array stockPrices where stockPrices[i] = [day_i, price_i] indicates the price of the stock on day day_i is price_i. A line chart is created from the array by plotting the points on an XY plane with the X-axis representing the day and the Y-axis representing the price and connecting adjacent p...
{ "language": "python", "source": "def check(candidate):\n assert candidate(stockPrices = [[3, 4], [1, 2], [7, 8], [2, 3]]) == 1\n assert candidate(stockPrices = [[1, 7], [2, 6], [3, 5], [4, 4], [5, 4], [6, 3], [7, 2], [8, 1]]) == 3\n assert candidate(stockPrices = [[1, 1], [2, 3], [4, 5], [6, 7], [8, 9], ...
[ "[[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]", "[[3,4],[1,2],[7,8],[2,3]]" ]
[ "When will three adjacent points lie on the same line? How can we generalize this for all points?", "Will calculating the slope of lines connecting adjacent points help us find the answer?" ]
{ "canonical_parameter_names": [ "stockPrices" ], "leetcode_dataset_entry_point": "Solution().minimumLines", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:23", "tests_total": 107, "t...
cpp
{ "raw_signature": "int minimumLines(vector<vector<int>>& stockPrices) {", "container": "Solution", "callable": "minimumLines", "parameters": [ { "name": "stockPrices", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source...
2,281
sum-of-total-strength-of-wizards
Hard
As the ruler of a kingdom, you have an army of wizards at your command. You are given a 0-indexed integer array strength, where strength[i] denotes the strength of the i^th wizard. For a contiguous group of wizards (i.e. the wizards' strengths form a subarray of strength), the total strength is defined as the product ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(strength = [1]) == 1\n assert candidate(strength = [1, 1, 1, 1, 1]) == 35\n assert candidate(strength = [10, 9, 8, 7, 6]) == 1988\n assert candidate(strength = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4576\n assert candidate(stren...
[ "[1,3,1,2]", "[5,4,6]" ]
[ "Consider the contribution of each wizard to the answer.", "Can you efficiently calculate the total contribution to the answer for all subarrays that end at each index?", "Denote the total contribution of all subarrays ending at index i as solve[i]. Can you express solve[i] in terms of solve[m] for some m < i?"...
{ "canonical_parameter_names": [ "strength" ], "leetcode_dataset_entry_point": "Solution().totalStrength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:26", "tests_total": 104, "tes...
cpp
{ "raw_signature": "int totalStrength(vector<int>& strength) {", "container": "Solution", "callable": "totalStrength", "parameters": [ { "name": "strength", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSni...
2,283
check-if-number-has-equal-digit-count-and-digit-value
Easy
You are given a 0-indexed string num of length n consisting of digits. Return true if for every index i in the range 0 <= i < n, the digit i occurs num[i] times in num, otherwise return false. Example 1: Input: num = "1210" Output: true Explanation: num[0] = '1'. The digit 0 occurs once in num. num[1] = '2'. The dig...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = \"1111\") == False\n assert candidate(num = \"00000\") == False\n assert candidate(num = \"10\") == False\n assert candidate(num = \"1111111111\") == False\n assert candidate(num = \"000\") == False\n assert candidat...
[ "\"1210\"", "\"030\"" ]
[ "Count the frequency of each digit in num." ]
{ "canonical_parameter_names": [ "num" ], "leetcode_dataset_entry_point": "Solution().digitCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:30", "tests_total": 150, "tests_dropp...
cpp
{ "raw_signature": "bool digitCount(string num) {", "container": "Solution", "callable": "digitCount", "parameters": [ { "name": "num", "type": "string" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,284
sender-with-largest-word-count
Medium
You have a chat log of n messages. You are given two string arrays messages and senders where messages[i] is a message sent by senders[i]. A message is list of words that are separated by a single space with no leading or trailing spaces. The word count of a sender is the total number of words sent by the sender. Note...
{ "language": "python", "source": "def check(candidate):\n assert candidate(messages = ['This is a test', 'Another test', 'Final test'],senders = ['Alice', 'Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Hi'],senders = ['Bob']) == \"Bob\"\n assert candidate(messages = ['Short', 'Longer messag...
[ "[\"Hello userTwooo\",\"Hi userThree\",\"Wonderful day Alice\",\"Nice day userThree\"]\n[\"Alice\",\"userTwo\",\"userThree\",\"Alice\"]", "[\"How is leetcode for everyone\",\"Leetcode is useful for practice\"]\n[\"Bob\",\"Charlie\"]" ]
[ "The number of words in a message is equal to the number of spaces + 1.", "Use a hash map to count the total number of words from each sender." ]
{ "canonical_parameter_names": [ "messages", "senders" ], "leetcode_dataset_entry_point": "Solution().largestWordCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:33", "tests_t...
cpp
{ "raw_signature": "string largestWordCount(vector<string>& messages, vector<string>& senders) {", "container": "Solution", "callable": "largestWordCount", "parameters": [ { "name": "messages", "type": "vector<string>&" }, { "name": "senders", "type": "vector<string>&" } ...
2,285
maximum-total-importance-of-roads
Medium
You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1. You are also given a 2D integer array roads where roads[i] = [a_i, b_i] denotes that there exists a bidirectional road connecting cities a_i and b_i. You need to assign each city with an integer value from ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,roads = [[0, 1], [1, 2], [2, 3], [0, 2], [1, 3], [2, 4]]) == 43\n assert candidate(n = 6,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5]]) == 45\n assert candidate(n = 3,roads = [[0, 1], [1, 2]]) == 9\n assert candidate(n ...
[ "5\n[[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]", "5\n[[0,3],[2,4],[1,3]]" ]
[ "Consider what each city contributes to the total importance of all roads.", "Based on that, how can you sort the cities such that assigning them values in that order will yield the maximum total importance?" ]
{ "canonical_parameter_names": [ "n", "roads" ], "leetcode_dataset_entry_point": "Solution().maximumImportance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:35", "tests_total": 6...
cpp
{ "raw_signature": "long long maximumImportance(int n, vector<vector<int>>& roads) {", "container": "Solution", "callable": "maximumImportance", "parameters": [ { "name": "n", "type": "int" }, { "name": "roads", "type": "vector<vector<int>>&" } ], "return_type": "long...
2,287
rearrange-characters-to-make-target-string
Easy
You are given two 0-indexed strings s and target. You can take some letters from s and rearrange them to form new strings. Return the maximum number of copies of target that can be formed by taking letters from s and rearranging them. Example 1: Input: s = "ilovecodingonleetcode", target = "code" Output: 2 Explanati...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbc\",target = \"abc\") == 1\n assert candidate(s = \"aabbbccc\",target = \"abc\") == 2\n assert candidate(s = \"zzzz\",target = \"zz\") == 2\n assert candidate(s = \"abcabcabc\",target = \"abc\") == 3\n assert candid...
[ "\"ilovecodingonleetcode\"\n\"code\"", "\"abcba\"\n\"abc\"", "\"abbaccaddaeea\"\n\"aaaaa\"" ]
[ "Count the frequency of each character in s and target.", "Consider each letter one at a time. If there are x occurrences of a letter in s and y occurrences of the same letter in target, how many copies of this letter can we make?", "We can make floor(x / y) copies of the letter." ]
{ "canonical_parameter_names": [ "s", "target" ], "leetcode_dataset_entry_point": "Solution().rearrangeCharacters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:37", "tests_total"...
cpp
{ "raw_signature": "int rearrangeCharacters(string s, string target) {", "container": "Solution", "callable": "rearrangeCharacters", "parameters": [ { "name": "s", "type": "string" }, { "name": "target", "type": "string" } ], "return_type": "int", "signature_source"...
2,288
apply-discount-to-prices
Medium
A sentence is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign '$'. A word represents a price if it is a sequence of digits preceded by a dollar sign. - For example, "$100", "$23", and "$6" represent prices while "100", "$", and "$1e5" do not. You are...
{ "language": "python", "source": "def check(candidate):\n assert candidate(sentence = \"$10 $20 $30 $40 $50\",discount = 0) == \"$10.00 $20.00 $30.00 $40.00 $50.00\"\n assert candidate(sentence = \"$100 $200 $300\",discount = 25) == \"$75.00 $150.00 $225.00\"\n assert candidate(sentence = \"no prices here...
[ "\"there are $1 $2 and 5$ candies in the shop\"\n50", "\"1 2 $3 4 $5 $6 7 8$ $9 $10$\"\n100" ]
[ "Extract each word from the sentence and check if it represents a price.", "For each price, apply the given discount to it and update it." ]
{ "canonical_parameter_names": [ "sentence", "discount" ], "leetcode_dataset_entry_point": "Solution().discountPrices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:40", "tests_to...
cpp
{ "raw_signature": "string discountPrices(string sentence, int discount) {", "container": "Solution", "callable": "discountPrices", "parameters": [ { "name": "sentence", "type": "string" }, { "name": "discount", "type": "int" } ], "return_type": "string", "signature...
2,289
steps-to-make-array-non-decreasing
Medium
You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i - 1] > nums[i] for all 0 < i < nums.length. Return the number of steps performed until nums becomes a non-decreasing array. Example 1: Input: nums = [5,3,4,4,7,3,6,11,8,5,11] Output: 3 Explanation: The following are t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 1\n assert candidate(nums = [3, 2, 1, 2, 1, 2, 3, 2, 1]) == 3\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000...
[ "[5,3,4,4,7,3,6,11,8,5,11]", "[4,5,7,7,13]" ]
[ "Notice that an element will be removed if and only if there exists a strictly greater element to the left of it in the array.", "For each element, we need to find the number of rounds it will take for it to be removed. The answer is the maximum number of rounds for all elements. Build an array dp to hold this in...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().totalSteps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:42", "tests_total": 129, "tests_drop...
cpp
{ "raw_signature": "int totalSteps(vector<int>& nums) {", "container": "Solution", "callable": "totalSteps", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,290
minimum-obstacle-removal-to-reach-corner
Hard
You are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values: - 0 represents an empty cell, - 1 represents an obstacle that may be removed. You can move up, down, left, or right from and to an empty cell. Return the minimum number of obstacles to remove so you can move from the uppe...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 1], [1, 0]]) == 1\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 0\n assert candidate(grid = [[0, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 0]]) == 4\n assert candidate(grid = [[0, 1, 1, 0], [1, 1, 1, 0], [1...
[ "[[0,1,1],[1,1,0],[1,1,0]]", "[[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]]" ]
[ "Model the grid as a graph where cells are nodes and edges are between adjacent cells. Edges to cells with obstacles have a cost of 1 and all other edges have a cost of 0.", "Could you use 0-1 Breadth-First Search or Dijkstra’s algorithm?" ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minimumObstacles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:45", "tests_total": 59, "tests...
cpp
{ "raw_signature": "int minimumObstacles(vector<vector<int>>& grid) {", "container": "Solution", "callable": "minimumObstacles", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "le...
2,293
min-max-game
Easy
You are given a 0-indexed integer array nums whose length is a power of 2. Apply the following algorithm on nums: 1. Let n be the length of nums. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n / 2. 2. For every even index i where 0 <= i < n / 2, assign the value of new...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 2, 4, 8, 2, 2]) == 1\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [5, 1, 4, 2, 7, 6, 3, 8]) == ...
[ "[1,3,5,2,4,8,2,2]", "[3]" ]
[ "Simply simulate the algorithm.", "Note that the size of the array decreases exponentially, so the process will terminate after just O(log n) steps." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minMaxGame", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:49", "tests_total": 93, "tests_dropp...
cpp
{ "raw_signature": "int minMaxGame(vector<int>& nums) {", "container": "Solution", "callable": "minMaxGame", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,294
partition-array-such-that-maximum-difference-is-k
Medium
You are given an integer array nums and an integer k. You may partition nums into one or more subsequences such that each element in nums appears in exactly one of the subsequences. Return the minimum number of subsequences needed such that the difference between the maximum and minimum values in each subsequence is a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 100000],k = 99999) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 4\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k...
[ "[3,6,1,2,5]\n2", "[1,2,3]\n1", "[2,2,4,5]\n0" ]
[ "Which values in each subsequence matter? The only values that matter are the maximum and minimum values.", "Let the maximum and minimum values of a subsequence be Max and Min. It is optimal to place all values in between Max and Min in the original array in the same subsequence as Max and Min.", "Sort the arra...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().partitionArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:52", "tests_total": 112, ...
cpp
{ "raw_signature": "int partitionArray(vector<int>& nums, int k) {", "container": "Solution", "callable": "partitionArray", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetc...
2,295
replace-elements-in-an-array
Medium
You are given a 0-indexed array nums that consists of n distinct positive integers. Apply m operations to this array, where in the i^th operation you replace the number operations[i][0] with operations[i][1]. It is guaranteed that in the i^th operation: - operations[i][0] exists in nums. - operations[i][1] does not e...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2],operations = [[1, 3], [2, 1], [3, 2]]) == [2, 1]\n assert candidate(nums = [5, 3, 7, 8],operations = [[5, 10], [3, 15], [7, 20], [8, 25]]) == [10, 15, 20, 25]\n assert candidate(nums = [1, 2, 3, 4, 5],operations = [[1...
[ "[1,2,4,6]\n[[1,3],[4,7],[6,1]]", "[1,2]\n[[1,3],[2,1],[3,2]]" ]
[ "Can you think of a data structure that will allow you to store the position of each number?", "Use that data structure to instantly replace a number with its new value." ]
{ "canonical_parameter_names": [ "nums", "operations" ], "leetcode_dataset_entry_point": "Solution().arrayChange", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:54", "tests_total":...
cpp
{ "raw_signature": "vector<int> arrayChange(vector<int>& nums, vector<vector<int>>& operations) {", "container": "Solution", "callable": "arrayChange", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "operations", "type": "vector<vector<int>>&" } ]...
2,300
successful-pairs-of-spells-and-potions
Medium
You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the i^th spell and potions[j] represents the strength of the j^th potion. You are also given an integer success. A spell and potion pair is considered successful if the product of th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(spells = [3, 1, 2],potions = [8, 5, 8],success = 16) == [2, 0, 2]\n assert candidate(spells = [1, 1, 1],potions = [1, 1, 1],success = 2) == [0, 0, 0]\n assert candidate(spells = [5, 1, 3],potions = [1, 2, 3, 4, 5],success = 7) == [...
[ "[5,1,3]\n[1,2,3,4,5]\n7", "[3,1,2]\n[8,5,8]\n16" ]
[ "Notice that if a spell and potion pair is successful, then the spell and all stronger potions will be successful too.", "Thus, for each spell, we need to find the potion with the least strength that will form a successful pair.", "We can efficiently do this by sorting the potions based on strength and using bi...
{ "canonical_parameter_names": [ "spells", "potions", "success" ], "leetcode_dataset_entry_point": "Solution().successfulPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:01"...
cpp
{ "raw_signature": "vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {", "container": "Solution", "callable": "successfulPairs", "parameters": [ { "name": "spells", "type": "vector<int>&" }, { "name": "potions", "type": "vector<int>&" ...
2,301
match-substring-after-replacement
Hard
You are given two strings s and sub. You are also given a 2D character array mappings where mappings[i] = [old_i, new_i] indicates that you may perform the following operation any number of times: - Replace a character old_i of sub with new_i. Each character in sub cannot be replaced more than once. Return true if i...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"fooleetbar\",sub = \"f00l\",mappings = [['o', '0']]) == False\n assert candidate(s = \"fool3e7bar\",sub = \"leet\",mappings = [['e', '3'], ['t', '7'], ['t', '8']]) == True\n assert candidate(s = \"Fool33tbaR\",sub = \"leetd\"...
[ "\"fool3e7bar\"\n\"leet\"\n[[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"]]", "\"fooleetbar\"\n\"f00l\"\n[[\"o\",\"0\"]]", "\"Fool33tbaR\"\n\"leetd\"\n[[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"],[\"d\",\"b\"],[\"p\",\"b\"]]" ]
[ "Enumerate all substrings of s with the same length as sub, and compare each substring to sub for equality.", "How can you quickly tell if a character of s can result from replacing the corresponding character in sub?" ]
{ "canonical_parameter_names": [ "s", "sub", "mappings" ], "leetcode_dataset_entry_point": "Solution().matchReplacement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:03", "te...
cpp
{ "raw_signature": "bool matchReplacement(string s, string sub, vector<vector<char>>& mappings) {", "container": "Solution", "callable": "matchReplacement", "parameters": [ { "name": "s", "type": "string" }, { "name": "sub", "type": "string" }, { "name": "mappin...
2,302
count-subarrays-with-score-less-than-k
Hard
The score of an array is defined as the product of its sum and its length. - For example, the score of [1, 2, 3, 4, 5] is (1 + 2 + 3 + 4 + 5) * 5 = 75. Given a positive integer array nums and an integer k, return the number of non-empty subarrays of nums whose score is strictly less than k. A subarray is a contiguou...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 100) == 15\n assert candidate(nums = [10, 10, 10],k = 100) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 50) == 24\n assert candidate(nums = [1, 1, 1],k = 5) == 5\n assert candi...
[ "[2,1,4,3,5]\n10", "[1,1,1]\n5" ]
[ "If we add an element to a list of elements, how will the score change?", "How can we use this to determine the number of subarrays with score less than k in a given range?", "How can we use “Two Pointers” to generalize the solution, and thus count all possible subarrays?" ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().countSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:06", "tests_total": 79, ...
cpp
{ "raw_signature": "long long countSubarrays(vector<int>& nums, long long k) {", "container": "Solution", "callable": "countSubarrays", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "k", "type": "long long" } ], "return_type": "long long", "s...
2,303
calculate-amount-paid-in-taxes
Easy
You are given a 0-indexed 2D integer array brackets where brackets[i] = [upper_i, percent_i] means that the i^th tax bracket has an upper bound of upper_i and is taxed at a rate of percent_i. The brackets are sorted by upper bound (i.e. upper_{i-1} < upper_i for 0 < i < brackets.length). Tax is calculated as follows: ...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat...
[ "[[3,50],[7,10],[12,25]]\n10", "[[1,0],[4,25],[5,50]]\n2", "[[2,50]]\n0" ]
[ "As you iterate through the tax brackets, keep track of the previous tax bracket’s upper bound in a variable called prev. If there is no previous tax bracket, use 0 instead.", "The amount of money in the ith tax bracket is min(income, upperi) - prev." ]
{ "canonical_parameter_names": [ "brackets", "income" ], "leetcode_dataset_entry_point": "Solution().calculateTax", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:08", "tests_total"...
cpp
{ "raw_signature": "double calculateTax(vector<vector<int>>& brackets, int income) {", "container": "Solution", "callable": "calculateTax", "parameters": [ { "name": "brackets", "type": "vector<vector<int>>&" }, { "name": "income", "type": "int" } ], "return_type": "d...
2,304
minimum-path-cost-in-a-grid
Medium
You are given a 0-indexed m x n integer matrix grid consisting of distinct integers from 0 to m * n - 1. You can move in this matrix from a cell to any other cell in the next row. That is, if you are in cell (x, y) such that x < m - 1, you can move to any of the cells (x + 1, 0), (x + 1, 1), ..., (x + 1, n - 1). Note t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],moveCost = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21], [22, 23, 24], [25, 26, 27]]) == 29\n assert candidate(grid = [[1, 2, 3], [4, 5, 6]],moveCost...
[ "[[5,3],[4,0],[2,1]]\n[[9,8],[1,5],[10,12],[18,6],[2,4],[14,3]]", "[[5,1,2],[4,0,3]]\n[[12,10,15],[20,23,8],[21,7,1],[8,1,13],[9,10,25],[5,3,2]]" ]
[ "What is the optimal cost to get to each of the cells in the second row? What about the third row?", "Use dynamic programming to compute the optimal cost to get to each cell." ]
{ "canonical_parameter_names": [ "grid", "moveCost" ], "leetcode_dataset_entry_point": "Solution().minPathCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:10", "tests_total": 2...
cpp
{ "raw_signature": "int minPathCost(vector<vector<int>>& grid, vector<vector<int>>& moveCost) {", "container": "Solution", "callable": "minPathCost", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" }, { "name": "moveCost", "type": "vector<vector<int>>&" }...
2,305
fair-distribution-of-cookies
Medium
You are given an integer array cookies, where cookies[i] denotes the number of cookies in the i^th bag. You are also given an integer k that denotes the number of children to distribute all the bags of cookies to. All the cookies in the same bag must go to the same child and cannot be split up. The unfairness of a dis...
{ "language": "python", "source": "def check(candidate):\n assert candidate(cookies = [1, 1, 1, 1, 1, 1, 1, 100000],k = 7) == 100000\n assert candidate(cookies = [8, 15, 10, 20, 8],k = 2) == 31\n assert candidate(cookies = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],k = 8) == 100000\n ...
[ "[8,15,10,20,8]\n2", "[6,1,3,2,2,4,1,2]\n3" ]
[ "We have to give each bag to one of the children. How can we enumerate all of the possibilities?", "Use recursion and keep track of the current number of cookies each child has. Once all the bags have been distributed, find the child with the most cookies." ]
{ "canonical_parameter_names": [ "cookies", "k" ], "leetcode_dataset_entry_point": "Solution().distributeCookies", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:13", "tests_total":...
cpp
{ "raw_signature": "int distributeCookies(vector<int>& cookies, int k) {", "container": "Solution", "callable": "distributeCookies", "parameters": [ { "name": "cookies", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_sou...
2,306
naming-a-company
Hard
You are given an array of strings ideas that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows: 1. Choose 2 distinct names from ideas, call them idea_A and idea_B. 2. Swap the first letters of idea_A and idea_B with each other. 3. If both of the new...
{ "language": "python", "source": "def check(candidate):\n assert candidate(ideas = ['coffee', 'donuts', 'time', 'toffee']) == 6\n assert candidate(ideas = ['aaa', 'bbb', 'ccc']) == 6\n assert candidate(ideas = ['abc', 'bcd', 'cde', 'dec']) == 12\n assert candidate(ideas = ['abcd', 'dcba', 'ddda', 'dccd...
[ "[\"coffee\",\"donuts\",\"time\",\"toffee\"]", "[\"lack\",\"back\"]" ]
[ "How can we divide the ideas into groups to make it easier to find valid pairs?", "Group ideas that share the same suffix (all characters except the first) together and notice that a pair of ideas from the same group is invalid. What about pairs of ideas from different groups?", "The first letter of the idea in...
{ "canonical_parameter_names": [ "ideas" ], "leetcode_dataset_entry_point": "Solution().distinctNames", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:15", "tests_total": 45, "tests_d...
cpp
{ "raw_signature": "long long distinctNames(vector<string>& ideas) {", "container": "Solution", "callable": "distinctNames", "parameters": [ { "name": "ideas", "type": "vector<string>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "leet...
2,309
greatest-english-letter-in-upper-and-lower-case
Easy
Given a string of English letters s, return the greatest English letter which occurs as both a lowercase and uppercase letter in s. The returned letter should be in uppercase. If no such letter exists, return an empty string. An English letter b is greater than another letter a if b appears after a in the English alph...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"Z\"\n assert candidate(s = \"mMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"Z\"\n assert candidate(s = \"zZyYxXwWeE\") == \"Z\"\n assert candidate(s = \"zZyYxXwWvVuUtTrRsS...
[ "\"lEeTcOdE\"", "\"arRAzFif\"", "\"AbCdEfGhIjK\"" ]
[ "Consider iterating through the string and storing each unique character that occurs in a set.", "From Z to A, check whether both the uppercase and lowercase version occur in the set." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().greatestLetter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:20", "tests_total": 117, "tests_dro...
cpp
{ "raw_signature": "string greatestLetter(string s) {", "container": "Solution", "callable": "greatestLetter", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,310
sum-of-numbers-with-units-digit-k
Medium
Given two integers num and k, consider a set of positive integers with the following properties: - The units digit of each integer is k. - The sum of the integers is num. Return the minimum possible size of such a set, or -1 if no such set exists. Note: - The set can contain multiple instances of the same integer, ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num = 25,k = 5) == 1\n assert candidate(num = 2023,k = 3) == 1\n assert candidate(num = 37,k = 2) == -1\n assert candidate(num = 100,k = 0) == 1\n assert candidate(num = 58,k = 9) == 2\n assert candidate(num = 99,k = 9) ==...
[ "58\n9", "37\n2", "0\n7" ]
[ "Try solving this recursively.", "Create a method that takes an integer x as a parameter. This method returns the minimum possible size of a set where each number has units digit k and the sum of the numbers in the set is x." ]
{ "canonical_parameter_names": [ "num", "k" ], "leetcode_dataset_entry_point": "Solution().minimumNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:22", "tests_total": 114, ...
cpp
{ "raw_signature": "int minimumNumbers(int num, int k) {", "container": "Solution", "callable": "minimumNumbers", "parameters": [ { "name": "num", "type": "int" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", ...
2,311
longest-binary-subsequence-less-than-or-equal-to-k
Medium
You are given a binary string s and a positive integer k. Return the length of the longest subsequence of s that makes up a binary number less than or equal to k. Note: - The subsequence can contain leading zeroes. - The empty string is considered to be equal to 0. - A subsequence is a string that can be derived fro...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"111000111\",k = 127) == 7\n assert candidate(s = \"1111111\",k = 127) == 7\n assert candidate(s = \"1111000011\",k = 255) == 8\n assert candidate(s = \"1100110011\",k = 10) == 6\n assert candidate(s = \"1010101010\",k =...
[ "\"1001010\"\n5", "\"00101001\"\n1" ]
[ "Choosing a subsequence from the string is equivalent to deleting all the other digits.", "If you were to remove a digit, which one should you remove to reduce the value of the string?" ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().longestSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:24", "tests_total": 101,...
cpp
{ "raw_signature": "int longestSubsequence(string s, int k) {", "container": "Solution", "callable": "longestSubsequence", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSn...
2,312
selling-pieces-of-wood
Hard
You are given two integers m and n that represent the height and width of a rectangular piece of wood. You are also given a 2D integer array prices, where prices[i] = [h_i, w_i, price_i] indicates you can sell a rectangular piece of wood of height h_i and width w_i for price_i dollars. To cut a piece of wood, you must...
{ "language": "python", "source": "def check(candidate):\n assert candidate(m = 4,n = 6,prices = [[3, 2, 10], [1, 4, 2], [4, 1, 3]]) == 32\n assert candidate(m = 2,n = 2,prices = [[1, 1, 1], [2, 2, 5]]) == 5\n assert candidate(m = 3,n = 5,prices = [[1, 4, 2], [2, 2, 7], [2, 1, 3]]) == 19\n assert candid...
[ "3\n5\n[[1,4,2],[2,2,7],[2,1,3]]", "4\n6\n[[3,2,10],[1,4,2],[4,1,3]]" ]
[ "Note down the different actions that can be done on a piece of wood with dimensions m x n. What do you notice?", "If possible, we could sell the m x n piece. We could also cut the piece vertically creating two pieces of size m x n1 and m x n2 where n1 + n2 = n, or horizontally creating two pieces of size m1 x n ...
{ "canonical_parameter_names": [ "m", "n", "prices" ], "leetcode_dataset_entry_point": "Solution().sellingWood", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:27", "tests_total...
cpp
{ "raw_signature": "long long sellingWood(int m, int n, vector<vector<int>>& prices) {", "container": "Solution", "callable": "sellingWood", "parameters": [ { "name": "m", "type": "int" }, { "name": "n", "type": "int" }, { "name": "prices", "type": "vector...
2,315
count-asterisks
Easy
You are given a string s, where every two consecutive vertical bars '|' are grouped into a pair. In other words, the 1^st and 2^nd '|' make a pair, the 3^rd and 4^th '|' make a pair, and so forth. Return the number of '*' in s, excluding the '*' between each pair of '|'. Note that each '|' will belong to exactly one ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"iamprogrammer\") == 0\n assert candidate(s = \"|*|*|*|*|\") == 2\n assert candidate(s = \"||||||||||\") == 0\n assert candidate(s = \"yo|uar|e**|b|e***au|tifu|l\") == 5\n assert candidate(s = \"l|*e*et|c**o|*de|\") == 2...
[ "\"l|*e*et|c**o|*de|\"", "\"iamprogrammer\"", "\"yo|uar|e**|b|e***au|tifu|l\"" ]
[ "Iterate through each character, while maintaining whether we are currently between a pair of ‘|’ or not.", "If we are not in between a pair of ‘|’ and there is a ‘*’, increment the answer by 1." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().countAsterisks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:29", "tests_total": 106, "tests_dro...
cpp
{ "raw_signature": "int countAsterisks(string s) {", "container": "Solution", "callable": "countAsterisks", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,316
count-unreachable-pairs-of-nodes-in-an-undirected-graph
Medium
You are given an integer n. There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [a_i, b_i] denotes that there exists an undirected edge connecting nodes a_i and b_i. Return the number of pairs of different nodes that are unreachable from each oth...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [3, 4]]) == 11\n assert candidate(n = 6,edges = []) == 15\n assert candidate(n = 3,edges = [[0, 1], [0, 2], [1, 2]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [2, 3]]) == 8\n assert candida...
[ "3\n[[0,1],[0,2],[1,2]]", "7\n[[0,2],[0,5],[2,4],[1,6],[5,4]]" ]
[ "Find the connected components of the graph. To find connected components, you can use Union Find (Disjoint Sets), BFS, or DFS.", "For a node u, the number of nodes that are unreachable from u is the number of nodes that are not in the same connected component as u.", "The number of unreachable nodes from node ...
{ "canonical_parameter_names": [ "n", "edges" ], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:31", "tests_total": 55, "t...
cpp
{ "raw_signature": "long long countPairs(int n, vector<vector<int>>& edges) {", "container": "Solution", "callable": "countPairs", "parameters": [ { "name": "n", "type": "int" }, { "name": "edges", "type": "vector<vector<int>>&" } ], "return_type": "long long", "sig...
2,317
maximum-xor-after-operations
Medium
You are given a 0-indexed integer array nums. In one operation, select any non-negative integer x and an index i, then update nums[i] to be equal to nums[i] AND (nums[i] XOR x). Note that AND is the bitwise AND operation and XOR is the bitwise XOR operation. Return the maximum possible bitwise XOR of all elements of ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [8, 1, 4, 2, 15]) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == 15\n assert candidate(nums = [1, 0, 3, 2]) == 3\n assert candidate(nums = [1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [1, 1, 1, 1]) ...
[ "[3,2,4,6]", "[1,2,3,9,2]" ]
[ "Consider what it means to be able to choose any x for the operation and which integers could be obtained from a given nums[i].", "The given operation can unset any bit in nums[i].", "The nth bit of the XOR of all the elements is 1 if the nth bit is 1 for an odd number of elements. When can we ensure it is odd?...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maximumXOR", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:34", "tests_total": 117, "tests_drop...
cpp
{ "raw_signature": "int maximumXOR(vector<int>& nums) {", "container": "Solution", "callable": "maximumXOR", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,318
number-of-distinct-roll-sequences
Hard
You are given an integer n. You roll a fair 6-sided dice n times. Determine the total number of distinct sequences of rolls possible such that the following conditions are satisfied: 1. The greatest common divisor of any adjacent values in the sequence is equal to 1. 2. There is at least a gap of 2 rolls between equal...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 66\n assert candidate(n = 100) == 534856607\n assert candidate(n = 4) == 184\n assert candidate(n = 10000) == 874574246\n assert candidate(n = 2) == 22\n assert candidate(n = 1) == 6\n assert candidate(n = 100...
[ "4", "2" ]
[ "Can you think of a DP solution?", "Consider a state that remembers the last 1 or 2 rolls.", "Do you need to consider the last 3 rolls?" ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().distinctSequences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:36", "tests_total": 21, "tests_d...
cpp
{ "raw_signature": "int distinctSequences(int n) {", "container": "Solution", "callable": "distinctSequences", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,319
check-if-matrix-is-x-matrix
Easy
A square matrix is said to be an X-Matrix if both of the following conditions hold: 1. All the elements in the diagonals of the matrix are non-zero. 2. All other elements are 0. Given a 2D integer array grid of size n x n representing a square matrix, return true if grid is an X-Matrix. Otherwise, return false. Exam...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2, 0, 0], [0, 0, 0, 3], [0, 0, 4, 0], [0, 5, 0, 0]]) == False\n assert candidate(grid = [[1, 2, 0, 0], [0, 3, 1, 0], [0, 5, 2, 0], [0, 0, 0, 4]]) == False\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0,...
[ "[[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]", "[[5,7,0],[0,3,1],[0,5,0]]" ]
[ "Assuming a 0-indexed matrix, for a given cell on row i and column j, it is in a diagonal if and only if i == j or i == n - 1 - j.", "We can then iterate through the elements in the matrix to check if all the elements in the diagonals are non-zero and all other elements are zero." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().checkXMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:38", "tests_total": 70, "tests_dro...
cpp
{ "raw_signature": "bool checkXMatrix(vector<vector<int>>& grid) {", "container": "Solution", "callable": "checkXMatrix", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode...
2,320
count-number-of-ways-to-place-houses
Medium
There is a street with n * 2 plots, where there are n plots on each side of the street. The plots on each side are numbered from 1 to n. On each plot, a house can be placed. Return the number of ways houses can be placed such that no two houses are adjacent to each other on the same side of the street. Since the answe...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 25\n assert candidate(n = 100) == 20522904\n assert candidate(n = 10000) == 402613600\n assert candidate(n = 2) == 9\n assert candidate(n = 1) == 4\n assert candidate(n = 1000) == 500478595\n assert candidate(...
[ "1", "2" ]
[ "Try coming up with a DP solution for one side of the street.", "The DP for one side of the street will bear resemblance to the Fibonacci sequence.", "The number of different arrangements on both side of the street is the same." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().countHousePlacements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:41", "tests_total": 33, "test...
cpp
{ "raw_signature": "int countHousePlacements(int n) {", "container": "Solution", "callable": "countHousePlacements", "parameters": [ { "name": "n", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,321
maximum-score-of-spliced-array
Hard
You are given two 0-indexed integer arrays nums1 and nums2, both of length n. You can choose two integers left and right where 0 <= left <= right < n and swap the subarray nums1[left...right] with the subarray nums2[left...right]. - For example, if nums1 = [1,2,3,4,5] and nums2 = [11,12,13,14,15] and you choose left ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [20, 40, 20, 70, 30],nums2 = [50, 20, 50, 40, 20]) == 220\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45]) == 150\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [10000, 10000, 10000, 10000, 1...
[ "[60,60,60]\n[10,90,10]", "[20,40,20,70,30]\n[50,20,50,40,20]", "[7,11,13]\n[1,1,1]" ]
[ "Think on Dynamic Programming.", "First assume you will be taking the array a and choose some subarray from b", "Suppose the DP is DP(pos, state). pos is the current position you are in. state is one of {0,1,2}, where 0 means taking the array a, 1 means we are taking the subarray b, and 2 means we are again tak...
{ "canonical_parameter_names": [ "nums1", "nums2" ], "leetcode_dataset_entry_point": "Solution().maximumsSplicedArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:43", "tests_to...
cpp
{ "raw_signature": "int maximumsSplicedArray(vector<int>& nums1, vector<int>& nums2) {", "container": "Solution", "callable": "maximumsSplicedArray", "parameters": [ { "name": "nums1", "type": "vector<int>&" }, { "name": "nums2", "type": "vector<int>&" } ], "return_ty...
2,322
minimum-score-after-removals-on-a-tree
Hard
There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the i^th node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [a_i, b_i] indicates that there is an ed...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 5, 5, 4, 11],edges = [[0, 1], [1, 2], [1, 3], [3, 4]]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50],edges = [[0, 1], [0, 2], [0, 3], [3, 4]]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6],edges = [[0, 1], [1, ...
[ "[1,5,5,4,11]\n[[0,1],[1,2],[1,3],[3,4]]", "[5,5,2,4,4,2]\n[[0,1],[1,2],[5,2],[4,3],[1,3]]" ]
[ "Consider iterating over the first edge to remove, and then doing some precalculations on the 2 resulting connected components.", "Will calculating the XOR of each subtree help?" ]
{ "canonical_parameter_names": [ "nums", "edges" ], "leetcode_dataset_entry_point": "Solution().minimumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:45", "tests_total": 55,...
cpp
{ "raw_signature": "int minimumScore(vector<int>& nums, vector<vector<int>>& edges) {", "container": "Solution", "callable": "minimumScore", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "edges", "type": "vector<vector<int>>&" } ], "return_type...
2,325
decode-the-message
Easy
You are given the strings key and message, which represent a cipher key and a secret message, respectively. The steps to decode message are as follows: 1. Use the first appearance of all 26 lowercase English letters in key as the order of the substitution table. 2. Align the substitution table with the regular English...
{ "language": "python", "source": "def check(candidate):\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"cba zyx\") == \"xyz abc\"\n assert candidate(key = \"a quick movement of the enemy will jeopardize five gunboats\",message = \"yfcj myj pyjl ufcj myj pyjl ufcj myj pyjl\") == \"omer gor...
[ "\"the quick brown fox jumps over the lazy dog\"\n\"vkbs bs t suepuv\"", "\"eljuxhpwnyrdgtqkviszcfmabo\"\n\"zwx hnfx lqantp mnoeius ycgk vcnjrdb\"" ]
[ "Iterate through the characters in the key to construct a mapping to the English alphabet.", "Make sure to check that the current character is not already in the mapping (only the first appearance is considered).", "Map the characters in the message according to the constructed mapping." ]
{ "canonical_parameter_names": [ "key", "message" ], "leetcode_dataset_entry_point": "Solution().decodeMessage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:50", "tests_total": 2...
cpp
{ "raw_signature": "string decodeMessage(string key, string message) {", "container": "Solution", "callable": "decodeMessage", "parameters": [ { "name": "key", "type": "string" }, { "name": "message", "type": "string" } ], "return_type": "string", "signature_source"...
2,327
number-of-people-aware-of-a-secret
Medium
On day 1, one person discovers a secret. You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the secret. You are also given an integer forget, which means that each person will forget the secret forget days after dis...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 8,delay = 3,forget = 6) == 6\n assert candidate(n = 500,delay = 100,forget = 400) == 5820125\n assert candidate(n = 4,delay = 1,forget = 3) == 6\n assert candidate(n = 1000,delay = 5,forget = 10) == 743819361\n assert can...
[ "6\n2\n4", "4\n1\n3" ]
[ "Let dp[i][j] be the number of people who have known the secret for exactly j + 1 days, at day i.", "If j > 0, dp[i][j] = dp[i – 1][j – 1].", "dp[i][0] = sum(dp[i – 1][j]) for j in [delay – 1, forget – 2]." ]
{ "canonical_parameter_names": [ "n", "delay", "forget" ], "leetcode_dataset_entry_point": "Solution().peopleAwareOfSecret", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:55", ...
cpp
{ "raw_signature": "int peopleAwareOfSecret(int n, int delay, int forget) {", "container": "Solution", "callable": "peopleAwareOfSecret", "parameters": [ { "name": "n", "type": "int" }, { "name": "delay", "type": "int" }, { "name": "forget", "type": "int" ...
2,328
number-of-increasing-paths-in-a-grid
Hard
You are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions. Return the number of strictly increasing paths in the grid such that you can start from any cell and end at any cell. Since the answer may be very large, return it modulo 10^9 + 7. Two paths are consid...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 9\n assert candidate(grid = [[4, 3, 2, 1], [3, 2, 1, 4], [2, 1, 4, 3], [1, 4, 3, 2]]) == 64\n assert candidate(grid = [[4, 3, 2, 1], [5, 6, 7, 8]]) == 50\n assert candidate(grid = [[1...
[ "[[1,1],[3,4]]", "[[1],[2]]" ]
[ "How can you calculate the number of increasing paths that start from a cell (i, j)? Think about dynamic programming.", "Define f(i, j) as the number of increasing paths starting from cell (i, j). Try to find how f(i, j) is related to each of f(i, j+1), f(i, j-1), f(i+1, j) and f(i-1, j)." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().countPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:57", "tests_total": 88, "tests_dropp...
cpp
{ "raw_signature": "int countPaths(vector<vector<int>>& grid) {", "container": "Solution", "callable": "countPaths", "parameters": [ { "name": "grid", "type": "vector<vector<int>>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeS...
2,332
the-latest-time-to-catch-a-bus
Medium
You are given a 0-indexed integer array buses of length n, where buses[i] represents the departure time of the i^th bus. You are also given a 0-indexed integer array passengers of length m, where passengers[j] represents the arrival time of the j^th passenger. All bus departure times are unique. All passenger arrival t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(buses = [50, 60, 70],passengers = [5, 10, 20, 30, 40],capacity = 5) == 70\n assert candidate(buses = [3, 5, 7],passengers = [2, 4, 6, 8],capacity = 1) == 5\n assert candidate(buses = [10, 20],passengers = [2, 17, 18, 19],capacity =...
[ "[10,20]\n[2,17,18,19]\n2", "[20,30,10]\n[19,13,26,4,25,11,21]\n2" ]
[ "Sort the buses and passengers arrays.", "Use 2 pointers to traverse buses and passengers with a simulation of passengers getting on a particular bus." ]
{ "canonical_parameter_names": [ "buses", "passengers", "capacity" ], "leetcode_dataset_entry_point": "Solution().latestTimeCatchTheBus", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T...
cpp
{ "raw_signature": "int latestTimeCatchTheBus(vector<int>& buses, vector<int>& passengers, int capacity) {", "container": "Solution", "callable": "latestTimeCatchTheBus", "parameters": [ { "name": "buses", "type": "vector<int>&" }, { "name": "passengers", "type": "vector<int>...
2,333
minimum-sum-of-squared-difference
Medium
You are given two positive 0-indexed integer arrays nums1 and nums2, both of length n. The sum of squared difference of arrays nums1 and nums2 is defined as the sum of (nums1[i] - nums2[i])^2 for each 0 <= i < n. You are also given two positive integers k1 and k2. You can modify any of the elements of nums1 by +1 or ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [5, 5, 5, 5],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45],k1 = 50,k2 = 50) == 0\n assert candidate(nums1 = [100000, 100000],nums2 = [0, 0],k1 = 100...
[ "[1,2,3,4]\n[2,10,20,19]\n0\n0", "[1,4,10,12]\n[5,8,6,9]\n1\n1" ]
[ "There is no difference between the purpose of k1 and k2. Adding +1 to one element in nums1 is same as performing -1 to one element in nums2, and vice versa.", "Reduce the sum of squared difference greedily. One operation of k should use the index that has the current maximum difference.", "Binary search the ma...
{ "canonical_parameter_names": [ "nums1", "nums2", "k1", "k2" ], "leetcode_dataset_entry_point": "Solution().minSumSquareDiff", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:...
cpp
{ "raw_signature": "long long minSumSquareDiff(vector<int>& nums1, vector<int>& nums2, int k1, int k2) {", "container": "Solution", "callable": "minSumSquareDiff", "parameters": [ { "name": "nums1", "type": "vector<int>&" }, { "name": "nums2", "type": "vector<int>&" }, ...
2,334
subarray-with-elements-greater-than-varying-threshold
Hard
You are given an integer array nums and an integer threshold. Find any subarray of nums of length k such that every element in the subarray is greater than threshold / k. Return the size of any such subarray. If there is no such subarray, return -1. A subarray is a contiguous non-empty sequence of elements within an...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],threshold = 15) == 1\n assert candidate(nums = [10, 10, 10, 10, 10],threshold = 1) == 1\n assert candidate(nums = [5, 5, 5, 5, 5],threshold = 25) == -1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4,...
[ "[1,3,4,3,1]\n6", "[6,5,6,5,8]\n7" ]
[ "For all elements to be greater than the threshold/length, the minimum element in the subarray must be greater than the threshold/length.", "For a given index, could you find the largest subarray such that the given index is the minimum element?", "Could you use a monotonic stack to get the next and previous sm...
{ "canonical_parameter_names": [ "nums", "threshold" ], "leetcode_dataset_entry_point": "Solution().validSubarraySize", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:10", "tests_to...
cpp
{ "raw_signature": "int validSubarraySize(vector<int>& nums, int threshold) {", "container": "Solution", "callable": "validSubarraySize", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "threshold", "type": "int" } ], "return_type": "int", "sig...
2,335
minimum-amount-of-time-to-fill-cups
Easy
You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up 2 cups with different types of water, or 1 cup of any type of water. You are given a 0-indexed integer array amount of length 3 where amount[0], amount[1], and amount[2] denote the number of cold, warm, and hot...
{ "language": "python", "source": "def check(candidate):\n assert candidate(amount = [33, 33, 34]) == 50\n assert candidate(amount = [0, 0, 0]) == 0\n assert candidate(amount = [99, 1, 1]) == 99\n assert candidate(amount = [7, 7, 7]) == 11\n assert candidate(amount = [10, 10, 10]) == 15\n assert c...
[ "[1,4,2]", "[5,4,4]", "[5,0,0]" ]
[ "To minimize the amount of time needed, you want to fill up as many cups as possible in each second. This means that you want to maximize the number of seconds where you are filling up two cups.", "You always want to fill up the two types of water with the most unfilled cups." ]
{ "canonical_parameter_names": [ "amount" ], "leetcode_dataset_entry_point": "Solution().fillCups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:12", "tests_total": 178, "tests_drop...
cpp
{ "raw_signature": "int fillCups(vector<int>& amount) {", "container": "Solution", "callable": "fillCups", "parameters": [ { "name": "amount", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,337
move-pieces-to-obtain-a-string
Medium
You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where: - The characters 'L' and 'R' represent pieces, where a piece 'L' can move to the left only if there is a blank space directly to its left, and a piece 'R' can move to the right only if the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(start = \"_R\",target = \"R_\") == False\n assert candidate(start = \"___\",target = \"___\") == True\n assert candidate(start = \"LR\",target = \"LR\") == True\n assert candidate(start = \"_LL_R\",target = \"LL__R\") == True\n ...
[ "\"_L__R__R_\"\n\"L______RR\"", "\"R_L_\"\n\"__LR\"", "\"_R\"\n\"R_\"" ]
[ "After some sequence of moves, can the order of the pieces change?", "Try to match each piece in s with a piece in e." ]
{ "canonical_parameter_names": [ "start", "target" ], "leetcode_dataset_entry_point": "Solution().canChange", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:14", "tests_total": 136,...
cpp
{ "raw_signature": "bool canChange(string start, string target) {", "container": "Solution", "callable": "canChange", "parameters": [ { "name": "start", "type": "string" }, { "name": "target", "type": "string" } ], "return_type": "bool", "signature_source": "leetcod...
2,338
count-the-number-of-ideal-arrays
Hard
You are given two integers n and maxValue, which are used to describe an ideal array. A 0-indexed integer array arr of length n is considered ideal if the following conditions hold: - Every arr[i] is a value from 1 to maxValue, for 0 <= i < n. - Every arr[i] is divisible by arr[i - 1], for 0 < i < n. Return the numb...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 7,maxValue = 7) == 106\n assert candidate(n = 2,maxValue = 5) == 10\n assert candidate(n = 3,maxValue = 7) == 28\n assert candidate(n = 3,maxValue = 6) == 25\n assert candidate(n = 6,maxValue = 12) == 327\n assert cand...
[ "2\n5", "5\n3" ]
[ "Notice that an ideal array is non-decreasing.", "Consider an alternative problem: where an ideal array must also be strictly increasing. Can you use DP to solve it?", "Will combinatorics help to get an answer from the alternative problem to the actual problem?" ]
{ "canonical_parameter_names": [ "n", "maxValue" ], "leetcode_dataset_entry_point": "Solution().idealArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:17", "tests_total": 80, ...
cpp
{ "raw_signature": "int idealArrays(int n, int maxValue) {", "container": "Solution", "callable": "idealArrays", "parameters": [ { "name": "n", "type": "int" }, { "name": "maxValue", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets...
2,341
maximum-number-of-pairs-in-array
Easy
You are given a 0-indexed integer array nums. In one operation, you may do the following: - Choose two integers in nums that are equal. - Remove both integers from nums, forming a pair. The operation is done on nums as many times as possible. Return a 0-indexed integer array answer of size 2 where answer[0] is the n...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [5, 0]\n assert candidate(nums = [100, 0, 50, 50, 0, 100]) == [3, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 10]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1,...
[ "[1,3,2,1,3,2,2]", "[1,1]", "[0]" ]
[ "What do we need to know to find how many pairs we can make? We need to know the frequency of each integer.", "When will there be a leftover number? When the frequency of an integer is an odd number." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:21", "tests_total": 126, "tests_d...
cpp
{ "raw_signature": "vector<int> numberOfPairs(vector<int>& nums) {", "container": "Solution", "callable": "numberOfPairs", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "vector<int>", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode...
2,342
max-sum-of-a-pair-with-equal-sum-of-digits
Medium
You are given a 0-indexed array nums consisting of positive integers. You can choose two indices i and j, such that i != j, and the sum of digits of the number nums[i] is equal to that of nums[j]. Return the maximum value of nums[i] + nums[j] that you can obtain over all possible indices i and j that satisfy the condi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [99, 18, 81, 27]) == 108\n assert candidate(nums = [55, 23, 45, 55, 23]) == 110\n assert candidate(nums = [55, 23, 45, 55]) == 110\n assert candidate(nums = [111, 222, 333, 444]) == -1\n assert candidate(nums = [100000...
[ "[18,43,36,13,7]", "[10,12,19,14]" ]
[ "What is the largest possible sum of digits a number can have?", "Group the array elements by the sum of their digits, and find the largest two elements of each group." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maximumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:24", "tests_total": 121, "tests_drop...
cpp
{ "raw_signature": "int maximumSum(vector<int>& nums) {", "container": "Solution", "callable": "maximumSum", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
2,343
query-kth-smallest-trimmed-number
Medium
You are given a 0-indexed array of strings nums, where each string is of equal length and consists of only digits. You are also given a 0-indexed 2D integer array queries where queries[i] = [k_i, trim_i]. For each queries[i], you need to: - Trim each number in nums to its rightmost trim_i digits. - Determine the inde...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = ['111', '222', '333', '444'],queries = [[1, 1], [2, 2], [3, 3], [4, 3]]) == [0, 1, 2, 3]\n assert candidate(nums = ['123', '456', '789', '012'],queries = [[1, 2], [3, 3], [2, 1]]) == [3, 1, 0]\n assert candidate(nums = ['001...
[ "[\"102\",\"473\",\"251\",\"814\"]\n[[1,1],[2,3],[4,2],[1,2]]", "[\"24\",\"37\",\"96\",\"04\"]\n[[2,1],[2,2]]" ]
[ "Run a simulation to follow the requirement of each query." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().smallestTrimmedNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:26", "tests...
cpp
{ "raw_signature": "vector<int> smallestTrimmedNumbers(vector<string>& nums, vector<vector<int>>& queries) {", "container": "Solution", "callable": "smallestTrimmedNumbers", "parameters": [ { "name": "nums", "type": "vector<string>&" }, { "name": "queries", "type": "vector<ve...
2,344
minimum-deletions-to-make-array-divisible
Hard
You are given two positive integer arrays nums and numsDivide. You can delete any number of elements from nums. Return the minimum number of deletions such that the smallest element in nums divides all the elements of numsDivide. If this is not possible, return -1. Note that an integer x divides y if y % x == 0. Exa...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],numsDivide = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums = [5, 10, 15, 20],numsDivide = [5, 15, 25, 35]) == 0\n assert candidate(nums = [1, 3, 5, 7],numsDivide = [2, 4, 6, 8]) == 0\n assert candidat...
[ "[2,3,2,4,3]\n[9,6,9,3,15]", "[4,3,6]\n[8,2,6,10]" ]
[ "How can we find an integer x that divides all the elements of numsDivide?", "Will finding GCD (Greatest Common Divisor) help here?" ]
{ "canonical_parameter_names": [ "nums", "numsDivide" ], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:29", "tests_total...
cpp
{ "raw_signature": "int minOperations(vector<int>& nums, vector<int>& numsDivide) {", "container": "Solution", "callable": "minOperations", "parameters": [ { "name": "nums", "type": "vector<int>&" }, { "name": "numsDivide", "type": "vector<int>&" } ], "return_type": "...
2,347
best-poker-hand
Easy
You are given an integer array ranks and a character array suits. You have 5 cards where the i^th card has a rank of ranks[i] and a suit of suits[i]. The following are the types of poker hands you can make from best to worst: 1. "Flush": Five cards of the same suit. 2. "Three of a Kind": Three cards of the same rank....
{ "language": "python", "source": "def check(candidate):\n assert candidate(ranks = [7, 7, 7, 8, 9],suits = ['a', 'b', 'c', 'a', 'd']) == \"Three of a Kind\"\n assert candidate(ranks = [10, 10, 2, 12, 9],suits = ['a', 'b', 'c', 'a', 'd']) == \"Pair\"\n assert candidate(ranks = [7, 7, 7, 7, 7],suits = ['a',...
[ "[13,2,3,1,9]\n[\"a\",\"a\",\"a\",\"a\",\"a\"]", "[4,4,2,4,4]\n[\"d\",\"a\",\"a\",\"b\",\"c\"]", "[10,10,2,12,9]\n[\"a\",\"b\",\"c\",\"a\",\"d\"]" ]
[ "Sequentially check the conditions 1 through 4, and return the outcome corresponding to the first met condition." ]
{ "canonical_parameter_names": [ "ranks", "suits" ], "leetcode_dataset_entry_point": "Solution().bestHand", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:33", "tests_total": 100, ...
cpp
{ "raw_signature": "string bestHand(vector<int>& ranks, vector<char>& suits) {", "container": "Solution", "callable": "bestHand", "parameters": [ { "name": "ranks", "type": "vector<int>&" }, { "name": "suits", "type": "vector<char>&" } ], "return_type": "string", "s...
2,348
number-of-zero-filled-subarrays
Medium
Given an integer array nums, return the number of subarrays filled with 0. A subarray is a contiguous non-empty sequence of elements within an array. Example 1: Input: nums = [1,3,0,0,2,0,0,4] Output: 6 Explanation: There are 4 occurrences of [0] as a subarray. There are 2 occurrences of [0,0] as a subarray. There i...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 45\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 55\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 2\n ...
[ "[1,3,0,0,2,0,0,4]", "[0,0,0,2,0,0]", "[2,10,2019]" ]
[ "For each zero, you can calculate the number of zero-filled subarrays that end on that index, which is the number of consecutive zeros behind the current element + 1.", "Maintain the number of consecutive zeros behind the current element, count the number of zero-filled subarrays that end on each index, sum it up...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().zeroFilledSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:36", "tests_total": 99, "tes...
cpp
{ "raw_signature": "long long zeroFilledSubarray(vector<int>& nums) {", "container": "Solution", "callable": "zeroFilledSubarray", "parameters": [ { "name": "nums", "type": "vector<int>&" } ], "return_type": "long long", "signature_source": "leetcode/codeSnippets", "type_source": "le...
2,350
shortest-impossible-sequence-of-rolls
Hard
You are given an integer array rolls of length n and an integer k. You roll a k sided dice numbered from 1 to k, n times, where the result of the i^th roll is rolls[i]. Return the length of the shortest sequence of rolls so that there's no such subsequence in rolls. A sequence of rolls of length len is the result of ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(rolls = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 2\n assert candidate(rolls = [1, 1, 1, 1, 1],k = 1) == 6\n assert candidate(rolls = [1, 2, 3, 1, 2, 3, 1, 2, 3],k = 3) == 4\n assert candidate(rolls = [6, 5, 4, 3, 2, 1, 6, 5, 4...
[ "[4,2,1,2,3,3,2,4,1]\n4", "[1,1,2,2]\n2", "[1,1,3,2,2,2,3,3]\n4" ]
[ "How can you find the minimum index such that all sequences of length 1 can be formed from the start until that index?", "Starting from the previous minimum index, what is the next index such that all sequences of length 2 can be formed?", "Can you extend the idea to sequences of length 3 and more?" ]
{ "canonical_parameter_names": [ "rolls", "k" ], "leetcode_dataset_entry_point": "Solution().shortestSequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:38", "tests_total": 97...
cpp
{ "raw_signature": "int shortestSequence(vector<int>& rolls, int k) {", "container": "Solution", "callable": "shortestSequence", "parameters": [ { "name": "rolls", "type": "vector<int>&" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": ...
2,351
first-letter-to-appear-twice
Easy
Given a string s consisting of lowercase English letters, return the first letter to appear twice. Note: - A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b. - s will contain at least one letter that appears twice. Example 1: Input: s = "abccbaacz" O...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"alphabet\") == \"a\"\n assert candidate(s = \"finding\") == \"i\"\n assert candidate(s = \"xyzxyz\") == \"x\"\n assert candidate(s = \"zabcdefghijkkl\") == \"k\"\n assert candidate(s = \"first\") == None\n assert can...
[ "\"abccbaacz\"", "\"abcdd\"" ]
[ "Iterate through the string from left to right. Keep track of the elements you have already seen in a set.", "If the current element is already in the set, return that element." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().repeatedCharacter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:40", "tests_total": 132, "tests_...
cpp
{ "raw_signature": "char repeatedCharacter(string s) {", "container": "Solution", "callable": "repeatedCharacter", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "char", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }