question_id
int64
1
3.24k
task_id
stringlengths
3
77
difficulty
stringclasses
3 values
problem_description
stringlengths
193
3.69k
canonical_tests
dict
public_tests
listlengths
1
5
hints
listlengths
0
8
metadata
dict
language
stringclasses
9 values
interface
dict
1,130
minimum-cost-tree-from-leaf-values
Medium
Given an array arr of positive integers, consider all binary trees such that: - Each node has either 0 or 2 children; - The values of arr correspond to the values of each leaf in an in-order traversal of the tree. - The value of each non-leaf node is equal to the product of the largest leaf value in its left and right...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4]) == 20\n assert candidate(arr = [3, 2, 1]) == 8\n assert candidate(arr = [15, 13, 5, 3, 15]) == 500\n assert candidate(arr = [4, 11]) == 44\n assert candidate(arr = [7, 12, 8, 10]) == 284\n assert candid...
[ "[6,2,4]", "[4,11]" ]
[ "Do a DP, where dp(i, j) is the answer for the subarray arr[i]..arr[j].", "For each possible way to partition the subarray i <= k < j, the answer is max(arr[i]..arr[k]) * max(arr[k+1]..arr[j]) + dp(i, k) + dp(k+1, j)." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().mctFromLeafValues", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:12", "tests_total": 108, "test...
typescript
{ "raw_signature": "function mctFromLeafValues(arr: number[]): number {", "container": null, "callable": "mctFromLeafValues", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,131
maximum-of-absolute-value-expression
Medium
Given two arrays of integers with equal lengths, return the maximum value of: |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j| where the maximum is taken over all 0 <= i, j < arr1.length. Example 1: Input: arr1 = [1,2,3,4], arr2 = [-1,4,5,6] Output: 13 Example 2: Input: arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr1 = [1, -2, -5, 0, 10],arr2 = [0, -2, -1, -7, -4]) == 20\n assert candidate(arr1 = [1, 3, 5, 7],arr2 = [2, 4, 6, 8]) == 15\n assert candidate(arr1 = [-1, -2, -3, -4, -5],arr2 = [1, 2, 3, 4, 5]) == 12\n assert candidate(arr1 =...
[ "[1,2,3,4]\n[-1,4,5,6]", "[1,-2,-5,0,10]\n[0,-2,-1,-7,-4]" ]
[ "Use the idea that abs(A) + abs(B) = max(A+B, A-B, -A+B, -A-B)." ]
{ "canonical_parameter_names": [ "arr1", "arr2" ], "leetcode_dataset_entry_point": "Solution().maxAbsValExpr", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:15", "tests_total": 94,...
typescript
{ "raw_signature": "function maxAbsValExpr(arr1: number[], arr2: number[]): number {", "container": null, "callable": "maxAbsValExpr", "parameters": [ { "name": "arr1", "type": "number[]" }, { "name": "arr2", "type": "number[]" } ], "return_type": "number", "signatu...
1,137
n-th-tribonacci-number
Easy
The Tribonacci sequence T_n is defined as follows: T_0 = 0, T_1 = 1, T_2 = 1, and T_{n+3} = T_n + T_{n+1} + T_{n+2} for n >= 0. Given n, return the value of T_n. Example 1: Input: n = 4 Output: 4 Explanation: T_3 = 0 + 1 + 1 = 2 T_4 = 1 + 1 + 2 = 4 Example 2: Input: n = 25 Output: 1389537 Constraints: - 0 <= n ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 0) == 0\n assert candidate(n = 3) == 2\n assert candidate(n = 4) == 4\n assert candidate(n = 37) == 2082876103\n assert candidate(n = 2) == 1\n assert candidate(n = 1) == 1\n assert candidate(n = 25) == 1389537\n ...
[ "4", "25" ]
[ "Make an array F of length 38, and set F[0] = 0, F[1] = F[2] = 1.", "Now write a loop where you set F[n+3] = F[n] + F[n+1] + F[n+2], and return F[n]." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().tribonacci", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:27", "tests_total": 18, "tests_dropped"...
typescript
{ "raw_signature": "function tribonacci(n: number): number {", "container": null, "callable": "tribonacci", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,138
alphabet-board-path
Medium
On an alphabet board, we start at position (0, 0), corresponding to character board[0][0]. Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"], as shown in the diagram below. We may make the following moves: - 'U' moves our position up one row, if the position exists on the board; - 'D' moves our positi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(target = \"azaz\") == \"!DDDDD!UUUUU!DDDDD!\"\n assert candidate(target = \"zm\") == \"DDDDD!UUURR!\"\n assert candidate(target = \"abcde\") == \"!R!R!R!R!\"\n assert candidate(target = \"leet\") == \"RDD!UURRR!!DDD!\"\n asse...
[ "\"leet\"", "\"code\"" ]
[ "Create a hashmap from letter to position on the board.", "Now for each letter, try moving there in steps, where at each step you check if it is inside the boundaries of the board." ]
{ "canonical_parameter_names": [ "target" ], "leetcode_dataset_entry_point": "Solution().alphabetBoardPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:29", "tests_total": 103, "t...
typescript
{ "raw_signature": "function alphabetBoardPath(target: string): string {", "container": null, "callable": "alphabetBoardPath", "parameters": [ { "name": "target", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
1,139
largest-1-bordered-square
Medium
Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn't exist in the grid. Example 1: Input: grid = [[1,1,1],[1,0,1],[1,1,1]] Output: 9 Example 2: Input: grid = [[1,1,0,0]] Output: 1 Constraints: - 1 <= grid.length <= ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1], [1, 0, 0, 1]]) == 1\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 25\n assert candidate(grid = [[1, 0], [0, 1]]...
[ "[[1,1,1],[1,0,1],[1,1,1]]", "[[1,1,0,0]]" ]
[ "For each square, know how many ones are up, left, down, and right of this square. You can find it in O(N^2) using dynamic programming.", "Now for each square ( O(N^3) ), we can evaluate whether that square is 1-bordered in O(1)." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().largest1BorderedSquare", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:32", "tests_total": 64, ...
typescript
{ "raw_signature": "function largest1BorderedSquare(grid: number[][]): number {", "container": null, "callable": "largest1BorderedSquare", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": ...
1,140
stone-game-ii
Medium
Alice and Bob continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to end with the most stones. Alice and Bob take turns, with Alice starting first. On each player's turn, that player can ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(piles = [1, 2, 3, 4, 5, 100]) == 104\n assert candidate(piles = [10]) == 10\n assert candidate(piles = [100, 100, 100, 100]) == 200\n assert candidate(piles = [1, 2, 3]) == 3\n assert candidate(piles = [1, 100, 1, 100, 1, 100...
[ "[2,7,9,4,4]", "[1,2,3,4,5,100]" ]
[ "Use dynamic programming: the states are (i, m) for the answer of piles[i:] and that given m." ]
{ "canonical_parameter_names": [ "piles" ], "leetcode_dataset_entry_point": "Solution().stoneGameII", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:34", "tests_total": 96, "tests_dro...
typescript
{ "raw_signature": "function stoneGameII(piles: number[]): number {", "container": null, "callable": "stoneGameII", "parameters": [ { "name": "piles", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,143
longest-common-subsequence
Medium
Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters....
{ "language": "python", "source": "def check(candidate):\n assert candidate(text1 = \"a\",text2 = \"b\") == 0\n assert candidate(text1 = \"xyz\",text2 = \"zyx\") == 1\n assert candidate(text1 = \"ezupkr\",text2 = \"ubmrapg\") == 2\n assert candidate(text1 = \"abcde\",text2 = \"ace\") == 3\n assert ca...
[ "\"abcde\"\n\"ace\"", "\"abc\"\n\"abc\"", "\"abc\"\n\"def\"" ]
[ "Try dynamic programming. DP[i][j] represents the longest common subsequence of text1[0 ... i] & text2[0 ... j].", "DP[i][j] = DP[i - 1][j - 1] + 1 , if text1[i] == text2[j] DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]) , otherwise" ]
{ "canonical_parameter_names": [ "text1", "text2" ], "leetcode_dataset_entry_point": "Solution().longestCommonSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:36", "test...
typescript
{ "raw_signature": "function longestCommonSubsequence(text1: string, text2: string): number {", "container": null, "callable": "longestCommonSubsequence", "parameters": [ { "name": "text1", "type": "string" }, { "name": "text2", "type": "string" } ], "return_type": "n...
1,144
decrease-elements-to-make-array-zigzag
Medium
Given an array nums of integers, a move consists of choosing any element and decreasing it by 1. An array A is a zigzag array if either: - Every even-indexed element is greater than adjacent elements, ie. A[0] > A[1] < A[2] > A[3] < A[4] > ... - OR, every odd-indexed element is greater than adjacent elements, ie. A[0...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 3, 2, 1]) == 2\n assert candidate(nums = [1, 3, 2, 2, 3, 1]) == 4\n assert candidate(nums = [1, 1, 1]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 8\n assert candidate(nums = [9, 6, 1, 6, 2])...
[ "[1,2,3]", "[9,6,1,6,2]" ]
[ "Do each case (even indexed is greater, odd indexed is greater) separately. In say the even case, you should decrease each even-indexed element until it is lower than its immediate neighbors." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().movesToMakeZigzag", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:38", "tests_total": 148, "tes...
typescript
{ "raw_signature": "function movesToMakeZigzag(nums: number[]): number {", "container": null, "callable": "movesToMakeZigzag", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
1,147
longest-chunked-palindrome-decomposition
Hard
You are given a string text. You should split it to k substrings (subtext_1, subtext_2, ..., subtext_k) such that: - subtext_i is a non-empty string. - The concatenation of all the substrings is equal to text (i.e., subtext_1 + subtext_2 + ... + subtext_k == text). - subtext_i == subtext_{k - i + 1} for all valid valu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(text = \"abcabc\") == 2\n assert candidate(text = \"abcabcabc\") == 3\n assert candidate(text = \"level\") == 5\n assert candidate(text = \"zyxzyxzyx\") == 3\n assert candidate(text = \"madam\") == 5\n assert candidate(tex...
[ "\"ghiabcdefhelloadamhelloabcdefghi\"", "\"merchant\"", "\"antaprezatepzapreanta\"" ]
[ "Using a rolling hash, we can quickly check whether two strings are equal.", "Use that as the basis of a dp." ]
{ "canonical_parameter_names": [ "text" ], "leetcode_dataset_entry_point": "Solution().longestDecomposition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:43", "tests_total": 181, "...
typescript
{ "raw_signature": "function longestDecomposition(text: string): number {", "container": null, "callable": "longestDecomposition", "parameters": [ { "name": "text", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/co...
1,154
day-of-the-year
Easy
Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year. Example 1: Input: date = "2019-01-09" Output: 9 Explanation: Given date is the 9th day of the year in 2019. Example 2: Input: date = "2019-02-10" Output: 41 Constraints: - date.length == 10 - dat...
{ "language": "python", "source": "def check(candidate):\n assert candidate(date = \"2017-03-01\") == 60\n assert candidate(date = \"2019-01-09\") == 9\n assert candidate(date = \"1900-02-28\") == 59\n assert candidate(date = \"2000-03-01\") == 61\n assert candidate(date = \"2018-08-20\") == 232\n ...
[ "\"2019-01-09\"", "\"2019-02-10\"" ]
[ "Have a integer array of how many days there are per month. February gets one extra day if its a leap year. Then, we can manually count the ordinal as day + (number of days in months before this one)." ]
{ "canonical_parameter_names": [ "date" ], "leetcode_dataset_entry_point": "Solution().dayOfYear", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:54", "tests_total": 119, "tests_dropp...
typescript
{ "raw_signature": "function dayOfYear(date: string): number {", "container": null, "callable": "dayOfYear", "parameters": [ { "name": "date", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,155
number-of-dice-rolls-with-target-sum
Medium
You have n dice, and each dice has k faces numbered from 1 to k. Given three integers n, k, and target, return the number of possible ways (out of the k^n total ways) to roll the dice, so the sum of the face-up numbers equals target. Since the answer may be too large, return it modulo 10^9 + 7. Example 1: Input: n =...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 15,k = 10,target = 100) == 794915145\n assert candidate(n = 4,k = 6,target = 12) == 125\n assert candidate(n = 30,k = 30,target = 500) == 222616187\n assert candidate(n = 2,k = 6,target = 7) == 6\n assert candidate(n = 10...
[ "1\n6\n3", "2\n6\n7", "30\n30\n500" ]
[ "Use dynamic programming. The states are how many dice are remaining, and what sum total you have rolled so far." ]
{ "canonical_parameter_names": [ "n", "k", "target" ], "leetcode_dataset_entry_point": "Solution().numRollsToTarget", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:56", "tests_...
typescript
{ "raw_signature": "function numRollsToTarget(n: number, k: number, target: number): number {", "container": null, "callable": "numRollsToTarget", "parameters": [ { "name": "n", "type": "number" }, { "name": "k", "type": "number" }, { "name": "target", "ty...
1,156
swap-for-longest-repeated-character-substring
Medium
You are given a string text. You can swap two of the characters in the text. Return the length of the longest substring with repeated characters. Example 1: Input: text = "ababa" Output: 3 Explanation: We can swap the first 'b' with the last 'a', or the last 'b' with the first 'a'. Then, the longest repeated charact...
{ "language": "python", "source": "def check(candidate):\n assert candidate(text = \"ababababab\") == 3\n assert candidate(text = \"abababababababab\") == 3\n assert candidate(text = \"ababa\") == 3\n assert candidate(text = \"aaaaa\") == 5\n assert candidate(text = \"zzzzzzzzzz\") == 10\n assert ...
[ "\"bbaababbba\"", "\"bbabbbbbaaba\"", "\"abaaaaabbbbbaa\"" ]
[ "There are two cases: a block of characters, or two blocks of characters between one different character. By keeping a run-length encoded version of the string, we can easily check these cases." ]
{ "canonical_parameter_names": [ "text" ], "leetcode_dataset_entry_point": "Solution().maxRepOpt1", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:11:58", "tests_total": 56, "tests_dropp...
typescript
{ "raw_signature": "function maxRepOpt1(text: string): number {", "container": null, "callable": "maxRepOpt1", "parameters": [ { "name": "text", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,160
find-words-that-can-be-formed-by-characters
Easy
You are given an array of strings words and a string chars. A string is good if it can be formed by characters from chars (each character can only be used once for each word in words). Return the sum of lengths of all good strings in words. Example 1: Input: words = ["cat","bt","hat","tree"], chars = "atach" Output...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['abcd', 'ab', 'bc', 'cd'],chars = \"abcd\") == 10\n assert candidate(words = ['cat', 'bt', 'hat', 'tree'],chars = \"atach\") == 6\n assert candidate(words = ['zxcvbnm', 'asdfghjkl', 'qwertyuiop'],chars = \"qwertyuiopasdfgh...
[ "[\"cat\",\"bt\",\"hat\",\"tree\"]\n\"atach\"", "[\"hello\",\"world\",\"leetcode\"]\n\"welldonehoneyr\"" ]
[ "Solve the problem for each string in words independently.", "Now try to think in frequency of letters.", "Count how many times each character occurs in string chars.", "To form a string using characters from chars, the frequency of each character in chars must be greater than or equal the frequency of that c...
{ "canonical_parameter_names": [ "words", "chars" ], "leetcode_dataset_entry_point": "Solution().countCharacters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:00", "tests_total":...
typescript
{ "raw_signature": "function countCharacters(words: string[], chars: string): number {", "container": null, "callable": "countCharacters", "parameters": [ { "name": "words", "type": "string[]" }, { "name": "chars", "type": "string" } ], "return_type": "number", "sig...
1,162
as-far-from-land-as-possible
Medium
Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or water exists in the grid, return -1. The distance used in this problem is the Manhattan distance: th...
{ "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, 0, 1, 0], [0, 0, 0, 0], [1, 0, 1, 0], [0, 0, 0, 0]]) == 2\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 6\n ...
[ "[[1,0,1],[0,0,0],[1,0,1]]", "[[1,0,0],[0,0,0],[0,0,0]]" ]
[ "Can you think of this problem in a backwards way ?", "Imagine expanding outward from each land cell. What kind of search does that ?", "Use BFS starting from all land cells in the same time.", "When do you reach the furthest water cell?" ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().maxDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:05", "tests_total": 62, "tests_drop...
typescript
{ "raw_signature": "function maxDistance(grid: number[][]): number {", "container": null, "callable": "maxDistance", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
1,163
last-substring-in-lexicographical-order
Hard
Given a string s, return the last substring of s in lexicographical order. Example 1: Input: s = "abab" Output: "bab" Explanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lexicographically maximum substring is "bab". Example 2: Input: s = "leetcode" Output: "tcode" Constraints: - 1 <=...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abab\") == \"bab\"\n assert candidate(s = \"mississippi\") == \"ssissippi\"\n assert candidate(s = \"abcdabcdabcd\") == \"dabcdabcd\"\n assert candidate(s = \"banana\") == \"nana\"\n assert candidate(s = \"zyxzy\") == \...
[ "\"abab\"", "\"leetcode\"" ]
[ "Assume that the answer is a sub-string from index i to j. If you add the character at index j+1 you get a better answer.", "The answer is always a suffix of the given string.", "Since the limits are high, we need an efficient data structure.", "Use suffix array." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().lastSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:07", "tests_total": 80, "tests_dropp...
typescript
{ "raw_signature": "function lastSubstring(s: string): string {", "container": null, "callable": "lastSubstring", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,169
invalid-transactions
Medium
A transaction is possibly invalid if: - the amount exceeds $1000, or; - if it occurs within (and including) 60 minutes of another transaction with the same name in a different city. You are given an array of strings transaction where transactions[i] consists of comma-separated values representing the name, time (in m...
{ "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 ...
[ "[\"alice,20,800,mtv\",\"alice,50,100,beijing\"]", "[\"alice,20,800,mtv\",\"alice,50,1200,mtv\"]", "[\"alice,20,800,mtv\",\"bob,50,1200,mtv\"]" ]
[ "Split each string into four arrays.", "For each transaction check if it's invalid, you can do this with just a loop with help of the four arrays generated on step 1.", "At the end you perform O(N ^ 2) operations." ]
{ "canonical_parameter_names": [ "transactions" ], "leetcode_dataset_entry_point": "Solution().invalidTransactions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:16", "tests_total": 7...
typescript
{ "raw_signature": "function invalidTransactions(transactions: string[]): string[] {", "container": null, "callable": "invalidTransactions", "parameters": [ { "name": "transactions", "type": "string[]" } ], "return_type": "string[]", "signature_source": "leetcode/codeSnippets", "type...
1,170
compare-strings-by-frequency-of-the-smallest-character
Medium
Let the function f(s) be the frequency of the lexicographically smallest character in a non-empty string s. For example, if s = "dcce" then f(s) = 2 because the lexicographically smallest character is 'c', which has a frequency of 2. You are given an array of strings words and another array of query strings queries. F...
{ "language": "python", "source": "def check(candidate):\n assert candidate(queries = ['ccc'],words = ['a', 'bb', 'ccc', 'dddd']) == [1]\n assert candidate(queries = ['a', 'b', 'c'],words = ['d', 'e', 'f', 'g']) == [0, 0, 0]\n assert candidate(queries = ['abc', 'def'],words = ['ghi', 'jkl']) == [0, 0]\n ...
[ "[\"cbd\"]\n[\"zaaaz\"]", "[\"bbb\",\"cc\"]\n[\"a\",\"aa\",\"aaa\",\"aaaa\"]" ]
[ "For each string from words calculate the leading count and store it in an array, then sort the integer array.", "For each string from queries calculate the leading count \"p\" and in base of the sorted array calculated on the step 1 do a binary search to count the number of items greater than \"p\"." ]
{ "canonical_parameter_names": [ "queries", "words" ], "leetcode_dataset_entry_point": "Solution().numSmallerByFrequency", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:18", "tests...
typescript
{ "raw_signature": "function numSmallerByFrequency(queries: string[], words: string[]): number[] {", "container": null, "callable": "numSmallerByFrequency", "parameters": [ { "name": "queries", "type": "string[]" }, { "name": "words", "type": "string[]" } ], "return_t...
1,175
prime-arrangements
Easy
Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.) (Recall that an integer is prime if and only if it is greater than 1, and cannot be written as a product of two positive integers both smaller than it.) Since the answer may be large, return the answer modulo 10^9 + 7....
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 30) == 13697484\n assert candidate(n = 99) == 75763854\n assert candidate(n = 75) == 918450925\n assert candidate(n = 20) == 344376809\n assert candidate(n = 2) == 1\n assert candidate(n = 19) == 445364737\n assert ...
[ "5", "100" ]
[ "Solve the problem for prime numbers and composite numbers separately.", "Multiply the number of permutations of prime numbers over prime indices with the number of permutations of composite numbers over composite indices.", "The number of permutations equals the factorial." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().numPrimeArrangements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:23", "tests_total": 27, "test...
typescript
{ "raw_signature": "function numPrimeArrangements(n: number): number {", "container": null, "callable": "numPrimeArrangements", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
1,177
can-make-palindrome-from-substring
Medium
You are given a string s and array queries where queries[i] = [left_i, right_i, k_i]. We may rearrange the substring s[left_i...right_i] for each query and then choose up to k_i of them to replace with any lowercase English letter. If the substring is possible to be a palindrome string after the operations above, the ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcd\",queries = [[0, 2, 1], [1, 3, 1]]) == [True, True]\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",queries = [[0, 25, 12], [0, 25, 13], [0, 25, 14]]) == [False, True, True]\n assert candidate(s = \"zaz\",queries =...
[ "\"abcda\"\n[[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]", "\"lyb\"\n[[0,1,0],[2,2,1]]" ]
[ "Since we can rearrange the substring, all we care about is the frequency of each character in that substring.", "How to find the character frequencies efficiently ?", "As a preprocess, calculate the accumulate frequency of all characters for all prefixes of the string.", "How to check if a substring can be c...
{ "canonical_parameter_names": [ "s", "queries" ], "leetcode_dataset_entry_point": "Solution().canMakePaliQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:27", "tests_total"...
typescript
{ "raw_signature": "function canMakePaliQueries(s: string, queries: number[][]): boolean[] {", "container": null, "callable": "canMakePaliQueries", "parameters": [ { "name": "s", "type": "string" }, { "name": "queries", "type": "number[][]" } ], "return_type": "boolea...
1,178
number-of-valid-words-for-each-puzzle
Hard
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied: - word contains the first letter of puzzle. - For each letter in word, that letter is in puzzle. - For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage", while - invalid w...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['apple', 'pleas', 'please'],puzzles = ['aelwxyz', 'aelpxyz', 'aelpsxy', 'saelpxy', 'xaelpsy']) == [0, 1, 3, 2, 0]\n assert candidate(words = ['aaaa', 'asas', 'able', 'ability', 'actt', 'actor', 'access'],puzzles = ['aboveyz',...
[ "[\"aaaa\",\"asas\",\"able\",\"ability\",\"actt\",\"actor\",\"access\"]\n[\"aboveyz\",\"abrodyz\",\"abslute\",\"absoryz\",\"actresz\",\"gaswxyz\"]", "[\"apple\",\"pleas\",\"please\"]\n[\"aelwxyz\",\"aelpxyz\",\"aelpsxy\",\"saelpxy\",\"xaelpsy\"]" ]
[ "Exploit the fact that the length of the puzzle is only 7.", "Use bit-masks to represent the word and puzzle strings.", "For each puzzle, count the number of words whose bit-mask is a sub-mask of the puzzle's bit-mask." ]
{ "canonical_parameter_names": [ "words", "puzzles" ], "leetcode_dataset_entry_point": "Solution().findNumOfValidWords", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:30", "tests_t...
typescript
{ "raw_signature": "function findNumOfValidWords(words: string[], puzzles: string[]): number[] {", "container": null, "callable": "findNumOfValidWords", "parameters": [ { "name": "words", "type": "string[]" }, { "name": "puzzles", "type": "string[]" } ], "return_type"...
1,184
distance-between-bus-stops
Easy
A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n. The bus goes along both directions i.e. clockwise and counterclockwise. Return the shortest distance between the give...
{ "language": "python", "source": "def check(candidate):\n assert candidate(distance = [7, 10, 1, 12, 11, 14, 5, 0],start = 7,destination = 2) == 17\n assert candidate(distance = [1, 2, 3, 4],start = 0,destination = 2) == 3\n assert candidate(distance = [4, 3, 2],start = 0,destination = 2) == 2\n assert...
[ "[1,2,3,4]\n0\n1", "[1,2,3,4]\n0\n2", "[1,2,3,4]\n0\n3" ]
[ "Find the distance between the two stops if the bus moved in clockwise or counterclockwise directions." ]
{ "canonical_parameter_names": [ "distance", "start", "destination" ], "leetcode_dataset_entry_point": "Solution().distanceBetweenBusStops", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-...
typescript
{ "raw_signature": "function distanceBetweenBusStops(distance: number[], start: number, destination: number): number {", "container": null, "callable": "distanceBetweenBusStops", "parameters": [ { "name": "distance", "type": "number[]" }, { "name": "start", "type": "number" ...
1,185
day-of-the-week
Easy
Given a date, return the corresponding day of the week for that date. The input is given as three integers representing the day, month and year respectively. Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}. Note: January 1, 1971 was a Fr...
{ "language": "python", "source": "def check(candidate):\n assert candidate(day = 31,month = 12,year = 2100) == \"Friday\"\n assert candidate(day = 15,month = 8,year = 1993) == \"Sunday\"\n assert candidate(day = 10,month = 9,year = 2023) == \"Sunday\"\n assert candidate(day = 18,month = 7,year = 1999) ...
[ "31\n8\n2019", "18\n7\n1999", "15\n8\n1993" ]
[ "Sum up the number of days for the years before the given year.", "Handle the case of a leap year.", "Find the number of days for each month of the given year." ]
{ "canonical_parameter_names": [ "day", "month", "year" ], "leetcode_dataset_entry_point": "Solution().dayOfTheWeek", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:44", "tests_...
typescript
{ "raw_signature": "function dayOfTheWeek(day: number, month: number, year: number): string {", "container": null, "callable": "dayOfTheWeek", "parameters": [ { "name": "day", "type": "number" }, { "name": "month", "type": "number" }, { "name": "year", "ty...
1,186
maximum-subarray-sum-with-one-deletion
Medium
Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maximum p...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [-1, 0, -2, 3, 4, -5, 3]) == 10\n assert candidate(arr = [5, -1, 5, -1, 5]) == 14\n assert candidate(arr = [2, 3, -2, 5, -3]) == 10\n assert candidate(arr = [-10000]) == -10000\n assert candidate(arr = [5, -3, -2, 7, 1]...
[ "[1,-2,0,3]", "[1,-2,-2,3]", "[-1,-1,-1,-1]" ]
[ "How to solve this problem if no deletions are allowed ?", "Try deleting each element and find the maximum subarray sum to both sides of that element.", "To do that efficiently, use the idea of Kadane's algorithm." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().maximumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:46", "tests_total": 139, "tests_dropp...
typescript
{ "raw_signature": "function maximumSum(arr: number[]): number {", "container": null, "callable": "maximumSum", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,187
make-array-strictly-increasing
Hard
Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing. In one operation, you can choose two indices 0 <= i < arr1.length and 0 <= j < arr2.length and do the assignment arr1[i] = arr2[j]. If there is no way to make arr1 strictly increasi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr1 = [1, 3, 5, 7],arr2 = [2, 4, 6, 8]) == 0\n assert candidate(arr1 = [1, 5, 3, 6, 7],arr2 = [1, 6, 3, 3]) == -1\n assert candidate(arr1 = [1, 2, 3, 4, 5],arr2 = [6, 7, 8, 9]) == 0\n assert candidate(arr1 = [1, 5, 3, 6, 7],arr...
[ "[1,5,3,6,7]\n[1,3,2,4]", "[1,5,3,6,7]\n[4,3,1]", "[1,5,3,6,7]\n[1,6,3,3]" ]
[ "Use dynamic programming.", "The state would be the index in arr1 and the index of the previous element in arr2 after sorting it and removing duplicates." ]
{ "canonical_parameter_names": [ "arr1", "arr2" ], "leetcode_dataset_entry_point": "Solution().makeArrayIncreasing", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:48", "tests_total...
typescript
{ "raw_signature": "function makeArrayIncreasing(arr1: number[], arr2: number[]): number {", "container": null, "callable": "makeArrayIncreasing", "parameters": [ { "name": "arr1", "type": "number[]" }, { "name": "arr2", "type": "number[]" } ], "return_type": "number"...
1,189
maximum-number-of-balloons
Easy
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible. You can use each character in text at most once. Return the maximum number of instances that can be formed. Example 1: Input: text = "nlaebolko" Output: 1 Example 2: Input: text = "loonbalxballp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(text = \"bbaalllooonn\") == 1\n assert candidate(text = \"ppooaallbboonn\") == 1\n assert candidate(text = \"leetcode\") == 0\n assert candidate(text = \"balloonballoonballoonballoonballoon\") == 5\n assert candidate(text = \...
[ "\"nlaebolko\"", "\"loonbalxballpoon\"", "\"leetcode\"" ]
[ "Count the frequency of letters in the given string.", "Find the letter than can make the minimum number of instances of the word \"balloon\"." ]
{ "canonical_parameter_names": [ "text" ], "leetcode_dataset_entry_point": "Solution().maxNumberOfBalloons", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:50", "tests_total": 117, "t...
typescript
{ "raw_signature": "function maxNumberOfBalloons(text: string): number {", "container": null, "callable": "maxNumberOfBalloons", "parameters": [ { "name": "text", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
1,190
reverse-substrings-between-each-pair-of-parentheses
Medium
You are given a string s that consists of lower case English letters and brackets. Reverse the strings in each pair of matching parentheses, starting from the innermost one. Your result should not contain any brackets. Example 1: Input: s = "(abcd)" Output: "dcba" Example 2: Input: s = "(u(love)i)" Output: "ilove...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"(a(b(c)d)e)\") == \"ebcda\"\n assert candidate(s = \"(a(b)c(d(e)f)g)\") == \"gdefcba\"\n assert candidate(s = \"(abc)(def)\") == \"cbafed\"\n assert candidate(s = \"(a(b)c(d)e(f)g)\") == \"gfedcba\"\n assert candidate(s...
[ "\"(abcd)\"", "\"(u(love)i)\"", "\"(ed(et(oc))el)\"" ]
[ "Find all brackets in the string.", "Does the order of the reverse matter ?", "The order does not matter." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().reverseParentheses", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:53", "tests_total": 93, "tests_...
typescript
{ "raw_signature": "function reverseParentheses(s: string): string {", "container": null, "callable": "reverseParentheses", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets...
1,191
k-concatenation-maximum-sum
Medium
Given an integer array arr and an integer k, modify the array by repeating it k times. For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2]. Return the maximum sub-array sum in the modified array. Note that the length of the sub-array can be 0 and its sum in that case is 0. As th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1],k = 1) == 1\n assert candidate(arr = [-1, 0, 1],k = 3) == 1\n assert candidate(arr = [1, -2, 1],k = 5) == 2\n assert candidate(arr = [3, -2, 2, -3],k = 3) == 3\n assert candidate(arr = [10000, -10000],k = 2) == 1000...
[ "[1,2]\n3", "[1,-2,1]\n5", "[-1,-2]\n7" ]
[ "How to solve the problem for k=1 ?", "Use Kadane's algorithm for k=1.", "What are the possible cases for the answer ?", "The answer is the maximum between, the answer for k=1, the sum of the whole array multiplied by k, or the maximum suffix sum plus the maximum prefix sum plus (k-2) multiplied by the whole ...
{ "canonical_parameter_names": [ "arr", "k" ], "leetcode_dataset_entry_point": "Solution().kConcatenationMaxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:55", "tests_total": ...
typescript
{ "raw_signature": "function kConcatenationMaxSum(arr: number[], k: number): number {", "container": null, "callable": "kConcatenationMaxSum", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signa...
1,192
critical-connections-in-a-network
Hard
There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [a_i, b_i] represents a connection between servers a_i and b_i. Any server can reach other servers directly or indirectly through the network. A critical connection is a connection...
{ "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 ...
[ "4\n[[0,1],[1,2],[2,0],[1,3]]", "2\n[[0,1]]" ]
[ "Use Tarjan's algorithm." ]
{ "canonical_parameter_names": [ "n", "connections" ], "leetcode_dataset_entry_point": "Solution().criticalConnections", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:12:57", "tests_t...
typescript
{ "raw_signature": "function criticalConnections(n: number, connections: number[][]): number[][] {", "container": null, "callable": "criticalConnections", "parameters": [ { "name": "n", "type": "number" }, { "name": "connections", "type": "number[][]" } ], "return_typ...
1,200
minimum-absolute-difference
Easy
Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements. Return a list of pairs in ascending order(with respect to pairs), each pair [a, b] follows - a, b are from arr - a < b - b - a equals to the minimum absolute difference of any two elements in ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [5, 1, 4, 1, 3]) == [[1, 1]]\n assert candidate(arr = [4, 2, 1, 3]) == [[1, 2], [2, 3], [3, 4]]\n assert candidate(arr = [3, 8, -10, 23, 19, -4, -14, 27]) == [[-14, -10], [19, 23], [23, 27]]\n assert candidate(arr = [10000...
[ "[4,2,1,3]", "[1,3,6,10,15]", "[3,8,-10,23,19,-4,-14,27]" ]
[ "Find the minimum absolute difference between two elements in the array.", "The minimum absolute difference must be a difference between two consecutive elements in the sorted array." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().minimumAbsDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:08", "tests_total": 101, "t...
typescript
{ "raw_signature": "function minimumAbsDifference(arr: number[]): number[][] {", "container": null, "callable": "minimumAbsDifference", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "number[][]", "signature_source": "leetcode/codeSnippets", "type_source": "l...
1,201
ugly-number-iii
Medium
An ugly number is a positive integer that is divisible by a, b, or c. Given four integers n, a, b, and c, return the n^th ugly number. Example 1: Input: n = 3, a = 2, b = 3, c = 5 Output: 4 Explanation: The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10... The 3^rd is 4. Example 2: Input: n = 4, a = 2, b = 3, c = 4 Outp...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 4,a = 2,b = 3,c = 4) == 6\n assert candidate(n = 1,a = 2,b = 3,c = 5) == 2\n assert candidate(n = 3,a = 2,b = 3,c = 5) == 4\n assert candidate(n = 10,a = 2,b = 7,c = 13) == 16\n assert candidate(n = 10,a = 5,b = 7,c = 15)...
[ "3\n2\n3\n5", "4\n2\n3\n4", "5\n2\n11\n13" ]
[ "Write a function f(k) to determine how many ugly numbers smaller than k. As f(k) is non-decreasing, try binary search.", "Find all ugly numbers in [1, LCM(a, b, c)] (LCM is Least Common Multiple). Use inclusion-exclusion principle to expand the result." ]
{ "canonical_parameter_names": [ "n", "a", "b", "c" ], "leetcode_dataset_entry_point": "Solution().nthUglyNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:10", "tests...
typescript
{ "raw_signature": "function nthUglyNumber(n: number, a: number, b: number, c: number): number {", "container": null, "callable": "nthUglyNumber", "parameters": [ { "name": "n", "type": "number" }, { "name": "a", "type": "number" }, { "name": "b", "type": ...
1,202
smallest-string-with-swaps
Medium
You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string. You can swap the characters at any pair of indices in the given pairs any number of times. Return the lexicographically smallest string that s can be changed to after us...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"acbd\",pairs = [[0, 3], [1, 2]]) == \"abcd\"\n assert candidate(s = \"cba\",pairs = [[0, 1], [1, 2]]) == \"abc\"\n assert candidate(s = \"aabbcc\",pairs = [[0, 1], [2, 3], [4, 5]]) == \"aabbcc\"\n assert candidate(s = \"zy...
[ "\"dcab\"\n[[0,3],[1,2]]", "\"dcab\"\n[[0,3],[1,2],[0,2]]", "\"cba\"\n[[0,1],[1,2]]" ]
[ "Think of it as a graph problem.", "Consider the pairs as connected nodes in the graph, what can you do with a connected component of indices ?", "We can sort each connected component alone to get the lexicographically minimum string." ]
{ "canonical_parameter_names": [ "s", "pairs" ], "leetcode_dataset_entry_point": "Solution().smallestStringWithSwaps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:13", "tests_tot...
typescript
{ "raw_signature": "function smallestStringWithSwaps(s: string, pairs: number[][]): string {", "container": null, "callable": "smallestStringWithSwaps", "parameters": [ { "name": "s", "type": "string" }, { "name": "pairs", "type": "number[][]" } ], "return_type": "str...
1,203
sort-items-by-groups-respecting-dependencies
Hard
There are n items each belonging to zero or one of m groups where group[i] is the group that the i-th item belongs to and it's equal to -1 if the i-th item belongs to no group. The items and the groups are zero indexed. A group can have no item belonging to it. Return a sorted list of the items such that: - The items...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 8,m = 2,group = [-1, -1, 1, 0, 0, 1, 0, -1],beforeItems = [[], [6], [5], [6], [3, 6], [], [], []]) == [6, 3, 4, 5, 2, 0, 7, 1]\n assert candidate(n = 5,m = 3,group = [0, 0, 1, 1, -1],beforeItems = [[], [2], [3], [], [1, 3]]) == [3...
[ "8\n2\n[-1,-1,1,0,0,1,0,-1]\n[[],[6],[5],[6],[3,6],[],[],[]]", "8\n2\n[-1,-1,1,0,0,1,0,-1]\n[[],[6],[5],[6],[3],[],[4],[]]" ]
[ "Think of it as a graph problem.", "We need to find a topological order on the dependency graph.", "Build two graphs, one for the groups and another for the items." ]
{ "canonical_parameter_names": [ "n", "m", "group", "beforeItems" ], "leetcode_dataset_entry_point": "Solution().sortItems", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:15"...
typescript
{ "raw_signature": "function sortItems(n: number, m: number, group: number[], beforeItems: number[][]): number[] {", "container": null, "callable": "sortItems", "parameters": [ { "name": "n", "type": "number" }, { "name": "m", "type": "number" }, { "name": "grou...
1,207
unique-number-of-occurrences
Easy
Given an array of integers arr, return true if the number of occurrences of each value in the array is unique or false otherwise. Example 1: Input: arr = [1,2,2,1,1,3] Output: true Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences. Example 2: Input: a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [-3, 0, 1, -3, 1, 1, 1, -3, 10, 0]) == True\n assert candidate(arr = [1, 2]) == False\n assert candidate(arr = [5]) == True\n assert candidate(arr = [5, 5, 5, 5, 5]) == True\n assert candidate(arr = [1, 1, 2, 2, 3, 3]) ...
[ "[1,2,2,1,1,3]", "[1,2]", "[-3,0,1,-3,1,1,1,-3,10,0]" ]
[ "Find the number of occurrences of each element in the array using a hash map.", "Iterate through the hash map and check if there is a repeated value." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().uniqueOccurrences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:17", "tests_total": 107, "test...
typescript
{ "raw_signature": "function uniqueOccurrences(arr: number[]): boolean {", "container": null, "callable": "uniqueOccurrences", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
1,208
get-equal-substrings-within-budget
Medium
You are given two strings s and t of the same length and an integer maxCost. You want to change s to t. Changing the i^th character of s to i^th character of t costs |s[i] - t[i]| (i.e., the absolute difference between the ASCII values of the characters). Return the maximum length of a substring of s that can be chan...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"a\",t = \"b\",maxCost = 1) == 1\n assert candidate(s = \"a\",t = \"a\",maxCost = 0) == 1\n assert candidate(s = \"krrgw\",t = \"grkwa\",maxCost = 3) == 1\n assert candidate(s = \"abcd\",t = \"abce\",maxCost = 1) == 4\n ...
[ "\"abcd\"\n\"bcdf\"\n3", "\"abcd\"\n\"cdef\"\n3", "\"abcd\"\n\"acde\"\n0" ]
[ "Calculate the differences between s[i] and t[i].", "Use a sliding window to track the longest valid substring." ]
{ "canonical_parameter_names": [ "s", "t", "maxCost" ], "leetcode_dataset_entry_point": "Solution().equalSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:19", "tests_t...
typescript
{ "raw_signature": "function equalSubstring(s: string, t: string, maxCost: number): number {", "container": null, "callable": "equalSubstring", "parameters": [ { "name": "s", "type": "string" }, { "name": "t", "type": "string" }, { "name": "maxCost", "type...
1,209
remove-all-adjacent-duplicates-in-string-ii
Medium
You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together. We repeatedly make k duplicate removals on s until we no longer can. Return the final strin...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"a\",k = 2) == \"a\"\n assert candidate(s = \"mississippi\",k = 2) == \"m\"\n assert candidate(s = \"deeedbbcccbdaa\",k = 3) == \"aa\"\n assert candidate(s = \"abcd\",k = 2) == \"abcd\"\n assert candidate(s = \"abcde\",k...
[ "\"abcd\"\n2", "\"deeedbbcccbdaa\"\n3", "\"pbbcggttciiippooaais\"\n2" ]
[ "Use a stack to store the characters, when there are k same characters, delete them.", "To make it more efficient, use a pair to store the value and the count of each character." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().removeDuplicates", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:21", "tests_total": 107, ...
typescript
{ "raw_signature": "function removeDuplicates(s: string, k: number): string {", "container": null, "callable": "removeDuplicates", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "string", "signature_source": "l...
1,210
minimum-moves-to-reach-target-with-rotations
Hard
In an n*n grid, there is a snake that spans 2 cells and starts moving from the top left corner at (0, 0) and (0, 1). The grid has empty cells represented by zeros and blocked cells represented by ones. The snake wants to reach the lower right corner at (n-1, n-2) and (n-1, n-1). In one move the snake can: - Move one ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0, 0, 0, 1], [1, 1, 0, 0, 1, 0], [0, 0, 0, 0, 1, 1], [0, 0, 1, 0, 1, 0], [0, 1, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0]]) == 11\n assert candidate(grid = [[0, 0, 1], [0, 1, 0], [0, 0, 0]]) == -1\n assert candidate(grid = [[0...
[ "[[0,0,0,0,0,1],[1,1,0,0,1,0],[0,0,0,0,1,1],[0,0,1,0,1,0],[0,1,1,0,0,0],[0,1,1,0,0,0]]\r", "[[0,0,1,1,1,1],[0,0,0,0,1,1],[1,1,0,0,0,1],[1,1,1,0,0,1],[1,1,1,0,0,1],[1,1,1,0,0,0]]\r" ]
[ "Use BFS to find the answer.", "The state of the BFS is the position (x, y) along with a binary value that specifies if the position is horizontal or vertical." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minimumMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:23", "tests_total": 64, "tests_dro...
typescript
{ "raw_signature": "function minimumMoves(grid: number[][]): number {", "container": null, "callable": "minimumMoves", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,217
minimum-cost-to-move-chips-to-the-same-position
Easy
We have n chips, where the position of the i^th chip is position[i]. We need to move all the chips to the same position. In one step, we can change the position of the i^th chip from position[i] to: - position[i] + 2 or position[i] - 2 with cost = 0. - position[i] + 1 or position[i] - 1 with cost = 1. Return the min...
{ "language": "python", "source": "def check(candidate):\n assert candidate(position = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(position = [1, 1000000000]) == 1\n assert candidate(position = [1, 2, 2, 2, 3, 3, 3]) == 3\n assert candidate(position = [5, 5, 5, 5, 5]) == 0\n assert candid...
[ "[1,2,3]", "[2,2,2,3,3]", "[1,1000000000]" ]
[ "The first move keeps the parity of the element as it is.", "The second move changes the parity of the element.", "Since the first move is free, if all the numbers have the same parity, the answer would be zero.", "Find the minimum cost to make all the numbers have the same parity." ]
{ "canonical_parameter_names": [ "position" ], "leetcode_dataset_entry_point": "Solution().minCostToMoveChips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:35", "tests_total": 105, ...
typescript
{ "raw_signature": "function minCostToMoveChips(position: number[]): number {", "container": null, "callable": "minCostToMoveChips", "parameters": [ { "name": "position", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "lee...
1,218
longest-arithmetic-subsequence-of-given-difference
Medium
Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference. A subsequence is a sequence that can be derived from arr by deleting some or no elements wit...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [3, 0, -3, 4, -5, 0, -7, 1],difference = -3) == 3\n assert candidate(arr = [1, 2, 3, 4],difference = 1) == 4\n assert candidate(arr = [1, 3, 5, 7],difference = 1) == 1\n assert candidate(arr = [1, 1, 1, 1, 1],difference = ...
[ "[1,2,3,4]\n1", "[1,3,5,7]\n1", "[1,5,7,8,5,3,4,2,1]\n-2" ]
[ "Use dynamic programming.", "Let dp[i] be the maximum length of a subsequence of the given difference whose last element is i.", "dp[i] = 1 + dp[i-k]" ]
{ "canonical_parameter_names": [ "arr", "difference" ], "leetcode_dataset_entry_point": "Solution().longestSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:37", "tests_t...
typescript
{ "raw_signature": "function longestSubsequence(arr: number[], difference: number): number {", "container": null, "callable": "longestSubsequence", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "difference", "type": "number" } ], "return_type": "num...
1,219
path-with-maximum-gold
Medium
In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: - Every time you are located in a cell you will collect all the gold in that cell. - From your position, you ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 0, 7, 0], [2, 0, 6, 8], [0, 4, 5, 0], [3, 0, 3, 0], [9, 0, 20, 0]]) == 42\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 6], [7, 0, 0, 0], [0, 0, 0, 8]]) == 8\n assert candidate(grid = [[0, 6, 0], [5, 8, 7], [0, 9, ...
[ "[[0,6,0],[5,8,7],[0,9,0]]", "[[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]" ]
[ "Use recursion to try all such paths and find the one with the maximum value." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().getMaximumGold", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:39", "tests_total": 99, "tests_d...
typescript
{ "raw_signature": "function getMaximumGold(grid: number[][]): number {", "container": null, "callable": "getMaximumGold", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,220
count-vowels-permutation
Hard
Given an integer n, your task is to count how many strings of length n can be formed under the following rules: - Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u') - Each vowel 'a' may only be followed by an 'e'. - Each vowel 'e' may only be followed by an 'a' or an 'i'. - Each vowel 'i' may not be follow...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 1000) == 89945857\n assert candidate(n = 100) == 173981881\n assert candidate(n = 20000) == 759959057\n assert candidate(n = 200) == 670333618\n assert candidate(n = 10000) == 76428576\n assert candidate(n = 5000) == 5...
[ "1", "2" ]
[ "Use dynamic programming.", "Let dp[i][j] be the number of strings of length i that ends with the j-th vowel.", "Deduce the recurrence from the given relations between vowels." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().countVowelPermutation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:41", "tests_total": 26, "tes...
typescript
{ "raw_signature": "function countVowelPermutation(n: number): number {", "container": null, "callable": "countVowelPermutation", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,221
split-a-string-in-balanced-strings
Easy
Balanced strings are those that have an equal quantity of 'L' and 'R' characters. Given a balanced string s, split it into some number of substrings such that: - Each substring is balanced. Return the maximum number of balanced strings you can obtain. Example 1: Input: s = "RLRRLLRLRL" Output: 4 Explanation: s can...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"RRLLRRLL\") == 2\n assert candidate(s = \"RLRRRLLRLL\") == 2\n assert candidate(s = \"RRRRLLLLRRRRLLLL\") == 2\n assert candidate(s = \"LRRLLRRL\") == 4\n assert candidate(s = \"LLLLRRRRLLRRRR\") == 2\n assert candid...
[ "\"RLRRLLRLRL\"", "\"RLRRRLLRLL\"", "\"LLLLRRRR\"" ]
[ "Loop from left to right maintaining a balance variable when it gets an L increase it by one otherwise decrease it by one.", "Whenever the balance variable reaches zero then we increase the answer by one." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().balancedStringSplit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:43", "tests_total": 118, "test...
typescript
{ "raw_signature": "function balancedStringSplit(s: string): number {", "container": null, "callable": "balancedStringSplit", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,222
queens-that-can-attack-the-king
Medium
On a 0-indexed 8 x 8 chessboard, there can be multiple black queens and one white king. You are given a 2D integer array queens where queens[i] = [xQueen_i, yQueen_i] represents the position of the i^th black queen on the chessboard. You are also given an integer array king of length 2 where king = [xKing, yKing] repr...
{ "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],[4,0],[0,4],[3,3],[2,4]]\n[0,0]", "[[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]]\n[3,3]" ]
[ "Check 8 directions around the King.", "Find the nearest queen in each direction." ]
{ "canonical_parameter_names": [ "queens", "king" ], "leetcode_dataset_entry_point": "Solution().queensAttacktheKing", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:46", "tests_tot...
typescript
{ "raw_signature": "function queensAttacktheKing(queens: number[][], king: number[]): number[][] {", "container": null, "callable": "queensAttacktheKing", "parameters": [ { "name": "queens", "type": "number[][]" }, { "name": "king", "type": "number[]" } ], "return_typ...
1,223
dice-roll-simulation
Hard
A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times. Given an array of integers rollMax and an integer n, return the number of distinct sequences that can be obtained w...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 5,rollMax = [2, 2, 2, 2, 2, 2]) == 7200\n assert candidate(n = 1,rollMax = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(n = 1,rollMax = [15, 15, 15, 15, 15, 15]) == 6\n assert candidate(n = 10,rollMax = [2, 3, 4, 5, 6, 7]) ==...
[ "2\n[1,1,2,2,2,3]", "2\n[1,1,1,1,1,1]", "3\n[1,1,1,2,2,3]" ]
[ "Think on Dynamic Programming.", "DP(pos, last) which means we are at the position pos having as last the last character seen." ]
{ "canonical_parameter_names": [ "n", "rollMax" ], "leetcode_dataset_entry_point": "Solution().dieSimulator", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:48", "tests_total": 41, ...
typescript
{ "raw_signature": "function dieSimulator(n: number, rollMax: number[]): number {", "container": null, "callable": "dieSimulator", "parameters": [ { "name": "n", "type": "number" }, { "name": "rollMax", "type": "number[]" } ], "return_type": "number", "signature_sou...
1,224
maximum-equal-frequency
Hard
Given an array nums of positive integers, return the longest possible length of an array prefix of nums, such that it is possible to remove exactly one element from this prefix so that every number that has appeared in it will have the same number of occurrences. If after removing one element there are no remaining el...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10, 1, 1, 1, 2, 2, 3]) == 7\n assert candidate(nums = [1, 2, 2, 2, 1, 1]) == 5\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, ...
[ "[2,2,1,1,5,3,3,5]", "[1,1,1,2,2,2,3,3,3,4,4,4,5]" ]
[ "Keep track of the min and max frequencies.", "The number to be eliminated must have a frequency of 1, same as the others or the same +1." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxEqualFreq", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:50", "tests_total": 104, "tests_dr...
typescript
{ "raw_signature": "function maxEqualFreq(nums: number[]): number {", "container": null, "callable": "maxEqualFreq", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,227
airplane-seat-assignment-probability
Medium
n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of the passengers will: - Take their own seat if it is still available, and - Pick other seats randomly when they find their seat occupied Return the probability that the n^...
{ "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...
[ "1", "2" ]
[ "Let f(n) denote the probability of the n-th person getting correct seat in n-person case, then: f(1) = 1 (base case, trivial) f(2) = 1/2 (also trivial)", "Try to calculate f(3), f(4), and f(5) using the base cases. What is the value of them? f(i) for i >= 2 will also be 1/2.", "Try to proof why f(i) = 1/2 for ...
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().nthPersonGetsNthSeat", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:13:52", "tests_total": 32, "test...
typescript
{ "raw_signature": "function nthPersonGetsNthSeat(n: number): number {", "container": null, "callable": "nthPersonGetsNthSeat", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
1,232
check-if-it-is-a-straight-line
Easy
You are given an integer array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane. Example 1: Input: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]] Output: true Example 2: Input: coordinates = [[1,1],[2,2],[3,4],[4...
{ "language": "python", "source": "def check(candidate):\n assert candidate(coordinates = [[0, 0], [0, 1], [0, 2], [0, 3]]) == True\n assert candidate(coordinates = [[-10000, -10000], [0, 0], [10000, 10000]]) == True\n assert candidate(coordinates = [[-4, -3], [1, 0], [3, -1], [0, -1], [-5, 2]]) == False\n...
[ "[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]", "[[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]" ]
[ "If there're only 2 points, return true.", "Check if all other points lie on the line defined by the first 2 points.", "Use cross product to check collinearity." ]
{ "canonical_parameter_names": [ "coordinates" ], "leetcode_dataset_entry_point": "Solution().checkStraightLine", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:03", "tests_total": 125,...
typescript
{ "raw_signature": "function checkStraightLine(coordinates: number[][]): boolean {", "container": null, "callable": "checkStraightLine", "parameters": [ { "name": "coordinates", "type": "number[][]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_sou...
1,233
remove-sub-folders-from-the-filesystem
Medium
Given a list of folders folder, return the folders after removing all sub-folders in those folders. You may return the answer in any order. If a folder[i] is located within another folder[j], it is called a sub-folder of it. A sub-folder of folder[j] must start with folder[j], followed by a "/". For example, "/a/b" is...
{ "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 ...
[ "[\"/a\",\"/a/b\",\"/c/d\",\"/c/d/e\",\"/c/f\"]", "[\"/a\",\"/a/b/c\",\"/a/b/d\"]", "[\"/a/b/c\",\"/a/b/ca\",\"/a/b/d\"]" ]
[ "Sort the folders lexicographically.", "Insert the current element in an array and then loop until we get rid of all of their subfolders, repeat this until no element is left." ]
{ "canonical_parameter_names": [ "folder" ], "leetcode_dataset_entry_point": "Solution().removeSubfolders", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:06", "tests_total": 97, "tes...
typescript
{ "raw_signature": "function removeSubfolders(folder: string[]): string[] {", "container": null, "callable": "removeSubfolders", "parameters": [ { "name": "folder", "type": "string[]" } ], "return_type": "string[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcod...
1,234
replace-the-substring-for-balanced-string
Medium
You are given a string s of length n containing only four kinds of characters: 'Q', 'W', 'E', and 'R'. A string is said to be balanced if each of its characters appears n / 4 times where n is the length of the string. Return the minimum length of the substring that can be replaced with any other string of the same le...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"QQQQQQQQWWWWEEEEEEEERRRRRRRR\") == 14\n assert candidate(s = \"QQQQWWER\") == 2\n assert candidate(s = \"QQQQWWWWEEEERRRR\") == 0\n assert candidate(s = \"QQWWRRER\") == 1\n assert candidate(s = \"QQQQWWWEERRR\") == 1\n...
[ "\"QWER\"", "\"QQWE\"", "\"QQQW\"" ]
[ "Use 2-pointers algorithm to make sure all amount of characters outside the 2 pointers are smaller or equal to n/4.", "That means you need to count the amount of each letter and make sure the amount is enough." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().balancedString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:08", "tests_total": 158, "tests_dro...
typescript
{ "raw_signature": "function balancedString(s: string): number {", "container": null, "callable": "balancedString", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,235
maximum-profit-in-job-scheduling
Hard
We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i]. You're given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range. If you choose a job that en...
{ "language": "python", "source": "def check(candidate):\n assert candidate(startTime = [1, 10, 4, 3, 8, 9],endTime = [2, 11, 5, 7, 9, 10],profit = [3, 1, 5, 6, 4, 3]) == 17\n assert candidate(startTime = [1, 3, 5, 6, 7],endTime = [3, 5, 9, 8, 9],profit = [50, 20, 60, 40, 30]) == 130\n assert candidate(sta...
[ "[1,2,3,3]\n[3,4,5,6]\n[50,10,40,70]", "[1,2,3,4,6]\n[3,5,10,6,9]\n[20,20,100,70,60]", "[1,1,1]\n[2,3,4]\n[5,6,4]" ]
[ "Think on DP.", "Sort the elements by starting time, then define the dp[i] as the maximum profit taking elements from the suffix starting at i.", "Use binarySearch (lower_bound/upper_bound on C++) to get the next index for the DP transition." ]
{ "canonical_parameter_names": [ "startTime", "endTime", "profit" ], "leetcode_dataset_entry_point": "Solution().jobScheduling", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:10"...
typescript
{ "raw_signature": "function jobScheduling(startTime: number[], endTime: number[], profit: number[]): number {", "container": null, "callable": "jobScheduling", "parameters": [ { "name": "startTime", "type": "number[]" }, { "name": "endTime", "type": "number[]" }, { ...
1,238
circular-permutation-in-binary-representation
Medium
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : - p[0] = start - p[i] and p[i+1] differ by only one bit in their binary representation. - p[0] and p[2^n -1] must also differ by only one bit in their binary representation. Example 1: Input: n = 2, start = 3 Outpu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 1,start = 0) == [0, 1]\n assert candidate(n = 12,start = 2048) == [2048, 0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8, 24, 25, 27, 26, 30, 31, 29, 28, 20, 21, 23, 22, 18, 19, 17, 16, 48, 49, 51, 50, 54, 55, 53, 52, 60, 61,...
[ "2\n3", "3\n2" ]
[ "Use gray code to generate a n-bit sequence.", "Rotate the sequence such that its first element is start." ]
{ "canonical_parameter_names": [ "n", "start" ], "leetcode_dataset_entry_point": "Solution().circularPermutation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:13", "tests_total":...
typescript
{ "raw_signature": "function circularPermutation(n: number, start: number): number[] {", "container": null, "callable": "circularPermutation", "parameters": [ { "name": "n", "type": "number" }, { "name": "start", "type": "number" } ], "return_type": "number[]", "sig...
1,239
maximum-length-of-a-concatenated-string-with-unique-characters
Medium
You are given an array of strings arr. A string s is formed by the concatenation of a subsequence of arr that has unique characters. Return the maximum possible length of s. A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining ele...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = ['abcd', 'abef', 'cdgh', 'cdef']) == 8\n assert candidate(arr = ['un', 'iq', 'ue']) == 4\n assert candidate(arr = ['abcdefghijklmnopqrstuvwxyz']) == 26\n assert candidate(arr = ['unique', 'strings', 'with', 'no', 'common',...
[ "[\"un\",\"iq\",\"ue\"]", "[\"cha\",\"r\",\"act\",\"ers\"]", "[\"abcdefghijklmnopqrstuvwxyz\"]" ]
[ "You can try all combinations and keep mask of characters you have.", "You can use DP." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().maxLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:15", "tests_total": 87, "tests_dropped...
typescript
{ "raw_signature": "function maxLength(arr: string[]): number {", "container": null, "callable": "maxLength", "parameters": [ { "name": "arr", "type": "string[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,240
tiling-a-rectangle-with-the-fewest-squares
Hard
Given a rectangle of size n x m, return the minimum number of integer-sided squares that tile the rectangle. Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 8,m = 8) == 1\n assert candidate(n = 1,m = 1) == 1\n assert candidate(n = 7,m = 7) == 1\n assert candidate(n = 9,m = 10) == 6\n assert candidate(n = 7,m = 8) == 7\n assert candidate(n = 6,m = 7) == 5\n assert candid...
[ "2\n3", "5\n8", "11\n13" ]
[ "Can you use backtracking to solve this problem ?.", "Suppose you've placed a bunch of squares. Where is the natural spot to place the next square ?.", "The maximum number of squares to be placed will be ≤ max(n,m)." ]
{ "canonical_parameter_names": [ "n", "m" ], "leetcode_dataset_entry_point": "Solution().tilingRectangle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:17", "tests_total": 66, "...
typescript
{ "raw_signature": "function tilingRectangle(n: number, m: number): number {", "container": null, "callable": "tilingRectangle", "parameters": [ { "name": "n", "type": "number" }, { "name": "m", "type": "number" } ], "return_type": "number", "signature_source": "lee...
1,247
minimum-swaps-to-make-strings-equal
Medium
You are given two strings s1 and s2 of equal length consisting of letters "x" and "y" only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings, which means: swap s1[i] and s2[j]. Return the minimum number of swaps required to make s1 and s2 equa...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s1 = \"xyyy\",s2 = \"yxxx\") == 3\n assert candidate(s1 = \"xx\",s2 = \"yy\") == 1\n assert candidate(s1 = \"xxyy\",s2 = \"xyxy\") == 2\n assert candidate(s1 = \"xxyyxyxyxx\",s2 = \"xyyxyxxxyx\") == 4\n assert candidate(s1 = ...
[ "\"xx\"\n\"yy\"", "\"xy\"\n\"yx\"", "\"xx\"\n\"xy\"" ]
[ "First, ignore all the already matched positions, they don't affect the answer at all. For the unmatched positions, there are three basic cases (already given in the examples):", "(\"xx\", \"yy\") => 1 swap, (\"xy\", \"yx\") => 2 swaps", "So the strategy is, apply case 1 as much as possible, then apply case 2 i...
{ "canonical_parameter_names": [ "s1", "s2" ], "leetcode_dataset_entry_point": "Solution().minimumSwap", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:28", "tests_total": 103, "t...
typescript
{ "raw_signature": "function minimumSwap(s1: string, s2: string): number {", "container": null, "callable": "minimumSwap", "parameters": [ { "name": "s1", "type": "string" }, { "name": "s2", "type": "string" } ], "return_type": "number", "signature_source": "leetcod...
1,248
count-number-of-nice-subarrays
Medium
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays. Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: num...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 2\n assert candidate(nums = [2],k = 1) == 0\n assert candidate(nums = [2, 4, 6],k = 1) == 0\n assert candidate(nums = [1, ...
[ "[1,1,2,1,1]\n3", "[2,4,6]\n1", "[2,2,2,1,2,2,1,2,2,2]\n2" ]
[ "After replacing each even by zero and every odd by one can we use prefix sum to find answer ?", "Can we use two pointers to count number of sub-arrays ?", "Can we store the indices of odd numbers and for each k indices count the number of sub-arrays that contains them ?" ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().numberOfSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:30", "tests_total": 68...
typescript
{ "raw_signature": "function numberOfSubarrays(nums: number[], k: number): number {", "container": null, "callable": "numberOfSubarrays", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature...
1,249
minimum-remove-to-make-valid-parentheses
Medium
Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a parentheses string is valid if and only if: - It is the empty string, co...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"(a(b)c)d(e(fg)h\") == \"(a(b)c)de(fg)h\"\n assert candidate(s = \"()\") == \"()\"\n assert candidate(s = \"))(()\") == \"()\"\n assert candidate(s = \"ab(c(d)e)f(g(h)i)j(kl)\") == \"ab(c(d)e)f(g(h)i)j(kl)\"\n assert can...
[ "\"lee(t(c)o)de)\"", "\"a)b(c)d\"", "\"))((\"" ]
[ "Each prefix of a balanced parentheses has a number of open parentheses greater or equal than closed parentheses, similar idea with each suffix.", "Check the array from left to right, remove characters that do not meet the property mentioned above, same idea in backward way." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minRemoveToMakeValid", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:33", "tests_total": 77, "test...
typescript
{ "raw_signature": "function minRemoveToMakeValid(s: string): string {", "container": null, "callable": "minRemoveToMakeValid", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnip...
1,250
check-if-it-is-a-good-array
Hard
Given an array nums of positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers. The array is said to be good if you can obtain a sum of 1 from the array by any possible subset and multiplicand. Return True if the array is good otherwise return False....
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 13, 19]) == True\n assert candidate(nums = [100, 200, 300, 400]) == False\n assert candidate(nums = [7, 13, 19, 29]) == True\n assert candidate(nums = [29, 6, 10]) == True\n assert candidate(nums = [7, 14, 21, 35])...
[ "[12,5,7,23]", "[29,6,10]", "[3,6]" ]
[ "Eq. ax+by=1 has solution x, y if gcd(a,b) = 1.", "Can you generalize the formula?. Check Bézout's lemma." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().isGoodArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:35", "tests_total": 138, "tests_dro...
typescript
{ "raw_signature": "function isGoodArray(nums: number[]): boolean {", "container": null, "callable": "isGoodArray", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,252
cells-with-odd-values-in-a-matrix
Easy
There is an m x n matrix that is initialized to all 0's. There is also a 2D array indices where each indices[i] = [r_i, c_i] represents a 0-indexed location to perform some increment operations on the matrix. For each location indices[i], do both of the following: 1. Increment all the cells on row r_i. 2. Increment a...
{ "language": "python", "source": "def check(candidate):\n assert candidate(m = 2,n = 3,indices = [[0, 1], [1, 1]]) == 6\n assert candidate(m = 50,n = 50,indices = [[0, 0], [1, 1], [2, 2], [3, 3]]) == 368\n assert candidate(m = 4,n = 5,indices = [[0, 1], [0, 1], [1, 2], [2, 3], [3, 4]]) == 9\n assert ca...
[ "2\n3\n[[0,1],[1,1]]", "2\n2\n[[1,1],[0,0]]" ]
[ "Simulation : With small constraints, it is possible to apply changes to each row and column and count odd cells after applying it.", "You can accumulate the number you should add to each row and column and then you can count the number of odd cells." ]
{ "canonical_parameter_names": [ "m", "n", "indices" ], "leetcode_dataset_entry_point": "Solution().oddCells", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:38", "tests_total":...
typescript
{ "raw_signature": "function oddCells(m: number, n: number, indices: number[][]): number {", "container": null, "callable": "oddCells", "parameters": [ { "name": "m", "type": "number" }, { "name": "n", "type": "number" }, { "name": "indices", "type": "numb...
1,253
reconstruct-a-2-row-binary-matrix
Medium
Given the following details of a matrix with n columns and 2 rows : - The matrix is a binary matrix, which means each element in the matrix can be 0 or 1. - The sum of elements of the 0-th(upper) row is given as upper. - The sum of elements of the 1-st(lower) row is given as lower. - The sum of elements in the i-th co...
{ "language": "python", "source": "def check(candidate):\n assert candidate(upper = 2,lower = 3,colsum = [2, 2, 1, 1]) == []\n assert candidate(upper = 1,lower = 1,colsum = [1, 0, 1]) == [[0, 0, 1], [1, 0, 0]]\n assert candidate(upper = 4,lower = 2,colsum = [2, 1, 1, 0, 0]) == []\n assert candidate(uppe...
[ "2\n1\n[1,1,1]", "2\n3\n[2,2,1,1]", "5\n5\n[2,1,2,0,1,0,1,2,0,1]" ]
[ "You cannot do anything about colsum[i] = 2 case or colsum[i] = 0 case. Then you put colsum[i] = 1 case to the upper row until upper has reached. Then put the rest into lower row.", "Fill 0 and 2 first, then fill 1 in the upper row or lower row in turn but be careful about exhausting permitted 1s in each row." ]
{ "canonical_parameter_names": [ "upper", "lower", "colsum" ], "leetcode_dataset_entry_point": "Solution().reconstructMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:40", ...
typescript
{ "raw_signature": "function reconstructMatrix(upper: number, lower: number, colsum: number[]): number[][] {", "container": null, "callable": "reconstructMatrix", "parameters": [ { "name": "upper", "type": "number" }, { "name": "lower", "type": "number" }, { "na...
1,254
number-of-closed-islands
Medium
Given a 2D grid consists of 0s (land) and 1s (water). An island is a maximal 4-directionally connected group of 0s and a closed island is an island totally (all left, top, right, bottom) surrounded by 1s. Return the number of closed islands. Example 1: Input: grid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]]) == 2\n assert candidate(grid = [[0, 0, 1, 0, 0], [0, 1, 0, 1, 0]...
[ "[[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]]", "[[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]]", "[[1,1,1,1,1,1,1],[1,0,0,0,0,0,1],[1,0,1,1,1,0,1],[1,0,1,0,1,0,1],[1,0,1,1,1,0,1],[1,0,0,0,0,0,1],[1,1,1,1,1,1,1]]" ]
[ "Exclude connected group of 0s on the corners because they are not closed island.", "Return number of connected component of 0s on the grid." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().closedIsland", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:43", "tests_total": 63, "tests_dro...
typescript
{ "raw_signature": "function closedIsland(grid: number[][]): number {", "container": null, "callable": "closedIsland", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,255
maximum-score-words-formed-by-letters
Hard
Given a list of words, list of single letters (might be repeating) and score of every character. Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times). It is not necessary to use all characters in letters and each letter can only be used once....
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['xxxz', 'ax', 'bx', 'cx'],letters = ['z', 'a', 'b', 'c', 'x', 'x', 'x'],score = [4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 10]) == 27\n assert candidate(words = ['leetcode'],letters = ['l', 'e...
[ "[\"dog\",\"cat\",\"dad\",\"good\"]\n[\"a\",\"a\",\"c\",\"d\",\"d\",\"d\",\"g\",\"o\",\"o\"]\n[1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]", "[\"xxxz\",\"ax\",\"bx\",\"cx\"]\n[\"z\",\"a\",\"b\",\"c\",\"x\",\"x\",\"x\"]\n[4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,10]", "[\"leetcode\"]\n[\"l\",\"...
[ "Note that words.length is small. This means you can iterate over every subset of words (2^N)." ]
{ "canonical_parameter_names": [ "words", "letters", "score" ], "leetcode_dataset_entry_point": "Solution().maxScoreWords", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:45", "...
typescript
{ "raw_signature": "function maxScoreWords(words: string[], letters: string[], score: number[]): number {", "container": null, "callable": "maxScoreWords", "parameters": [ { "name": "words", "type": "string[]" }, { "name": "letters", "type": "string[]" }, { "nam...
1,260
shift-2d-grid
Easy
Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operation: - Element at grid[i][j] moves to grid[i][j + 1]. - Element at grid[i][n - 1] moves to grid[i + 1][0]. - Element at grid[m - 1][n - 1] moves to grid[0][0]. Return the 2D grid after applying shift operation k ti...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[3, 8, 1, 9], [19, 7, 2, 5], [4, 6, 11, 10], [12, 0, 21, 13]],k = 4) == [[12, 0, 21, 13], [3, 8, 1, 9], [19, 7, 2, 5], [4, 6, 11, 10]]\n assert candidate(grid = [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]],k = 2) == [[-8, -9, -1...
[ "[[1,2,3],[4,5,6],[7,8,9]]\n1", "[[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]]\n4", "[[1,2,3],[4,5,6],[7,8,9]]\n9" ]
[ "Simulate step by step. move grid[i][j] to grid[i][j+1]. handle last column of the grid.", "Put the matrix row by row to a vector. take k % vector.length and move last k of the vector to the beginning. put the vector to the matrix back the same way." ]
{ "canonical_parameter_names": [ "grid", "k" ], "leetcode_dataset_entry_point": "Solution().shiftGrid", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:56", "tests_total": 84, "tes...
typescript
{ "raw_signature": "function shiftGrid(grid: number[][], k: number): number[][] {", "container": null, "callable": "shiftGrid", "parameters": [ { "name": "grid", "type": "number[][]" }, { "name": "k", "type": "number" } ], "return_type": "number[][]", "signature_sou...
1,262
greatest-sum-divisible-by-three
Medium
Given an integer array nums, return the maximum possible sum of elements of the array such that it is divisible by three. Example 1: Input: nums = [3,6,5,1,8] Output: 18 Explanation: Pick numbers 3, 6, 1 and 8 their sum is 18 (maximum sum divisible by 3). Example 2: Input: nums = [4] Output: 0 Explanation: Since 4 ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 18\n assert candidate(nums = [2, 3, 5, 7, 11]) == 21\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 30\n assert candidate(nums = [4]) == 0\n assert candidate(nums = [100...
[ "[3,6,5,1,8]", "[4]", "[1,2,3,4,4]" ]
[ "Represent the state as DP[pos][mod]: maximum possible sum starting in the position \"pos\" in the array where the current sum modulo 3 is equal to mod." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().maxSumDivThree", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:14:58", "tests_total": 139, "tests_...
typescript
{ "raw_signature": "function maxSumDivThree(nums: number[]): number {", "container": null, "callable": "maxSumDivThree", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,263
minimum-moves-to-move-a-box-to-their-target-location
Hard
A storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations. The game is represented by an m x n grid of characters grid where each element is a wall, floor, or box. Your task is to move the box 'B' to the target position 'T' under the following rules: - The ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [['#', '#', '#', '#', '#', '#'], ['#', 'T', '#', '#', '#', '#'], ['#', '.', '.', 'B', '.', '#'], ['#', '.', '#', '#', '.', '#'], ['#', '.', '.', '.', 'S', '#'], ['#', '#', '#', '#', '#', '#']]) == 3\n assert candidate(grid = [[...
[ "[[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],[\"#\",\"T\",\"#\",\"#\",\"#\",\"#\"],[\"#\",\".\",\".\",\"B\",\".\",\"#\"],[\"#\",\".\",\"#\",\"#\",\".\",\"#\"],[\"#\",\".\",\".\",\".\",\"S\",\"#\"],[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]", "[[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],[\"#\",\"T\",\"#\",\"#\",\"#\",\"#\"],[\"...
[ "We represent the search state as (player_row, player_col, box_row, box_col).", "You need to count only the number of pushes. Then inside of your BFS check if the box could be pushed (in any direction) given the current position of the player." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minPushBox", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:00", "tests_total": 82, "tests_dropp...
typescript
{ "raw_signature": "function minPushBox(grid: string[][]): number {", "container": null, "callable": "minPushBox", "parameters": [ { "name": "grid", "type": "string[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,266
minimum-time-visiting-all-points
Easy
On a 2D plane, there are n points with integer coordinates points[i] = [x_i, y_i]. Return the minimum time in seconds to visit all the points in the order given by points. You can move according to these rules: - In 1 second, you can either: - move vertically by one unit, - move horizontally by one unit, or - m...
{ "language": "python", "source": "def check(candidate):\n assert candidate(points = [[0, 0], [1, 1], [0, 0], [1, 1]]) == 3\n assert candidate(points = [[5, 5], [5, 5], [5, 5], [5, 5]]) == 0\n assert candidate(points = [[-5, -5], [-4, -4], [-3, -3], [-2, -2]]) == 3\n assert candidate(points = [[0, 0], [...
[ "[[1,1],[3,4],[-1,0]]", "[[3,2],[-2,2]]" ]
[ "To walk from point A to point B there will be an optimal strategy to walk ?", "Advance in diagonal as possible then after that go in straight line.", "Repeat the process until visiting all the points." ]
{ "canonical_parameter_names": [ "points" ], "leetcode_dataset_entry_point": "Solution().minTimeToVisitAllPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:03", "tests_total": 120...
typescript
{ "raw_signature": "function minTimeToVisitAllPoints(points: number[][]): number {", "container": null, "callable": "minTimeToVisitAllPoints", "parameters": [ { "name": "points", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_sou...
1,267
count-servers-that-communicate
Medium
You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row or on the same column. Return the number of servers that communicate with any other serv...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1, 0], [0, 0, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0]]) == 6\n assert candidate(grid = [[1, 0], [1, 1]]) == 3\n assert candidate(grid = [[1, 1, 0, 0, 0], [1, 0, 1, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 1, 1]]) == 8\n assert...
[ "[[1,0],[0,1]]", "[[1,0],[1,1]]", "[[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]" ]
[ "Store number of computer in each row and column.", "Count all servers that are not isolated." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().countServers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:05", "tests_total": 50, "tests_dro...
typescript
{ "raw_signature": "function countServers(grid: number[][]): number {", "container": null, "callable": "countServers", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,268
search-suggestions-system
Medium
You are given an array of strings products and a string searchWord. Design a system that suggests at most three product names from products after each character of searchWord is typed. Suggested products should have common prefix with searchWord. If there are more than three products with a common prefix return the th...
{ "language": "python", "source": "def check(candidate):\n assert candidate(products = ['keyboard', 'keypad', 'keys', 'kick'],searchWord = \"key\") == [['keyboard', 'keypad', 'keys'], ['keyboard', 'keypad', 'keys'], ['keyboard', 'keypad', 'keys']]\n assert candidate(products = ['keyboard', 'keypad', 'mousepad...
[ "[\"mobile\",\"mouse\",\"moneypot\",\"monitor\",\"mousepad\"]\n\"mouse\"", "[\"havana\"]\n\"havana\"" ]
[ "Brute force is a good choice because length of the string is ≤ 1000.", "Binary search the answer.", "Use Trie data structure to store the best three matching. Traverse the Trie." ]
{ "canonical_parameter_names": [ "products", "searchWord" ], "leetcode_dataset_entry_point": "Solution().suggestedProducts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:07", "tes...
typescript
{ "raw_signature": "function suggestedProducts(products: string[], searchWord: string): string[][] {", "container": null, "callable": "suggestedProducts", "parameters": [ { "name": "products", "type": "string[]" }, { "name": "searchWord", "type": "string" } ], "return...
1,269
number-of-ways-to-stay-in-the-same-place-after-some-steps
Hard
You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time). Given two integers steps and arrLen, return the number of ways such that your po...
{ "language": "python", "source": "def check(candidate):\n assert candidate(steps = 5,arrLen = 3) == 21\n assert candidate(steps = 10,arrLen = 5) == 2187\n assert candidate(steps = 5,arrLen = 5) == 21\n assert candidate(steps = 2,arrLen = 4) == 2\n assert candidate(steps = 3,arrLen = 2) == 4\n ass...
[ "3\n2", "2\n4", "4\n2" ]
[ "Try with Dynamic programming, dp(pos,steps): number of ways to back pos = 0 using exactly \"steps\" moves.", "Notice that the computational complexity does not depend of \"arrlen\"." ]
{ "canonical_parameter_names": [ "steps", "arrLen" ], "leetcode_dataset_entry_point": "Solution().numWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:09", "tests_total": 65, ...
typescript
{ "raw_signature": "function numWays(steps: number, arrLen: number): number {", "container": null, "callable": "numWays", "parameters": [ { "name": "steps", "type": "number" }, { "name": "arrLen", "type": "number" } ], "return_type": "number", "signature_source": "l...
1,275
find-winner-on-a-tic-tac-toe-game
Easy
Tic-tac-toe is played by two players A and B on a 3 x 3 grid. The rules of Tic-Tac-Toe are: - Players take turns placing characters into empty squares ' '. - The first player A always places 'X' characters, while the second player B always places 'O' characters. - 'X' and 'O' characters are always placed into empty sq...
{ "language": "python", "source": "def check(candidate):\n assert candidate(moves = [[0, 0], [1, 1], [2, 2], [1, 0], [1, 2], [2, 0], [2, 1]]) == \"Pending\"\n assert candidate(moves = [[0, 0], [2, 0], [1, 1], [2, 1], [2, 2]]) == \"A\"\n assert candidate(moves = [[0, 2], [1, 1], [2, 0]]) == \"Pending\"\n ...
[ "[[0,0],[2,0],[1,1],[2,1],[2,2]]", "[[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]", "[[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]" ]
[ "It's straightforward to check if A or B won or not, check for each row/column/diag if all the three are the same.", "Then if no one wins, the game is a draw iff the board is full, i.e. moves.length = 9 otherwise is pending." ]
{ "canonical_parameter_names": [ "moves" ], "leetcode_dataset_entry_point": "Solution().tictactoe", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:18", "tests_total": 114, "tests_drop...
typescript
{ "raw_signature": "function tictactoe(moves: number[][]): string {", "container": null, "callable": "tictactoe", "parameters": [ { "name": "moves", "type": "number[][]" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" ...
1,276
number-of-burgers-with-no-waste-of-ingredients
Medium
Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as follows: - Jumbo Burger: 4 tomato slices and 1 cheese slice. - Small Burger: 2 Tomato slices and 1 cheese slice. Return [total_jumbo, total_small] so that the number of remaining tomatoSlices equal to 0 and the number of rem...
{ "language": "python", "source": "def check(candidate):\n assert candidate(tomatoSlices = 10000000,cheeseSlices = 5000000) == [0, 5000000]\n assert candidate(tomatoSlices = 16,cheeseSlices = 7) == [1, 6]\n assert candidate(tomatoSlices = 14,cheeseSlices = 5) == [2, 3]\n assert candidate(tomatoSlices = ...
[ "16\n7", "17\n4", "4\n17" ]
[ "Can we have an answer if the number of tomatoes is odd ?", "If we have answer will be there multiple answers or just one answer ?", "Let us define number of jumbo burgers as X and number of small burgers as Y We have to find an x and y in this equation", "1. 4X + 2Y = tomato", "2. X + Y = cheese" ]
{ "canonical_parameter_names": [ "tomatoSlices", "cheeseSlices" ], "leetcode_dataset_entry_point": "Solution().numOfBurgers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:21", "te...
typescript
{ "raw_signature": "function numOfBurgers(tomatoSlices: number, cheeseSlices: number): number[] {", "container": null, "callable": "numOfBurgers", "parameters": [ { "name": "tomatoSlices", "type": "number" }, { "name": "cheeseSlices", "type": "number" } ], "return_typ...
1,277
count-square-submatrices-with-all-ones
Medium
Given a m * n matrix of ones and zeros, return how many square submatrices have all ones. Example 1: Input: matrix = [ [0,1,1,1], [1,1,1,1], [0,1,1,1] ] Output: 15 Explanation: There are 10 squares of side 1. There are 4 squares of side 2. There is 1 square of side 3. Total number of squares = 10 + 4 + 1 = 15....
{ "language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[1, 0, 1, 0, 1], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [1, 0, 1, 0, 1]]) == 24\n assert candidate(matrix = [[1]]) == 1\n assert candidate(matrix = [[0]]) == 0\n assert candidate(matrix = [[0, 1, 1, 1], [1,...
[ "[[0,1,1,1],[1,1,1,1],[0,1,1,1]]", "[[1,0,1],[1,1,0],[1,1,0]]" ]
[ "Create an additive table that counts the sum of elements of submatrix with the superior corner at (0,0).", "Loop over all subsquares in O(n^3) and check if the sum make the whole array to be ones, if it checks then add 1 to the answer." ]
{ "canonical_parameter_names": [ "matrix" ], "leetcode_dataset_entry_point": "Solution().countSquares", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:23", "tests_total": 67, "tests_d...
typescript
{ "raw_signature": "function countSquares(matrix: number[][]): number {", "container": null, "callable": "countSquares", "parameters": [ { "name": "matrix", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,278
palindrome-partitioning-iii
Hard
You are given a string s containing lowercase letters and an integer k. You need to : - First, change some characters of s to other lowercase English letters. - Then divide s into k non-empty disjoint substrings such that each substring is a palindrome. Return the minimal number of characters that you need to change ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc\",k = 2) == 1\n assert candidate(s = \"abababa\",k = 4) == 1\n assert candidate(s = \"aaaa\",k = 2) == 0\n assert candidate(s = \"leetcode\",k = 8) == 0\n assert candidate(s = \"abcd\",k = 2) == 1\n assert candid...
[ "\"abc\"\n2", "\"aabbc\"\n3", "\"leetcode\"\n8" ]
[ "For each substring calculate the minimum number of steps to make it palindrome and store it in a table.", "Create a dp(pos, cnt) which means the minimum number of characters changed for the suffix of s starting on pos splitting the suffix on cnt chunks." ]
{ "canonical_parameter_names": [ "s", "k" ], "leetcode_dataset_entry_point": "Solution().palindromePartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:25", "tests_total": 89,...
typescript
{ "raw_signature": "function palindromePartition(s: string, k: number): number {", "container": null, "callable": "palindromePartition", "parameters": [ { "name": "s", "type": "string" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_sourc...
1,281
subtract-the-product-and-sum-of-digits-of-an-integer
Easy
Given an integer number n, return the difference between the product of its digits and the sum of its digits. Example 1: Input: n = 234 Output: 15 Explanation: Product of digits = 2 * 3 * 4 = 24 Sum of digits = 2 + 3 + 4 = 9 Result = 24 - 9 = 15 Example 2: Input: n = 4421 Output: 21 Explanation: Product of digits =...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 99999) == 59004\n assert candidate(n = 11111) == -4\n assert candidate(n = 789) == 480\n assert candidate(n = 1111) == -3\n assert candidate(n = 234) == 15\n assert candidate(n = 12345) == 105\n assert candidate(n =...
[ "234", "4421" ]
[ "How to compute all digits of the number ?", "Use modulus operator (%) to compute the last digit.", "Generalise modulus operator idea to compute all digits." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().subtractProductAndSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:27", "tests_total": 55, "tes...
typescript
{ "raw_signature": "function subtractProductAndSum(n: number): number {", "container": null, "callable": "subtractProductAndSum", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,282
group-the-people-given-the-group-size-they-belong-to
Medium
There are n people that are split into some unknown number of groups. Each person is labeled with a unique ID from 0 to n - 1. You are given an integer array groupSizes, where groupSizes[i] is the size of the group that person i is in. For example, if groupSizes[1] = 3, then person 1 must be in a group of size 3. Ret...
{ "language": "python", "source": "def check(candidate):\n assert candidate(groupSizes = [1, 2, 2, 1, 1]) == [[0], [3], [4], [1, 2]]\n assert candidate(groupSizes = [1, 1, 1, 1, 1, 1]) == [[0], [1], [2], [3], [4], [5]]\n assert candidate(groupSizes = [1, 2, 2, 1]) == [[0], [3], [1, 2]]\n assert candidat...
[ "[3,3,3,3,3,1,3]", "[2,1,3,3,3,2]" ]
[ "Put people's IDs with same groupSize into buckets, then split each bucket into groups.", "Greedy fill until you need a new group." ]
{ "canonical_parameter_names": [ "groupSizes" ], "leetcode_dataset_entry_point": "Solution().groupThePeople", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:29", "tests_total": 83, "t...
typescript
{ "raw_signature": "function groupThePeople(groupSizes: number[]): number[][] {", "container": null, "callable": "groupThePeople", "parameters": [ { "name": "groupSizes", "type": "number[]" } ], "return_type": "number[][]", "signature_source": "leetcode/codeSnippets", "type_source": ...
1,283
find-the-smallest-divisor-given-a-threshold
Medium
Given an array of integers nums and an integer threshold, we will choose a positive integer divisor, divide all the array by it, and sum the division's result. Find the smallest divisor such that the result mentioned above is less than or equal to threshold. Each result of the division is rounded to the nearest intege...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],threshold = 15) == 10\n assert candidate(nums = [44, 22, 33, 11, 1],threshold = 5) == 44\n assert candidate(nums = [1, 1, 1, 1, 1],threshold = 5) == 1\n assert candidate(nums = [10, 20, 30, 40, 50],th...
[ "[1,2,5,9]\n6", "[44,22,33,11,1]\n5" ]
[ "Examine every possible number for solution. Choose the largest of them.", "Use binary search to reduce the time complexity." ]
{ "canonical_parameter_names": [ "nums", "threshold" ], "leetcode_dataset_entry_point": "Solution().smallestDivisor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:32", "tests_tota...
typescript
{ "raw_signature": "function smallestDivisor(nums: number[], threshold: number): number {", "container": null, "callable": "smallestDivisor", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "threshold", "type": "number" } ], "return_type": "number", ...
1,284
minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix
Hard
Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing 1 to 0 and 0 to 1). A pair of cells are called neighbors if they share one edge. Return the minimum number of steps required to convert mat to a zero matrix or -1 if you ca...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[0, 0], [0, 1]]) == 3\n assert candidate(mat = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 5\n assert candidate(mat = [[1, 1], [1, 1]]) == 4\n assert candidate(mat = [[0]]) == 0\n assert candidate(mat = [[1, 1, 0], [0, 0, 0]...
[ "[[0,0],[0,1]]", "[[0]]", "[[1,0,0],[1,0,0]]" ]
[ "Flipping same index two times is like not flipping it at all. Each index can be flipped one time. Try all possible combinations. O(2^(n*m))." ]
{ "canonical_parameter_names": [ "mat" ], "leetcode_dataset_entry_point": "Solution().minFlips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:34", "tests_total": 53, "tests_dropped"...
typescript
{ "raw_signature": "function minFlips(mat: number[][]): number {", "container": null, "callable": "minFlips", "parameters": [ { "name": "mat", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,287
element-appearing-more-than-25-in-sorted-array
Easy
Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer. Example 1: Input: arr = [1,2,2,6,6,6,6,7,10] Output: 6 Example 2: Input: arr = [1,1] Output: 1 Constraints: - 1 <= arr.length <= 10^4 - 0 <= arr[i] <= 10^5
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(arr = [1, 1]) == 1\n assert candidate(arr = [1, 2, 2, 2, 3, 4, 5, 6]) == 2\n assert candidate(arr = [1, 1, 2, 3, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10]) == 4\n a...
[ "[1,2,2,6,6,6,6,7,10]", "[1,1]" ]
[ "Divide the array in four parts [1 - 25%] [25 - 50 %] [50 - 75 %] [75% - 100%]", "The answer should be in one of the ends of the intervals.", "In order to check which is element is the answer we can count the frequency with binarySearch." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().findSpecialInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:36", "tests_total": 83, "test...
typescript
{ "raw_signature": "function findSpecialInteger(arr: number[]): number {", "container": null, "callable": "findSpecialInteger", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/code...
1,288
remove-covered-intervals
Medium
Given an array intervals where intervals[i] = [l_i, r_i] represent the interval [l_i, r_i), remove all intervals that are covered by another interval in the list. The interval [a, b) is covered by the interval [c, d) if and only if c <= a and b <= d. Return the number of remaining intervals. Example 1: Input: inter...
{ "language": "python", "source": "def check(candidate):\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 4\n assert candidate(intervals = [[1, 100], [2, 50], [3, 75]]) == 1\n assert candidate(intervals = [[1, 3], [2, 4], [3, 5]]) == 3\n assert candidate(intervals = [[1, 4], [3, 6], [...
[ "[[52141,92589],[52991,93486],[46321,59199],[51955,78788],[18533,23127]]", "[[14041,32641],[24914,51477],[4983,81235],[62018,77987],[31523,32192],[74196,96194],[16126,52652],[59901,67707],[36502,51366],[56437,86744]]" ]
[ "How to check if an interval is covered by another?", "Compare each interval to all others and check if it is covered by any interval." ]
{ "canonical_parameter_names": [ "intervals" ], "leetcode_dataset_entry_point": "Solution().removeCoveredIntervals", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:38", "tests_total": 1...
typescript
{ "raw_signature": "function removeCoveredIntervals(intervals: number[][]): number {", "container": null, "callable": "removeCoveredIntervals", "parameters": [ { "name": "intervals", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type...
1,289
minimum-falling-path-sum-ii
Hard
Given an n x n integer matrix grid, return the minimum sum of a falling path with non-zero shifts. A falling path with non-zero shifts is a choice of exactly one element from each row of grid such that no two elements chosen in adjacent rows are in the same column. Example 1: Input: grid = [[1,2,3],[4,5,6],[7,8,9]] ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[3, 1, 1], [1, 2, 3], [2, 3, 4]]) == 5\n assert candidate(grid = [[10, 20, 30], [30, 20, 10], [10, 10, 10]]) == 30\n assert candidate(grid = [[7]]) == 7\n assert candidate(grid = [[3, 1, 1], [1, 7, 6], [2, 7, 7]]) == 9\n...
[ "[[1,2,3],[4,5,6],[7,8,9]]", "[[7]]" ]
[ "Use dynamic programming.", "Let dp[i][j] be the answer for the first i rows such that column j is chosen from row i.", "Use the concept of cumulative array to optimize the complexity of the solution." ]
{ "canonical_parameter_names": [ "grid" ], "leetcode_dataset_entry_point": "Solution().minFallingPathSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:40", "tests_total": 83, "test...
typescript
{ "raw_signature": "function minFallingPathSum(grid: number[][]): number {", "container": null, "callable": "minFallingPathSum", "parameters": [ { "name": "grid", "type": "number[][]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
1,291
sequential-digits
Medium
An integer has sequential digits if and only if each digit in the number is one more than the previous digit. Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits. Example 1: Input: low = 100, high = 300 Output: [123,234] Example 2: Input: low = 1000, high = 13000...
{ "language": "python", "source": "def check(candidate):\n assert candidate(low = 567,high = 6789) == [567, 678, 789, 1234, 2345, 3456, 4567, 5678, 6789]\n assert candidate(low = 500,high = 700) == [567, 678]\n assert candidate(low = 10,high = 100) == [12, 23, 34, 45, 56, 67, 78, 89]\n assert candidate(...
[ "100\n300", "1000\n13000" ]
[ "Generate all numbers with sequential digits and check if they are in the given range.", "Fix the starting digit then do a recursion that tries to append all valid digits." ]
{ "canonical_parameter_names": [ "low", "high" ], "leetcode_dataset_entry_point": "Solution().sequentialDigits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:45", "tests_total": 8...
typescript
{ "raw_signature": "function sequentialDigits(low: number, high: number): number[] {", "container": null, "callable": "sequentialDigits", "parameters": [ { "name": "low", "type": "number" }, { "name": "high", "type": "number" } ], "return_type": "number[]", "signatu...
1,292
maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold
Medium
Given a m x n matrix mat and an integer threshold, return the maximum side-length of a square with a sum less than or equal to threshold or return 0 if there is no such square. Example 1: Input: mat = [[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], threshold = 4 Output: 2 Explanation: The maximum side length of sq...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],threshold = 10) == 3\n assert candidate(mat = [[1, 1, 3, 2, 4, 3, 2], [1, 1, 3, 2, 4, 3, 2], [1, 1, 3, 2, 4, 3, 2]],threshold = 4) == 2\n assert candidate(mat = [[2, 2,...
[ "[[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]]\n4", "[[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]]\n1" ]
[ "Store prefix sum of all grids in another 2D array.", "Try all possible solutions and if you cannot find one return 0.", "If x is a valid answer then any y < x is also valid answer. Use binary search to find answer." ]
{ "canonical_parameter_names": [ "mat", "threshold" ], "leetcode_dataset_entry_point": "Solution().maxSideLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:47", "tests_total":...
typescript
{ "raw_signature": "function maxSideLength(mat: number[][], threshold: number): number {", "container": null, "callable": "maxSideLength", "parameters": [ { "name": "mat", "type": "number[][]" }, { "name": "threshold", "type": "number" } ], "return_type": "number", ...
1,293
shortest-path-in-a-grid-with-obstacles-elimination
Hard
You are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an empty cell in one step. Return the minimum number of steps to walk from the upper left corner (0, 0) to the lower right corner (m - 1, n - 1) given that you can eliminate...
{ "language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 1, 0, 0, 0, 1, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 1, 0, 0, 0, 0]],k = 2) == 9\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 0, 0], [0, 1, 1, 0]],k = 2) == 6\n assert candidate(grid = [[0, 0, 0], ...
[ "[[0,0,0],[1,1,0],[0,0,0],[0,1,1],[0,0,0]]\n1", "[[0,1,1],[1,1,1],[1,0,0]]\n1" ]
[ "Use BFS.", "BFS on (x,y,r) x,y is coordinate, r is remain number of obstacles you can remove." ]
{ "canonical_parameter_names": [ "grid", "k" ], "leetcode_dataset_entry_point": "Solution().shortestPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:50", "tests_total": 75, "...
typescript
{ "raw_signature": "function shortestPath(grid: number[][], k: number): number {", "container": null, "callable": "shortestPath", "parameters": [ { "name": "grid", "type": "number[][]" }, { "name": "k", "type": "number" } ], "return_type": "number", "signature_sourc...
1,295
find-numbers-with-even-number-of-digits
Easy
Given an array nums of integers, return how many of them contain an even number of digits. Example 1: Input: nums = [12,345,2,6,7896] Output: 2 Explanation: 12 contains 2 digits (even number of digits). 345 contains 3 digits (odd number of digits). 2 contains 1 digit (odd number of digits). 6 contains 1 digit (odd nu...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 100, 1000, 10000, 100000]) == 3\n assert candidate(nums = [10, 100, 1000, 10000]) == 2\n assert candidate(nums = [10, 22, 333, 4444, 55555]) == 3\n assert candidate(nums = [100000, 10000, 1000, 100, 10]) == 3\n as...
[ "[12,345,2,6,7896]", "[555,901,482,1771]" ]
[ "How to compute the number of digits of a number ?", "Divide the number by 10 again and again to get the number of digits." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().findNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:52", "tests_total": 110, "tests_dro...
typescript
{ "raw_signature": "function findNumbers(nums: number[]): number {", "container": null, "callable": "findNumbers", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,296
divide-array-in-sets-of-k-consecutive-numbers
Medium
Given an array of integers nums and a positive integer k, check whether it is possible to divide this array into sets of k consecutive numbers. Return true if it is possible. Otherwise, return false. Example 1: Input: nums = [1,2,3,3,4,4,5,6], k = 4 Output: true Explanation: Array can be divided into [1,2,3,4] and [...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 3, 4, 4, 5, 6],k = 4) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5],k = 2) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 4) == True\n assert candidate(nums = [1, ...
[ "[1,2,3,3,4,4,5,6]\n4", "[3,2,1,2,3,4,3,4,5,9,10,11]\n3", "[3,3,2,2,1,1]\n3" ]
[ "If the smallest number in the possible-to-split array is V, then numbers V+1, V+2, ... V+k-1 must contain there as well.", "You can iteratively find k sets and remove them from array until it becomes empty.", "Failure to do so would mean that array is unsplittable." ]
{ "canonical_parameter_names": [ "nums", "k" ], "leetcode_dataset_entry_point": "Solution().isPossibleDivide", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:15:54", "tests_total": 90,...
typescript
{ "raw_signature": "function isPossibleDivide(nums: number[], k: number): boolean {", "container": null, "callable": "isPossibleDivide", "parameters": [ { "name": "nums", "type": "number[]" }, { "name": "k", "type": "number" } ], "return_type": "boolean", "signature...
1,297
maximum-number-of-occurrences-of-a-substring
Medium
Given a string s, return the maximum number of occurrences of any substring under the following rules: - The number of unique characters in the substring must be less than or equal to maxLetters. - The substring size must be between minSize and maxSize inclusive. Example 1: Input: s = "aababcaab", maxLetters = 2, mi...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"aaaa\",maxLetters = 1,minSize = 3,maxSize = 3) == 2\n assert candidate(s = \"abacabadabacaba\",maxLetters = 3,minSize = 3,maxSize = 5) == 4\n assert candidate(s = \"xyzxyzxyz\",maxLetters = 3,minSize = 3,maxSize = 3) == 3\n ...
[ "\"aababcaab\"\n2\n3\n4", "\"aaaa\"\n1\n3\n3" ]
[ "Check out the constraints, (maxSize <=26).", "This means you can explore all substrings in O(n * 26).", "Find the Maximum Number of Occurrences of a Substring with bruteforce." ]
{ "canonical_parameter_names": [ "s", "maxLetters", "minSize", "maxSize" ], "leetcode_dataset_entry_point": "Solution().maxFreq", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:1...
typescript
{ "raw_signature": "function maxFreq(s: string, maxLetters: number, minSize: number, maxSize: number): number {", "container": null, "callable": "maxFreq", "parameters": [ { "name": "s", "type": "string" }, { "name": "maxLetters", "type": "number" }, { "name": "...
1,298
maximum-candies-you-can-get-from-boxes
Hard
You have n boxes labeled from 0 to n - 1. You are given four arrays: status, candies, keys, and containedBoxes where: - status[i] is 1 if the i^th box is open and 0 if the i^th box is closed, - candies[i] is the number of candies in the i^th box, - keys[i] is a list of the labels of the boxes you can open after openin...
{ "language": "python", "source": "def check(candidate):\n assert candidate(status = [0, 0, 0],candies = [100, 200, 300],keys = [[1, 2], [0, 2], [0, 1]],containedBoxes = [[1, 2], [0, 2], [0, 1]],initialBoxes = [0]) == 0\n assert candidate(status = [0, 0, 0],candies = [10, 20, 30],keys = [[1], [2], []],contain...
[ "[1,0,1,0]\n[7,5,4,100]\n[[],[],[1],[]]\n[[1,2],[3],[],[]]\n[0]", "[1,0,0,0,0,0]\n[1,1,1,1,1,1]\n[[1,2,3,4,5],[],[],[],[],[]]\n[[1,2,3,4,5],[],[],[],[],[]]\n[0]" ]
[ "Use Breadth First Search (BFS) to traverse all possible boxes you can open. Only push to the queue the boxes the you have with their keys." ]
{ "canonical_parameter_names": [ "status", "candies", "keys", "containedBoxes", "initialBoxes" ], "leetcode_dataset_entry_point": "Solution().maxCandies", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "...
typescript
{ "raw_signature": "function maxCandies(status: number[], candies: number[], keys: number[][], containedBoxes: number[][], initialBoxes: number[]): number {", "container": null, "callable": "maxCandies", "parameters": [ { "name": "status", "type": "number[]" }, { "name": "candies",...
1,299
replace-elements-with-greatest-element-on-right-side
Easy
Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array. Example 1: Input: arr = [17,18,5,4,6,1] Output: [18,6,6,6,1,-1] Explanation: - index 0 --> the greatest element to the right of in...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, -1]\n assert candidate(arr = [5, 4, 3, 2, 1]) == [4, 3, 2, 1, -1]\n assert candidate(arr = [1, 2, 3, 4, 5]) == [5, 5, 5, 5, -1]\n assert candidate(ar...
[ "[17,18,5,4,6,1]", "[400]" ]
[ "Loop through the array starting from the end.", "Keep the maximum value seen so far." ]
{ "canonical_parameter_names": [ "arr" ], "leetcode_dataset_entry_point": "Solution().replaceElements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:01", "tests_total": 104, "tests_...
typescript
{ "raw_signature": "function replaceElements(arr: number[]): number[] {", "container": null, "callable": "replaceElements", "parameters": [ { "name": "arr", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSn...
1,300
sum-of-mutated-array-closest-to-target
Medium
Given an integer array arr and a target value target, return the integer value such that when we change all the integers larger than value in the given array to be equal to value, the sum of the array gets as close as possible (in absolute difference) to target. In case of a tie, return the minimum such integer. Noti...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5],target = 11) == 3\n assert candidate(arr = [5, 5, 5, 5, 5],target = 17) == 3\n assert candidate(arr = [10, 20, 30, 40, 50],target = 100) == 23\n assert candidate(arr = [2, 3, 5],target = 10) == 5\n asser...
[ "[4,9,3]\n10", "[2,3,5]\n10", "[60864,25176,27249,21296,20204]\n56803" ]
[ "If you draw a graph with the value on one axis and the absolute difference between the target and the array sum, what will you get?", "That graph is uni-modal.", "Use ternary search on that graph to find the best value." ]
{ "canonical_parameter_names": [ "arr", "target" ], "leetcode_dataset_entry_point": "Solution().findBestValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:03", "tests_total": 11...
typescript
{ "raw_signature": "function findBestValue(arr: number[], target: number): number {", "container": null, "callable": "findBestValue", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "target", "type": "number" } ], "return_type": "number", "signature...
1,301
number-of-paths-with-max-score
Hard
You are given a square board of characters. You can move on the board starting at the bottom right square marked with the character 'S'. You need to reach the top left square marked with the character 'E'. The rest of the squares are labeled either with a numeric character 1, 2, ..., 9 or with an obstacle 'X'. In one ...
{ "language": "python", "source": "def check(candidate):\n assert candidate(board = ['E11', 'XXX', '11S']) == [0, 0]\n assert candidate(board = ['EX', 'XS']) == [0, 1]\n assert candidate(board = ['E111', '1X11', '1111', '111S']) == [5, 8]\n assert candidate(board = ['E22', '222', '22S']) == [6, 6]\n ...
[ "[\"E3283\",\"47715\",\"31479\",\"X1X32\",\"721XS\"]", "[\"E8X84\",\"98635\",\"24233\",\"X64X3\",\"281XS\"]", "[\"E3231\",\"3X588\",\"X2715\",\"94342\",\"6X82S\"]" ]
[ "Use dynamic programming to find the path with the max score.", "Use another dynamic programming array to count the number of paths with max score." ]
{ "canonical_parameter_names": [ "board" ], "leetcode_dataset_entry_point": "Solution().pathsWithMaxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:05", "tests_total": 95, "tes...
typescript
{ "raw_signature": "function pathsWithMaxScore(board: string[]): number[] {", "container": null, "callable": "pathsWithMaxScore", "parameters": [ { "name": "board", "type": "string[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcod...
1,304
find-n-unique-integers-sum-up-to-zero
Easy
Given an integer n, return any array containing n unique integers such that they add up to 0. Example 1: Input: n = 5 Output: [-7,-1,1,3,4] Explanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4]. Example 2: Input: n = 3 Output: [-1,0,1] Example 3: Input: n = 1 Output: [0] Constraints: - 1 <=...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == [1, -1, 0]\n assert candidate(n = 100) == [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15, 16, -16, 17, -17, 18, -18, 19, -19, 20, -20, 21, -21, 22, -22, 2...
[ "5", "3", "1" ]
[ "Return an array where the values are symmetric. (+x , -x).", "If n is odd, append value 0 in your returned array." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().sumZero", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:10", "tests_total": 60, "tests_dropped": 0...
typescript
{ "raw_signature": "function sumZero(n: number): number[] {", "container": null, "callable": "sumZero", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,306
jump-game-iii
Medium
Given an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + arr[i] or i - arr[i], check if you can reach any index with value 0. Notice that you can not jump outside of the array at any time. Example 1: Input: arr = [4,2,3,0,3,1,...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [5, 0, 5, 0, 5, 0],start = 1) == True\n assert candidate(arr = [5, 0, 0, 0, 0, 0],start = 0) == True\n assert candidate(arr = [4, 2, 3, 0, 3, 1, 2],start = 0) == True\n assert candidate(arr = [0, 1, 0, 1, 0, 1, 0],start = ...
[ "[4,2,3,0,3,1,2]\n5", "[4,2,3,0,3,1,2]\n0", "[3,0,2,1,2]\n2" ]
[ "Think of BFS to solve the problem.", "When you reach a position with a value = 0 then return true." ]
{ "canonical_parameter_names": [ "arr", "start" ], "leetcode_dataset_entry_point": "Solution().canReach", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:14", "tests_total": 111, "...
typescript
{ "raw_signature": "function canReach(arr: number[], start: number): boolean {", "container": null, "callable": "canReach", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "start", "type": "number" } ], "return_type": "boolean", "signature_source": ...
1,307
verbal-arithmetic-puzzle
Hard
Given an equation, represented by words on the left side and the result on the right side. You need to check if the equation is solvable under the following rules: - Each character is decoded as one digit (0 - 9). - No two characters can map to the same digit. - Each words[i] and result are decoded as one number with...
{ "language": "python", "source": "def check(candidate):\n assert candidate(words = ['SEND', 'MORE'],result = \"MONEY\") == True\n assert candidate(words = ['A', 'A', 'A', 'A'],result = \"AA\") == False\n assert candidate(words = ['LEET', 'CODE'],result = \"POINT\") == False\n assert candidate(words = [...
[ "[\"SEND\",\"MORE\"]\n\"MONEY\"", "[\"SIX\",\"SEVEN\",\"SEVEN\"]\n\"TWENTY\"", "[\"LEET\",\"CODE\"]\n\"POINT\"" ]
[ "Use Backtracking and pruning to solve this problem.", "If you set the values of some digits (from right to left), the other digits will be constrained." ]
{ "canonical_parameter_names": [ "words", "result" ], "leetcode_dataset_entry_point": "Solution().isSolvable", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:16", "tests_total": 148...
typescript
{ "raw_signature": "function isSolvable(words: string[], result: string): boolean {", "container": null, "callable": "isSolvable", "parameters": [ { "name": "words", "type": "string[]" }, { "name": "result", "type": "string" } ], "return_type": "boolean", "signature...
1,309
decrypt-string-from-alphabet-to-integer-mapping
Easy
You are given a string s formed by digits and '#'. We want to map s to English lowercase characters as follows: - Characters ('a' to 'i') are represented by ('1' to '9') respectively. - Characters ('j' to 'z') are represented by ('10#' to '26#') respectively. Return the string formed after mapping. The test cases ar...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"11#11#11#11#11#11#11#11#11#11#\") == \"kkkkkkkkkk\"\n assert candidate(s = \"12345678910#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"26#25#24#23#22#21#\") == ...
[ "\"10#11#12\"", "\"1326#\"" ]
[ "Scan from right to left, in each step of the scanning check whether there is a trailing \"#\" 2 indexes away." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().freqAlphabets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:19", "tests_total": 43, "tests_dropp...
typescript
{ "raw_signature": "function freqAlphabets(s: string): string {", "container": null, "callable": "freqAlphabets", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "string", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,310
xor-queries-of-a-subarray
Medium
You are given an array arr of positive integers. You are also given the array queries where queries[i] = [left_i,right_i]. For each query i compute the XOR of elements from left_i to right_i (that is, arr[left_i] XOR arr[left_i + 1] XOR ... XOR arr[right_i] ). Return an array answer where answer[i] is the answer to t...
{ "language": "python", "source": "def check(candidate):\n assert candidate(arr = [4, 8, 2, 10],queries = [[2, 3], [1, 3], [0, 0], [0, 3]]) == [8, 0, 4, 4]\n assert candidate(arr = [10, 5, 2, 3, 15],queries = [[0, 4], [1, 2], [2, 3], [0, 1], [3, 4]]) == [1, 7, 1, 15, 12]\n assert candidate(arr = [5, 2, 3, ...
[ "[1,3,4,8]\n[[0,1],[1,2],[0,3],[3,3]]", "[4,8,2,10]\n[[2,3],[1,3],[0,0],[0,3]]" ]
[ "What is the result of x ^ y ^ x ?", "Compute the prefix sum for XOR.", "Process the queries with the prefix sum values." ]
{ "canonical_parameter_names": [ "arr", "queries" ], "leetcode_dataset_entry_point": "Solution().xorQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:21", "tests_total": 77, ...
typescript
{ "raw_signature": "function xorQueries(arr: number[], queries: number[][]): number[] {", "container": null, "callable": "xorQueries", "parameters": [ { "name": "arr", "type": "number[]" }, { "name": "queries", "type": "number[][]" } ], "return_type": "number[]", "s...
1,311
get-watched-videos-by-your-friends
Medium
There are n people, each person has a unique id between 0 and n-1. Given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] contain the list of watched videos and the list of friends respectively for the person with id = i. Level 1 of videos are all watched videos by your friends, level 2 of v...
{ "language": "python", "source": "def check(candidate):\n assert candidate(watchedVideos = [['Action', 'Comedy'], ['Action'], ['Comedy', 'Drama'], ['Drama']],friends = [[1, 2], [0, 3], [0, 3], [1, 2]],id = 3,level = 1) == ['Action', 'Comedy', 'Drama']\n assert candidate(watchedVideos = [['X', 'Y'], ['Y', 'Z'...
[ "[[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]]\n[[1,2],[0,3],[0,3],[1,2]]\n0\n1", "[[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]]\n[[1,2],[0,3],[0,3],[1,2]]\n0\n2" ]
[ "Do BFS to find the kth level friends.", "Then collect movies saw by kth level friends and sort them accordingly." ]
{ "canonical_parameter_names": [ "watchedVideos", "friends", "id", "level" ], "leetcode_dataset_entry_point": "Solution().watchedVideosByFriends", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at":...
typescript
{ "raw_signature": "function watchedVideosByFriends(watchedVideos: string[][], friends: number[][], id: number, level: number): string[] {", "container": null, "callable": "watchedVideosByFriends", "parameters": [ { "name": "watchedVideos", "type": "string[][]" }, { "name": "friend...
1,312
minimum-insertion-steps-to-make-a-string-palindrome
Hard
Given a string s. In one step you can insert any character at any index of the string. Return the minimum number of steps to make s palindrome. A Palindrome String is one that reads the same backward as well as forward. Example 1: Input: s = "zzazz" Output: 0 Explanation: The string "zzazz" is already palindrome we...
{ "language": "python", "source": "def check(candidate):\n assert candidate(s = \"race\") == 3\n assert candidate(s = \"noon\") == 0\n assert candidate(s = \"abcba\") == 0\n assert candidate(s = \"abcdef\") == 5\n assert candidate(s = \"zzazz\") == 0\n assert candidate(s = \"google\") == 2\n as...
[ "\"zzazz\"", "\"mbadm\"", "\"leetcode\"" ]
[ "Is dynamic programming suitable for this problem ?", "If we know the longest palindromic sub-sequence is x and the length of the string is n then, what is the answer to this problem? It is n - x as we need n - x insertions to make the remaining characters also palindrome." ]
{ "canonical_parameter_names": [ "s" ], "leetcode_dataset_entry_point": "Solution().minInsertions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:26", "tests_total": 123, "tests_drop...
typescript
{ "raw_signature": "function minInsertions(s: string): number {", "container": null, "callable": "minInsertions", "parameters": [ { "name": "s", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets" }
1,313
decompress-run-length-encoded-list
Easy
We are given a list nums of integers representing a list compressed with run-length encoding. Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0). For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to rig...
{ "language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 9, 2, 8, 3, 7]) == [9, 8, 8, 7, 7, 7]\n assert candidate(nums = [3, 1, 2, 2]) == [1, 1, 1, 2, 2]\n assert candidate(nums = [2, 5, 3, 1]) == [5, 5, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4]) == [2, 4, 4, 4]\n ...
[ "[1,2,3,4]", "[1,1,2,3]" ]
[ "Decompress the given array by repeating nums[2*i+1] a number of times equal to nums[2*i]." ]
{ "canonical_parameter_names": [ "nums" ], "leetcode_dataset_entry_point": "Solution().decompressRLElist", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:28", "tests_total": 86, "test...
typescript
{ "raw_signature": "function decompressRLElist(nums: number[]): number[] {", "container": null, "callable": "decompressRLElist", "parameters": [ { "name": "nums", "type": "number[]" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/...
1,314
matrix-block-sum
Medium
Given a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for: - i - k <= r <= i + k, - j - k <= c <= j + k, and - (r, c) is a valid position in the matrix. Example 1: Input: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1 Output: [[12,21,16],[27,45,33],[24...
{ "language": "python", "source": "def check(candidate):\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],k = 2) == [[45, 45, 45], [45, 45, 45], [45, 45, 45]]\n assert candidate(mat = [[1, 2], [3, 4]],k = 1) == [[10, 10], [10, 10]]\n assert candidate(mat = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],k = 1)...
[ "[[1,2,3],[4,5,6],[7,8,9]]\n1", "[[1,2,3],[4,5,6],[7,8,9]]\n2" ]
[ "How to calculate the required sum for a cell (i,j) fast ?", "Use the concept of cumulative sum array.", "Create a cumulative sum matrix where dp[i][j] is the sum of all cells in the rectangle from (0,0) to (i,j), use inclusion-exclusion idea." ]
{ "canonical_parameter_names": [ "mat", "k" ], "leetcode_dataset_entry_point": "Solution().matrixBlockSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:30", "tests_total": 88, ...
typescript
{ "raw_signature": "function matrixBlockSum(mat: number[][], k: number): number[][] {", "container": null, "callable": "matrixBlockSum", "parameters": [ { "name": "mat", "type": "number[][]" }, { "name": "k", "type": "number" } ], "return_type": "number[][]", "signa...
1,316
distinct-echo-substrings
Hard
Return the number of distinct non-empty substrings of text that can be written as the concatenation of some string with itself (i.e. it can be written as a + a where a is some string). Example 1: Input: text = "abcabcabc" Output: 3 Explanation: The 3 substrings are "abcabc", "bcabca" and "cabcab". Example 2: Input:...
{ "language": "python", "source": "def check(candidate):\n assert candidate(text = \"ababab\") == 2\n assert candidate(text = \"abcabcabc\") == 3\n assert candidate(text = \"aaaa\") == 2\n assert candidate(text = \"ab\") == 0\n assert candidate(text = \"abbbabbb\") == 2\n assert candidate(text = \...
[ "\"abcabcabc\"", "\"leetcodeleetcode\"" ]
[ "Given a substring of the text, how to check if it can be written as the concatenation of a string with itself ?", "We can do that in linear time, a faster way is to use hashing.", "Try all substrings and use hashing to check them." ]
{ "canonical_parameter_names": [ "text" ], "leetcode_dataset_entry_point": "Solution().distinctEchoSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:35", "tests_total": 98, ...
typescript
{ "raw_signature": "function distinctEchoSubstrings(text: string): number {", "container": null, "callable": "distinctEchoSubstrings", "parameters": [ { "name": "text", "type": "string" } ], "return_type": "number", "signature_source": "leetcode/codeSnippets", "type_source": "leetcod...
1,317
convert-integer-to-the-sum-of-two-no-zero-integers
Easy
No-Zero integer is a positive integer that does not contain any 0 in its decimal representation. Given an integer n, return a list of two integers [a, b] where: - a and b are No-Zero integers. - a + b = n The test cases are generated so that there is at least one valid solution. If there are many valid solutions, yo...
{ "language": "python", "source": "def check(candidate):\n assert candidate(n = 101) == [2, 99]\n assert candidate(n = 1010) == [11, 999]\n assert candidate(n = 11) == [2, 9]\n assert candidate(n = 104) == [5, 99]\n assert candidate(n = 1001) == [2, 999]\n assert candidate(n = 2) == [1, 1]\n as...
[ "19", "139" ]
[ "Loop through all elements from 1 to n.", "Choose A = i and B = n - i then check if A and B are both No-Zero integers." ]
{ "canonical_parameter_names": [ "n" ], "leetcode_dataset_entry_point": "Solution().getNoZeroIntegers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:37", "tests_total": 115, "tests_...
typescript
{ "raw_signature": "function getNoZeroIntegers(n: number): number[] {", "container": null, "callable": "getNoZeroIntegers", "parameters": [ { "name": "n", "type": "number" } ], "return_type": "number[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippe...
1,318
minimum-flips-to-make-a-or-b-equal-to-c
Medium
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation. Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation:...
{ "language": "python", "source": "def check(candidate):\n assert candidate(a = 10,b = 15,c = 25) == 4\n assert candidate(a = 2,b = 6,c = 5) == 3\n assert candidate(a = 1,b = 2,c = 3) == 0\n assert candidate(a = 8,b = 3,c = 11) == 0\n assert candidate(a = 4,b = 2,c = 7) == 1\n assert candidate(a =...
[ "2\n6\n5", "4\n2\n7", "1\n2\n3" ]
[ "Check the bits one by one whether they need to be flipped." ]
{ "canonical_parameter_names": [ "a", "b", "c" ], "leetcode_dataset_entry_point": "Solution().minFlips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:16:39", "tests_total": 92, ...
typescript
{ "raw_signature": "function minFlips(a: number, b: number, c: number): number {", "container": null, "callable": "minFlips", "parameters": [ { "name": "a", "type": "number" }, { "name": "b", "type": "number" }, { "name": "c", "type": "number" } ], ...