task_id stringlengths 3 79 | prompt stringlengths 255 3.9k |
|---|---|
license-key-formatting | def licenseKeyFormatting(s: str, k: int) -> str:
"""
You are given a license key represented as a string s that consists of only alphanumeric characters and dashes. The string is separated into n + 1 groups by n dashes. You are also given an integer k.
We want to reformat the string s such that each group c... |
smallest-good-base | def smallestGoodBase(n: str) -> str:
"""
Given an integer n represented as a string, return the smallest good base of n.
We call k >= 2 a good base of n, if all digits of n base k are 1's.
Example 1:
>>> smallestGoodBase(n = "13")
>>> "3"
Explanation: 13 base 3 is 111.
Exa... |
find-permutation | def findPermutation(s: str) -> List[int]:
"""
A permutation perm of n integers of all the integers in the range [1, n] can be represented as a string s of length n - 1 where:
s[i] == 'I' if perm[i] < perm[i + 1], and
s[i] == 'D' if perm[i] > perm[i + 1].
Given a string s, reconstruct the l... |
max-consecutive-ones | def findMaxConsecutiveOnes(nums: List[int]) -> int:
"""
Given a binary array nums, return the maximum number of consecutive 1's in the array.
Example 1:
>>> findMaxConsecutiveOnes(nums = [1,1,0,1,1,1])
>>> 3
Explanation: The first two digits or the last three digits are consecutive 1s.... |
predict-the-winner | def predictTheWinner(nums: List[int]) -> bool:
"""
You are given an integer array nums. Two players are playing a game with this array: player 1 and player 2.
Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of 0. At each turn, the player takes one of ... |
max-consecutive-ones-ii | def findMaxConsecutiveOnes(nums: List[int]) -> int:
"""
Given a binary array nums, return the maximum number of consecutive 1's in the array if you can flip at most one 0.
Example 1:
>>> findMaxConsecutiveOnes(nums = [1,0,1,1,0])
>>> 4
Explanation:
- If we flip the first zero, nums... |
zuma-game | def findMinStep(board: str, hand: str) -> int:
"""
You are playing a variation of the game Zuma.
In this variation of Zuma, there is a single row of colored balls on a board, where each ball can be colored red 'R', yellow 'Y', blue 'B', green 'G', or white 'W'. You also have several colored balls in your ha... |
the-maze | def hasPath(maze: List[List[int]], start: List[int], destination: List[int]) -> bool:
"""
There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When... |
non-decreasing-subsequences | def findSubsequences(nums: List[int]) -> List[List[int]]:
"""
Given an integer array nums, return all the different possible non-decreasing subsequences of the given array with at least two elements. You may return the answer in any order.
Example 1:
>>> findSubsequences(nums = [4,6,7,7])
... |
construct-the-rectangle | def constructRectangle(area: int) -> List[int]:
"""
A web developer needs to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:
The area of the rectan... |
reverse-pairs | def reversePairs(nums: List[int]) -> int:
"""
Given an integer array nums, return the number of reverse pairs in the array.
A reverse pair is a pair (i, j) where:
0 <= i < j < nums.length and
nums[i] > 2 * nums[j].
Example 1:
>>> reversePairs(nums = [1,3,2,3,1])
>>> 2... |
target-sum | def findTargetSumWays(nums: List[int], target: int) -> int:
"""
You are given an integer array nums and an integer target.
You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers.
For example, if nums = [... |
teemo-attacking | def findPoisonedDuration(timeSeries: List[int], duration: int) -> int:
"""
Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval... |
next-greater-element-i | def nextGreaterElement(nums1: List[int], nums2: List[int]) -> List[int]:
"""
The next greater element of some element x in an array is the first greater element that is to the right of x in the same array.
You are given two distinct 0-indexed integer arrays nums1 and nums2, where nums1 is a subset of nums2.... |
diagonal-traverse | def findDiagonalOrder(mat: List[List[int]]) -> List[int]:
"""
Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order.
Example 1:
>>> findDiagonalOrder(mat = [[1,2,3],[4,5,6],[7,8,9]])
>>> [1,2,4,7,5,3,6,8,9]
Example 2:
>>> fin... |
the-maze-iii | def findShortestWay(maze: List[List[int]], ball: List[int], hole: List[int]) -> str:
"""
There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When ... |
keyboard-row | def findWords(words: List[str]) -> List[str]:
"""
Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.
Note that the strings are case-insensitive, both lowercased and uppercased of the same letter are tre... |
find-mode-in-binary-search-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def findMode(root: Optional[TreeNode]) -> List[int]:
"""
Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (... |
ipo | def findMaximizedCapital(k: int, w: int, profits: List[int], capital: List[int]) -> int:
"""
Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the IPO. Since it has limited resourc... |
next-greater-element-ii | def nextGreaterElements(nums: List[int]) -> List[int]:
"""
Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums.
The next greater number of a number x is the first greater number to its traversing-order nex... |
base-7 | def convertToBase7(num: int) -> str:
"""
Given an integer num, return a string of its base 7 representation.
Example 1:
>>> convertToBase7(num = 100)
>>> "202"
Example 2:
>>> convertToBase7(num = -7)
>>> "-10"
"""
|
the-maze-ii | def shortestDistance(maze: List[List[int]], start: List[int], destination: List[int]) -> int:
"""
There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wa... |
relative-ranks | def findRelativeRanks(score: List[int]) -> List[str]:
"""
You are given an integer array score of size n, where score[i] is the score of the ith athlete in a competition. All the scores are guaranteed to be unique.
The athletes are placed based on their scores, where the 1st place athlete has the highest sc... |
perfect-number | def checkPerfectNumber(num: int) -> bool:
"""
A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly.
Given an integer n, return true if n is a perfect number, otherwise return fa... |
most-frequent-subtree-sum | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def findFrequentTreeSum(root: Optional[TreeNode]) -> List[int]:
"""
Given the root of a binary tree, return the most frequent subtree sum. If t... |
fibonacci-number | def fib(n: int) -> int:
"""
The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
Given n, calculate ... |
find-bottom-left-tree-value | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def findBottomLeftValue(root: Optional[TreeNode]) -> int:
"""
Given the root of a binary tree, return the leftmost value in the last row of the... |
freedom-trail | def findRotateSteps(ring: str, key: str) -> int:
"""
In the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal dial called the "Freedom Trail Ring" and use the dial to spell a specific keyword to open the door.
Given a string ring that represents the code engraved on the out... |
find-largest-value-in-each-tree-row | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def largestValues(root: Optional[TreeNode]) -> List[int]:
"""
Given the root of a binary tree, return an array of the largest value in each row... |
longest-palindromic-subsequence | def longestPalindromeSubseq(s: str) -> int:
"""
Given a string s, find the longest palindromic subsequence's length in s.
A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
Example 1:
>... |
super-washing-machines | def findMinMoves(machines: List[int]) -> int:
"""
You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty.
For each move, you could choose any m (1 <= m <= n) washing machines, and pass one dress of each washing machine to one of its adjacent washing machine... |
coin-change-ii | def change(amount: int, coins: List[int]) -> int:
"""
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.
Return the number of combinations that make up that amount. If that amount of money cannot be made up by any co... |
detect-capital | def detectCapitalUse(word: str) -> bool:
"""
We define the usage of capitals in a word to be right when one of the following cases holds:
All letters in this word are capitals, like "USA".
All letters in this word are not capitals, like "leetcode".
Only the first letter in this word is capital,... |
longest-uncommon-subsequence-i | def findLUSlength(a: str, b: str) -> int:
"""
Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If no such uncommon subsequence exists, return -1.
An uncommon subsequence between two strings is a string that is a subsequence of exactly one of them.
Ex... |
longest-uncommon-subsequence-ii | def findLUSlength(strs: List[str]) -> int:
"""
Given an array of strings strs, return the length of the longest uncommon subsequence between them. If the longest uncommon subsequence does not exist, return -1.
An uncommon subsequence between an array of strings is a string that is a subsequence of one strin... |
continuous-subarray-sum | def checkSubarraySum(nums: List[int], k: int) -> bool:
"""
Given an integer array nums and an integer k, return true if nums has a good subarray or false otherwise.
A good subarray is a subarray where:
its length is at least two, and
the sum of the elements of the subarray is a multiple of k.
... |
longest-word-in-dictionary-through-deleting | def findLongestWord(s: str, dictionary: List[str]) -> str:
"""
Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the longest word with the smallest lexi... |
contiguous-array | def findMaxLength(nums: List[int]) -> int:
"""
Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.
Example 1:
>>> findMaxLength(nums = [0,1])
>>> 2
Explanation: [0, 1] is the longest contiguous subarray with an equal number of ... |
beautiful-arrangement | def countArrangement(n: int) -> int:
"""
Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i <= n), either of the following is true:
perm[i] is divisible by i.
i is divisible by perm[i].
... |
word-abbreviation | def wordsAbbreviation(words: List[str]) -> List[str]:
"""
Given an array of distinct strings words, return the minimal possible abbreviations for every word.
The following are the rules for a string abbreviation:
The initial abbreviation for each word is: the first character, then the number of cha... |
minesweeper | def updateBoard(board: List[List[str]], click: List[int]) -> List[List[str]]:
"""
Let's play the minesweeper game (Wikipedia, online game)!
You are given an m x n char matrix board representing the game board where:
'M' represents an unrevealed mine,
'E' represents an unrevealed empty square,
... |
minimum-absolute-difference-in-bst | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def getMinimumDifference(root: Optional[TreeNode]) -> int:
"""
Given the root of a Binary Search Tree (BST), return the minimum absolute differ... |
lonely-pixel-i | def findLonelyPixel(picture: List[List[str]]) -> int:
"""
Given an m x n picture consisting of black 'B' and white 'W' pixels, return the number of black lonely pixels.
A black lonely pixel is a character 'B' that located at a specific position where the same row and same column don't have any other black p... |
k-diff-pairs-in-an-array | def findPairs(nums: List[int], k: int) -> int:
"""
Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.
A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true:
0 <= i, j < nums.length
i != j
|nums[i] - nums[j]| =... |
lonely-pixel-ii | def findBlackPixel(picture: List[List[str]], target: int) -> int:
"""
Given an m x n picture consisting of black 'B' and white 'W' pixels and an integer target, return the number of black lonely pixels.
A black lonely pixel is a character 'B' that located at a specific position (r, c) where:
Row r ... |
construct-binary-tree-from-string | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def str2tree(s: str) -> Optional[TreeNode]:
"""
You need to construct a binary tree from a string consisting of parenthesis and integers.
T... |
complex-number-multiplication | def complexNumberMultiply(num1: str, num2: str) -> str:
"""
A complex number can be represented as a string on the form "real+imaginaryi" where:
real is the real part and is an integer in the range [-100, 100].
imaginary is the imaginary part and is an integer in the range [-100, 100].
i2 == -1... |
convert-bst-to-greater-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def convertBST(root: Optional[TreeNode]) -> Optional[TreeNode]:
"""
Given the root of a Binary Search Tree (BST), convert it to a Greater Tree ... |
minimum-time-difference | def findMinDifference(timePoints: List[str]) -> int:
"""
Given a list of 24-hour clock time points in "HH:MM" format, return the minimum minutes difference between any two time-points in the list.
Example 1:
>>> findMinDifference(timePoints = ["23:59","00:00"])
>>> 1
Example 2:
>>> find... |
single-element-in-a-sorted-array | def singleNonDuplicate(nums: List[int]) -> int:
"""
You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.
Return the single element that appears only once.
Your solution must run in O(log n) time and O(1) sp... |
reverse-string-ii | def reverseStr(s: str, k: int) -> str:
"""
Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string.
If there are fewer than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, the... |
01-matrix | def updateMatrix(mat: List[List[int]]) -> List[List[int]]:
"""
Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.
The distance between two cells sharing a common edge is 1.
Example 1:
>>> updateMatrix(mat = [[0,0,0],[0,1,0],[0,0,0]])
>>> [[0,0,0]... |
diameter-of-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def diameterOfBinaryTree(root: Optional[TreeNode]) -> int:
"""
Given the root of a binary tree, return the length of the diameter of the tree.
... |
output-contest-matches | def findContestMatch(n: int) -> str:
"""
During the NBA playoffs, we always set the rather strong team to play with the rather weak team, like making the rank 1 team play with the rank nth team, which is a good strategy to make the contest more interesting.
Given n teams, return their final contest matches ... |
boundary-of-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def boundaryOfBinaryTree(root: Optional[TreeNode]) -> List[int]:
"""
The boundary of a binary tree is the concatenation of the root, the left b... |
remove-boxes | def removeBoxes(boxes: List[int]) -> int:
"""
You are given several boxes with different colors represented by different positive numbers.
You may experience several rounds to remove boxes until there is no box left. Each time you can choose some continuous boxes with the same color (i.e., composed of k box... |
number-of-provinces | def findCircleNum(isConnected: List[List[int]]) -> int:
"""
There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with city c, then city a is connected indirectly with city c.
A province is a group of directly or ind... |
split-array-with-equal-sum | def splitArray(nums: List[int]) -> bool:
"""
Given an integer array nums of length n, return true if there is a triplet (i, j, k) which satisfies the following conditions:
0 < i, i + 1 < j, j + 1 < k < n - 1
The sum of subarrays (0, i - 1), (i + 1, j - 1), (j + 1, k - 1) and (k + 1, n - 1) is equal... |
binary-tree-longest-consecutive-sequence-ii | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def longestConsecutive(root: Optional[TreeNode]) -> int:
"""
Given the root of a binary tree, return the length of the longest consecutive path... |
student-attendance-record-i | def checkRecord(s: str) -> bool:
"""
You are given a string s representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:
'A': Absent.
'L': Late.
'P': Presen... |
student-attendance-record-ii | def checkRecord(n: int) -> int:
"""
An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:
'A': Absent.
'L': Late.
'P': Present.
... |
optimal-division | def optimalDivision(nums: List[int]) -> str:
"""
You are given an integer array nums. The adjacent integers in nums will perform the float division.
For example, for nums = [2,3,4], we will evaluate the expression "2/3/4".
However, you can add any number of parenthesis at any position to chang... |
brick-wall | def leastBricks(wall: List[List[int]]) -> int:
"""
There is a rectangular brick wall in front of you with n rows of bricks. The ith row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row is the same.
Draw a vertical line from t... |
split-concatenated-strings | def splitLoopedString(strs: List[str]) -> str:
"""
You are given an array of strings strs. You could concatenate these strings together into a loop, where for each string, you could choose to reverse it or not. Among all the possible loops
Return the lexicographically largest string after cutting the loop, ... |
next-greater-element-iii | def nextGreaterElement(n: int) -> int:
"""
Given a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive integer exists, return -1.
Note that the returned integer should fit in 32-bit integer, if there is... |
reverse-words-in-a-string-iii | def reverseWords(s: str) -> str:
"""
Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
>>> reverseWords(s = "Let's take LeetCode contest")
>>> "s'teL ekat edoCteeL tsetnoc"
Example ... |
subarray-sum-equals-k | def subarraySum(nums: List[int], k: int) -> int:
"""
Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.
A subarray is a contiguous non-empty sequence of elements within an array.
Example 1:
>>> subarraySum(nums = [1,1,1], k = 2)
>>>... |
array-partition | def arrayPairSum(nums: List[int]) -> int:
"""
Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.
Example 1:
>>> arrayPairSum(nums = [1,4,3,2])
>>>... |
longest-line-of-consecutive-one-in-matrix | def longestLine(mat: List[List[int]]) -> int:
"""
Given an m x n binary matrix mat, return the length of the longest line of consecutive one in the matrix.
The line could be horizontal, vertical, diagonal, or anti-diagonal.
Example 1:
>>> longestLine(mat = [[0,1,1,0],[0,1,1,0],[0,0,0,... |
binary-tree-tilt | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def findTilt(root: Optional[TreeNode]) -> int:
"""
Given the root of a binary tree, return the sum of every tree node's tilt.
The tilt of a... |
find-the-closest-palindrome | def nearestPalindromic(n: str) -> str:
"""
Given a string n representing an integer, return the closest integer (not including itself), which is a palindrome. If there is a tie, return the smaller one.
The closest is defined as the absolute difference minimized between two integers.
Example 1:
... |
array-nesting | def arrayNesting(nums: List[int]) -> int:
"""
You are given an integer array nums of length n where nums is a permutation of the numbers in the range [0, n - 1].
You should build a set s[k] = {nums[k], nums[nums[k]], nums[nums[nums[k]]], ... } subjected to the following rule:
The first element in s... |
reshape-the-matrix | def matrixReshape(mat: List[List[int]], r: int, c: int) -> List[List[int]]:
"""
In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data.
You are given an m x n matrix mat and two integers r and c representing ... |
permutation-in-string | def checkInclusion(s1: str, s2: str) -> bool:
"""
Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.
In other words, return true if one of s1's permutations is the substring of s2.
Example 1:
>>> checkInclusion(s1 = "ab", s2 = "eidbaooo")
>... |
maximum-vacation-days | def maxVacationDays(flights: List[List[int]], days: List[List[int]]) -> int:
"""
LeetCode wants to give one of its best employees the option to travel among n cities to collect algorithm problems. But all work and no play makes Jack a dull boy, you could take vacations in some particular cities and weeks. Your ... |
subtree-of-another-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isSubtree(root: Optional[TreeNode], subRoot: Optional[TreeNode]) -> bool:
"""
Given the roots of two binary trees root and subRoot, return ... |
squirrel-simulation | def minDistance(height: int, width: int, tree: List[int], squirrel: List[int], nuts: List[List[int]]) -> int:
"""
You are given two integers height and width representing a garden of size height x width. You are also given:
an array tree where tree = [treer, treec] is the position of the tree in the ga... |
distribute-candies | def distributeCandies(candyType: List[int]) -> int:
"""
Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor.
The doctor advised Alice to only eat n / 2 of the candies she has (n is always even). Alice likes her candies very... |
out-of-boundary-paths | def findPaths(m: int, n: int, maxMove: int, startRow: int, startColumn: int) -> int:
"""
There is an m x n grid with a ball. The ball is initially at the position [startRow, startColumn]. You are allowed to move the ball to one of the four adjacent cells in the grid (possibly out of the grid crossing the grid b... |
shortest-unsorted-continuous-subarray | def findUnsortedSubarray(nums: List[int]) -> int:
"""
Given an integer array nums, you need to find one continuous subarray such that if you only sort this subarray in non-decreasing order, then the whole array will be sorted in non-decreasing order.
Return the shortest such subarray and output its length.
... |
kill-process | def killProcess(pid: List[int], ppid: List[int], kill: int) -> List[int]:
"""
You have n processes forming a rooted tree structure. You are given two integer arrays pid and ppid, where pid[i] is the ID of the ith process and ppid[i] is the ID of the ith process's parent process.
Each process has only one pa... |
delete-operation-for-two-strings | def minDistance(word1: str, word2: str) -> int:
"""
Given two strings word1 and word2, return the minimum number of steps required to make word1 and word2 the same.
In one step, you can delete exactly one character in either string.
Example 1:
>>> minDistance(word1 = "sea", word2 = "eat")
... |
erect-the-fence | def outerTrees(trees: List[List[int]]) -> List[List[int]]:
"""
You are given an array trees where trees[i] = [xi, yi] represents the location of a tree in the garden.
Fence the entire garden using the minimum length of rope, as it is expensive. The garden is well-fenced only if all the trees are enclosed.
... |
tag-validator | def isValid(code: str) -> bool:
"""
Given a string representing a code snippet, implement a tag validator to parse the code and return whether it is valid.
A code snippet is valid if all the following rules hold:
The code must be wrapped in a valid closed tag. Otherwise, the code is invalid.
A ... |
fraction-addition-and-subtraction | def fractionAddition(expression: str) -> str:
"""
Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format.
The final result should be an irreducible fraction. If your final result is an integer, change it to the format of a fr... |
valid-square | def validSquare(p1: List[int], p2: List[int], p3: List[int], p4: List[int]) -> bool:
"""
Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square.
The coordinate of a point pi is represented as [xi, yi]. The input is not given in any order.
A ... |
longest-harmonious-subsequence | def findLHS(nums: List[int]) -> int:
"""
We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.
Given an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences.
Example 1:
... |
range-addition-ii | def maxCount(m: int, n: int, ops: List[List[int]]) -> int:
"""
You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented by one for all 0 <= x < ai and 0 <= y < bi.
Count and return the number of maximum integers in t... |
minimum-index-sum-of-two-lists | def findRestaurant(list1: List[str], list2: List[str]) -> List[str]:
"""
Given two arrays of strings list1 and list2, find the common strings with the least index sum.
A common string is a string that appeared in both list1 and list2.
A common string with the least index sum is a common string such that... |
non-negative-integers-without-consecutive-ones | def findIntegers(n: int) -> int:
"""
Given a positive integer n, return the number of the integers in the range [0, n] whose binary representations do not contain consecutive ones.
Example 1:
>>> findIntegers(n = 5)
>>> 5
Explanation:
Here are the non-negative integers <= 5 with th... |
can-place-flowers | def canPlaceFlowers(flowerbed: List[int], n: int) -> bool:
"""
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.
Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an ... |
construct-string-from-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def tree2str(root: Optional[TreeNode]) -> str:
"""
Given the root node of a binary tree, your task is to create a string representation of the ... |
find-duplicate-file-in-system | def findDuplicate(paths: List[str]) -> List[List[str]]:
"""
Given a list paths of directory info, including the directory path, and all the files with contents in this directory, return all the duplicate files in the file system in terms of their paths. You may return the answer in any order.
A group of dup... |
valid-triangle-number | def triangleNumber(nums: List[int]) -> int:
"""
Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.
Example 1:
>>> triangleNumber(nums = [2,2,3,4])
>>> 3
Explanation: Valid combinations ... |
add-bold-tag-in-string | def addBoldTag(s: str, words: List[str]) -> str:
"""
You are given a string s and an array of strings words.
You should add a closed pair of bold tag and to wrap the substrings in s that exist in words.
If two such substrings overlap, you should wrap them together with only one pair of closed bol... |
merge-two-binary-trees | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def mergeTrees(root1: Optional[TreeNode], root2: Optional[TreeNode]) -> Optional[TreeNode]:
"""
You are given two binary trees root1 and root2.... |
task-scheduler | def leastInterval(tasks: List[str], n: int) -> int:
"""
You are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed in any order, but there's a constraint: there has to be a gap of at least... |
add-one-row-to-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def addOneRow(root: Optional[TreeNode], val: int, depth: int) -> Optional[TreeNode]:
"""
Given the root of a binary tree and two integers val a... |
maximum-distance-in-arrays | def maxDistance(arrays: List[List[int]]) -> int:
"""
You are given m arrays, where each array is sorted in ascending order.
You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute diffe... |
minimum-factorization | def smallestFactorization(num: int) -> int:
"""
Given a positive integer num, return the smallest positive integer x whose multiplication of each digit equals num. If there is no answer or the answer is not fit in 32-bit signed integer, return 0.
Example 1:
>>> smallestFactorization(num = 48)
>... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.