question_id
int64
3.24k
3.51k
task_id
stringclasses
191 values
difficulty
stringclasses
3 values
problem_description
stringclasses
191 values
canonical_tests
dict
public_tests
listlengths
2
4
hints
listlengths
0
7
metadata
dict
language
stringclasses
9 values
interface
dict
3,409
longest-subsequence-with-decreasing-adjacent-difference
Medium
You are given an array of integers nums. Your task is to find the length of the longest subsequence seq of nums, such that the absolute differences between consecutive elements form a non-increasing sequence of integers. In other words, for a subsequence seq_0, seq_1, seq_2, ..., seq_m of nums, |seq_1 - seq_0| >= |seq...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 6\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10]) == 8\n assert candidate(nums = [300, 1, 300, 2, 300, 3, 300]) == 7\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == ...
[ "[16,6,3]", "[6,5,3,4,2,1]", "[10,20,10,19,10,20]" ]
[ "Use dynamic programming.", "Store the maximum answer for each index and every possible difference." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().longestSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:11", "tests_total": 121, "te...
java
{ "raw_signature": "public int longestSubsequence(int[] nums) {", "container": "Solution", "callable": "longestSubsequence", "parameters": [ { "name": "nums", "type": "int[]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
3,410
maximize-subarray-sum-after-removing-all-occurrences-of-one-element
Hard
You are given an integer array nums. You can do the following operation on the array at most once: - Choose any integer x such that nums remains non-empty on removing all occurrences of x. - Remove all occurrences of x from the array. Return the maximum subarray sum across all possible resulting arrays. Example 1: ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, -1, 3, -2, 4, -3, 5]) == 12\n assert candidate(nums = [1, -1, 1, -1, 1]) == 3\n assert candidate(nums = [1, 2, 2, 1]) == 6\n assert candidate(nums = [5, -3, 5, -2, 5, -1, 5]) == 17\n assert candidate(nums = [-3,...
[ "[-3,2,-2,-1,3,-2,3]", "[1,2,3,4]" ]
[ "Use a segment tree data structure to solve the problem.", "Each node of the segment tree should store the subarray sum, the maximum subarray sum, the maximum prefix sum, and the maximum suffix sum within the subarray defined by that node." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxSubarraySum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:14", "tests_total": 140, "tests_...
java
{ "raw_signature": "public long maxSubarraySum(int[] nums) {", "container": "Solution", "callable": "maxSubarraySum", "parameters": [ { "name": "nums", "type": "int[]" } ], "return_type": "long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,411
maximum-subarray-with-equal-products
Easy
You are given an array of positive integers nums. An array arr is called product equivalent if prod(arr) == lcm(arr) * gcd(arr), where: - prod(arr) is the product of all elements of arr. - gcd(arr) is the GCD of all elements of arr. - lcm(arr) is the LCM of all elements of arr. Return the length of the longest produ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [6, 3, 2, 1, 5, 4]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert...
[ "[1,2,1,2,1,1,1]", "[2,3,4,5,6]", "[1,2,3,1,4,5,1]" ]
[ "What is the maximum possible lcm?" ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:16", "tests_total": 126, "tests_dropp...
java
{ "raw_signature": "public int maxLength(int[] nums) {", "container": "Solution", "callable": "maxLength", "parameters": [ { "name": "nums", "type": "int[]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,412
find-mirror-score-of-a-string
Medium
You are given a string s. We define the mirror of a letter in the English alphabet as its corresponding letter when the alphabet is reversed. For example, the mirror of 'a' is 'z', and the mirror of 'y' is 'b'. Initially, all characters in the string s are unmarked. You start with a score of 0, and you perform the f...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"b\") == 0\n assert candidate(s = \"mirror\") == 1\n assert candidate(s = \"az\") == 1\n assert candidate(s = \"abbabba\") == 0\n assert candidate(s = \"abcba\") == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxy...
[ "\"aczzx\"", "\"abcdef\"" ]
[ "Create a stack for every character.", "For each index, check if the stack for mirror of the letter at that index is empty." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().calculateScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:18", "tests_total": 74, "tests_drop...
java
{ "raw_signature": "public long calculateScore(String s) {", "container": "Solution", "callable": "calculateScore", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,413
maximum-coins-from-k-consecutive-bags
Medium
There are an infinite amount of bags on a number line, one bag for each coordinate. Some of these bags contain coins. You are given a 2D array coins, where coins[i] = [l_i, r_i, c_i] denotes that every bag from l_i to r_i contains c_i coins. The segments that coins contain are non-overlapping. You are also given an ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(coins = [[8, 10, 1], [1, 3, 2], [5, 6, 4]],k = 4) == 10\n assert candidate(coins = [[1, 10, 3]],k = 2) == 6\n assert candidate(coins = [[10, 20, 5], [30, 40, 10], [50, 60, 15]],k = 5) == 75\n assert candidate(coins = [[1, 2, 5],...
[ "[[8,10,1],[1,3,2],[5,6,4]]\n4", "[[1,10,3]]\n2" ]
[ "An optimal starting position for k consecutive bags will be either l_i or r_i - k + 1." ]
{ "canonical_parameter_names": [ "coins", "k" ], "leetcode_dataset_entry_point": "Solution().maximumCoins", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:21", "tests_total": 115, ...
java
{ "raw_signature": "public long maximumCoins(int[][] coins, int k) {", "container": "Solution", "callable": "maximumCoins", "parameters": [ { "name": "coins", "type": "int[][]" }, { "name": "k", "type": "int" } ], "return_type": "long", "signature_source": "leetcode...
3,417
zigzag-grid-traversal-with-skip
Easy
You are given an m x n 2D array grid of positive integers. Your task is to traverse grid in a zigzag pattern while skipping every alternate cell. Zigzag pattern traversal is defined as following the below actions: - Start at the top-left cell (0, 0). - Move right within a row until the end of the row is reached. - D...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 3, 5], [2, 4, 6], [7, 9, 11], [8, 10, 12]]) == [1, 5, 4, 7, 11, 10]\n assert candidate(grid = [[2, 4, 6], [8, 10, 12], [14, 16, 18], [20, 22, 24], [26, 28, 30]]) == [2, 6, 10, 14, 18, 22, 26, 30]\n assert candidate(grid...
[ "[[1,2],[3,4]]", "[[2,1],[2,1],[2,1]]", "[[1,2,3],[4,5,6],[7,8,9]]" ]
[]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().zigzagTraversal", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:26", "tests_total": 71, "tests_...
java
{ "raw_signature": "public List<Integer> zigzagTraversal(int[][] grid) {", "container": "Solution", "callable": "zigzagTraversal", "parameters": [ { "name": "grid", "type": "int[][]" } ], "return_type": "List<Integer>", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
3,418
maximum-amount-of-money-robot-can-earn
Medium
You are given an m x n grid. A robot starts at the top-left corner of the grid (0, 0) and wants to reach the bottom-right corner (m - 1, n - 1). The robot can move either right or down at any point in time. The grid contains a value coins[i][j] in each cell: - If coins[i][j] >= 0, the robot gains that many coins. - I...
{ "language": "python", "source": "def check(candidate):\n assert candidate(coins = [[0, 1, -1], [1, -2, 3], [2, -3, 4]]) == 8\n assert candidate(coins = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9]]) == 34\n assert candidate(coins = [[1000, -1000, 1000, -1000], [-1000, 1000, -1000, 1000], [1000, -10...
[ "[[0,1,-1],[1,-2,3],[2,-3,4]]", "[[10,10,10],[10,10,10]]" ]
[ "Use Dynamic Programming.", "Let dp[i][j][k] denote the maximum amount of money a robot can earn by starting at cell (i,j) and having neutralized k robbers." ]
{ "canonical_parameter_names": [ "coins" ], "leetcode_dataset_entry_point": "Solution().maximumAmount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:29", "tests_total": 85, "tests_d...
java
{ "raw_signature": "public int maximumAmount(int[][] coins) {", "container": "Solution", "callable": "maximumAmount", "parameters": [ { "name": "coins", "type": "int[][]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,419
minimize-the-maximum-edge-weight-of-graph
Medium
You are given two integers, n and threshold, as well as a directed weighted graph of n nodes numbered from 0 to n - 1. The graph is represented by a 2D integer array edges, where edges[i] = [A_i, B_i, W_i] indicates that there is an edge going from node A_i to node B_i with weight W_i. You have to remove some edges fr...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,edges = [[1, 2, 1], [1, 3, 3], [1, 4, 5], [2, 3, 2], [3, 4, 2], [4, 0, 1]],threshold = 1) == 2\n assert candidate(n = 5,edges = [[1, 0, 1], [2, 0, 2], [3, 0, 1], [4, 3, 1], [2, 1, 1]],threshold = 2) == 1\n assert candidate(n ...
[ "5\n[[1,0,1],[2,0,2],[3,0,1],[4,3,1],[2,1,1]]\n2", "5\n[[0,1,1],[0,2,2],[0,3,1],[0,4,1],[1,2,1],[1,4,1]]\n1", "5\n[[1,2,1],[1,3,3],[1,4,5],[2,3,2],[3,4,2],[4,0,1]]\n1", "5\n[[1,2,1],[1,3,3],[1,4,5],[2,3,2],[4,0,1]]\n1" ]
[ "Can we use binary search?", "Invert the edges in the graph." ]
{ "canonical_parameter_names": [ "n", "edges", "threshold" ], "leetcode_dataset_entry_point": "Solution().minMaxWeight", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:32", "tes...
java
{ "raw_signature": "public int minMaxWeight(int n, int[][] edges, int threshold) {", "container": "Solution", "callable": "minMaxWeight", "parameters": [ { "name": "n", "type": "int" }, { "name": "edges", "type": "int[][]" }, { "name": "threshold", "type":...
3,420
count-non-decreasing-subarrays-after-k-operations
Hard
You are given an array nums of n integers and an integer k. For each subarray of nums, you can apply up to k operations on it. In each operation, you increment any element of the subarray by 1. Note that each subarray is considered independently, meaning changes made to one subarray do not persist to another. Return...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1],k = 10) == 15\n assert candidate(nums = [10, 20, 10, 20, 10],k = 15) == 13\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 55\n assert candidate(nums = [1, 100, 2, 99, 3, 98],k = 100) =...
[ "[6,3,1,2,4,4]\n7", "[6,3,1,3,6]\n4" ]
[ "Use a sparse table.", "Compute sp[e][i] = [lastElement, operations] where operations is the number of operations required to make the subarray nums[i...i + 2^e - 1] non-decreasing, and lastElement be the value of the last element after the operations were applied on it.", "How can we combine sp[a][i] with sp[b...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().countNonDecreasingSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:35", "tests_...
java
{ "raw_signature": "public long countNonDecreasingSubarrays(int[] nums, int k) {", "container": "Solution", "callable": "countNonDecreasingSubarrays", "parameters": [ { "name": "nums", "type": "int[]" }, { "name": "k", "type": "int" } ], "return_type": "long", "sign...
3,423
maximum-difference-between-adjacent-elements-in-a-circular-array
Easy
Given a circular array nums, find the maximum absolute difference between adjacent elements. Note: In a circular array, the first and last elements are adjacent. Example 1: Input: nums = [1,2,4] Output: 3 Explanation: Because nums is circular, nums[0] and nums[2] are adjacent. They have the maximum absolute differen...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 1, 100, 1, 100]) == 99\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 50\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == 6\n assert candidate(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == 45\n as...
[ "[1,2,4]", "[-5,-10,-5]" ]
[ "Traverse from the second element to the last element and check the difference of every adjacent pair.", "The edge case is to check the difference between the first and last elements." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxAdjacentDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:40", "tests_total": 120, "t...
java
{ "raw_signature": "public int maxAdjacentDistance(int[] nums) {", "container": "Solution", "callable": "maxAdjacentDistance", "parameters": [ { "name": "nums", "type": "int[]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
3,424
minimum-cost-to-make-arrays-identical
Medium
You are given two integer arrays arr and brr of length n, and an integer k. You can perform the following operations on arr any number of times: - Split arr into any number of contiguous subarrays and rearrange these subarrays in any order. This operation has a fixed cost of k. - Choose any element in arr and add or s...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [0, 0, 0],brr = [0, 0, 0],k = 10) == 0\n assert candidate(arr = [2, 1],brr = [2, 1],k = 0) == 0\n assert candidate(arr = [0, 0, 0],brr = [0, 0, 0],k = 100) == 0\n assert candidate(arr = [1, 2, 3],brr = [3, 2, 1],k = 10) ==...
[ "[-7,9,5]\n[7,-2,-5]\n2", "[2,1]\n[2,1]\n0" ]
[ "What does Operation 1 (rearranging subarrays) actually accomplish?", "Calculate sum(abs(arr[i] - brr[i])) if you do not use Operation 1.", "Calculate sum(abs(arr[i] - brr[i])) after sorting both arrays if you use Operation 1." ]
{ "canonical_parameter_names": [ "arr", "brr", "k" ], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:44", "tests_total": 12...
java
{ "raw_signature": "public long minCost(int[] arr, int[] brr, long k) {", "container": "Solution", "callable": "minCost", "parameters": [ { "name": "arr", "type": "int[]" }, { "name": "brr", "type": "int[]" }, { "name": "k", "type": "long" } ], "re...
3,426
manhattan-distances-of-all-arrangements-of-pieces
Hard
You are given three integers m, n, and k. There is a rectangular grid of size m × n containing k identical pieces. Return the sum of Manhattan distances between every pair of pieces over all valid arrangements of pieces. A valid arrangement is a placement of all k pieces on the grid with at most one piece per cell. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(m = 5,n = 5,k = 5) == 1771000\n assert candidate(m = 100,n = 100,k = 10) == 384963906\n assert candidate(m = 10,n = 10,k = 20) == 80781589\n assert candidate(m = 1,n = 4,k = 3) == 20\n assert candidate(m = 10,n = 10,k = 10) =...
[ "2\n2\n2", "1\n4\n3" ]
[ "Fix two pieces in two specific locations and find the number of boards where this can happen.", "A particular pair of positions will be counted exactly C(m * n - 2, k - 2) times. Calculate the total distance for all pairs of positions and multiply it with C(m * n - 2, k - 2)." ]
{ "canonical_parameter_names": [ "m", "n", "k" ], "leetcode_dataset_entry_point": "Solution().distanceSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:49", "tests_total": 89...
java
{ "raw_signature": "public int distanceSum(int m, int n, int k) {", "container": "Solution", "callable": "distanceSum", "parameters": [ { "name": "m", "type": "int" }, { "name": "n", "type": "int" }, { "name": "k", "type": "int" } ], "return_type":...
3,427
sum-of-variable-length-subarrays
Easy
You are given an integer array nums of size n. For each index i where 0 <= i < n, define a subarray nums[start ... i] where start = max(0, i - nums[i]). Return the total sum of all elements from the subarray defined for each index in the array. Example 1: Input: nums = [2,3,1] Output: 11 Explanation: i | Subarray |...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 38\n assert candidate(nums = [50, 25, 50, 25, 50]) == 600\n assert candidate(nums = [10, 5, 2, 3]) == 62\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 19\n assert candidate(nums = [10...
[ "[2,3,1]", "[3,1,1,2]" ]
[ "The constraints are small, so brute force for each index." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().subarraySum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:51", "tests_total": 94, "tests_drop...
java
{ "raw_signature": "public int subarraySum(int[] nums) {", "container": "Solution", "callable": "subarraySum", "parameters": [ { "name": "nums", "type": "int[]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,428
maximum-and-minimum-sums-of-at-most-size-k-subsequences
Medium
You are given an integer array nums and a positive integer k. Return the sum of the maximum and minimum elements of all subsequences of nums with at most k elements. Since the answer may be very large, return it modulo 10^9 + 7. Example 1: Input: nums = [1,2,3], k = 2 Output: 24 Explanation: The subsequences of nums...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 8, 9, 10, 11],k = 4) == 540\n assert candidate(nums = [5, 0, 6],k = 1) == 22\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 7007\n assert candidate(nums = [4, 3, 2, 1],k = 3) == 70\n assert can...
[ "[1,2,3]\n2", "[5,0,6]\n1", "[1,1,1]\n2" ]
[ "Sort the array." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().minMaxSums", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:53", "tests_total": 107, "t...
java
{ "raw_signature": "public int minMaxSums(int[] nums, int k) {", "container": "Solution", "callable": "minMaxSums", "parameters": [ { "name": "nums", "type": "int[]" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippet...
3,429
paint-house-iv
Medium
You are given an even integer n representing the number of houses arranged in a straight line, and a 2D array cost of size n x 3, where cost[i][j] represents the cost of painting house i with color j + 1. The houses will look beautiful if they satisfy the following conditions: - No two adjacent houses are painted the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,cost = [[3, 5, 7], [6, 2, 9], [4, 8, 1], [7, 3, 5]]) == 9\n assert candidate(n = 10,cost = [[5, 5, 5], [4, 4, 4], [3, 3, 3], [2, 2, 2], [1, 1, 1], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]]) == 30\n assert candida...
[ "4\n[[3,5,7],[6,2,9],[4,8,1],[7,3,5]]", "6\n[[2,4,6],[5,3,8],[7,1,9],[4,6,2],[3,5,7],[8,2,4]]" ]
[ "Use dynamic programming to calculate the minimum cost while ensuring that the adjacency and equidistant constraints are satisfied.", "Try all 9 combinations of colors for equidistant pairs to get the minimum cost." ]
{ "canonical_parameter_names": [ "n", "cost" ], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:24:56", "tests_total": 91, "tests...
java
{ "raw_signature": "public long minCost(int n, int[][] cost) {", "container": "Solution", "callable": "minCost", "parameters": [ { "name": "n", "type": "int" }, { "name": "cost", "type": "int[][]" } ], "return_type": "long", "signature_source": "leetcode/codeSnippet...
3,432
count-partitions-with-even-sum-difference
Easy
You are given an integer array nums of length n. A partition is defined as an index i where 0 <= i < n - 1, splitting the array into two non-empty subarrays such that: - Left subarray contains indices [0, i]. - Right subarray contains indices [i + 1, n - 1]. Return the number of partitions where the difference betwe...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 100, 100, 100]) == 3\n assert candidate(nums = [100, 100]) == 1\n assert candidate(nums = [100, 100, 100, 100, 100]) == 4\n assert candidate(nums = [1, 2, 2]) == 0\n assert candidate(nums = [1, 1, 1, 1]) == 3\n ...
[ "[10,10,3,7,6]", "[1,2,2]", "[2,4,6,8]" ]
[ "If the parity of the sum is even, the partition is valid; otherwise, there is no partition." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countPartitions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:01", "tests_total": 92, "tests_...
java
{ "raw_signature": "public int countPartitions(int[] nums) {", "container": "Solution", "callable": "countPartitions", "parameters": [ { "name": "nums", "type": "int[]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,433
count-mentions-per-user
Medium
You are given an integer numberOfUsers representing the total number of users and an array events of size n x 3. Each events[i] can be either of the following two types: 1. Message Event: ["MESSAGE", "timestamp_i", "mentions_string_i"] - This event indicates that a set of users was mentioned in a message at timesta...
{ "language": "python", "source": "def check(candidate):\n assert candidate(numberOfUsers = 1,events = [['MESSAGE', '1', 'id0'], ['MESSAGE', '1', 'HERE'], ['MESSAGE', '1', 'ALL']]) == [3]\n assert candidate(numberOfUsers = 2,events = [['OFFLINE', '10', '0'], ['MESSAGE', '12', 'HERE']]) == [0, 1]\n assert c...
[ "2\n[[\"MESSAGE\",\"10\",\"id1 id0\"],[\"OFFLINE\",\"11\",\"0\"],[\"MESSAGE\",\"71\",\"HERE\"]]", "2\n[[\"MESSAGE\",\"10\",\"id1 id0\"],[\"OFFLINE\",\"11\",\"0\"],[\"MESSAGE\",\"12\",\"ALL\"]]", "2\n[[\"OFFLINE\",\"10\",\"0\"],[\"MESSAGE\",\"12\",\"HERE\"]]" ]
[ "Sort events by timestamp and then process each event.", "Maintain two sets for offline and online user IDs." ]
{ "canonical_parameter_names": [ "numberOfUsers", "events" ], "leetcode_dataset_entry_point": "Solution().countMentions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:04", "tests_...
java
{ "raw_signature": "public int[] countMentions(int numberOfUsers, List<List<String>> events) {", "container": "Solution", "callable": "countMentions", "parameters": [ { "name": "numberOfUsers", "type": "int" }, { "name": "events", "type": "List<List<String>>" } ], "re...
3,434
maximum-frequency-after-subarray-operation
Medium
You are given an array nums of length n. You are also given an integer k. You perform the following operation on nums once: - Select a subarray nums[i..j] where 0 <= i <= j <= n - 1. - Select an integer x and add x to all the elements in nums[i..j]. Find the maximum frequency of the value k after the operation. Exa...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 5\n assert candidate(nums = [10, 20, 30, 40, 50],k = 50) == 2\n assert candidate(nums = [1, 50, 1, 50, 1],k = 50) == 3\n assert candidate(nums = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25],k = 25) =...
[ "[1,2,3,4,5,6]\n1", "[10,2,3,4,5,5,4,3,2,2]\n10" ]
[ "Fix the element you want to convert to k.", "Use prefix sums to optimize counting occurrences of an element." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maxFrequency", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:06", "tests_total": 132, ...
java
{ "raw_signature": "public int maxFrequency(int[] nums, int k) {", "container": "Solution", "callable": "maxFrequency", "parameters": [ { "name": "nums", "type": "int[]" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSni...
3,435
frequencies-of-shortest-supersequences
Hard
You are given an array of strings words. Find all shortest common supersequences (SCS) of words that are not permutations of each other. A shortest common supersequence is a string of minimum length that contains each string in words as a subsequence. Return a 2D array of integers freqs that represent all the SCSs. E...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ...
[ "[\"ab\",\"ba\"]", "[\"aa\",\"ac\"]", "[\"aa\",\"bb\",\"cc\"]" ]
[ "Each SCS contains at most 2 occurrences of each character. Why?", "Construct every subset of possible characters (1 or 2).", "Check if a supersequence could be constructed using Topological Sort." ]
{ "canonical_parameter_names": [ "words" ], "leetcode_dataset_entry_point": "Solution().supersequences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:08", "tests_total": 146, "tests...
java
{ "raw_signature": "public List<List<Integer>> supersequences(String[] words) {", "container": "Solution", "callable": "supersequences", "parameters": [ { "name": "words", "type": "String[]" } ], "return_type": "List<List<Integer>>", "signature_source": "leetcode/codeSnippets", "type...
3,438
find-valid-pair-of-adjacent-digits-in-string
Easy
You are given a string s consisting only of digits. A valid pair is defined as two adjacent digits in s such that: - The first digit is not equal to the second. - Each digit in the pair appears in s exactly as many times as its numeric value. Return the first valid pair found in the string s when traversing from left...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"213123\") == \"\"\n assert candidate(s = \"9999999998888888777777666665555444332211\") == \"\"\n assert candidate(s = \"221\") == \"21\"\n assert candidate(s = \"22221111\") == \"\"\n assert candidate(s = \"122223333344...
[ "\"2523533\"", "\"221\"", "\"22\"" ]
[ "Use a HashMap to count the frequency of each digit." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().findValidPair", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:13", "tests_total": 166, "tests_drop...
java
{ "raw_signature": "public String findValidPair(String s) {", "container": "Solution", "callable": "findValidPair", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,439
reschedule-meetings-for-maximum-free-time-i
Medium
You are given an integer eventTime denoting the duration of an event, where the event occurs from time t = 0 to time t = eventTime. You are also given two integer arrays startTime and endTime, each of length n. These represent the start and end time of n non-overlapping meetings, where the i^th meeting occurs during t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(eventTime = 15,k = 3,startTime = [1, 5, 9],endTime = [3, 7, 12]) == 8\n assert candidate(eventTime = 10,k = 1,startTime = [0, 2, 9],endTime = [1, 4, 10]) == 6\n assert candidate(eventTime = 5,k = 1,startTime = [1, 3],endTime = [2, ...
[ "5\n1\n[1,3]\n[2,5]", "10\n1\n[0,2,9]\n[1,4,10]", "5\n2\n[0,1,2,3,4]\n[1,2,3,4,5]" ]
[ "In a sequence of K meetings and K + 1 gaps, you could move all meetings to the start of the sequence to get the max free time.", "Use a sliding window of K + 1 size to store sum of gaps and take the maximum." ]
{ "canonical_parameter_names": [ "eventTime", "k", "startTime", "endTime" ], "leetcode_dataset_entry_point": "Solution().maxFreeTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30...
java
{ "raw_signature": "public int maxFreeTime(int eventTime, int k, int[] startTime, int[] endTime) {", "container": "Solution", "callable": "maxFreeTime", "parameters": [ { "name": "eventTime", "type": "int" }, { "name": "k", "type": "int" }, { "name": "startTime"...
3,440
reschedule-meetings-for-maximum-free-time-ii
Medium
You are given an integer eventTime denoting the duration of an event. You are also given two integer arrays startTime and endTime, each of length n. These represent the start and end times of n non-overlapping meetings that occur during the event between time t = 0 and time t = eventTime, where the i^th meeting occurs...
{ "language": "python", "source": "def check(candidate):\n assert candidate(eventTime = 50,startTime = [0, 5, 10, 15, 20],endTime = [3, 8, 13, 18, 23]) == 29\n assert candidate(eventTime = 50,startTime = [5, 15, 25, 35],endTime = [10, 20, 30, 40]) == 20\n assert candidate(eventTime = 20,startTime = [0, 5, ...
[ "5\n[1,3]\n[2,5]", "10\n[0,7,9]\n[1,8,10]", "10\n[0,3,7,9]\n[1,4,8,10]", "5\n[0,1,2,3,4]\n[1,2,3,4,5]" ]
[ "If we reschedule a meeting earlier or later, we need to find a gap of length at least endTime[i] - startTime[i]. Try maintaining the gaps in some sorted data structure." ]
{ "canonical_parameter_names": [ "eventTime", "startTime", "endTime" ], "leetcode_dataset_entry_point": "Solution().maxFreeTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:18...
java
{ "raw_signature": "public int maxFreeTime(int eventTime, int[] startTime, int[] endTime) {", "container": "Solution", "callable": "maxFreeTime", "parameters": [ { "name": "eventTime", "type": "int" }, { "name": "startTime", "type": "int[]" }, { "name": "endTime...
3,441
minimum-cost-good-caption
Hard
You are given a string caption of length n. A good caption is a string where every character appears in groups of at least 3 consecutive occurrences. For example: - "aaabbb" and "aaaaccc" are good captions. - "aabbb" and "ccccd" are not good captions. You can perform the following operation any number of times: Cho...
{ "language": "python", "source": "def check(candidate):\n assert candidate(caption = \"cdcd\") == \"cccc\"\n assert candidate(caption = \"xyz\") == \"yyy\"\n assert candidate(caption = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"aaaaccceeefffhhhiiikkklllnnnoooqqqrrrtttuuuwwwxxxzzz\"\n ...
[ "\"cdcd\"", "\"aca\"", "\"bc\"" ]
[ "Construct a DP table and try all possible characters at every index.", "Choose characters greedily to get the lexicographically smallest caption." ]
{ "canonical_parameter_names": [ "caption" ], "leetcode_dataset_entry_point": "Solution().minCostGoodCaption", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:21", "tests_total": 80, "...
java
{ "raw_signature": "public String minCostGoodCaption(String caption) {", "container": "Solution", "callable": "minCostGoodCaption", "parameters": [ { "name": "caption", "type": "String" } ], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcod...
3,442
maximum-difference-between-even-and-odd-frequency-i
Easy
You are given a string s consisting of lowercase English letters. Your task is to find the maximum difference diff = freq(a_1) - freq(a_2) between the frequency of characters a_1 and a_2 in the string such that: - a_1 has an odd frequency in the string. - a_2 has an even frequency in the string. Return this maximum ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abacabadabacaba\") == -1\n assert candidate(s = \"aabbc\") == -1\n assert candidate(s = \"aaabbbcccdddeeefffgghhhiiiijjjjkkkkllllmmmmmnnnnooooo\") == 3\n assert candidate(s = \"aabbccdde\") == -1\n assert candidate(s = ...
[ "\"aaaaabbc\"", "\"abcabcab\"" ]
[ "Use a frequency map to identify the maximum odd and minimum even frequencies. Then, calculate their difference." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().maxDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:23", "tests_total": 49, "tests_dropp...
java
{ "raw_signature": "public int maxDifference(String s) {", "container": "Solution", "callable": "maxDifference", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,443
maximum-manhattan-distance-after-k-changes
Medium
You are given a string s consisting of the characters 'N', 'S', 'E', and 'W', where s[i] indicates movements in an infinite grid: - 'N' : Move north by 1 unit. - 'S' : Move south by 1 unit. - 'E' : Move east by 1 unit. - 'W' : Move west by 1 unit. Initially, you are at the origin (0, 0). You can change at most k char...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"NSWWEW\",k = 3) == 6\n assert candidate(s = \"EEEEEE\",k = 0) == 6\n assert candidate(s = \"NNN\",k = 0) == 3\n assert candidate(s = \"NWSE\",k = 1) == 3\n assert candidate(s = \"EEEE\",k = 4) == 4\n assert candidate...
[ "\"NWSE\"\n1", "\"NSWWEW\"\n3" ]
[ "We can brute force all the possible directions (NE, NW, SE, SW).", "Change up to k characters to maximize the distance in the chosen direction." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().maxDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:26", "tests_total": 108, "tes...
java
{ "raw_signature": "public int maxDistance(String s, int k) {", "container": "Solution", "callable": "maxDistance", "parameters": [ { "name": "s", "type": "String" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets"...
3,444
minimum-increments-for-target-multiples-in-an-array
Hard
You are given two arrays, nums and target. In a single operation, you may increment any element of nums by 1. Return the minimum number of operations required so that each element in target has at least one multiple in nums. Example 1: Input: nums = [1,2,3], target = [4] Output: 1 Explanation: The minimum number of...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 10, 15],target = [5, 10, 15]) == 0\n assert candidate(nums = [5, 10, 15, 20],target = [5, 15]) == 0\n assert candidate(nums = [10, 20, 30],target = [5, 15]) == 0\n assert candidate(nums = [1, 1, 1],target = [3]) == 2\...
[ "[1,2,3]\n[4]", "[8,4]\n[10,5]", "[7,9,10]\n[7]" ]
[ "Use bitmask dynamic programming." ]
{ "canonical_parameter_names": [ "nums", "target" ], "leetcode_dataset_entry_point": "Solution().minimumIncrements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:28", "tests_total...
java
{ "raw_signature": "public int minimumIncrements(int[] nums, int[] target) {", "container": "Solution", "callable": "minimumIncrements", "parameters": [ { "name": "nums", "type": "int[]" }, { "name": "target", "type": "int[]" } ], "return_type": "int", "signature_so...
3,445
maximum-difference-between-even-and-odd-frequency-ii
Hard
You are given a string s and an integer k. Your task is to find the maximum difference between the frequency of two characters, freq[a] - freq[b], in a substring subs of s, such that: - subs has a size of at least k. - Character a has an odd frequency in subs. - Character b has a non-zero even frequency in subs. Retu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"1010101010\",k = 4) == 1\n assert candidate(s = \"000111\",k = 2) == 1\n assert candidate(s = \"101010101\",k = 4) == 1\n assert candidate(s = \"444333222111\",k = 6) == 1\n assert candidate(s = \"111222333\",k = 6) == ...
[ "\"12233\"\n4", "\"1122211\"\n3", "\"110\"\n3" ]
[ "Fix the two characters.", "Use prefix sum (maintain 2 characters' parities as status)." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().maxDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:30", "tests_total": 137, "t...
java
{ "raw_signature": "public int maxDifference(String s, int k) {", "container": "Solution", "callable": "maxDifference", "parameters": [ { "name": "s", "type": "String" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnipp...
3,446
sort-matrix-by-diagonals
Medium
You are given an n x n square matrix of integers grid. Return the matrix such that: - The diagonals in the bottom-left triangle (including the middle diagonal) are sorted in non-increasing order. - The diagonals in the top-right triangle are sorted in non-decreasing order. Example 1: Input: grid = [[1,7,3],[9,8,2],[...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[5, 2, 9], [8, 3, 6], [1, 4, 7]]) == [[7, 2, 9], [8, 5, 6], [1, 4, 3]]\n assert candidate(grid = [[0, 1], [1, 2]]) == [[2, 1], [1, 0]]\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == [[9, 4, 7], [6, 5, 8], [...
[ "[[1,7,3],[9,8,2],[4,5,6]]", "[[0,1],[1,2]]", "[[1]]" ]
[ "Use a data structure to store all values in each diagonal.", "Sort and replace them in the matrix." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().sortMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:32", "tests_total": 79, "tests_dropp...
java
{ "raw_signature": "public int[][] sortMatrix(int[][] grid) {", "container": "Solution", "callable": "sortMatrix", "parameters": [ { "name": "grid", "type": "int[][]" } ], "return_type": "int[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,447
assign-elements-to-groups-with-constraints
Medium
You are given an integer array groups, where groups[i] represents the size of the i^th group. You are also given an integer array elements. Your task is to assign one element to each group based on the following rules: - An element at index j can be assigned to a group i if groups[i] is divisible by elements[j]. - If...
{ "language": "python", "source": "def check(candidate):\n assert candidate(groups = [1, 1, 1, 1, 1],elements = [1]) == [0, 0, 0, 0, 0]\n assert candidate(groups = [10, 10, 10, 10],elements = [5, 10]) == [0, 0, 0, 0]\n assert candidate(groups = [11, 22, 33, 44, 55],elements = [11, 22]) == [0, 0, 0, 0, 0]\n...
[ "[8,4,3,2,4]\n[4,2]", "[2,3,5,7]\n[5,3,3]", "[10,21,30,41]\n[2,1]" ]
[ "Can a sieve-like approach be applied here?", "Starting from the smallest index, iterate through the multiples of the element and assign it to groups divisible by that value.", "Process each element once.", "Find all divisors of each group, then match them with elements." ]
{ "canonical_parameter_names": [ "groups", "elements" ], "leetcode_dataset_entry_point": "Solution().assignElements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:36", "tests_tota...
java
{ "raw_signature": "public int[] assignElements(int[] groups, int[] elements) {", "container": "Solution", "callable": "assignElements", "parameters": [ { "name": "groups", "type": "int[]" }, { "name": "elements", "type": "int[]" } ], "return_type": "int[]", "signat...
3,448
count-substrings-divisible-by-last-digit
Hard
You are given a string s consisting of digits. Return the number of substrings of s divisible by their non-zero last digit. Note: A substring may contain leading zeros. Example 1: Input: s = "12936" Output: 11 Explanation: Substrings "29", "129", "293" and "2936" are not divisible by their last digit. There are 15 ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"24680\") == 6\n assert candidate(s = \"11111\") == 15\n assert candidate(s = \"5701283\") == 18\n assert candidate(s = \"9876543210\") == 35\n assert candidate(s = \"1001001001\") == 22\n assert candidate(s = \"99999...
[ "\"12936\"", "\"5701283\"", "\"1010101010\"" ]
[ "Let dp[index][i][j] be the number of subarrays s[start...index] such that s[start...index] % i == j.", "For every pair (i, j), add dp[index - 1][i][j] to dp[index][i][(j * 10 + x)%i)].", "You should optimize this solution so that it can fit into the memory limit.", "In order to find dp[index][i][j] we use va...
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().countSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:38", "tests_total": 113, "tests_dr...
java
{ "raw_signature": "public long countSubstrings(String s) {", "container": "Solution", "callable": "countSubstrings", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,449
maximize-the-minimum-game-score
Hard
You are given an array points of size n and an integer m. There is another array gameScore of size n, where gameScore[i] represents the score achieved at the i^th game. Initially, gameScore[i] == 0 for all i. You start at index -1, which is outside the array (before the first position at index 0). You can make at most...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [5, 3, 8, 2, 6],m = 10) == 6\n assert candidate(points = [5, 9, 3, 7],m = 7) == 6\n assert candidate(points = [1, 1, 1, 1, 1],m = 5) == 1\n assert candidate(points = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],m = 20) == 2\n asse...
[ "[2,4]\n3", "[1,2,3]\n5" ]
[ "Can we use binary search?", "What happens if you fix the game score as x?", "We should go from i to (i + 1) back and forth, making the value for each index i (from left to right) no less than x." ]
{ "canonical_parameter_names": [ "points", "m" ], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:41", "tests_total": 95, "te...
java
{ "raw_signature": "public long maxScore(int[] points, int m) {", "container": "Solution", "callable": "maxScore", "parameters": [ { "name": "points", "type": "int[]" }, { "name": "m", "type": "int" } ], "return_type": "long", "signature_source": "leetcode/codeSnipp...
3,452
sum-of-good-numbers
Easy
Given an array of integers nums and an integer k, an element nums[i] is considered good if it is strictly greater than the elements at indices i - k and i + k (if those indices exist). If neither of these indices exists, nums[i] is still considered good. Return the sum of all the good elements in the array. Example 1...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 1],k = 1) == 2\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 2) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 27\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],...
[ "[1,3,2,1,5,4]\n2", "[2,1]\n1" ]
[ "For each index, check if nums[i] is strictly greater than nums[i - k] and nums[i + k]." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().sumOfGoodNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:45", "tests_total": 109...
java
{ "raw_signature": "public int sumOfGoodNumbers(int[] nums, int k) {", "container": "Solution", "callable": "sumOfGoodNumbers", "parameters": [ { "name": "nums", "type": "int[]" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode...
3,453
separate-squares-i
Medium
You are given a 2D integer array squares. Each squares[i] = [x_i, y_i, l_i] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis. Find the minimum y-coordinate value of a horizontal line such that the total area of the squares above the line equals the total area o...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat...
[ "[[0,0,1],[2,2,1]]", "[[0,0,2],[1,1,1]]" ]
[ "Binary search on the answer." ]
{ "canonical_parameter_names": [ "squares" ], "leetcode_dataset_entry_point": "Solution().separateSquares", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:48", "tests_total": 107, "te...
java
{ "raw_signature": "public double separateSquares(int[][] squares) {", "container": "Solution", "callable": "separateSquares", "parameters": [ { "name": "squares", "type": "int[][]" } ], "return_type": "double", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
3,454
separate-squares-ii
Hard
You are given a 2D integer array squares. Each squares[i] = [x_i, y_i, l_i] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis. Find the minimum y-coordinate value of a horizontal line such that the total area covered by squares above the line equals the total ar...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_mat...
[ "[[0,0,1],[2,2,1]]", "[[0,0,2],[1,1,1]]" ]
[ "Use a line sweep and a segment tree.", "The line must lie in one of the squares." ]
{ "canonical_parameter_names": [ "squares" ], "leetcode_dataset_entry_point": "Solution().separateSquares", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:51", "tests_total": 103, "te...
java
{ "raw_signature": "public double separateSquares(int[][] squares) {", "container": "Solution", "callable": "separateSquares", "parameters": [ { "name": "squares", "type": "int[][]" } ], "return_type": "double", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
3,455
shortest-matching-substring
Hard
You are given a string s and a pattern string p, where p contains exactly two '*' characters. The '*' in p matches any sequence of zero or more characters. Return the length of the shortest substring in s that matches p. If there is no such substring, return -1. Note: The empty substring is considered valid. Exampl...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefg\",p = \"*bcd*fg\") == 6\n assert candidate(s = \"abcabcabc\",p = \"*bc*bc\") == 5\n assert candidate(s = \"mississippi\",p = \"mis*si*\") == 5\n assert candidate(s = \"baccbaadbc\",p = \"cc*baa*adb\") == -1\n as...
[ "\"abaacbaecebce\"\n\"ba*c*ce\"", "\"baccbaadbc\"\n\"cc*baa*adb\"", "\"a\"\n\"**\"", "\"madlogic\"\n\"*adlogi*\"" ]
[ "The pattern string p can be divided into three segments.", "Use the KMP algorithm to locate all occurrences of each segment in s." ]
{ "canonical_parameter_names": [ "s", "p" ], "leetcode_dataset_entry_point": "Solution().shortestMatchingSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:53", "tests_total...
java
{ "raw_signature": "public int shortestMatchingSubstring(String s, String p) {", "container": "Solution", "callable": "shortestMatchingSubstring", "parameters": [ { "name": "s", "type": "String" }, { "name": "p", "type": "String" } ], "return_type": "int", "signatur...
3,456
find-special-substring-of-length-k
Easy
You are given a string s and an integer k. Determine if there exists a substring of length exactly k in s that satisfies the following conditions: 1. The substring consists of only one distinct character (e.g., "aaa" or "bbb"). 2. If there is a character immediately before the substring, it must be different from the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc\",k = 2) == False\n assert candidate(s = \"aabbccddeeff\",k = 2) == True\n assert candidate(s = \"abcde\",k = 1) == True\n assert candidate(s = \"zzzz\",k = 4) == True\n assert candidate(s = \"xyzxyz\",k = 1) == Tru...
[ "\"aaabaaa\"\n3", "\"abc\"\n2" ]
[ "Return true if there is a sequence of consecutive characters of length k" ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().hasSpecialSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:56", "tests_total": 111...
java
{ "raw_signature": "public boolean hasSpecialSubstring(String s, int k) {", "container": "Solution", "callable": "hasSpecialSubstring", "parameters": [ { "name": "s", "type": "String" }, { "name": "k", "type": "int" } ], "return_type": "boolean", "signature_source":...
3,457
eat-pizzas
Medium
You are given an integer array pizzas of size n, where pizzas[i] represents the weight of the i^th pizza. Every day, you eat exactly 4 pizzas. Due to your incredible metabolism, when you eat pizzas of weights W, X, Y, and Z, where W <= X <= Y <= Z, you gain the weight of only 1 pizza! - On odd-numbered days (1-indexed...
{ "language": "python", "source": "def check(candidate):\n assert candidate(pizzas = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 320\n assert candidate(pizzas = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 20\n assert candidate(pizzas = [1, 3, 2, 4, 7, 6, 9, 8, 13, 12, 11, 10, 15, 14, 1...
[ "[1,2,3,4,5,6,7,8]", "[2,1,1,1,1,1,1,1]" ]
[ "On odd-numbered days, it is optimal to pair the smallest three and the largest one.", "On even-numbered days, it is optimal to pair the smallest two and the largest two.", "There will be ceil((n / 4) / 2) odd-numbered days. Select pizzas for all odd-numbered days first.", "Select the remaining pizzas for the...
{ "canonical_parameter_names": [ "pizzas" ], "leetcode_dataset_entry_point": "Solution().maxWeight", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:58", "tests_total": 103, "tests_dro...
java
{ "raw_signature": "public long maxWeight(int[] pizzas) {", "container": "Solution", "callable": "maxWeight", "parameters": [ { "name": "pizzas", "type": "int[]" } ], "return_type": "long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,458
select-k-disjoint-special-substrings
Medium
Given a string s of length n and an integer k, determine whether it is possible to select k disjoint special substrings. A special substring is a substring where: - Any character present inside the substring should not appear outside it in the string. - The substring is not the entire string s. Note that all k subst...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"single\",k = 0) == True\n assert candidate(s = \"abeabe\",k = 0) == True\n assert candidate(s = \"cdefdc\",k = 3) == False\n assert candidate(s = \"abacabadabacaba\",k = 3) == False\n assert candidate(s = \"aabbccddeeff...
[ "\"abcdbaefab\"\n2", "\"cdefdc\"\n3", "\"abeabe\"\n0" ]
[ "There are at most 26 start points (which are the first occurrence of each letter) and at most 26 end points (which are the last occurrence of each letter) of the substring.", "Starting from each character, build the smallest special substring interval containing it.", "Use dynamic programming on the obtained i...
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().maxSubstringLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:00", "tests_total": 95, ...
java
{ "raw_signature": "public boolean maxSubstringLength(String s, int k) {", "container": "Solution", "callable": "maxSubstringLength", "parameters": [ { "name": "s", "type": "String" }, { "name": "k", "type": "int" } ], "return_type": "boolean", "signature_source": "...
3,459
length-of-longest-v-shaped-diagonal-segment
Hard
You are given a 2D integer matrix grid of size n x m, where each element is either 0, 1, or 2. A V-shaped diagonal segment is defined as: - The segment starts with 1. - The subsequent elements follow this infinite sequence: 2, 0, 2, 0, .... - The segment: - Starts along a diagonal direction (top-left to bottom-righ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 1\n assert candidate(grid = [[1, 2, 0, 2, 0, 1, 2], [0, 2, 1, 2, 1, 2, 2], [0, 0, 2, 1, 2, 1, 2], [2, 0, 2, 1, 2, 1, 0]]) == 3\n assert candidate(grid = [[2, 0, 0, 0], [1, 2, 2, 2], [0, ...
[ "[[2,2,1,2,2],[2,0,2,2,0],[2,0,1,1,0],[1,0,2,2,2],[2,0,0,2,2]]", "[[2,2,2,2,2],[2,0,2,2,0],[2,0,1,1,0],[1,0,2,2,2],[2,0,0,2,2]]", "[[1,2,2,2,2],[2,2,2,2,0],[2,0,0,0,0],[0,0,2,2,2],[2,0,0,2,0]]", "[[1]]" ]
[ "Use dynamic programming to determine the best point to make a 90-degree rotation in the diagonal path while maintaining the required sequence.", "Represent dynamic programming states as (row, col, currentDirection, hasMadeTurnYet). Track the current position, direction of traversal, and whether a turn has alread...
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().lenOfVDiagonal", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:03", "tests_total": 76, "tests_d...
java
{ "raw_signature": "public int lenOfVDiagonal(int[][] grid) {", "container": "Solution", "callable": "lenOfVDiagonal", "parameters": [ { "name": "grid", "type": "int[][]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,461
check-if-digits-are-equal-in-string-after-operations-i
Easy
You are given a string s consisting of digits. Perform the following operation repeatedly until the string has exactly two digits: - For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10. - Replace s with the sequence of newly calculated d...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"9876543210\") == False\n assert candidate(s = \"100100\") == False\n assert candidate(s = \"123321\") == True\n assert candidate(s = \"111\") == True\n assert candidate(s = \"1234567890\") == False\n assert candidate...
[ "\"3902\"", "\"34789\"" ]
[ "Simulate the operations as described." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().hasSameDigits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:07", "tests_total": 127, "tests_drop...
java
{ "raw_signature": "public boolean hasSameDigits(String s) {", "container": "Solution", "callable": "hasSameDigits", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,462
maximum-sum-with-at-most-k-elements
Medium
You are given a 2D integer matrix grid of size n x m, an integer array limits of length n, and an integer k. The task is to find the maximum sum of at most k elements from the matrix grid such that: - The number of elements taken from the i^th row of grid does not exceed limits[i]. Return the maximum sum. Example 1:...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[10, 20, 30], [5, 15, 25], [1, 9, 18]],limits = [2, 1, 2],k = 5) == 102\n assert candidate(grid = [[5, 3, 7], [8, 2, 6]],limits = [2, 2],k = 3) == 21\n assert candidate(grid = [[1, 2], [3, 4]],limits = [1, 2],k = 2) == 7\n ...
[ "[[1,2],[3,4]]\n[1,2]\n2", "[[5,3,7],[8,2,6]]\n[2,2]\n3" ]
[ "Sort each row in descending order and extract the top limits[i] elements.", "Use a max-heap to efficiently pick the largest k elements across all rows." ]
{ "canonical_parameter_names": [ "grid", "limits", "k" ], "leetcode_dataset_entry_point": "Solution().maxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:10", "tests_total":...
java
{ "raw_signature": "public long maxSum(int[][] grid, int[] limits, int k) {", "container": "Solution", "callable": "maxSum", "parameters": [ { "name": "grid", "type": "int[][]" }, { "name": "limits", "type": "int[]" }, { "name": "k", "type": "int" } ...
3,463
check-if-digits-are-equal-in-string-after-operations-ii
Hard
You are given a string s consisting of digits. Perform the following operation repeatedly until the string has exactly two digits: - For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10. - Replace s with the sequence of newly calculated d...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"9876543210\") == False\n assert candidate(s = \"111\") == True\n assert candidate(s = \"1234567890\") == False\n assert candidate(s = \"898989898\") == True\n assert candidate(s = \"1111111111\") == True\n assert can...
[ "\"3902\"", "\"34789\"" ]
[ "Can we use nCr and use Pascal's triangle values here?", "nCr mod 10 can be uniquely determined from nCr mod 2 and nCr mod 5.", "Use Lucas's theorem." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().hasSameDigits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:12", "tests_total": 108, "tests_drop...
java
{ "raw_signature": "public boolean hasSameDigits(String s) {", "container": "Solution", "callable": "hasSameDigits", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,464
maximize-the-distance-between-points-on-a-square
Hard
You are given an integer side, representing the edge length of a square with corners at (0, 0), (0, side), (side, 0), and (side, side) on a Cartesian plane. You are also given a positive integer k and a 2D integer array points, where points[i] = [x_i, y_i] represents the coordinate of a point lying on the boundary of ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(side = 4,points = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 4], [2, 4], [3, 4], [4, 4], [4, 3], [4, 2], [4, 1], [4, 0], [3, 0], [2, 0], [1, 0]],k = 8) == 2\n assert candidate(side = 3,points = [[0, 0], [0, 1], [0, 2], [0, 3], [3, 0...
[ "2\n[[0,2],[2,0],[2,2],[0,0]]\n4", "2\n[[0,0],[1,2],[2,0],[2,2],[2,1]]\n4", "2\n[[0,0],[0,1],[0,2],[1,2],[2,0],[2,2],[2,1]]\n5" ]
[ "Can we use binary search for this problem?", "Think of the coordinates on a straight line in clockwise order.", "Binary search on the minimum Manhattan distance x.", "During the binary search, for each coordinate, find the immediate next coordinate with distance >= x.", "Greedily select up to k coordinates...
{ "canonical_parameter_names": [ "side", "points", "k" ], "leetcode_dataset_entry_point": "Solution().maxDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:14", "tests_to...
java
{ "raw_signature": "public int maxDistance(int side, int[][] points, int k) {", "container": "Solution", "callable": "maxDistance", "parameters": [ { "name": "side", "type": "int" }, { "name": "points", "type": "int[][]" }, { "name": "k", "type": "int" ...
3,467
transform-array-by-parity
Easy
You are given an integer array nums. Transform nums by performing the following operations in the exact order specified: 1. Replace each even number with 0. 2. Replace each odd numbers with 1. 3. Sort the modified array in non-decreasing order. Return the resulting array after performing these operations. Example 1:...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == [0, 0, 0, 0, 1, 1, 1, 1, 1]\n assert candidate(nums = [4, 3, 2, 1]) == [0, 0, 1, 1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 0, 0, 0, 0, 1, 1, 1, 1, ...
[ "[4,3,2,1]", "[1,5,1,4,2]" ]
[ "Let x be the number of even numbers, and y be the number of odd numbers. Output 0 x times, followed by 1 y times." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().transformArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:20", "tests_total": 104, "tests_...
java
{ "raw_signature": "public int[] transformArray(int[] nums) {", "container": "Solution", "callable": "transformArray", "parameters": [ { "name": "nums", "type": "int[]" } ], "return_type": "int[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,468
find-the-number-of-copy-arrays
Medium
You are given an array original of length n and a 2D array bounds of length n x 2, where bounds[i] = [u_i, v_i]. You need to find the number of possible arrays copy of length n such that: 1. (copy[i] - copy[i - 1]) == (original[i] - original[i - 1]) for 1 <= i <= n - 1. 2. u_i <= copy[i] <= v_i for 0 <= i <= n - 1. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(original = [1, 2, 3, 4],bounds = [[1, 10], [2, 9], [3, 8], [4, 7]]) == 4\n assert candidate(original = [3, 5, 7, 9],bounds = [[2, 4], [4, 6], [6, 8], [8, 10]]) == 3\n assert candidate(original = [10, 11, 12, 13],bounds = [[8, 10], ...
[ "[1,2,3,4]\n[[1,2],[2,3],[3,4],[4,5]]", "[1,2,3,4]\n[[1,10],[2,9],[3,8],[4,7]]", "[1,2,1,2]\n[[1,1],[2,3],[3,3],[2,3]]" ]
[ "copy[0] uniquely determines all other values.", "Possible values for copy[0] are in [u[0], v[0]].", "From left to right, compute valid ranges for each index by intersecting bounds with the previous range.", "The answer is the size of the valid range for the last index." ]
{ "canonical_parameter_names": [ "original", "bounds" ], "leetcode_dataset_entry_point": "Solution().countArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:23", "tests_total":...
java
{ "raw_signature": "public int countArrays(int[] original, int[][] bounds) {", "container": "Solution", "callable": "countArrays", "parameters": [ { "name": "original", "type": "int[]" }, { "name": "bounds", "type": "int[][]" } ], "return_type": "int", "signature_so...
3,469
find-minimum-cost-to-remove-array-elements
Medium
You are given an integer array nums. Your task is to remove all elements from the array by performing one of the following operations at each step until nums is empty: - Choose any two elements from the first three elements of nums and remove them. The cost of this operation is the maximum of the two elements removed....
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10]) == 20\n assert candidate(nums = [10, 20, 30]) == 40\n assert candidate(nums = [999999, 1]) == 999999\n assert candidate(nums = [5, 3, 7, 9, 1, 4]) == 18\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3,...
[ "[6,2,8,4]", "[2,1,3,3]" ]
[ "Can we use dynamic programming here?", "Use dynamic programming. The process guarantees that the remaining elements form a prefix of the array with at most one previous element.", "Define the state as dp[i][j], where i represents the last remaining element and j represents the starting index of the current pre...
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:25", "tests_total": 116, "tests_dropped...
java
{ "raw_signature": "public int minCost(int[] nums) {", "container": "Solution", "callable": "minCost", "parameters": [ { "name": "nums", "type": "int[]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,470
permutations-iv
Hard
Given two integers, n and k, an alternating permutation is a permutation of the first n positive integers such that no two adjacent elements are both odd or both even. Return the k-th alternating permutation sorted in lexicographical order. If there are fewer than k valid alternating permutations, return an empty list...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 100,k = 1000000000000000) == [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, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, ...
[ "4\n6", "3\n2", "2\n3" ]
[ "If n is odd, the first number must be odd.", "If n is even, the first number can be either odd or even.", "From smallest to largest, place each number and subtract the number of permutations from k.", "The number of permutations can be calculated using factorials." ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().permute", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:27", "tests_total": 97, "tests_dr...
java
{ "raw_signature": "public int[] permute(int n, long k) {", "container": "Solution", "callable": "permute", "parameters": [ { "name": "n", "type": "int" }, { "name": "k", "type": "long" } ], "return_type": "int[]", "signature_source": "leetcode/codeSnippets", "typ...
3,471
find-the-largest-almost-missing-integer
Easy
You are given an integer array nums and an integer k. An integer x is almost missing from nums if x appears in exactly one subarray of size k within nums. Return the largest almost missing integer from nums. If no such integer exists, return -1. A subarray is a contiguous sequence of elements within an array. Examp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5],k = 2) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 10\n assert candidate(nums = [1, 2, 3, 4, 5...
[ "[3,9,2,1,7]\n3", "[3,9,7,2,1,7]\n4", "[0,0]\n1" ]
[ "Solve the problem for three different cases: k = 1, k = n, and 1 < k < n", "If k = 1, return the largest element that occurs exactly once in nums", "If k = n, return the largest element in nums", "If 1 < k < n, all elements different from nums[0] and nums[n - 1] will occur in more than one subarray of size k...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().largestInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:29", "tests_total": 120, ...
java
{ "raw_signature": "public int largestInteger(int[] nums, int k) {", "container": "Solution", "callable": "largestInteger", "parameters": [ { "name": "nums", "type": "int[]" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/cod...
3,472
longest-palindromic-subsequence-after-at-most-k-operations
Medium
You are given a string s and an integer k. In one operation, you can replace the character at any position with the next or previous letter in the alphabet (wrapping around so that 'a' is after 'z'). For example, replacing 'a' with the next letter results in 'b', and replacing 'a' with the previous letter results in '...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zxy\",k = 1) == 3\n assert candidate(s = \"a\",k = 5) == 1\n assert candidate(s = \"abced\",k = 2) == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 25) == 14\n assert candidate(s = \"zzzzz\",k = 1) == 5\n ...
[ "\"abced\"\n2", "\"aaazzz\"\n4" ]
[ "Use dynamic programming.", "dp[i][j][k] is the length of the longest palindromic subsequence in substring [i..j] with cost at most k.", "dp[i][j][k] = max(dp[i + 1][j][k], dp[i][j - 1][k], dp[i + 1][j - 1][k - dist(s[i], s[j])] + 2), where dist(x, y) is the minimum cyclic distance between x and y." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().longestPalindromicSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:32", "tests_t...
java
{ "raw_signature": "public int longestPalindromicSubsequence(String s, int k) {", "container": "Solution", "callable": "longestPalindromicSubsequence", "parameters": [ { "name": "s", "type": "String" }, { "name": "k", "type": "int" } ], "return_type": "int", "signat...
3,473
sum-of-k-subarrays-with-length-at-least-m
Medium
You are given an integer array nums and two integers, k and m. Return the maximum sum of k non-overlapping subarrays of nums, where each subarray has a length of at least m. Example 1: Input: nums = [1,2,-1,3,3,4], k = 2, m = 2 Output: 13 Explanation: The optimal choice is: - Subarray nums[3..5] with sum 3 + 3 + 4 =...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 0, -1, 0, 1, -1, 0, 1],k = 2,m = 2) == 2\n assert candidate(nums = [5, 4, 3, 2, 1],k = 2,m = 2) == 15\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 2,m = 3) == 0\n assert candidate(nums = [1, 2, 3, 4, 5...
[ "[1,2,-1,3,3,4]\n2\n2", "[-10,3,-1,-2]\n4\n1" ]
[ "Dynamic Programming", "Prefix Sum", "Let dp[i][j] be the maximum sum with i subarrays for the first j elements" ]
{ "canonical_parameter_names": [ "nums", "k", "m" ], "leetcode_dataset_entry_point": "Solution().maxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:34", "tests_total": 211,...
java
{ "raw_signature": "public int maxSum(int[] nums, int k, int m) {", "container": "Solution", "callable": "maxSum", "parameters": [ { "name": "nums", "type": "int[]" }, { "name": "k", "type": "int" }, { "name": "m", "type": "int" } ], "return_type":...
3,474
lexicographically-smallest-generated-string
Hard
You are given two strings, str1 and str2, of lengths n and m, respectively. A string word of length n + m - 1 is defined to be generated by str1 and str2 if it satisfies the following conditions for each index 0 <= i <= n - 1: - If str1[i] == 'T', the substring of word with size m starting at index i is equal to str2...
{ "language": "python", "source": "def check(candidate):\n assert candidate(str1 = \"FF\",str2 = \"z\") == \"aa\"\n assert candidate(str1 = \"FT\",str2 = \"c\") == \"ac\"\n assert candidate(str1 = \"FT\",str2 = \"yz\") == \"ayz\"\n assert candidate(str1 = \"TTT\",str2 = \"aaa\") == \"aaaaa\"\n assert...
[ "\"TFTF\"\n\"ab\"", "\"TFTF\"\n\"abc\"", "\"FT\"\n\"aa\"" ]
[ "Use dynamic programming.", "Fill the fixed part.", "Use KMP's next table for DP.", "The state is the prefix length and the longest suffix length that matches the pattern.", "Each unknown character can be selected from ['a', 'b'].", "Can you think of a greedy approach?" ]
{ "canonical_parameter_names": [ "str1", "str2" ], "leetcode_dataset_entry_point": "Solution().generateString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:36", "tests_total": 26...
java
{ "raw_signature": "public String generateString(String str1, String str2) {", "container": "Solution", "callable": "generateString", "parameters": [ { "name": "str1", "type": "String" }, { "name": "str2", "type": "String" } ], "return_type": "String", "signature_so...
3,477
fruits-into-baskets-ii
Easy
You are given two arrays of integers, fruits and baskets, each of length n, where fruits[i] represents the quantity of the i^th type of fruit, and baskets[j] represents the capacity of the j^th basket. From left to right, place the fruits according to these rules: - Each fruit type must be placed in the leftmost avai...
{ "language": "python", "source": "def check(candidate):\n assert candidate(fruits = [5, 5, 5, 5],baskets = [4, 4, 4, 4]) == 4\n assert candidate(fruits = [100, 200, 300],baskets = [100, 200, 300]) == 0\n assert candidate(fruits = [1, 3, 5, 7],baskets = [2, 4, 6, 8]) == 0\n assert candidate(fruits = [10...
[ "[4,2,5]\n[3,5,4]", "[3,6,1]\n[6,4,7]" ]
[ "Simulate the operations for each fruit as described" ]
{ "canonical_parameter_names": [ "fruits", "baskets" ], "leetcode_dataset_entry_point": "Solution().numOfUnplacedFruits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:41", "tests_...
java
{ "raw_signature": "public int numOfUnplacedFruits(int[] fruits, int[] baskets) {", "container": "Solution", "callable": "numOfUnplacedFruits", "parameters": [ { "name": "fruits", "type": "int[]" }, { "name": "baskets", "type": "int[]" } ], "return_type": "int", "si...
3,478
choose-k-elements-with-maximum-sum
Medium
You are given two integer arrays, nums1 and nums2, both of length n, along with a positive integer k. For each index i from 0 to n - 1, perform the following: - Find all indices j where nums1[j] is less than nums1[i]. - Choose at most k values of nums2[j] at these indices to maximize the total sum. Return an array a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],k = 2) == [0, 50, 90, 90, 90]\n assert candidate(nums1 = [100000, 90000, 80000, 70000, 60000],nums2 = [1, 2, 3, 4, 5],k = 4) == [14, 12, 9, 5, 0]\n assert candidate(nums1 = ...
[ "[4,2,1,5,3]\n[10,20,30,40,50]\n2", "[2,2,2,2]\n[3,1,2,3]\n1" ]
[ "Sort nums1 and its corresponding nums2 values together based on nums1.", "Use a max heap to track the top k values of nums2 as you process each element in the sorted order." ]
{ "canonical_parameter_names": [ "nums1", "nums2", "k" ], "leetcode_dataset_entry_point": "Solution().findMaxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:43", "tests_tot...
java
{ "raw_signature": "public long[] findMaxSum(int[] nums1, int[] nums2, int k) {", "container": "Solution", "callable": "findMaxSum", "parameters": [ { "name": "nums1", "type": "int[]" }, { "name": "nums2", "type": "int[]" }, { "name": "k", "type": "int" ...
3,479
fruits-into-baskets-iii
Medium
You are given two arrays of integers, fruits and baskets, each of length n, where fruits[i] represents the quantity of the i^th type of fruit, and baskets[j] represents the capacity of the j^th basket. From left to right, place the fruits according to these rules: - Each fruit type must be placed in the leftmost avai...
{ "language": "python", "source": "def check(candidate):\n assert candidate(fruits = [5, 5, 5, 5, 5],baskets = [1, 2, 3, 4, 5]) == 4\n assert candidate(fruits = [4, 2, 5],baskets = [3, 5, 4]) == 1\n assert candidate(fruits = [1, 1, 1, 1],baskets = [1, 1, 1, 1]) == 0\n assert candidate(fruits = [10000000...
[ "[4,2,5]\n[3,5,4]", "[3,6,1]\n[6,4,7]" ]
[ "Sort the baskets by the pair of (basket[i], i) in the array.", "For each fruit from left to right, use binary search to find the first index in the sorted array such that basket[i] >= fruit.", "Use a segment tree to maintain the smallest original indices where basket[i] >= fruit.", "When a valid index is fou...
{ "canonical_parameter_names": [ "fruits", "baskets" ], "leetcode_dataset_entry_point": "Solution().numOfUnplacedFruits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:46", "tests_...
java
{ "raw_signature": "public int numOfUnplacedFruits(int[] fruits, int[] baskets) {", "container": "Solution", "callable": "numOfUnplacedFruits", "parameters": [ { "name": "fruits", "type": "int[]" }, { "name": "baskets", "type": "int[]" } ], "return_type": "int", "si...
3,480
maximize-subarrays-after-removing-one-conflicting-pair
Hard
You are given an integer n which represents an array nums containing the numbers from 1 to n in order. Additionally, you are given a 2D array conflictingPairs, where conflictingPairs[i] = [a, b] indicates that a and b form a conflicting pair. Remove exactly one element from conflictingPairs. Afterward, count the numbe...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 7,conflictingPairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 8\n assert candidate(n = 6,conflictingPairs = [[1, 3], [2, 4], [3, 5], [4, 6]]) == 12\n assert candidate(n = 6,conflictingPairs = [[1, 3], [3, 5], [2, 4]...
[ "4\n[[2,3],[1,4]]", "5\n[[1,2],[2,5],[3,5]]" ]
[ "Let f[i] (where i = 1, 2, 3, ..., n) be the end index of the longest valid subarray (without any conflicting pair) starting at index i.", "The answer is: sigma(f[i] - i + 1) for i in [1..n], which simplifies to: sigma(f[i]) - n * (n + 1) / 2 + n.", "Focus on maintaining f[i].", "If we have a conflicting pair...
{ "canonical_parameter_names": [ "n", "conflictingPairs" ], "leetcode_dataset_entry_point": "Solution().maxSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:49", "tests_tot...
java
{ "raw_signature": "public long maxSubarrays(int n, int[][] conflictingPairs) {", "container": "Solution", "callable": "maxSubarrays", "parameters": [ { "name": "n", "type": "int" }, { "name": "conflictingPairs", "type": "int[][]" } ], "return_type": "long", "signat...
3,483
unique-3-digit-even-numbers
Easy
You are given an array of digits called digits. Your task is to determine the number of distinct three-digit even numbers that can be formed using these digits. Note: Each copy of a digit can only be used once per number, and there may not be leading zeros. Example 1: Input: digits = [1,2,3,4] Output: 12 Explanation...
{ "language": "python", "source": "def check(candidate):\n assert candidate(digits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(digits = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 1\n assert candidate(digits = [6, 6, 6]) == 1\n assert candidate(digits = [1, 3, 5]) == 0\n assert candidate(digits ...
[ "[1,2,3,4]", "[0,2,2]", "[6,6,6]", "[1,3,5]" ]
[ "Use brute force to try all possibilities" ]
{ "canonical_parameter_names": [ "digits" ], "leetcode_dataset_entry_point": "Solution().totalNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:53", "tests_total": 128, "tests_...
java
{ "raw_signature": "public int totalNumbers(int[] digits) {", "container": "Solution", "callable": "totalNumbers", "parameters": [ { "name": "digits", "type": "int[]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,485
longest-common-prefix-of-k-strings-after-removal
Hard
You are given an array of strings words and an integer k. For each index i in the range [0, words.length - 1], find the length of the longest common prefix among any k strings (selected at distinct indices) from the remaining array after removing the i^th element. Return an array answer, where answer[i] is the answer...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['banana', 'band', 'bend', 'bendy'],k = 3) == [1, 1, 1, 1]\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abcg'],k = 2) == [3, 3, 3, 3]\n assert candidate(words = ['apple', 'application', 'aptitude', 'appetite'],k = 3...
[ "[\"jump\",\"run\",\"run\",\"jump\",\"run\"]\n2", "[\"dog\",\"racer\",\"car\"]\n2" ]
[ "Use a trie to store all the strings initially.", "For each node in the trie, maintain the count of paths ending there.", "For each arr[i], remove it from the trie and update the counts.", "During evaluation, find the innermost node with at least k paths ending there.", "Use a multiset or similar structure ...
{ "canonical_parameter_names": [ "words", "k" ], "leetcode_dataset_entry_point": "Solution().longestCommonPrefix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:26:56", "tests_total":...
java
{ "raw_signature": "public int[] longestCommonPrefix(String[] words, int k) {", "container": "Solution", "callable": "longestCommonPrefix", "parameters": [ { "name": "words", "type": "String[]" }, { "name": "k", "type": "int" } ], "return_type": "int[]", "signature_...
3,487
maximum-unique-subarray-sum-after-deletion
Easy
You are given an integer array nums. You are allowed to delete any number of elements from nums without making it empty. After performing the deletions, select a subarray of nums such that: 1. All elements in the subarray are unique. 2. The sum of the elements in the subarray is maximized. Return the maximum sum of ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, 2, -3, 4, -5]) == 6\n assert candidate(nums = [-10, 1, 20, -30, 40, -50, 60]) == 121\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == 1\n assert ...
[ "[1,2,3,4,5]", "[1,1,0,1,1]", "[1,2,-1,-2,1,0,-1]" ]
[ "If the maximum element in the array is less than zero, the answer is the maximum element.", "Otherwise, the answer is the sum of all unique values that are greater than or equal to zero." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:00", "tests_total": 121, "tests_dropped"...
java
{ "raw_signature": "public int maxSum(int[] nums) {", "container": "Solution", "callable": "maxSum", "parameters": [ { "name": "nums", "type": "int[]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,488
closest-equal-element-queries
Medium
You are given a circular array nums and an array queries. For each query i, you have to find the following: - The minimum distance between the element at index queries[i] and any other index j in the circular array, where nums[j] == nums[queries[i]]. If no such index exists, the answer for that query should be -1. R...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 1, 4, 1, 3, 2],queries = [0, 3, 5]) == [2, -1, 3]\n assert candidate(nums = [1, 2, 3, 4],queries = [0, 1, 2, 3]) == [-1, -1, -1, -1]\n assert candidate(nums = [1000000, 1000000, 1000000],queries = [0, 1, 2]) == [1, 1,...
[ "[1,3,1,4,1,3,2]\n[0,3,5]", "[1,2,3,4]\n[0,1,2,3]" ]
[ "Use a dictionary that maps each unique value in the array to a sorted list of its indices.", "For each query, use binary search on the sorted indices list to find the nearest occurrences of the target value." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().solveQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:03", "tests_total": 9...
java
{ "raw_signature": "public List<Integer> solveQueries(int[] nums, int[] queries) {", "container": "Solution", "callable": "solveQueries", "parameters": [ { "name": "nums", "type": "int[]" }, { "name": "queries", "type": "int[]" } ], "return_type": "List<Integer>", "...
3,489
zero-array-transformation-iv
Medium
You are given an integer array nums of length n and a 2D array queries, where queries[i] = [l_i, r_i, val_i]. Each queries[i] represents the following action on nums: - Select a subset of indices in the range [l_i, r_i] from nums. - Decrement the value at each selected index by exactly val_i. A Zero Array is an arra...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 2, 6],queries = [[0, 1, 1], [0, 2, 1], [1, 4, 2], [4, 4, 4], [3, 4, 1], [4, 4, 5]]) == 4\n assert candidate(nums = [2, 0, 2],queries = [[0, 2, 1], [0, 2, 1], [1, 1, 3]]) == 2\n assert candidate(nums = [1, 2, 3, 2, ...
[ "[2,0,2]\n[[0,2,1],[0,2,1],[1,1,3]]", "[4,3,2,1]\n[[1,3,2],[0,2,1]]", "[1,2,3,2,1]\n[[0,1,1],[1,2,1],[2,3,2],[3,4,1],[4,4,1]]", "[1,2,3,2,6]\n[[0,1,1],[0,2,1],[1,4,2],[4,4,4],[3,4,1],[4,4,5]]" ]
[ "Use dynamic programming.", "For each nums[i], use DP to check whether the queries[.][2] values (i.e., the val values) of the queries that affect it can form a combination with a sum equal to nums[i]." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().minZeroArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:06", "tests_total": 1...
java
{ "raw_signature": "public int minZeroArray(int[] nums, int[][] queries) {", "container": "Solution", "callable": "minZeroArray", "parameters": [ { "name": "nums", "type": "int[]" }, { "name": "queries", "type": "int[][]" } ], "return_type": "int", "signature_source...
3,490
count-beautiful-numbers
Hard
You are given two positive integers, l and r. A positive integer is called beautiful if the product of its digits is divisible by the sum of its digits. Return the count of beautiful numbers between l and r, inclusive. Example 1: Input: l = 10, r = 20 Output: 2 Explanation: The beautiful numbers in the range are 10 ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(l = 999,r = 999) == 1\n assert candidate(l = 1,r = 9) == 9\n assert candidate(l = 900,r = 1000) == 35\n assert candidate(l = 789,r = 890) == 35\n assert candidate(l = 500,r = 5000) == 1800\n assert candidate(l = 5,r = 50) ...
[ "10\n20", "1\n15" ]
[ "Use digit dynamic programming." ]
{ "canonical_parameter_names": [ "l", "r" ], "leetcode_dataset_entry_point": "Solution().beautifulNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:08", "tests_total": 92, ...
java
{ "raw_signature": "public int beautifulNumbers(int l, int r) {", "container": "Solution", "callable": "beautifulNumbers", "parameters": [ { "name": "l", "type": "int" }, { "name": "r", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/codeSnipp...
3,492
maximum-containers-on-a-ship
Easy
You are given a positive integer n representing an n x n cargo deck on a ship. Each cell on the deck can hold one container with a weight of exactly w. However, the total weight of all containers, if loaded onto the deck, must not exceed the ship's maximum weight capacity, maxWeight. Return the maximum number of cont...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 10,w = 5,maxWeight = 25) == 5\n assert candidate(n = 10,w = 1,maxWeight = 10) == 10\n assert candidate(n = 5,w = 2,maxWeight = 20) == 10\n assert candidate(n = 5,w = 10,maxWeight = 50) == 5\n assert candidate(n = 5,w = 10...
[ "2\n3\n15", "3\n5\n20" ]
[ "What are the limits on the number of containers?", "We can load at most min(n * n, maxWeight / w) containers." ]
{ "canonical_parameter_names": [ "n", "w", "maxWeight" ], "leetcode_dataset_entry_point": "Solution().maxContainers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:12", "tests_...
java
{ "raw_signature": "public int maxContainers(int n, int w, int maxWeight) {", "container": "Solution", "callable": "maxContainers", "parameters": [ { "name": "n", "type": "int" }, { "name": "w", "type": "int" }, { "name": "maxWeight", "type": "int" } ...
3,493
properties-graph
Medium
You are given a 2D integer array properties having dimensions n x m and an integer k. Define a function intersect(a, b) that returns the number of distinct integers common to both arrays a and b. Construct an undirected graph where each index i corresponds to properties[i]. There is an edge between node i and node j ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(properties = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]],k = 3) == 1\n assert candidate(properties = [[10, 20, 30], [30, 40, 50], [40, 50, 60], [50, 60, 70]],k = 1) == 1\n assert candidate(properties = [[1, 1, 1, 1], [...
[ "[[1,2],[1,1],[3,4],[4,5],[5,6],[7,7]]\n1", "[[1,2,3],[2,3,4],[4,3,5]]\n2", "[[1,1],[1,1]]\n2" ]
[ "How can we optimally find the intersection of two arrays? One way is to use len(set(a) & set(b)).", "For connected components, think about using DFS, BFS, or DSU." ]
{ "canonical_parameter_names": [ "properties", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfComponents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:15", "tests_tot...
java
{ "raw_signature": "public int numberOfComponents(int[][] properties, int k) {", "container": "Solution", "callable": "numberOfComponents", "parameters": [ { "name": "properties", "type": "int[][]" }, { "name": "k", "type": "int" } ], "return_type": "int", "signatur...
3,494
find-the-minimum-amount-of-time-to-brew-potions
Medium
You are given two integer arrays, skill and mana, of length n and m, respectively. In a laboratory, n wizards must brew m potions in order. Each potion has a mana capacity mana[j] and must pass through all the wizards sequentially to be brewed properly. The time taken by the i^th wizard on the j^th potion is time_ij =...
{ "language": "python", "source": "def check(candidate):\n assert candidate(skill = [10, 20, 30],mana = [1, 2, 3, 4, 5]) == 490\n assert candidate(skill = [3, 2, 1],mana = [6, 5, 4]) == 57\n assert candidate(skill = [1, 1, 1],mana = [1, 1, 1]) == 5\n assert candidate(skill = [1, 2, 3],mana = [4, 5, 6, 7...
[ "[1,5,2,4]\n[5,1,4,2]", "[1,1,1]\n[1,1,1]", "[1,2,3,4]\n[1,2]" ]
[ "Maintain each wizard's earliest free time (for the last potion) as f[i].", "Let x be the current mana value. Starting from now = f[0], update now = max(now + skill[i - 1] * x, f[i]) for i in [1..n]. Then, the final f[n - 1] = now + skill[n - 1] * x for this potion.", "Update all other f values by f[i] = f[i + ...
{ "canonical_parameter_names": [ "skill", "mana" ], "leetcode_dataset_entry_point": "Solution().minTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:17", "tests_total": 103, "...
java
{ "raw_signature": "public long minTime(int[] skill, int[] mana) {", "container": "Solution", "callable": "minTime", "parameters": [ { "name": "skill", "type": "int[]" }, { "name": "mana", "type": "int[]" } ], "return_type": "long", "signature_source": "leetcode/cod...
3,495
minimum-operations-to-make-array-elements-zero
Hard
You are given a 2D array queries, where queries[i] is of the form [l, r]. Each queries[i] defines an array of integers nums consisting of elements ranging from l to r, both inclusive. In one operation, you can: - Select two integers a and b from the array. - Replace them with floor(a / 4) and floor(b / 4). Your task...
{ "language": "python", "source": "def check(candidate):\n assert candidate(queries = [[1, 2], [2, 4]]) == 3\n assert candidate(queries = [[10, 20], [20, 30], [30, 40]]) == 48\n assert candidate(queries = [[1, 1000000000], [500000000, 1000000000]]) == 11071043045\n assert candidate(queries = [[1, 100], ...
[ "[[1,2],[2,4]]", "[[2,6]]" ]
[ "For a number x, the number of \"/4\" operations to change it to 0 is floor(log4(x)) + 1.", "Always pair the 2 numbers with the maximum \"/4\" operations needed." ]
{ "canonical_parameter_names": [ "queries" ], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:20", "tests_total": 94, "tests...
java
{ "raw_signature": "public long minOperations(int[][] queries) {", "container": "Solution", "callable": "minOperations", "parameters": [ { "name": "queries", "type": "int[][]" } ], "return_type": "long", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
3,498
reverse-degree-of-a-string
Easy
Given a string s, calculate its reverse degree. The reverse degree is calculated as follows: 1. For each character, multiply its position in the reversed alphabet ('a' = 26, 'b' = 25, ..., 'z' = 1) with its position in the string (1-indexed). 2. Sum these products for all characters in the string. Return the reverse...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzz\") == 10\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 15678\n assert candidate(s = \"world\") == 230\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 3276\n assert ca...
[ "\"abc\"", "\"zaza\"" ]
[ "Simulate the operations as described." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().reverseDegree", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:25", "tests_total": 55, "tests_dropp...
java
{ "raw_signature": "public int reverseDegree(String s) {", "container": "Solution", "callable": "reverseDegree", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,499
maximize-active-section-with-trade-i
Medium
You are given a binary string s of length n, where: - '1' represents an active section. - '0' represents an inactive section. You can perform at most one trade to maximize the number of active sections in s. In a trade, you: - Convert a contiguous block of '1's that is surrounded by '0's to all '0's. - Afterward, co...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"01010\") == 4\n assert candidate(s = \"1000100\") == 7\n assert candidate(s = \"010101010\") == 6\n assert candidate(s = \"1001001001\") == 8\n assert candidate(s = \"11111\") == 5\n assert candidate(s = \"0011001100...
[ "\"01\"", "\"0100\"", "\"1000100\"", "\"01010\"" ]
[ "Split the string into several zero-one segments.", "For each one-segment, if it has two neighbors (i.e., it is surrounded by two zero-segments), the total sum of their lengths is one of the candidates for delta.", "Find the maximum delta and add it to the total number of ones in the string." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().maxActiveSectionsAfterTrade", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:28", "tests_total": 88, ...
java
{ "raw_signature": "public int maxActiveSectionsAfterTrade(String s) {", "container": "Solution", "callable": "maxActiveSectionsAfterTrade", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcod...
3,500
minimum-cost-to-divide-array-into-subarrays
Hard
You are given two integer arrays, nums and cost, of the same size, and an integer k. You can divide nums into subarrays. The cost of the i^th subarray consisting of elements nums[l..r] is: - (nums[0] + nums[1] + ... + nums[r] + k * i) * (cost[l] + cost[l + 1] + ... + cost[r]). Note that i represents the order of the...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1],cost = [1],k = 1) == 2\n assert candidate(nums = [4, 8, 5, 1, 14, 2, 2, 12, 1],cost = [7, 2, 8, 4, 2, 2, 1, 1, 2],k = 7) == 985\n assert candidate(nums = [1, 2, 3, 4, 5],cost = [5, 4, 3, 2, 1],k = 2) == 130\n assert c...
[ "[3,1,4]\n[4,6,6]\n1", "[4,8,5,1,14,2,2,12,1]\n[7,2,8,4,2,2,1,1,2]\n7" ]
[ "dp[i] is the minimum cost to split the array suffix starting at i.", "Observe that no matter how many subarrays we have, if we have the first subarray on the left, the total cost of the previous subarrays increases by k * total_cost_of_the_subarray. This is because when we increase i to (i + 1), the cost increas...
{ "canonical_parameter_names": [ "nums", "cost", "k" ], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:31", "tests_tota...
java
{ "raw_signature": "public long minimumCost(int[] nums, int[] cost, int k) {", "container": "Solution", "callable": "minimumCost", "parameters": [ { "name": "nums", "type": "int[]" }, { "name": "cost", "type": "int[]" }, { "name": "k", "type": "int" } ...
3,501
maximize-active-section-with-trade-ii
Hard
You are given a binary string s of length n, where: - '1' represents an active section. - '0' represents an inactive section. You can perform at most one trade to maximize the number of active sections in s. In a trade, you: - Convert a contiguous block of '1's that is surrounded by '0's to all '0's. - Afterward, co...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"0100\",queries = [[0, 3], [0, 2], [1, 3], [2, 3]]) == [4, 3, 1, 1]\n assert candidate(s = \"01\",queries = [[0, 1]]) == [1]\n assert candidate(s = \"01010\",queries = [[0, 3], [1, 4], [1, 3]]) == [4, 4, 2]\n assert candida...
[ "\"01\"\n[[0,1]]", "\"0100\"\n[[0,3],[0,2],[1,3],[2,3]]", "\"1000100\"\n[[1,5],[0,6],[0,4]]", "\"01010\"\n[[0,3],[1,4],[1,3]]" ]
[ "Split consecutive zeros and ones into segments and give each segment an ID.", "The answer should be the maximum of ans[i] = len[i - 1] + len[i + 1], where i is a one-segment.", "For a zero-segment, define ans[i] = 0.", "Note that all three segments (i - 1, i, and i + 1) should be fully covered by the substri...
{ "canonical_parameter_names": [ "s", "queries" ], "leetcode_dataset_entry_point": "Solution().maxActiveSectionsAfterTrade", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:34", "tes...
java
{ "raw_signature": "public List<Integer> maxActiveSectionsAfterTrade(String s, int[][] queries) {", "container": "Solution", "callable": "maxActiveSectionsAfterTrade", "parameters": [ { "name": "s", "type": "String" }, { "name": "queries", "type": "int[][]" } ], "retu...
3,502
minimum-cost-to-reach-every-position
Easy
You are given an integer array cost of size n. You are currently at position n (at the end of the line) in a line of n + 1 people (numbered from 0 to n). You wish to move forward in the line, but each person in front of you charges a specific amount to swap places. The cost to swap with person i is given by cost[i]. ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(cost = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(cost = [10, 20, 30, 40, 50]) == [10, 10, 10, 10, 10]\n assert candidate(cost = [50, 25, 75, 100, 20, 30, 40, 60, 80, 90]) == [50, 25, ...
[ "[5,3,4,1,3,2]", "[1,2,4,6,7]" ]
[ "Note that once you swap to a position with a lower cost, you can reach any later position for free.", "Use a min prefix array." ]
{ "canonical_parameter_names": [ "cost" ], "leetcode_dataset_entry_point": "Solution().minCosts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:36", "tests_total": 109, "tests_droppe...
java
{ "raw_signature": "public int[] minCosts(int[] cost) {", "container": "Solution", "callable": "minCosts", "parameters": [ { "name": "cost", "type": "int[]" } ], "return_type": "int[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,503
longest-palindrome-after-substring-concatenation-i
Medium
You are given two strings, s and t. You can create a new string by selecting a substring from s (possibly empty) and a substring from t (possibly empty), then concatenating them in order. Return the length of the longest palindrome that can be formed this way. Example 1: Input: s = "a", t = "a" Output: 2 Explanatio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"b\",t = \"aaaa\") == 4\n assert candidate(s = \"hello\",t = \"world\") == 3\n assert candidate(s = \"different\",t = \"entirely\") == 5\n assert candidate(s = \"level\",t = \"deified\") == 7\n assert candidate(s = \"xyz...
[ "\"a\"\n\"a\"", "\"abc\"\n\"def\"", "\"b\"\n\"aaaa\"", "\"abcde\"\n\"ecdba\"" ]
[ "Brute force" ]
{ "canonical_parameter_names": [ "s", "t" ], "leetcode_dataset_entry_point": "Solution().longestPalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:39", "tests_total": 101, ...
java
{ "raw_signature": "public int longestPalindrome(String s, String t) {", "container": "Solution", "callable": "longestPalindrome", "parameters": [ { "name": "s", "type": "String" }, { "name": "t", "type": "String" } ], "return_type": "int", "signature_source": "leet...
3,504
longest-palindrome-after-substring-concatenation-ii
Hard
You are given two strings, s and t. You can create a new string by selecting a substring from s (possibly empty) and a substring from t (possibly empty), then concatenating them in order. Return the length of the longest palindrome that can be formed this way. Example 1: Input: s = "a", t = "a" Output: 2 Explanatio...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"b\",t = \"aaaa\") == 4\n assert candidate(s = \"hello\",t = \"world\") == 3\n assert candidate(s = \"aaaa\",t = \"bbbb\") == 4\n assert candidate(s = \"abcde\",t = \"ecdba\") == 5\n assert candidate(s = \"noon\",t = \"m...
[ "\"a\"\n\"a\"", "\"abc\"\n\"def\"", "\"b\"\n\"aaaa\"", "\"abcde\"\n\"ecdba\"" ]
[ "Let dp[i][j] be the length of the longest answer if we try starting it with s[i] and ending it with t[j].", "For s, preprocess the length of the longest palindrome starting at index i as p[i].", "For t, preprocess the length of the longest palindrome ending at index j as q[j].", "If s[i] != t[j], then dp[i][...
{ "canonical_parameter_names": [ "s", "t" ], "leetcode_dataset_entry_point": "Solution().longestPalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:41", "tests_total": 122, ...
java
{ "raw_signature": "public int longestPalindrome(String s, String t) {", "container": "Solution", "callable": "longestPalindrome", "parameters": [ { "name": "s", "type": "String" }, { "name": "t", "type": "String" } ], "return_type": "int", "signature_source": "leet...
3,505
minimum-operations-to-make-elements-within-k-subarrays-equal
Hard
You are given an integer array nums and two integers, x and k. You can perform the following operation any number of times (including zero): - Increase or decrease any element of nums by 1. Return the minimum number of operations needed to have at least k non-overlapping subarrays of size exactly x in nums, where all...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000, -1000000, 1000000, -1000000, 1000000],x = 2,k = 2) == 4000000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 10,k = 1) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
[ "[5,-2,1,3,7,3,6,4,-1]\n3\n2", "[9,-2,-2,-2,1,5]\n2\n2" ]
[ "Making every element of an x-sized window equal to its median is optimal.", "Precalculate this for each window." ]
{ "canonical_parameter_names": [ "nums", "x", "k" ], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:27:44", "tests_total...
java
{ "raw_signature": "public long minOperations(int[] nums, int x, int k) {", "container": "Solution", "callable": "minOperations", "parameters": [ { "name": "nums", "type": "int[]" }, { "name": "x", "type": "int" }, { "name": "k", "type": "int" } ], ...
3,243
shortest-distance-after-road-addition-queries-i
Medium
You are given an integer n and a 2D integer array queries. There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0 <= i < n - 1. queries[i] = [u_i, v_i] represents the addition of a new unidirectional road from city u_i to city v_i. After each query, ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 7,queries = [[0, 5], [1, 6], [2, 4]]) == [2, 2, 2]\n assert candidate(n = 8,queries = [[1, 5], [2, 6], [3, 7], [0, 4], [0, 6], [0, 7]]) == [4, 4, 4, 4, 2, 1]\n assert candidate(n = 6,queries = [[1, 3], [2, 5], [0, 3]]) == [4, 3...
[ "5\n[[2,4],[0,2],[0,4]]", "4\n[[0,3],[0,2]]" ]
[ "Maintain the graph and use an efficient shortest path algorithm after each update.", "We use BFS/Dijkstra for each query." ]
{ "canonical_parameter_names": [ "n", "queries" ], "leetcode_dataset_entry_point": "Solution().shortestDistanceAfterQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:12", "te...
javascript
{ "raw_signature": "var shortestDistanceAfterQueries = function(n, queries) {", "container": null, "callable": "shortestDistanceAfterQueries", "parameters": [ { "name": "n", "type": "number" }, { "name": "queries", "type": "number[][]" } ], "return_type": "number[]", ...
3,244
shortest-distance-after-road-addition-queries-ii
Hard
You are given an integer n and a 2D integer array queries. There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0 <= i < n - 1. queries[i] = [u_i, v_i] represents the addition of a new unidirectional road from city u_i to city v_i. After each query, ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,queries = [[2, 4], [0, 2], [0, 4]]) == [3, 2, 1]\n assert candidate(n = 4,queries = [[0, 3], [0, 2]]) == [1, 1]\n assert candidate(n = 75000,queries = [[37500, 74999], [18750, 74999], [56250, 74999], [9375, 74999], [28125, 74...
[ "5\n[[2,4],[0,2],[0,4]]", "4\n[[0,3],[0,2]]" ]
[]
{ "canonical_parameter_names": [ "n", "queries" ], "leetcode_dataset_entry_point": "Solution().shortestDistanceAfterQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:15", "te...
javascript
{ "raw_signature": "var shortestDistanceAfterQueries = function(n, queries) {", "container": null, "callable": "shortestDistanceAfterQueries", "parameters": [ { "name": "n", "type": "number" }, { "name": "queries", "type": "number[][]" } ], "return_type": "number[]", ...
3,248
snake-in-matrix
Easy
There is a snake in an n x n matrix grid and can move in four possible directions. Each cell in the grid is identified by the position: grid[i][j] = (i * n) + j. The snake starts at cell 0 and follows a sequence of commands. You are given an integer n representing the size of the grid and an array of strings commands...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 2,commands = ['RIGHT', 'DOWN']) == 3\n assert candidate(n = 5,commands = ['RIGHT', 'DOWN', 'RIGHT', 'DOWN', 'RIGHT', 'DOWN']) == 18\n assert candidate(n = 2,commands = ['RIGHT', 'DOWN']) == 3\n assert candidate(n = 4,command...
[ "2\n[\"RIGHT\",\"DOWN\"]", "3\n[\"DOWN\",\"RIGHT\",\"UP\"]" ]
[ "Try to update the row and column of the snake after each command." ]
{ "canonical_parameter_names": [ "n", "commands" ], "leetcode_dataset_entry_point": "Solution().finalPositionOfSnake", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:20", "tests_tot...
javascript
{ "raw_signature": "var finalPositionOfSnake = function(n, commands) {", "container": null, "callable": "finalPositionOfSnake", "parameters": [ { "name": "n", "type": "number" }, { "name": "commands", "type": "string[]" } ], "return_type": "number", "signature_sourc...
3,250
find-the-count-of-monotonic-pairs-i
Hard
You are given an array of positive integers nums of length n. We call a pair of non-negative integer arrays (arr1, arr2) monotonic if: - The lengths of both arrays are n. - arr1 is monotonically non-decreasing, in other words, arr1[0] <= arr1[1] <= ... <= arr1[n - 1]. - arr2 is monotonically non-increasing, in other ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [50, 1, 50, 1, 50]) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3]) == 84\n assert candidate(nums = [10, 20, 30, 40, 50]) == 3003\n assert candidate(nums = [5, 5, 5, 5]) == 126\n assert candidate(nums = [1, 2, 3, 4,...
[ "[2,3,2]", "[5,5,5,5]" ]
[ "Let dp[i][s] is the number of monotonic pairs of length i with the arr1[i - 1] = s.", "If arr1[i - 1] = s, arr2[i - 1] = nums[i - 1] - s.", "Check if the state in recurrence is valid." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:25", "tests_total": 105, "tests_dr...
javascript
{ "raw_signature": "var countOfPairs = function(nums) {", "container": null, "callable": "countOfPairs", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,251
find-the-count-of-monotonic-pairs-ii
Hard
You are given an array of positive integers nums of length n. We call a pair of non-negative integer arrays (arr1, arr2) monotonic if: - The lengths of both arrays are n. - arr1 is monotonically non-decreasing, in other words, arr1[0] <= arr1[1] <= ... <= arr1[n - 1]. - arr2 is monotonically non-increasing, in other ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 3, 2]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 659632782\n assert candidate(nums = [1, 1, 1, 1, ...
[ "[2,3,2]", "[5,5,5,5]" ]
[]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:27", "tests_total": 82, "tests_dro...
javascript
{ "raw_signature": "var countOfPairs = function(nums) {", "container": null, "callable": "countOfPairs", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,254
find-the-power-of-k-size-subarrays-i
Medium
You are given an array of integers nums of length n and a positive integer k. The power of an array is defined as: - Its maximum element if all of its elements are consecutive and sorted in ascending order. - -1 otherwise. You need to find the power of all subarrays of nums of size k. Return an integer array result...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == [5]\n assert candidate(nums = [2, 2, 2, 2, 2],k = 4) == [-1, -1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11],k = 5) == [-1, -1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5],k = 4) == [-1, -1, ...
[ "[1,2,3,4,3,2,5]\n3", "[2,2,2,2,2]\n4", "[3,2,3,2,3,2]\n2" ]
[ "Can we use a brute force solution with nested loops and HashSet?" ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().resultsArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:32", "tests_total": 127, ...
javascript
{ "raw_signature": "var resultsArray = function(nums, k) {", "container": null, "callable": "resultsArray", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnip...
3,255
find-the-power-of-k-size-subarrays-ii
Medium
You are given an array of integers nums of length n and a positive integer k. The power of an array is defined as: - Its maximum element if all of its elements are consecutive and sorted in ascending order. - -1 otherwise. You need to find the power of all subarrays of nums of size k. Return an integer array result...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 101, 102, 103, 104, 105],k = 2) == [101, 102, 103, 104, 105]\n assert candidate(nums = [2, 2, 2, 2, 2],k = 4) == [-1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, ...
[ "[1,2,3,4,3,2,5]\n3", "[2,2,2,2,2]\n4", "[3,2,3,2,3,2]\n2" ]
[ "Let dp[i] denote the length of the longest subarray ending at index i that has consecutive and sorted elements.", "Use a TreeMap with a sliding window to check if there are k elements in the subarray ending at index i.", "If TreeMap has less than k elements and dp[i] < k, the subarray has power equal to -1.", ...
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().resultsArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:35", "tests_total": 140, ...
javascript
{ "raw_signature": "var resultsArray = function(nums, k) {", "container": null, "callable": "resultsArray", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnip...
3,256
maximum-value-sum-by-placing-three-rooks-i
Hard
You are given a m x n 2D array board representing a chessboard, where board[i][j] represents the value of the cell (i, j). Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other. Return the maximum sum of the cell values on which...
{ "language": "python", "source": "def check(candidate):\n assert candidate(board = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]) == 150\n assert candidate(board = [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]) == -15\n assert candidate(board = [[-3, 1, 1, 1], [-3, 1, -3, 1], [-3, 2, 1, 1]]) == 4\n assert ca...
[ "[[-3,1,1,1],[-3,1,-3,1],[-3,2,1,1]]", "[[1,2,3],[4,5,6],[7,8,9]]", "[[1,1,1],[1,1,1],[1,1,1]]" ]
[ "Store the largest 3 values for each row.", "Select any 3 rows and brute force all combinations." ]
{ "canonical_parameter_names": [ "board" ], "leetcode_dataset_entry_point": "Solution().maximumValueSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:37", "tests_total": 144, "test...
javascript
{ "raw_signature": "var maximumValueSum = function(board) {", "container": null, "callable": "maximumValueSum", "parameters": [ { "name": "board", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,257
maximum-value-sum-by-placing-three-rooks-ii
Hard
You are given a m x n 2D array board representing a chessboard, where board[i][j] represents the value of the cell (i, j). Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other. Return the maximum sum of the cell values on which...
{ "language": "python", "source": "def check(candidate):\n assert candidate(board = [[5, -2, 3, 7], [1, 8, -1, 2], [-4, 4, -3, 6], [3, 7, 5, -9]]) == 20\n assert candidate(board = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 3\n assert candidate(board = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [1...
[ "[[-3,1,1,1],[-3,1,-3,1],[-3,2,1,1]]", "[[1,2,3],[4,5,6],[7,8,9]]", "[[1,1,1],[1,1,1],[1,1,1]]" ]
[ "Save the top 3 largest values in each row.", "Select any row, and select any of the three values stored in it.", "Get the top 4 values from all of the other 3 largest values of the other rows, which do not share the same column as the selected value.", "Brute force the selection of 2 positions from the top 4...
{ "canonical_parameter_names": [ "board" ], "leetcode_dataset_entry_point": "Solution().maximumValueSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:40", "tests_total": 81, "tests...
javascript
{ "raw_signature": "var maximumValueSum = function(board) {", "container": null, "callable": "maximumValueSum", "parameters": [ { "name": "board", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,258
count-substrings-that-satisfy-k-constraint-i
Easy
You are given a binary string s and an integer k. A binary string satisfies the k-constraint if either of the following conditions holds: - The number of 0's in the string is at most k. - The number of 1's in the string is at most k. Return an integer denoting the number of substrings of s that satisfy the k-constra...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"0101010101\",k = 5) == 55\n assert candidate(s = \"11111\",k = 1) == 15\n assert candidate(s = \"00000\",k = 2) == 15\n assert candidate(s = \"101010101010\",k = 4) == 72\n assert candidate(s = \"100100100\",k = 3) == 4...
[ "\"10101\"\n1", "\"1010101\"\n2", "\"11111\"\n1" ]
[ "Using a brute force approach, check each index until a substring satisfying the k-constraint is found, then increment." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().countKConstraintSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:42", "tests_tota...
javascript
{ "raw_signature": "var countKConstraintSubstrings = function(s, k) {", "container": null, "callable": "countKConstraintSubstrings", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": ...
3,259
maximum-energy-boost-from-two-drinks
Medium
You are given two integer arrays energyDrinkA and energyDrinkB of the same length n by a futuristic sports scientist. These arrays represent the energy boosts per hour provided by two different energy drinks, A and B, respectively. You want to maximize your total energy boost by drinking one energy drink per hour. How...
{ "language": "python", "source": "def check(candidate):\n assert candidate(energyDrinkA = [1, 1, 1, 1, 1, 1],energyDrinkB = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(energyDrinkA = [1, 100000, 1],energyDrinkB = [100000, 1, 100000]) == 200001\n assert candidate(energyDrinkA = [4, 1, 1],energyDrinkB = [1,...
[ "[1,3,1]\n[3,1,1]", "[4,1,1]\n[1,1,3]" ]
[ "Can we solve it using dynamic programming?", "Define dpA[i] as the maximum energy boost if we consider only the first i + 1 hours such that in the last hour, we drink the energy drink A.", "Similarly define dpB[i].", "dpA[i] = max(dpA[i - 1], dpB[i - 2]) + energyDrinkA[i]", "Similarly, fill dpB.", "The a...
{ "canonical_parameter_names": [ "energyDrinkA", "energyDrinkB" ], "leetcode_dataset_entry_point": "Solution().maxEnergyBoost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:45", "...
javascript
{ "raw_signature": "var maxEnergyBoost = function(energyDrinkA, energyDrinkB) {", "container": null, "callable": "maxEnergyBoost", "parameters": [ { "name": "energyDrinkA", "type": "number[]" }, { "name": "energyDrinkB", "type": "number[]" } ], "return_type": "number"...
3,260
find-the-largest-palindrome-divisible-by-k
Hard
You are given two positive integers n and k. An integer x is called k-palindromic if: - x is a palindrome. - x is divisible by k. Return the largest integer having n digits (as a string) that is k-palindromic. Note that the integer must not have leading zeros. Example 1: Input: n = 3, k = 5 Output: "595" Explanat...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 1,k = 4) == \"8\"\n assert candidate(n = 6,k = 9) == \"999999\"\n assert candidate(n = 6,k = 7) == \"999999\"\n assert candidate(n = 3,k = 5) == \"595\"\n assert candidate(n = 5,k = 6) == \"89898\"\n assert candidate(n...
[ "3\n5", "1\n4", "5\n6" ]
[ "It must have a solution since we can have all digits equal to k.", "Use string dp, store modulus along with length of number currently formed.", "Is it possible to solve greedily using divisibility rules?" ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().largestPalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:47", "tests_total": 49, ...
javascript
{ "raw_signature": "var largestPalindrome = function(n, k) {", "container": null, "callable": "largestPalindrome", "parameters": [ { "name": "n", "type": "number" }, { "name": "k", "type": "number" } ], "return_type": "string", "signature_source": "leetcode/codeSnip...
3,261
count-substrings-that-satisfy-k-constraint-ii
Hard
You are given a binary string s and an integer k. You are also given a 2D integer array queries, where queries[i] = [l_i, r_i]. A binary string satisfies the k-constraint if either of the following conditions holds: - The number of 0's in the string is at most k. - The number of 1's in the string is at most k. Retu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"010101\",k = 1,queries = [[0, 5], [1, 4], [2, 3]]) == [15, 9, 3]\n assert candidate(s = \"111111\",k = 3,queries = [[0, 5], [1, 4], [2, 3]]) == [21, 10, 3]\n assert candidate(s = \"000000\",k = 3,queries = [[0, 5], [1, 4], [2...
[ "\"0001111\"\n2\n[[0,6]]", "\"010101\"\n1\n[[0,5],[1,4],[2,3]]" ]
[ "Answering online queries is tough. Try to answer them offline since the queries are known beforehand.", "For each index, how do you calculate the left boundary so that the given condition is satisfied?", "Using the precomputed left boundaries and a range data structure, you can now answer the queries optimally...
{ "canonical_parameter_names": [ "s", "k", "queries" ], "leetcode_dataset_entry_point": "Solution().countKConstraintSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:50"...
javascript
{ "raw_signature": "var countKConstraintSubstrings = function(s, k, queries) {", "container": null, "callable": "countKConstraintSubstrings", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "number" }, { "name": "queries", "type":...
3,264
final-array-state-after-k-multiplication-operations-i
Easy
You are given an integer array nums, an integer k, and an integer multiplier. You need to perform k operations on nums. In each operation: - Find the minimum value x in nums. If there are multiple occurrences of the minimum value, select the one that appears first. - Replace the selected minimum value x with x * mult...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [3],k = 1,multiplier = 5) == [15]\n assert candidate(nums = [5, 5, 5, 5],k = 4,multiplier = 2) == [10, 10, 10, 10]\n assert candidate(nums = [10, 9, 8, 7],k = 4,multiplier = 1) == [10, 9, 8, 7]\n assert candidate(nums = [...
[ "[2,1,3,5,6]\n5\n2", "[1,2]\n3\n4" ]
[ "Maintain sorted pairs (nums[index], index) in a priority queue.", "Simulate the operation k times." ]
{ "canonical_parameter_names": [ "nums", "k", "multiplier" ], "leetcode_dataset_entry_point": "Solution().getFinalState", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:52", "te...
javascript
{ "raw_signature": "var getFinalState = function(nums, k, multiplier) {", "container": null, "callable": "getFinalState", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" }, { "name": "multiplier", "type": "number" ...
3,265
count-almost-equal-pairs-i
Medium
You are given an array nums consisting of positive integers. We call two integers x and y in this problem almost equal if both integers can become equal after performing the following operation at most once: - Choose either x or y and swap any two digits within the chosen number. Return the number of indices i and j...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == 0\n assert candidate(nums = [101, 110, 111, 1001, 1100]) == 5\n assert candidate(nums = [12, 21, 13, 31, 14]) == 2\n assert candidate(nums = [12, 21, 13, 31, 23, 32, 45, 5...
[ "[3,12,30,17,21]", "[1,1,1,1,1]", "[123,231]" ]
[ "Since the constraint on the number of elements is small, you can check all pairs in the array.", "For each pair, perform an operation on one of the elements and check if it becomes equal to the other." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:54", "tests_total": 123, "tests_drop...
javascript
{ "raw_signature": "var countPairs = function(nums) {", "container": null, "callable": "countPairs", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,267
count-almost-equal-pairs-ii
Hard
Attention: In this version, the number of operations that can be performed, has been increased to twice. You are given an array nums consisting of positive integers. We call two integers x and y almost equal if both integers can become equal after performing the following operation at most twice: - Choose either x o...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [123, 321, 213, 132]) == 6\n assert candidate(nums = [1111, 2222, 3333, 4444]) == 0\n assert candidate(nums = [12, 21, 13, 31, 23, 32]) == 3\n assert candidate(nums = [111, 222, 333, 444, 555]) == 0\n assert candidate(...
[ "[1023,2310,2130,213]", "[1,10,100]" ]
[ "For each element, find all possible integers we can get by applying the operations.", "Store the frequencies of all the integers in a hashmap." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:59", "tests_total": 132, "tests_drop...
javascript
{ "raw_signature": "var countPairs = function(nums) {", "container": null, "callable": "countPairs", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,270
find-the-key-of-the-numbers
Easy
You are given three positive integers num1, num2, and num3. The key of num1, num2, and num3 is defined as a four-digit number such that: - Initially, if any number has less than four digits, it is padded with leading zeros. - The i^th digit (1 <= i <= 4) of the key is generated by taking the smallest digit among the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(num1 = 9999,num2 = 9999,num3 = 9999) == 9999\n assert candidate(num1 = 1000,num2 = 1000,num3 = 1000) == 1000\n assert candidate(num1 = 12,num2 = 345,num3 = 6789) == 12\n assert candidate(num1 = 5555,num2 = 5555,num3 = 6666) == 5...
[ "1\n10\n1000", "987\n879\n798", "1\n2\n3" ]
[]
{ "canonical_parameter_names": [ "num1", "num2", "num3" ], "leetcode_dataset_entry_point": "Solution().generateKey", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:04", "tests_t...
javascript
{ "raw_signature": "var generateKey = function(num1, num2, num3) {", "container": null, "callable": "generateKey", "parameters": [ { "name": "num1", "type": "number" }, { "name": "num2", "type": "number" }, { "name": "num3", "type": "number" } ], "...
3,271
hash-divided-string
Medium
You are given a string s of length n and an integer k, where n is a multiple of k. Your task is to hash the string s into a new string called result, which has a length of n / k. First, divide s into n / k substrings, each with a length of k. Then, initialize result as an empty string. For each substring in order fro...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aaaa\",k = 2) == \"aa\"\n assert candidate(s = \"mnopqr\",k = 3) == \"nw\"\n assert candidate(s = \"hellohellohellohello\",k = 5) == \"vvvv\"\n assert candidate(s = \"ababababab\",k = 2) == \"bbbbb\"\n assert candidate(...
[ "\"abcd\"\n2", "\"mxz\"\n3" ]
[ "Try to find each substring.", "Use a for loop to find hashedChar of each substring.", "Find the answer using hashedChar of each substring." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().stringHash", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:06", "tests_total": 38, "tests...
javascript
{ "raw_signature": "var stringHash = function(s, k) {", "container": null, "callable": "stringHash", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type...
3,272
find-the-count-of-good-integers
Hard
You are given two positive integers n and k. An integer x is called k-palindromic if: - x is a palindrome. - x is divisible by k. An integer is called good if its digits can be rearranged to form a k-palindromic integer. For example, for k = 2, 2020 can be rearranged to form the k-palindromic integer 2002, whereas 1...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 6,k = 8) == 5221\n assert candidate(n = 10,k = 9) == 4610368\n assert candidate(n = 1,k = 4) == 2\n assert candidate(n = 6,k = 9) == 1248\n assert candidate(n = 9,k = 1) == 41457015\n assert candidate(n = 8,k = 2) == 5...
[ "3\n5", "1\n4", "5\n6" ]
[ "How to generate all K-palindromic strings of length n? Do we need to go through all n digits?", "Use permutations to calculate the number of possible rearrangements." ]
{ "canonical_parameter_names": [ "n", "k" ], "leetcode_dataset_entry_point": "Solution().countGoodIntegers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:08", "tests_total": 56, ...
javascript
{ "raw_signature": "var countGoodIntegers = function(n, k) {", "container": null, "callable": "countGoodIntegers", "parameters": [ { "name": "n", "type": "number" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnip...
3,273
minimum-amount-of-damage-dealt-to-bob
Hard
You are given an integer power and two integer arrays damage and health, both having length n. Bob has n enemies, where enemy i will deal Bob damage[i] points of damage per second while they are alive (i.e. health[i] > 0). Every second, after the enemies deal damage to Bob, he chooses one of the enemies that is still...
{ "language": "python", "source": "def check(candidate):\n assert candidate(power = 2,damage = [1, 1, 1, 1, 1],health = [1, 2, 3, 4, 5]) == 22\n assert candidate(power = 100,damage = [10, 20, 30],health = [100, 100, 100]) == 100\n assert candidate(power = 4,damage = [1, 2, 3, 4],health = [4, 5, 6, 8]) == 3...
[ "4\n[1,2,3,4]\n[4,5,6,8]", "1\n[1,1,1,1]\n[1,2,3,4]", "8\n[40]\n[59]" ]
[ "Can we use sorting here along with a custom comparator?", "For any two enemies i and j with damages damage[i] and damage[j], and time to take each of them down t_i and t_j, when is it better to choose enemy i over enemy j first?" ]
{ "canonical_parameter_names": [ "power", "damage", "health" ], "leetcode_dataset_entry_point": "Solution().minDamage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:11", "test...
javascript
{ "raw_signature": "var minDamage = function(power, damage, health) {", "container": null, "callable": "minDamage", "parameters": [ { "name": "power", "type": "number" }, { "name": "damage", "type": "number[]" }, { "name": "health", "type": "number[]" ...
3,274
check-if-two-chessboard-squares-have-the-same-color
Easy
You are given two strings, coordinate1 and coordinate2, representing the coordinates of a square on an 8 x 8 chessboard. Below is the chessboard for reference. Return true if these two squares have the same color and false otherwise. The coordinate will always represent a valid chessboard square. The coordinate will...
{ "language": "python", "source": "def check(candidate):\n assert candidate(coordinate1 = \"g7\",coordinate2 = \"f8\") == True\n assert candidate(coordinate1 = \"a1\",coordinate2 = \"c3\") == True\n assert candidate(coordinate1 = \"e5\",coordinate2 = \"g7\") == True\n assert candidate(coordinate1 = \"b2...
[ "\"a1\"\n\"c3\"", "\"a1\"\n\"h3\"" ]
[ "The color of the chessboard is black the sum of row coordinates and column coordinates is even. Otherwise, it's white." ]
{ "canonical_parameter_names": [ "coordinate1", "coordinate2" ], "leetcode_dataset_entry_point": "Solution().checkTwoChessboards", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:13", ...
javascript
{ "raw_signature": "var checkTwoChessboards = function(coordinate1, coordinate2) {", "container": null, "callable": "checkTwoChessboards", "parameters": [ { "name": "coordinate1", "type": "string" }, { "name": "coordinate2", "type": "string" } ], "return_type": "boole...
3,275
k-th-nearest-obstacle-queries
Medium
There is an infinite 2D plane. You are given a positive integer k. You are also given a 2D array queries, which contains the following queries: - queries[i] = [x, y]: Build an obstacle at coordinate (x, y) in the plane. It is guaranteed that there is no obstacle at this coordinate when this query is made. After each...
{ "language": "python", "source": "def check(candidate):\n assert candidate(queries = [[5, 5], [4, 4], [3, 3]],k = 1) == [10, 8, 6]\n assert candidate(queries = [[-1000000000, 1000000000], [1000000000, -1000000000]],k = 1) == [2000000000, 2000000000]\n assert candidate(queries = [[-1, 1], [0, 0], [1, -1]],...
[ "[[1,2],[3,4],[2,3],[-3,0]]\n2", "[[5,5],[4,4],[3,3]]\n1" ]
[ "Consider if there are more than k obstacles. Can the k + 1^th obstacle ever be the answer to any query?", "Maintain a max heap of size k, thus heap will contain minimum element at the top in that queue.", "Remove top element and insert new element from input array if current max is larger than this." ]
{ "canonical_parameter_names": [ "queries", "k" ], "leetcode_dataset_entry_point": "Solution().resultsArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:17", "tests_total": 85, ...
javascript
{ "raw_signature": "var resultsArray = function(queries, k) {", "container": null, "callable": "resultsArray", "parameters": [ { "name": "queries", "type": "number[][]" }, { "name": "k", "type": "number" } ], "return_type": "number[]", "signature_source": "leetcode/...
3,276
select-cells-in-grid-with-maximum-score
Hard
You are given a 2D matrix grid consisting of positive integers. You have to select one or more cells from the matrix such that the following conditions are satisfied: - No two selected cells are in the same row of the matrix. - The values in the set of selected cells are unique. Your score will be the sum of the val...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 5\n assert candidate(grid = [[8, 7, 6], [8, 3, 2]]) == 15\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 1]]) == 12\n assert candidate(grid = [[5, 9, 1], [9...
[ "[[1,2,3],[4,3,2],[1,1,1]]", "[[8,7,6],[8,3,2]]" ]
[ "Sort all the cells in the grid by their values and keep track of their original positions.", "Try dynamic programming with the following states: the current cell that we might select and a bitmask representing all the rows from which we have already selected a cell so far." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:19", "tests_total": 97, "tests_dropped...
javascript
{ "raw_signature": "var maxScore = function(grid) {", "container": null, "callable": "maxScore", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,277
maximum-xor-score-subarray-queries
Hard
You are given an array nums of n integers, and a 2D integer array queries of size q, where queries[i] = [l_i, r_i]. For each query, you must find the maximum XOR score of any subarray of nums[l_i..r_i]. The XOR score of an array a is found by repeatedly applying the following operations on a so that only one element ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 7, 3, 2, 8, 5, 1],queries = [[0, 3], [1, 5], [2, 4], [2, 6], [5, 6]]) == [7, 14, 11, 14, 5]\n assert candidate(nums = [2, 8, 4, 32, 16, 1],queries = [[0, 2], [1, 4], [0, 5]]) == [12, 60, 60]\n assert candidate(nums = [10...
[ "[2,8,4,32,16,1]\n[[0,2],[1,4],[0,5]]", "[0,7,3,2,8,5,1]\n[[0,3],[1,5],[2,4],[2,6],[5,6]]" ]
[ "Precompute the XOR score of every subarray.", "Try to find a relationship between XOR score of nums[i..j], nums[i..j + 1], nums[i..j + 2], …. Do you notice any pattern?", "If dp[i][j] is the XOR score of subarray nums[i..j], dp[i][j] = dp[i - 1][j] XOR dp[i - 1][j + 1]." ]
{ "canonical_parameter_names": [ "nums", "queries" ], "leetcode_dataset_entry_point": "Solution().maximumSubarrayXor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:22", "tests_tot...
javascript
{ "raw_signature": "var maximumSubarrayXor = function(nums, queries) {", "container": null, "callable": "maximumSubarrayXor", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "queries", "type": "number[][]" } ], "return_type": "number[]", "signature...
3,280
convert-date-to-binary
Easy
You are given a string date representing a Gregorian calendar date in the yyyy-mm-dd format. date can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in year-month-day format. Return the binary represe...
{ "language": "python", "source": "def check(candidate):\n assert candidate(date = \"1950-06-30\") == \"11110011110-110-11110\"\n assert candidate(date = \"1912-04-20\") == \"11101111000-100-10100\"\n assert candidate(date = \"2080-02-29\") == \"100000100000-10-11101\"\n assert candidate(date = \"2023-1...
[ "\"2080-02-29\"", "\"1900-01-01\"" ]
[]
{ "canonical_parameter_names": [ "date" ], "leetcode_dataset_entry_point": "Solution().convertDateToBinary", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:27", "tests_total": 87, "te...
javascript
{ "raw_signature": "var convertDateToBinary = function(date) {", "container": null, "callable": "convertDateToBinary", "parameters": [ { "name": "date", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
3,281
maximize-score-of-numbers-in-ranges
Medium
You are given an array of integers start and an integer d, representing n intervals [start[i], start[i] + d]. You are asked to choose n integers where the i^th integer must belong to the i^th interval. The score of the chosen integers is defined as the minimum absolute difference between any two integers that have bee...
{ "language": "python", "source": "def check(candidate):\n assert candidate(start = [5, 10, 15, 20, 25],d = 4) == 6\n assert candidate(start = [1, 10, 20, 30],d = 9) == 12\n assert candidate(start = [10, 20, 30, 40, 50],d = 15) == 13\n assert candidate(start = [100, 200, 300, 400, 500],d = 50) == 112\n ...
[ "[6,0,3]\n2", "[2,6,13,13]\n5" ]
[ "Can we use binary search here?", "Suppose that the answer is x. We can find a valid configuration of integers by sorting start, the first integer should be start[0], then each subsequent integer should be the smallest one in [start[i], start[i] + d] that is greater than last_chosen_value + x.", "Binary search ...
{ "canonical_parameter_names": [ "start", "d" ], "leetcode_dataset_entry_point": "Solution().maxPossibleScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:30", "tests_total": 10...
javascript
{ "raw_signature": "var maxPossibleScore = function(start, d) {", "container": null, "callable": "maxPossibleScore", "parameters": [ { "name": "start", "type": "number[]" }, { "name": "d", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/...
3,282
reach-end-of-array-with-max-score
Medium
You are given an integer array nums of length n. Your goal is to start at index 0 and reach index n - 1. You can only jump to indices greater than your current index. The score for a jump from index i to index j is calculated as (j - i) * nums[i]. Return the maximum possible total score by the time you reach the las...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 3, 5, 6, 7, 8]) == 23\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 90\n assert candidate(nums = [2, 4, 6, 8, 10]) == 20\n assert candidate(nums = [4, 3, 1, 3, 2]) == 16\n assert candidate(nums = [1...
[ "[1,3,1,5]", "[4,3,1,3,2]" ]
[ "It can be proven that from each index i, the optimal solution is to jump to the nearest index j > i such that nums[j] > nums[i]." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findMaximumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:33", "tests_total": 99, "tests...
javascript
{ "raw_signature": "var findMaximumScore = function(nums) {", "container": null, "callable": "findMaximumScore", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }