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,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...
php
{ "raw_signature": "function supersequences($words) {", "container": "Solution", "callable": "supersequences", "parameters": [ { "name": "words", "type": "String[]" } ], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
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...
php
{ "raw_signature": "function findValidPair($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...
php
{ "raw_signature": "function maxFreeTime($eventTime, $k, $startTime, $endTime) {", "container": "Solution", "callable": "maxFreeTime", "parameters": [ { "name": "eventTime", "type": "Integer" }, { "name": "k", "type": "Integer" }, { "name": "startTime", "t...
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...
php
{ "raw_signature": "function maxFreeTime($eventTime, $startTime, $endTime) {", "container": "Solution", "callable": "maxFreeTime", "parameters": [ { "name": "eventTime", "type": "Integer" }, { "name": "startTime", "type": "Integer[]" }, { "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, "...
php
{ "raw_signature": "function minCostGoodCaption($caption) {", "container": "Solution", "callable": "minCostGoodCaption", "parameters": [ { "name": "caption", "type": "String" } ], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnipp...
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...
php
{ "raw_signature": "function maxDifference($s) {", "container": "Solution", "callable": "maxDifference", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "Integer", "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...
php
{ "raw_signature": "function maxDistance($s, $k) {", "container": "Solution", "callable": "maxDistance", "parameters": [ { "name": "s", "type": "String" }, { "name": "k", "type": "Integer" } ], "return_type": "Integer", "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...
php
{ "raw_signature": "function minimumIncrements($nums, $target) {", "container": "Solution", "callable": "minimumIncrements", "parameters": [ { "name": "nums", "type": "Integer[]" }, { "name": "target", "type": "Integer[]" } ], "return_type": "Integer", "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...
php
{ "raw_signature": "function maxDifference($s, $k) {", "container": "Solution", "callable": "maxDifference", "parameters": [ { "name": "s", "type": "String" }, { "name": "k", "type": "Integer" } ], "return_type": "Integer", "signature_source": "leetcode/codeSnippets...
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...
php
{ "raw_signature": "function sortMatrix($grid) {", "container": "Solution", "callable": "sortMatrix", "parameters": [ { "name": "grid", "type": "Integer[][]" } ], "return_type": "Integer[][]", "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...
php
{ "raw_signature": "function assignElements($groups, $elements) {", "container": "Solution", "callable": "assignElements", "parameters": [ { "name": "groups", "type": "Integer[]" }, { "name": "elements", "type": "Integer[]" } ], "return_type": "Integer[]", "signatur...
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...
php
{ "raw_signature": "function countSubstrings($s) {", "container": "Solution", "callable": "countSubstrings", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "Integer", "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...
php
{ "raw_signature": "function maxScore($points, $m) {", "container": "Solution", "callable": "maxScore", "parameters": [ { "name": "points", "type": "Integer[]" }, { "name": "m", "type": "Integer" } ], "return_type": "Integer", "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...
php
{ "raw_signature": "function sumOfGoodNumbers($nums, $k) {", "container": "Solution", "callable": "sumOfGoodNumbers", "parameters": [ { "name": "nums", "type": "Integer[]" }, { "name": "k", "type": "Integer" } ], "return_type": "Integer", "signature_source": "leetco...
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...
php
{ "raw_signature": "function separateSquares($squares) {", "container": "Solution", "callable": "separateSquares", "parameters": [ { "name": "squares", "type": "Integer[][]" } ], "return_type": "Float", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
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...
php
{ "raw_signature": "function separateSquares($squares) {", "container": "Solution", "callable": "separateSquares", "parameters": [ { "name": "squares", "type": "Integer[][]" } ], "return_type": "Float", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippet...
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...
php
{ "raw_signature": "function shortestMatchingSubstring($s, $p) {", "container": "Solution", "callable": "shortestMatchingSubstring", "parameters": [ { "name": "s", "type": "String" }, { "name": "p", "type": "String" } ], "return_type": "Integer", "signature_source":...
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...
php
{ "raw_signature": "function hasSpecialSubstring($s, $k) {", "container": "Solution", "callable": "hasSpecialSubstring", "parameters": [ { "name": "s", "type": "String" }, { "name": "k", "type": "Integer" } ], "return_type": "Boolean", "signature_source": "leetcode/...
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...
php
{ "raw_signature": "function maxWeight($pizzas) {", "container": "Solution", "callable": "maxWeight", "parameters": [ { "name": "pizzas", "type": "Integer[]" } ], "return_type": "Integer", "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, ...
php
{ "raw_signature": "function maxSubstringLength($s, $k) {", "container": "Solution", "callable": "maxSubstringLength", "parameters": [ { "name": "s", "type": "String" }, { "name": "k", "type": "Integer" } ], "return_type": "Boolean", "signature_source": "leetcode/co...
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...
php
{ "raw_signature": "function lenOfVDiagonal($grid) {", "container": "Solution", "callable": "lenOfVDiagonal", "parameters": [ { "name": "grid", "type": "Integer[][]" } ], "return_type": "Integer", "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...
php
{ "raw_signature": "function hasSameDigits($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":...
php
{ "raw_signature": "function maxSum($grid, $limits, $k) {", "container": "Solution", "callable": "maxSum", "parameters": [ { "name": "grid", "type": "Integer[][]" }, { "name": "limits", "type": "Integer[]" }, { "name": "k", "type": "Integer" } ], "...
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...
php
{ "raw_signature": "function hasSameDigits($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...
php
{ "raw_signature": "function maxDistance($side, $points, $k) {", "container": "Solution", "callable": "maxDistance", "parameters": [ { "name": "side", "type": "Integer" }, { "name": "points", "type": "Integer[][]" }, { "name": "k", "type": "Integer" } ...
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_...
php
{ "raw_signature": "function transformArray($nums) {", "container": "Solution", "callable": "transformArray", "parameters": [ { "name": "nums", "type": "Integer[]" } ], "return_type": "Integer[]", "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":...
php
{ "raw_signature": "function countArrays($original, $bounds) {", "container": "Solution", "callable": "countArrays", "parameters": [ { "name": "original", "type": "Integer[]" }, { "name": "bounds", "type": "Integer[][]" } ], "return_type": "Integer", "signature_sour...
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...
php
{ "raw_signature": "function minCost($nums) {", "container": "Solution", "callable": "minCost", "parameters": [ { "name": "nums", "type": "Integer[]" } ], "return_type": "Integer", "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...
php
{ "raw_signature": "function permute($n, $k) {", "container": "Solution", "callable": "permute", "parameters": [ { "name": "n", "type": "Integer" }, { "name": "k", "type": "Integer" } ], "return_type": "Integer[]", "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, ...
php
{ "raw_signature": "function largestInteger($nums, $k) {", "container": "Solution", "callable": "largestInteger", "parameters": [ { "name": "nums", "type": "Integer[]" }, { "name": "k", "type": "Integer" } ], "return_type": "Integer", "signature_source": "leetcode/c...
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...
php
{ "raw_signature": "function longestPalindromicSubsequence($s, $k) {", "container": "Solution", "callable": "longestPalindromicSubsequence", "parameters": [ { "name": "s", "type": "String" }, { "name": "k", "type": "Integer" } ], "return_type": "Integer", "signature...
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,...
php
{ "raw_signature": "function maxSum($nums, $k, $m) {", "container": "Solution", "callable": "maxSum", "parameters": [ { "name": "nums", "type": "Integer[]" }, { "name": "k", "type": "Integer" }, { "name": "m", "type": "Integer" } ], "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...
php
{ "raw_signature": "function generateString($str1, $str2) {", "container": "Solution", "callable": "generateString", "parameters": [ { "name": "str1", "type": "String" }, { "name": "str2", "type": "String" } ], "return_type": "String", "signature_source": "leetcode/...
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_...
php
{ "raw_signature": "function numOfUnplacedFruits($fruits, $baskets) {", "container": "Solution", "callable": "numOfUnplacedFruits", "parameters": [ { "name": "fruits", "type": "Integer[]" }, { "name": "baskets", "type": "Integer[]" } ], "return_type": "Integer", "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...
php
{ "raw_signature": "function findMaxSum($nums1, $nums2, $k) {", "container": "Solution", "callable": "findMaxSum", "parameters": [ { "name": "nums1", "type": "Integer[]" }, { "name": "nums2", "type": "Integer[]" }, { "name": "k", "type": "Integer" } ...
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_...
php
{ "raw_signature": "function numOfUnplacedFruits($fruits, $baskets) {", "container": "Solution", "callable": "numOfUnplacedFruits", "parameters": [ { "name": "fruits", "type": "Integer[]" }, { "name": "baskets", "type": "Integer[]" } ], "return_type": "Integer", "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...
php
{ "raw_signature": "function maxSubarrays($n, $conflictingPairs) {", "container": "Solution", "callable": "maxSubarrays", "parameters": [ { "name": "n", "type": "Integer" }, { "name": "conflictingPairs", "type": "Integer[][]" } ], "return_type": "Integer", "signatur...
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_...
php
{ "raw_signature": "function totalNumbers($digits) {", "container": "Solution", "callable": "totalNumbers", "parameters": [ { "name": "digits", "type": "Integer[]" } ], "return_type": "Integer", "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":...
php
{ "raw_signature": "function longestCommonPrefix($words, $k) {", "container": "Solution", "callable": "longestCommonPrefix", "parameters": [ { "name": "words", "type": "String[]" }, { "name": "k", "type": "Integer" } ], "return_type": "Integer[]", "signature_source"...
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"...
php
{ "raw_signature": "function maxSum($nums) {", "container": "Solution", "callable": "maxSum", "parameters": [ { "name": "nums", "type": "Integer[]" } ], "return_type": "Integer", "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...
php
{ "raw_signature": "function solveQueries($nums, $queries) {", "container": "Solution", "callable": "solveQueries", "parameters": [ { "name": "nums", "type": "Integer[]" }, { "name": "queries", "type": "Integer[]" } ], "return_type": "Integer[]", "signature_source":...
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...
php
{ "raw_signature": "function minZeroArray($nums, $queries) {", "container": "Solution", "callable": "minZeroArray", "parameters": [ { "name": "nums", "type": "Integer[]" }, { "name": "queries", "type": "Integer[][]" } ], "return_type": "Integer", "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, ...
php
{ "raw_signature": "function beautifulNumbers($l, $r) {", "container": "Solution", "callable": "beautifulNumbers", "parameters": [ { "name": "l", "type": "Integer" }, { "name": "r", "type": "Integer" } ], "return_type": "Integer", "signature_source": "leetcode/codeS...
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_...
php
{ "raw_signature": "function maxContainers($n, $w, $maxWeight) {", "container": "Solution", "callable": "maxContainers", "parameters": [ { "name": "n", "type": "Integer" }, { "name": "w", "type": "Integer" }, { "name": "maxWeight", "type": "Integer" } ...
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...
php
{ "raw_signature": "function numberOfComponents($properties, $k) {", "container": "Solution", "callable": "numberOfComponents", "parameters": [ { "name": "properties", "type": "Integer[][]" }, { "name": "k", "type": "Integer" } ], "return_type": "Integer", "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, "...
php
{ "raw_signature": "function minTime($skill, $mana) {", "container": "Solution", "callable": "minTime", "parameters": [ { "name": "skill", "type": "Integer[]" }, { "name": "mana", "type": "Integer[]" } ], "return_type": "Integer", "signature_source": "leetcode/codeS...
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...
php
{ "raw_signature": "function minOperations($queries) {", "container": "Solution", "callable": "minOperations", "parameters": [ { "name": "queries", "type": "Integer[][]" } ], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"...
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...
php
{ "raw_signature": "function reverseDegree($s) {", "container": "Solution", "callable": "reverseDegree", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "Integer", "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, ...
php
{ "raw_signature": "function maxActiveSectionsAfterTrade($s) {", "container": "Solution", "callable": "maxActiveSectionsAfterTrade", "parameters": [ { "name": "s", "type": "String" } ], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
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...
php
{ "raw_signature": "function minimumCost($nums, $cost, $k) {", "container": "Solution", "callable": "minimumCost", "parameters": [ { "name": "nums", "type": "Integer[]" }, { "name": "cost", "type": "Integer[]" }, { "name": "k", "type": "Integer" } ],...
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...
php
{ "raw_signature": "function maxActiveSectionsAfterTrade($s, $queries) {", "container": "Solution", "callable": "maxActiveSectionsAfterTrade", "parameters": [ { "name": "s", "type": "String" }, { "name": "queries", "type": "Integer[][]" } ], "return_type": "Integer[]"...
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...
php
{ "raw_signature": "function minCosts($cost) {", "container": "Solution", "callable": "minCosts", "parameters": [ { "name": "cost", "type": "Integer[]" } ], "return_type": "Integer[]", "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, ...
php
{ "raw_signature": "function longestPalindrome($s, $t) {", "container": "Solution", "callable": "longestPalindrome", "parameters": [ { "name": "s", "type": "String" }, { "name": "t", "type": "String" } ], "return_type": "Integer", "signature_source": "leetcode/codeS...
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, ...
php
{ "raw_signature": "function longestPalindrome($s, $t) {", "container": "Solution", "callable": "longestPalindrome", "parameters": [ { "name": "s", "type": "String" }, { "name": "t", "type": "String" } ], "return_type": "Integer", "signature_source": "leetcode/codeS...
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...
php
{ "raw_signature": "function minOperations($nums, $x, $k) {", "container": "Solution", "callable": "minOperations", "parameters": [ { "name": "nums", "type": "Integer[]" }, { "name": "x", "type": "Integer" }, { "name": "k", "type": "Integer" } ], "...
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...
python
{ "raw_signature": "def shortestDistanceAfterQueries(self, n: int, queries: List[List[int]]) -> List[int]:", "container": "Solution", "callable": "shortestDistanceAfterQueries", "parameters": [ { "name": "n", "type": "int" }, { "name": "queries", "type": "List[List[int]]" ...
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...
python
{ "raw_signature": "def shortestDistanceAfterQueries(self, n: int, queries: List[List[int]]) -> List[int]:", "container": "Solution", "callable": "shortestDistanceAfterQueries", "parameters": [ { "name": "n", "type": "int" }, { "name": "queries", "type": "List[List[int]]" ...
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...
python
{ "raw_signature": "def finalPositionOfSnake(self, n: int, commands: List[str]) -> int:", "container": "Solution", "callable": "finalPositionOfSnake", "parameters": [ { "name": "n", "type": "int" }, { "name": "commands", "type": "List[str]" } ], "return_type": "int", ...
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...
python
{ "raw_signature": "def countOfPairs(self, nums: List[int]) -> int:", "container": "Solution", "callable": "countOfPairs", "parameters": [ { "name": "nums", "type": "List[int]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
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...
python
{ "raw_signature": "def countOfPairs(self, nums: List[int]) -> int:", "container": "Solution", "callable": "countOfPairs", "parameters": [ { "name": "nums", "type": "List[int]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
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, ...
python
{ "raw_signature": "def resultsArray(self, nums: List[int], k: int) -> List[int]:", "container": "Solution", "callable": "resultsArray", "parameters": [ { "name": "nums", "type": "List[int]" }, { "name": "k", "type": "int" } ], "return_type": "List[int]", "signature...
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, ...
python
{ "raw_signature": "def resultsArray(self, nums: List[int], k: int) -> List[int]:", "container": "Solution", "callable": "resultsArray", "parameters": [ { "name": "nums", "type": "List[int]" }, { "name": "k", "type": "int" } ], "return_type": "List[int]", "signature...
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...
python
{ "raw_signature": "def maximumValueSum(self, board: List[List[int]]) -> int:", "container": "Solution", "callable": "maximumValueSum", "parameters": [ { "name": "board", "type": "List[List[int]]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": ...
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...
python
{ "raw_signature": "def maximumValueSum(self, board: List[List[int]]) -> int:", "container": "Solution", "callable": "maximumValueSum", "parameters": [ { "name": "board", "type": "List[List[int]]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": ...
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...
python
{ "raw_signature": "def countKConstraintSubstrings(self, s: str, k: int) -> int:", "container": "Solution", "callable": "countKConstraintSubstrings", "parameters": [ { "name": "s", "type": "str" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_s...
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", "...
python
{ "raw_signature": "def maxEnergyBoost(self, energyDrinkA: List[int], energyDrinkB: List[int]) -> int:", "container": "Solution", "callable": "maxEnergyBoost", "parameters": [ { "name": "energyDrinkA", "type": "List[int]" }, { "name": "energyDrinkB", "type": "List[int]" }...
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, ...
python
{ "raw_signature": "def largestPalindrome(self, n: int, k: int) -> str:", "container": "Solution", "callable": "largestPalindrome", "parameters": [ { "name": "n", "type": "int" }, { "name": "k", "type": "int" } ], "return_type": "str", "signature_source": "leetcode/...
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"...
python
{ "raw_signature": "def countKConstraintSubstrings(self, s: str, k: int, queries: List[List[int]]) -> List[int]:", "container": "Solution", "callable": "countKConstraintSubstrings", "parameters": [ { "name": "s", "type": "str" }, { "name": "k", "type": "int" }, { ...
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...
python
{ "raw_signature": "def getFinalState(self, nums: List[int], k: int, multiplier: int) -> List[int]:", "container": "Solution", "callable": "getFinalState", "parameters": [ { "name": "nums", "type": "List[int]" }, { "name": "k", "type": "int" }, { "name": "multip...
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...
python
{ "raw_signature": "def countPairs(self, nums: List[int]) -> int:", "container": "Solution", "callable": "countPairs", "parameters": [ { "name": "nums", "type": "List[int]" } ], "return_type": "int", "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...
python
{ "raw_signature": "def countPairs(self, nums: List[int]) -> int:", "container": "Solution", "callable": "countPairs", "parameters": [ { "name": "nums", "type": "List[int]" } ], "return_type": "int", "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...
python
{ "raw_signature": "def generateKey(self, num1: int, num2: int, num3: int) -> int:", "container": "Solution", "callable": "generateKey", "parameters": [ { "name": "num1", "type": "int" }, { "name": "num2", "type": "int" }, { "name": "num3", "type": "int" ...
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...
python
{ "raw_signature": "def stringHash(self, s: str, k: int) -> str:", "container": "Solution", "callable": "stringHash", "parameters": [ { "name": "s", "type": "str" }, { "name": "k", "type": "int" } ], "return_type": "str", "signature_source": "leetcode/codeSnippets",...
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, ...
python
{ "raw_signature": "def countGoodIntegers(self, n: int, k: int) -> int:", "container": "Solution", "callable": "countGoodIntegers", "parameters": [ { "name": "n", "type": "int" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/...
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...
python
{ "raw_signature": "def minDamage(self, power: int, damage: List[int], health: List[int]) -> int:", "container": "Solution", "callable": "minDamage", "parameters": [ { "name": "power", "type": "int" }, { "name": "damage", "type": "List[int]" }, { "name": "health...
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", ...
python
{ "raw_signature": "def checkTwoChessboards(self, coordinate1: str, coordinate2: str) -> bool:", "container": "Solution", "callable": "checkTwoChessboards", "parameters": [ { "name": "coordinate1", "type": "str" }, { "name": "coordinate2", "type": "str" } ], "return_t...
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, ...
python
{ "raw_signature": "def resultsArray(self, queries: List[List[int]], k: int) -> List[int]:", "container": "Solution", "callable": "resultsArray", "parameters": [ { "name": "queries", "type": "List[List[int]]" }, { "name": "k", "type": "int" } ], "return_type": "List[i...
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...
python
{ "raw_signature": "def maxScore(self, grid: List[List[int]]) -> int:", "container": "Solution", "callable": "maxScore", "parameters": [ { "name": "grid", "type": "List[List[int]]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
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...
python
{ "raw_signature": "def maximumSubarrayXor(self, nums: List[int], queries: List[List[int]]) -> List[int]:", "container": "Solution", "callable": "maximumSubarrayXor", "parameters": [ { "name": "nums", "type": "List[int]" }, { "name": "queries", "type": "List[List[int]]" }...
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...
python
{ "raw_signature": "def convertDateToBinary(self, date: str) -> str:", "container": "Solution", "callable": "convertDateToBinary", "parameters": [ { "name": "date", "type": "str" } ], "return_type": "str", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
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...
python
{ "raw_signature": "def maxPossibleScore(self, start: List[int], d: int) -> int:", "container": "Solution", "callable": "maxPossibleScore", "parameters": [ { "name": "start", "type": "List[int]" }, { "name": "d", "type": "int" } ], "return_type": "int", "signature_s...
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...
python
{ "raw_signature": "def findMaximumScore(self, nums: List[int]) -> int:", "container": "Solution", "callable": "findMaximumScore", "parameters": [ { "name": "nums", "type": "List[int]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
3,285
find-indices-of-stable-mountains
Easy
There are n mountains in a row, and each mountain has a height. You are given an integer array height where height[i] represents the height of mountain i, and an integer threshold. A mountain is called stable if the mountain just before it (if it exists) has a height strictly greater than threshold. Note that mountain...
{ "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 ...
[ "[1,2,3,4,5]\n2", "[10,1,10,1,10]\n3", "[10,1,10,1,10]\n10" ]
[]
{ "canonical_parameter_names": [ "height", "threshold" ], "leetcode_dataset_entry_point": "Solution().stableMountains", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:40", "tests_to...
python
{ "raw_signature": "def stableMountains(self, height: List[int], threshold: int) -> List[int]:", "container": "Solution", "callable": "stableMountains", "parameters": [ { "name": "height", "type": "List[int]" }, { "name": "threshold", "type": "int" } ], "return_type":...
3,286
find-a-safe-walk-through-a-grid
Medium
You are given an m x n binary matrix grid and an integer health. You start on the upper-left corner (0, 0) and would like to get to the lower-right corner (m - 1, n - 1). You can move up, down, left, or right from one cell to another adjacent cell as long as your health remains positive. Cells (i, j) with grid[i][j]...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 1, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 1, 0]],health = 1) == True\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]],health = 1) == True\n assert candidate(grid = [[1, 1, 1], [1, 0, 1], [1, 1, 1]],health = 5) ...
[ "[[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]]\n1", "[[0,1,1,0,0,0],[1,0,1,0,0,0],[0,1,1,1,0,1],[0,0,1,0,1,0]]\n3", "[[1,1,1],[1,0,1],[1,1,1]]\n5" ]
[ "Use 01 BFS." ]
{ "canonical_parameter_names": [ "grid", "health" ], "leetcode_dataset_entry_point": "Solution().findSafeWalk", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:42", "tests_total": 81...
python
{ "raw_signature": "def findSafeWalk(self, grid: List[List[int]], health: int) -> bool:", "container": "Solution", "callable": "findSafeWalk", "parameters": [ { "name": "grid", "type": "List[List[int]]" }, { "name": "health", "type": "int" } ], "return_type": "bool", ...
3,287
find-the-maximum-sequence-value-of-array
Hard
You are given an integer array nums and a positive integer k. The value of a sequence seq of size 2 * x is defined as: - (seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 * x - 1]). Return the maximum value of any subsequence of nums having size 2 * k. Example 1: Input: nums = [2,6,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 7, 9, 11],k = 3) == 8\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 0\n assert candidate(nums = [31, 15, 7, 3, 1],k = 2) == 28\n assert candidate(nums = [26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16...
[ "[2,6,7]\n1", "[4,2,5,6,7]\n2" ]
[ "Find all the possible OR till each i with k elements backward and forward." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().maxValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:44", "tests_total": 65, "test...
python
{ "raw_signature": "def maxValue(self, nums: List[int], k: int) -> int:", "container": "Solution", "callable": "maxValue", "parameters": [ { "name": "nums", "type": "List[int]" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "leetcode/...
3,288
length-of-the-longest-increasing-path
Hard
You are given a 2D array of integers coordinates of length n and an integer k, where 0 <= k < n. coordinates[i] = [x_i, y_i] indicates the point (x_i, y_i) in a 2D plane. An increasing path of length m is defined as a list of points (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_m, y_m) such that: - x_i < x_{i + 1} and...
{ "language": "python", "source": "def check(candidate):\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]],k = 4) == 7\n assert candidate(coordinates = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5]],k = 4) == 1\n assert candidate(coordinates = [[10, 9], [9, 8], [8, 7], [7...
[ "[[3,1],[2,2],[4,1],[0,0],[5,3]]\n1", "[[2,1],[7,0],[5,6]]\n2" ]
[ "Only keep coordinates with both x and y being strictly less than coordinates[k].", "Sort them by x’s, in the case of equal, the y values should be decreasing.", "Calculate LIS only using y values.", "Do the same for coordinates with both x and y being strictly larger than coordinates[k]." ]
{ "canonical_parameter_names": [ "coordinates", "k" ], "leetcode_dataset_entry_point": "Solution().maxPathLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:47", "tests_total":...
python
{ "raw_signature": "def maxPathLength(self, coordinates: List[List[int]], k: int) -> int:", "container": "Solution", "callable": "maxPathLength", "parameters": [ { "name": "coordinates", "type": "List[List[int]]" }, { "name": "k", "type": "int" } ], "return_type": "in...
3,289
the-two-sneaky-numbers-of-digitville
Easy
In the town of Digitville, there was a list of numbers called nums containing integers from 0 to n - 1. Each number was supposed to appear exactly once in the list, however, two mischievous numbers sneaked in an additional time, making the list longer than usual. As the town detective, your task is to find these two s...
{ "language": "python", "source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return ...
[ "[0,1,1,0]", "[0,3,2,1,3,2]", "[7,1,5,4,3,4,6,0,9,5,8,2]" ]
[ "To solve the problem without the extra space, we need to think about how many times each number occurs in relation to the index." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().getSneakyNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:50", "tests_total": 74, "tests...
python
{ "raw_signature": "def getSneakyNumbers(self, nums: List[int]) -> List[int]:", "container": "Solution", "callable": "getSneakyNumbers", "parameters": [ { "name": "nums", "type": "List[int]" } ], "return_type": "List[int]", "signature_source": "leetcode/codeSnippets", "type_source": ...
3,290
maximum-multiplication-score
Medium
You are given an integer array a of size 4 and another integer array b of size at least 4. You need to choose 4 indices i_0, i_1, i_2, and i_3 from the array b such that i_0 < i_1 < i_2 < i_3. Your score will be equal to the value a[0] * b[i_0] + a[1] * b[i_1] + a[2] * b[i_2] + a[3] * b[i_3]. Return the maximum score...
{ "language": "python", "source": "def check(candidate):\n assert candidate(a = [0, 0, 0, 0],b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(a = [1, 2, 3, 4],b = [10, 20, 30, 40, 50, 60, 70, 80]) == 700\n assert candidate(a = [10, 20, 30, 40],b = [1, 2, 3, 4]) == 300\n assert candidate(a = ...
[ "[3,2,5,6]\n[2,-6,4,-5,-3,2,-7]", "[-1,4,5,-2]\n[-5,-1,-3,-2,-4]" ]
[ "Try using dynamic programming.", "Consider a dp with the following states: The current position in the array b, and the number of indices considered." ]
{ "canonical_parameter_names": [ "a", "b" ], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:52", "tests_total": 104, "tests_...
python
{ "raw_signature": "def maxScore(self, a: List[int], b: List[int]) -> int:", "container": "Solution", "callable": "maxScore", "parameters": [ { "name": "a", "type": "List[int]" }, { "name": "b", "type": "List[int]" } ], "return_type": "int", "signature_source": "lee...
3,291
minimum-number-of-valid-strings-to-form-target-i
Medium
You are given an array of strings words and a string target. A string x is called valid if x is a prefix of any string in words. Return the minimum number of valid strings that can be concatenated to form target. If it is not possible to form target, return -1. Example 1: Input: words = ["abc","aaaaa","bcdef"], tar...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['abc'],target = \"abcabc\") == 2\n assert candidate(words = ['ab', 'ba'],target = \"abab\") == 2\n assert candidate(words = ['a', 'b', 'c', 'd'],target = \"abcdabcdabcd\") == 12\n assert candidate(words = ['abcde', 'fgh...
[ "[\"abc\",\"aaaaa\",\"bcdef\"]\n\"aabcdabc\"", "[\"abababab\",\"ab\"]\n\"ababaababa\"", "[\"abcdef\"]\n\"xyz\"" ]
[ "Let dp[i] be the minimum cost to form the prefix of length i of target.", "If target[(i + 1)..j] matches any prefix, update the range dp[(i + 1)..j] to minimum between original value and dp[i] + 1.", "Use a Trie to check prefix matching." ]
{ "canonical_parameter_names": [ "words", "target" ], "leetcode_dataset_entry_point": "Solution().minValidStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:55", "tests_total"...
python
{ "raw_signature": "def minValidStrings(self, words: List[str], target: str) -> int:", "container": "Solution", "callable": "minValidStrings", "parameters": [ { "name": "words", "type": "List[str]" }, { "name": "target", "type": "str" } ], "return_type": "int", "sig...
3,292
minimum-number-of-valid-strings-to-form-target-ii
Hard
You are given an array of strings words and a string target. A string x is called valid if x is a prefix of any string in words. Return the minimum number of valid strings that can be concatenated to form target. If it is not possible to form target, return -1. Example 1: Input: words = ["abc","aaaaa","bcdef"], tar...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['abc'],target = \"abcabc\") == 2\n assert candidate(words = ['a'],target = \"a\") == 1\n assert candidate(words = ['a', 'aa', 'aaa'],target = \"aaaaaaaa\") == 3\n assert candidate(words = ['xyz'],target = \"xyz\") == 1\...
[ "[\"abc\",\"aaaaa\",\"bcdef\"]\n\"aabcdabc\"", "[\"abababab\",\"ab\"]\n\"ababaababa\"", "[\"abcdef\"]\n\"xyz\"" ]
[ "Let dp[i] be the minimum cost to form the prefix of length i of target.", "Use Rabin-Karp to hash every prefix and store it in a HashSet.", "Use Binary search to find the longest substring starting at index i (target[i..j]) that has a hash present in the HashSet.", "Inverse Modulo precomputation can optimise...
{ "canonical_parameter_names": [ "words", "target" ], "leetcode_dataset_entry_point": "Solution().minValidStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:19:57", "tests_total"...
python
{ "raw_signature": "def minValidStrings(self, words: List[str], target: str) -> int:", "container": "Solution", "callable": "minValidStrings", "parameters": [ { "name": "words", "type": "List[str]" }, { "name": "target", "type": "str" } ], "return_type": "int", "sig...
3,295
report-spam-message
Medium
You are given an array of strings message and an array of strings bannedWords. An array of words is considered spam if there are at least two words in it that exactly match any word in bannedWords. Return true if the array message is spam, and false otherwise. Example 1: Input: message = ["hello","world","leetcode"...
{ "language": "python", "source": "def check(candidate):\n assert candidate(message = ['spam', 'egg', 'ham'],bannedWords = ['spam', 'bacon', 'egg']) == True\n assert candidate(message = ['spam', 'eggs', 'spam'],bannedWords = ['spam']) == True\n assert candidate(message = ['spam', 'spam', 'spam'],bannedWord...
[ "[\"hello\",\"world\",\"leetcode\"]\n[\"world\",\"hello\"]", "[\"hello\",\"programming\",\"fun\"]\n[\"world\",\"programming\",\"leetcode\"]" ]
[ "Use hash set." ]
{ "canonical_parameter_names": [ "message", "bannedWords" ], "leetcode_dataset_entry_point": "Solution().reportSpam", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:20:00", "tests_tota...
python
{ "raw_signature": "def reportSpam(self, message: List[str], bannedWords: List[str]) -> bool:", "container": "Solution", "callable": "reportSpam", "parameters": [ { "name": "message", "type": "List[str]" }, { "name": "bannedWords", "type": "List[str]" } ], "return_typ...
3,296
minimum-number-of-seconds-to-make-mountain-height-zero
Medium
You are given an integer mountainHeight denoting the height of a mountain. You are also given an integer array workerTimes representing the work time of workers in seconds. Each worker may reduce the mountain's height by any non-negative integer amount. If worker i reduces the height by x, then: - reducing the first...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mountainHeight = 15,workerTimes = [5, 5, 5]) == 75\n assert candidate(mountainHeight = 15,workerTimes = [1, 2, 3]) == 30\n assert candidate(mountainHeight = 15,workerTimes = [1, 2, 3, 4, 5]) == 18\n assert candidate(mountainHeig...
[ "4\n[2,1,1]", "10\n[3,2,2,4]", "5\n[1]" ]
[ "Can we use binary search to solve this problem?", "Do a binary search on the number of seconds to check if it's enough to reduce the mountain height to 0 or less with all workers working simultaneously." ]
{ "canonical_parameter_names": [ "mountainHeight", "workerTimes" ], "leetcode_dataset_entry_point": "Solution().minNumberOfSeconds", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:20:02"...
python
{ "raw_signature": "def minNumberOfSeconds(self, mountainHeight: int, workerTimes: List[int]) -> int:", "container": "Solution", "callable": "minNumberOfSeconds", "parameters": [ { "name": "mountainHeight", "type": "int" }, { "name": "workerTimes", "type": "List[int]" } ...
3,297
count-substrings-that-can-be-rearranged-to-contain-a-string-i
Medium
You are given two strings word1 and word2. A string x is called valid if x can be rearranged to have word2 as a prefix. Return the total number of valid substrings of word1. Example 1: Input: word1 = "bcca", word2 = "abc" Output: 1 Explanation: The only valid substring is "bcca" which can be rearranged to "abcc" ha...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word1 = \"banana\",word2 = \"ban\") == 4\n assert candidate(word1 = \"abc\",word2 = \"abcd\") == 0\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == 1\n assert candidate(word1 =...
[ "\"bcca\"\n\"abc\"", "\"abcabc\"\n\"abc\"", "\"abcabc\"\n\"aaabc\"" ]
[ "Store the frequency of each character for all prefixes.", "Use Binary Search." ]
{ "canonical_parameter_names": [ "word1", "word2" ], "leetcode_dataset_entry_point": "Solution().validSubstringCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:20:04", "tests_tot...
python
{ "raw_signature": "def validSubstringCount(self, word1: str, word2: str) -> int:", "container": "Solution", "callable": "validSubstringCount", "parameters": [ { "name": "word1", "type": "str" }, { "name": "word2", "type": "str" } ], "return_type": "int", "signature...
3,298
count-substrings-that-can-be-rearranged-to-contain-a-string-ii
Hard
You are given two strings word1 and word2. A string x is called valid if x can be rearranged to have word2 as a prefix. Return the total number of valid substrings of word1. Note that the memory limits in this problem are smaller than usual, so you must implement a solution with a linear runtime complexity. Example...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word1 = \"bcca\",word2 = \"abc\") == 1\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == 1\n assert candidate(word1 = \"aabbcc\",word2 = \"abc\") == 4\n assert candidate(word1 =...
[ "\"bcca\"\n\"abc\"", "\"abcabc\"\n\"abc\"", "\"abcabc\"\n\"aaabc\"" ]
[ "Use sliding window along with two-pointer here.", "Use constant space to store the frequency of characters." ]
{ "canonical_parameter_names": [ "word1", "word2" ], "leetcode_dataset_entry_point": "Solution().validSubstringCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:20:07", "tests_tot...
python
{ "raw_signature": "def validSubstringCount(self, word1: str, word2: str) -> int:", "container": "Solution", "callable": "validSubstringCount", "parameters": [ { "name": "word1", "type": "str" }, { "name": "word2", "type": "str" } ], "return_type": "int", "signature...
3,300
minimum-element-after-replacement-with-digit-sum
Easy
You are given an integer array nums. You replace each element in nums with the sum of its digits. Return the minimum element in nums after all replacements. Example 1: Input: nums = [10,12,13,14] Output: 1 Explanation: nums becomes [1, 3, 4, 5] after all replacements, with minimum element 1. Example 2: Input: num...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [9999, 1001, 1111]) == 2\n assert candidate(nums = [111, 222, 333]) == 3\n assert candidate(nums = [1234, 4321, 2134, 3412]) == 10\n assert candidate(nums = [10, 12, 13, 14]) == 1\n assert candidate(nums = [100, 200, 3...
[ "[10,12,13,14]", "[1,2,3,4]", "[999,19,199]" ]
[ "Convert to string and calculate the sum for each element." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().minElement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:20:12", "tests_total": 109, "tests_drop...
python
{ "raw_signature": "def minElement(self, nums: List[int]) -> int:", "container": "Solution", "callable": "minElement", "parameters": [ { "name": "nums", "type": "List[int]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
3,301
maximize-the-total-height-of-unique-towers
Medium
You are given an array maximumHeight, where maximumHeight[i] denotes the maximum height the i^th tower can be assigned. Your task is to assign a height to each tower so that: 1. The height of the i^th tower is a positive integer and does not exceed maximumHeight[i]. 2. No two towers have the same height. Return the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(maximumHeight = [2, 3, 4, 3]) == 10\n assert candidate(maximumHeight = [5, 5, 5, 5, 5]) == 15\n assert candidate(maximumHeight = [1, 2, 3, 4, 5]) == 15\n assert candidate(maximumHeight = [1000000000, 999999999, 999999998, 999999...
[ "[2,3,4,3]", "[15,10]", "[2,2,1]" ]
[ "Sort the array maximumHeight in descending order.", "After sorting, it can be seen that the maximum height that we can assign to the i^th element is min(maximumHeight[i], maximumHeight[i - 1] - 1)." ]
{ "canonical_parameter_names": [ "maximumHeight" ], "leetcode_dataset_entry_point": "Solution().maximumTotalSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:20:14", "tests_total": 73, ...
python
{ "raw_signature": "def maximumTotalSum(self, maximumHeight: List[int]) -> int:", "container": "Solution", "callable": "maximumTotalSum", "parameters": [ { "name": "maximumHeight", "type": "List[int]" } ], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_sourc...
3,302
find-the-lexicographically-smallest-valid-sequence
Medium
You are given two strings word1 and word2. A string x is called almost equal to y if you can change at most one character in x to make it identical to y. A sequence of indices seq is called valid if: - The indices are sorted in ascending order. - Concatenating the characters at these indices in word1 in the same ord...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word1 = \"hello\",word2 = \"heo\") == [0, 1, 2]\n assert candidate(word1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word2 = \"abc\") == []\n assert candidate(word1 = \"abcdefg\",word2 = \"bdf\") == [0, 3, 5]\n...
[ "\"vbcca\"\n\"abc\"", "\"bacdc\"\n\"abc\"", "\"aaaaaa\"\n\"aaabc\"", "\"abc\"\n\"ab\"" ]
[ "Let dp[i] be the longest suffix of word2 that exists as a subsequence of suffix of the substring of word1 starting at index i.", "If dp[i + 1] < m and word1[i] == word2[m - dp[i + 1] - 1],dp[i] = dp[i + 1] + 1. Otherwise, dp[i] = dp[i + 1].", "For each index i, greedily select characters using the dp array to ...
{ "canonical_parameter_names": [ "word1", "word2" ], "leetcode_dataset_entry_point": "Solution().validSequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:20:17", "tests_total": 1...
python
{ "raw_signature": "def validSequence(self, word1: str, word2: str) -> List[int]:", "container": "Solution", "callable": "validSequence", "parameters": [ { "name": "word1", "type": "str" }, { "name": "word2", "type": "str" } ], "return_type": "List[int]", "signature...
3,303
find-the-occurrence-of-first-almost-equal-substring
Hard
You are given two strings s and pattern. A string x is called almost equal to y if you can change at most one character in x to make it identical to y. Return the smallest starting index of a substring in s that is almost equal to pattern. If no such index exists, return -1. A substring is a contiguous non-empty seq...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"mississippi\",pattern = \"missiippi\") == -1\n assert candidate(s = \"abcd\",pattern = \"dba\") == -1\n assert candidate(s = \"abcdefg\",pattern = \"bcdffg\") == 1\n assert candidate(s = \"mississippi\",pattern = \"misosip...
[ "\"abcdefg\"\n\"bcdffg\"", "\"ababbababa\"\n\"bacaba\"", "\"abcd\"\n\"dba\"", "\"dde\"\n\"d\"" ]
[ "Let dp1[i] represent the maximum length of a substring of s starting at index i that is also a prefix of pattern.", "Let dp2[i] represent the maximum length of a substring of s ending at index i that is also a suffix of pattern.", "Consider a window of size pattern.length. If dp1[i] + i == i + pattern.length -...
{ "canonical_parameter_names": [ "s", "pattern" ], "leetcode_dataset_entry_point": "Solution().minStartingIndex", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:20:20", "tests_total": ...
python
{ "raw_signature": "def minStartingIndex(self, s: str, pattern: str) -> int:", "container": "Solution", "callable": "minStartingIndex", "parameters": [ { "name": "s", "type": "str" }, { "name": "pattern", "type": "str" } ], "return_type": "int", "signature_source": ...
3,304
find-the-k-th-character-in-string-game-i
Easy
Alice and Bob are playing a game. Initially, Alice has a string word = "a". You are given a positive integer k. Now Bob will ask Alice to perform the following operation forever: - Generate a new string by changing each character in word to its next character in the English alphabet, and append it to the original wo...
{ "language": "python", "source": "def check(candidate):\n assert candidate(k = 27) == \"d\"\n assert candidate(k = 1) == \"a\"\n assert candidate(k = 7) == \"c\"\n assert candidate(k = 500) == \"h\"\n assert candidate(k = 26) == \"d\"\n assert candidate(k = 5) == \"b\"\n assert candidate(k = 1...
[ "5", "10" ]
[ "The constraints are small. Construct the string by simulating the operations." ]
{ "canonical_parameter_names": [ "k" ], "leetcode_dataset_entry_point": "Solution().kthCharacter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:20:22", "tests_total": 37, "tests_droppe...
python
{ "raw_signature": "def kthCharacter(self, k: int) -> str:", "container": "Solution", "callable": "kthCharacter", "parameters": [ { "name": "k", "type": "int" } ], "return_type": "str", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
3,305
count-of-substrings-containing-every-vowel-and-k-consonants-i
Medium
You are given a string word and a non-negative integer k. Return the total number of substrings of word that contain every vowel ('a', 'e', 'i', 'o', and 'u') at least once and exactly k consonants. Example 1: Input: word = "aeioqq", k = 1 Output: 0 Explanation: There is no substring with every vowel. Example 2: I...
{ "language": "python", "source": "def check(candidate):\n assert candidate(word = \"uuuaaeiooouueiiaaoou\",k = 3) == 0\n assert candidate(word = \"aeiouaeiouaeiouaeiou\",k = 0) == 136\n assert candidate(word = \"aeiouzzzzz\",k = 5) == 1\n assert candidate(word = \"aeioqq\",k = 1) == 0\n assert candi...
[ "\"aeioqq\"\n1", "\"aeiou\"\n0", "\"ieaouqqieaouqq\"\n1" ]
[ "Use a HashMap and check all the substrings." ]
{ "canonical_parameter_names": [ "word", "k" ], "leetcode_dataset_entry_point": "Solution().countOfSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:20:24", "tests_total": 67...
python
{ "raw_signature": "def countOfSubstrings(self, word: str, k: int) -> int:", "container": "Solution", "callable": "countOfSubstrings", "parameters": [ { "name": "word", "type": "str" }, { "name": "k", "type": "int" } ], "return_type": "int", "signature_source": "lee...