task_id stringlengths 3 79 | prompt stringlengths 255 3.9k |
|---|---|
maximum-product-of-three-numbers | def maximumProduct(nums: List[int]) -> int:
"""
Given an integer array nums, find three numbers whose product is maximum and return the maximum product.
Example 1:
>>> maximumProduct(nums = [1,2,3])
>>> 6
Example 2:
>>> maximumProduct(nums = [1,2,3,4])
>>> 24
Example 3:
>>> ... |
k-inverse-pairs-array | def kInversePairs(n: int, k: int) -> int:
"""
For an integer array nums, an inverse pair is a pair of integers [i, j] where 0 <= i < j < nums.length and nums[i] > nums[j].
Given two integers n and k, return the number of different arrays consisting of numbers from 1 to n such that there are exactly k invers... |
course-schedule-iii | def scheduleCourse(courses: List[List[int]]) -> int:
"""
There are n different online courses numbered from 1 to n. You are given an array courses where courses[i] = [durationi, lastDayi] indicate that the ith course should be taken continuously for durationi days and must be finished before or on lastDayi.
... |
smallest-range-covering-elements-from-k-lists | def smallestRange(nums: List[List[int]]) -> List[int]:
"""
You have k lists of sorted integers in non-decreasing order. Find the smallest range that includes at least one number from each of the k lists.
We define the range [a, b] is smaller than range [c, d] if b - a < d - c or a < c if b - a == d - c.
... |
sum-of-square-numbers | def judgeSquareSum(c: int) -> bool:
"""
Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.
Example 1:
>>> judgeSquareSum(c = 5)
>>> true
Explanation: 1 * 1 + 2 * 2 = 5
Example 2:
>>> judgeSquareSum(c = 3)
>>> false
... |
find-the-derangement-of-an-array | def findDerangement(n: int) -> int:
"""
In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position.
You are given an integer n. There is originally an array consisting of n integers from 1 to n in ascending order, return the n... |
exclusive-time-of-functions | def exclusiveTime(n: int, logs: List[str]) -> List[int]:
"""
On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1.
Function calls are stored in a call stack: when a function call starts, its ID is pushed onto the stack, and when a function ca... |
average-of-levels-in-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def averageOfLevels(root: Optional[TreeNode]) -> List[float]:
"""
Given the root of a binary tree, return the average value of the nodes on eac... |
shopping-offers | def shoppingOffers(price: List[int], special: List[List[int]], needs: List[int]) -> int:
"""
In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.
You are given an i... |
decode-ways-ii | def numDecodings(s: str) -> int:
"""
A message containing letters from A-Z can be encoded into numbers using the following mapping:
'A' -> "1"
'B' -> "2"
...
'Z' -> "26"
To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of ... |
solve-the-equation | def solveEquation(equation: str) -> str:
"""
Solve a given equation and return the value of 'x' in the form of a string "x=#value". The equation contains only '+', '-' operation, the variable 'x' and its coefficient. You should return "No solution" if there is no solution for the equation, or "Infinite solution... |
maximum-average-subarray-i | def findMaxAverage(nums: List[int], k: int) -> float:
"""
You are given an integer array nums consisting of n elements, and an integer k.
Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10-5 will be... |
maximum-average-subarray-ii | def findMaxAverage(nums: List[int], k: int) -> float:
"""
You are given an integer array nums consisting of n elements, and an integer k.
Find a contiguous subarray whose length is greater than or equal to k that has the maximum average value and return this value. Any answer with a calculation error less t... |
set-mismatch | def findErrorNums(nums: List[int]) -> List[int]:
"""
You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number.
... |
maximum-length-of-pair-chain | def findLongestChain(pairs: List[List[int]]) -> int:
"""
You are given an array of n pairs pairs where pairs[i] = [lefti, righti] and lefti < righti.
A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c. A chain of pairs can be formed in this fashion.
Return the length longest chain which can be forme... |
palindromic-substrings | def countSubstrings(s: str) -> int:
"""
Given a string s, return the number of palindromic substrings in it.
A string is a palindrome when it reads the same backward as forward.
A substring is a contiguous sequence of characters within the string.
Example 1:
>>> countSubstrings(s = "ab... |
replace-words | def replaceWords(dictionary: List[str], sentence: str) -> str:
"""
In English, we have a concept called root, which can be followed by some other word to form another longer word - let's call this word derivative. For example, when the root "help" is followed by the word "ful", we can form a derivative "helpful... |
dota2-senate | def predictPartyVictory(senate: str) -> str:
"""
In the world of Dota2, there are two parties: the Radiant and the Dire.
The Dota2 senate consists of senators coming from two parties. Now the Senate wants to decide on a change in the Dota2 game. The voting for this change is a round-based procedure. In each... |
2-keys-keyboard | def minSteps(n: int) -> int:
"""
There is only one character 'A' on the screen of a notepad. You can perform one of two operations on this notepad for each step:
Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).
Paste: You can paste the characters whic... |
4-keys-keyboard | def maxA(n: int) -> int:
"""
Imagine you have a special keyboard with the following keys:
A: Print one 'A' on the screen.
Ctrl-A: Select the whole screen.
Ctrl-C: Copy selection to buffer.
Ctrl-V: Print buffer on screen appending it after what has already been printed.
Given an int... |
two-sum-iv-input-is-a-bst | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def findTarget(root: Optional[TreeNode], k: int) -> bool:
"""
Given the root of a binary search tree and an integer k, return true if there exi... |
maximum-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def constructMaximumBinaryTree(nums: List[int]) -> Optional[TreeNode]:
"""
You are given an integer array nums with no duplicates. A maximum bi... |
print-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def printTree(root: Optional[TreeNode]) -> List[List[str]]:
"""
Given the root of a binary tree, construct a 0-indexed m x n string matrix res ... |
coin-path | def cheapestJump(coins: List[int], maxJump: int) -> List[int]:
"""
You are given an integer array coins (1-indexed) of length n and an integer maxJump. You can jump to any index i of the array coins if coins[i] != -1 and you have to pay coins[i] when you visit index i. In addition to that, if you are currently ... |
robot-return-to-origin | def judgeCircle(moves: str) -> bool:
"""
There is a robot starting at the position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.
You are given a string moves that represents the move sequence of the robot where moves[i] ... |
find-k-closest-elements | def findClosestElements(arr: List[int], k: int, x: int) -> List[int]:
"""
Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order.
An integer a is closer to x than an integer b if:
|a - x| < |b - x|... |
split-array-into-consecutive-subsequences | def isPossible(nums: List[int]) -> bool:
"""
You are given an integer array nums that is sorted in non-decreasing order.
Determine if it is possible to split nums into one or more subsequences such that both of the following conditions are true:
Each subsequence is a consecutive increasing sequence... |
remove-9 | def newInteger(n: int) -> int:
"""
Start from integer 1, remove any integer that contains 9 such as 9, 19, 29...
Now, you will have a new integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, ...].
Given an integer n, return the nth (1-indexed) integer in the new sequence.
Example 1:
>>> n... |
image-smoother | def imageSmoother(img: List[List[int]]) -> List[List[int]]:
"""
An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nine cells in the blue smoother). If one or more of the ... |
maximum-width-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 widthOfBinaryTree(root: Optional[TreeNode]) -> int:
"""
Given the root of a binary tree, return the maximum width of the given tree.
Th... |
equal-tree-partition | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def checkEqualTree(root: Optional[TreeNode]) -> bool:
"""
Given the root of a binary tree, return true if you can partition the tree into two t... |
strange-printer | def strangePrinter(s: str) -> int:
"""
There is a strange printer with the following two special properties:
The printer can only print a sequence of the same character each time.
At each turn, the printer can print new characters starting from and ending at any place and will cover the original ex... |
non-decreasing-array | def checkPossibility(nums: List[int]) -> bool:
"""
Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element.
We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2).
E... |
path-sum-iv | def pathSum(nums: List[int]) -> int:
"""
If the depth of a tree is smaller than 5, then this tree can be represented by an array of three-digit integers. You are given an ascending array nums consisting of three-digit integers representing a binary tree with a depth smaller than 5, where for each integer:
... |
beautiful-arrangement-ii | def constructArray(n: int, k: int) -> List[int]:
"""
Given two integers n and k, construct a list answer that contains n different positive integers ranging from 1 to n and obeys the following requirement:
Suppose this list is answer = [a1, a2, a3, ... , an], then the list [|a1 - a2|, |a2 - a3|, |a3 - ... |
kth-smallest-number-in-multiplication-table | def findKthNumber(m: int, n: int, k: int) -> int:
"""
Nearly everyone has used the Multiplication Table. The multiplication table of size m x n is an integer matrix mat where mat[i][j] == i * j (1-indexed).
Given three integers m, n, and k, return the kth smallest element in the m x n multiplication table.
... |
trim-a-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 trimBST(root: Optional[TreeNode], low: int, high: int) -> Optional[TreeNode]:
"""
Given the root of a binary search tree and the lowest and... |
maximum-swap | def maximumSwap(num: int) -> int:
"""
You are given an integer num. You can swap two digits at most once to get the maximum valued number.
Return the maximum valued number you can get.
Example 1:
>>> maximumSwap(num = 2736)
>>> 7236
Explanation: Swap the number 2 and the number 7.
... |
second-minimum-node-in-a-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def findSecondMinimumValue(root: Optional[TreeNode]) -> int:
"""
Given a non-empty special binary tree consisting of nodes with the non-negativ... |
bulb-switcher-ii | def flipLights(n: int, presses: int) -> int:
"""
There is a room with n bulbs labeled from 1 to n that all are turned on initially, and four buttons on the wall. Each of the four buttons has a different functionality where:
Button 1: Flips the status of all the bulbs.
Button 2: Flips the status of ... |
number-of-longest-increasing-subsequence | def findNumberOfLIS(nums: List[int]) -> int:
"""
Given an integer array nums, return the number of longest increasing subsequences.
Notice that the sequence has to be strictly increasing.
Example 1:
>>> findNumberOfLIS(nums = [1,3,5,4,7])
>>> 2
Explanation: The two longest increasi... |
longest-continuous-increasing-subsequence | def findLengthOfLCIS(nums: List[int]) -> int:
"""
Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (i.e. subarray). The subsequence must be strictly increasing.
A continuous increasing subsequence is defined by two indices l and r (l < r) such that... |
cut-off-trees-for-golf-event | def cutOffTree(forest: List[List[int]]) -> int:
"""
You are asked to cut off all the trees in a forest for a golf event. The forest is represented as an m x n matrix. In this matrix:
0 means the cell cannot be walked through.
1 represents an empty cell that can be walked through.
A number great... |
valid-parenthesis-string | def checkValidString(s: str) -> bool:
"""
Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid.
The following rules define a valid string:
Any left parenthesis '(' must have a corresponding right parenthesis ')'.
Any right parenthesis ')' must ... |
24-game | def judgePoint24(cards: List[int]) -> bool:
"""
You are given an integer array cards of length 4. You have four cards, each containing a number in the range [1, 9]. You should arrange the numbers on these cards in a mathematical expression using the operators ['+', '-', '*', '/'] and the parentheses '(' and ')'... |
valid-palindrome-ii | def validPalindrome(s: str) -> bool:
"""
Given a string s, return true if the s can be palindrome after deleting at most one character from it.
Example 1:
>>> validPalindrome(s = "aba")
>>> true
Example 2:
>>> validPalindrome(s = "abca")
>>> true
Explanation: You ... |
next-closest-time | def nextClosestTime(time: str) -> str:
"""
Given a time represented in the format "HH:MM", form the next closest time by reusing the current digits. There is no limit on how many times a digit can be reused.
You may assume the given input string is always valid. For example, "01:34", "12:09" are all valid. ... |
baseball-game | def calPoints(operations: List[str]) -> int:
"""
You are keeping the scores for a baseball game with strange rules. At the beginning of the game, you start with an empty record.
You are given a list of strings operations, where operations[i] is the ith operation you must apply to the record and is one of th... |
k-empty-slots | def kEmptySlots(bulbs: List[int], k: int) -> int:
"""
You have n bulbs in a row numbered from 1 to n. Initially, all the bulbs are turned off. We turn on exactly one bulb every day until all bulbs are on after n days.
You are given an array bulbs of length n where bulbs[i] = x means that on the (i+1)th day,... |
redundant-connection | def findRedundantConnection(edges: List[List[int]]) -> List[int]:
"""
In this problem, a tree is an undirected graph that is connected and has no cycles.
You are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edge added. The added edge has two different vertices c... |
redundant-connection-ii | def findRedundantDirectedConnection(edges: List[List[int]]) -> List[int]:
"""
In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, except for the root node which has no p... |
repeated-string-match | def repeatedStringMatch(a: str, b: str) -> int:
"""
Given two strings a and b, return the minimum number of times you should repeat string a so that string b is a substring of it. If it is impossible for b to be a substring of a after repeating it, return -1.
Notice: string "abc" repeated 0 times is "... |
longest-univalue-path | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def longestUnivaluePath(root: Optional[TreeNode]) -> int:
"""
Given the root of a binary tree, return the length of the longest path, where eac... |
knight-probability-in-chessboard | def knightProbability(n: int, k: int, row: int, column: int) -> float:
"""
On an n x n chessboard, a knight starts at the cell (row, column) and attempts to make exactly k moves. The rows and columns are 0-indexed, so the top-left cell is (0, 0), and the bottom-right cell is (n - 1, n - 1).
A chess knight h... |
maximum-sum-of-3-non-overlapping-subarrays | def maxSumOfThreeSubarrays(nums: List[int], k: int) -> List[int]:
"""
Given an integer array nums and an integer k, find three non-overlapping subarrays of length k with maximum sum and return them.
Return the result as a list of indices representing the starting position of each interval (0-indexed). If th... |
stickers-to-spell-word | def minStickers(stickers: List[str], target: str) -> int:
"""
We are given n different types of stickers. Each sticker has a lowercase English word on it.
You would like to spell out the given string target by cutting individual letters from your collection of stickers and rearranging them. You can use each... |
top-k-frequent-words | def topKFrequent(words: List[str], k: int) -> List[str]:
"""
Given an array of strings words and an integer k, return the k most frequent strings.
Return the answer sorted by the frequency from highest to lowest. Sort the words with the same frequency by their lexicographical order.
Example 1:
... |
binary-number-with-alternating-bits | def hasAlternatingBits(n: int) -> bool:
"""
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
Example 1:
>>> hasAlternatingBits(n = 5)
>>> true
Explanation: The binary representation of 5 is: 101
Ex... |
number-of-distinct-islands | def numDistinctIslands(grid: List[List[int]]) -> int:
"""
You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
An island is considered to be the same a... |
max-area-of-island | def maxAreaOfIsland(grid: List[List[int]]) -> int:
"""
You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
The area of an island is the number of cell... |
count-binary-substrings | def countBinarySubstrings(s: str) -> int:
"""
Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively.
Substrings that occur multiple times are counted the number of times they ... |
degree-of-an-array | def findShortestSubArray(nums: List[int]) -> int:
"""
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.
Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree... |
partition-to-k-equal-sum-subsets | def canPartitionKSubsets(nums: List[int], k: int) -> bool:
"""
Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
>>> canPartitionKSubsets(nums = [4,3,2,3,5,2,1], k = 4)
>>> true
... |
falling-squares | def fallingSquares(positions: List[List[int]]) -> List[int]:
"""
There are several squares being dropped onto the X-axis of a 2D plane.
You are given a 2D integer array positions where positions[i] = [lefti, sideLengthi] represents the ith square with a side length of sideLengthi that is dropped with its le... |
search-in-a-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 searchBST(root: Optional[TreeNode], val: int) -> Optional[TreeNode]:
"""
You are given the root of a binary search tree (BST) and an intege... |
insert-into-a-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 insertIntoBST(root: Optional[TreeNode], val: int) -> Optional[TreeNode]:
"""
You are given the root node of a binary search tree (BST) and ... |
binary-search | def search(nums: List[int], target: int) -> int:
"""
Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.
You must write an algorithm with O(log n) runtime complexi... |
to-lower-case | def toLowerCase(s: str) -> str:
"""
Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.
Example 1:
>>> toLowerCase(s = "Hello")
>>> "hello"
Example 2:
>>> toLowerCase(s = "here")
>>> "here"
Example 3:
... |
number-of-distinct-islands-ii | def numDistinctIslands2(grid: List[List[int]]) -> int:
"""
You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
An island is considered to be the same ... |
minimum-ascii-delete-sum-for-two-strings | def minimumDeleteSum(s1: str, s2: str) -> int:
"""
Given two strings s1 and s2, return the lowest ASCII sum of deleted characters to make two strings equal.
Example 1:
>>> minimumDeleteSum(s1 = "sea", s2 = "eat")
>>> 231
Explanation: Deleting "s" from "sea" adds the ASCII value of "s" ... |
subarray-product-less-than-k | def numSubarrayProductLessThanK(nums: List[int], k: int) -> int:
"""
Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k.
Example 1:
>>> numSubarrayProductLessThanK(nums = [10,... |
best-time-to-buy-and-sell-stock-with-transaction-fee | def maxProfit(prices: List[int], fee: int) -> int:
"""
You are given an array prices where prices[i] is the price of a given stock on the ith day, and an integer fee representing a transaction fee.
Find the maximum profit you can achieve. You may complete as many transactions as you like, but you need to pa... |
1-bit-and-2-bit-characters | def isOneBitCharacter(bits: List[int]) -> bool:
"""
We have two special characters:
The first character can be represented by one bit 0.
The second character can be represented by two bits (10 or 11).
Given a binary array bits that ends with 0, return true if the last character must be a o... |
maximum-length-of-repeated-subarray | def findLength(nums1: List[int], nums2: List[int]) -> int:
"""
Given two integer arrays nums1 and nums2, return the maximum length of a subarray that appears in both arrays.
Example 1:
>>> findLength(nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7])
>>> 3
Explanation: The repeated subarray wit... |
find-k-th-smallest-pair-distance | def smallestDistancePair(nums: List[int], k: int) -> int:
"""
The distance of a pair of integers a and b is defined as the absolute difference between a and b.
Given an integer array nums and an integer k, return the kth smallest distance among all the pairs nums[i] and nums[j] where 0 <= i < j < nums.lengt... |
longest-word-in-dictionary | def longestWord(words: List[str]) -> str:
"""
Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.
If there is more than one possible answer, return the longest word with the smallest lexicogra... |
accounts-merge | def accountsMerge(accounts: List[List[str]]) -> List[List[str]]:
"""
Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.
Now, we would like to merge these a... |
remove-comments | def removeComments(source: List[str]) -> List[str]:
"""
Given a C++ program, remove comments from it. The program source is an array of strings source where source[i] is the ith line of the source code. This represents the result of splitting the original source code string by the newline character '\
'.
... |
candy-crush | def candyCrush(board: List[List[int]]) -> List[List[int]]:
"""
This question is about implementing a basic elimination algorithm for Candy Crush.
Given an m x n integer array board representing the grid of candy where board[i][j] represents the type of candy. A value of board[i][j] == 0 represents that the ... |
find-pivot-index | def pivotIndex(nums: List[int]) -> int:
"""
Given an array of integers nums, calculate the pivot index of this array.
The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.
If the index is on t... |
number-of-atoms | def countOfAtoms(formula: str) -> str:
"""
Given a string formula representing a chemical formula, return the count of each atom.
The atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.
One or more digits representing that element's count... |
minimum-window-subsequence | def minWindow(s1: str, s2: str) -> str:
"""
Given strings s1 and s2, return the minimum contiguous substring part of s1, so that s2 is a subsequence of the part.
If there is no such window in s1 that covers all characters in s2, return the empty string "". If there are multiple such minimum-length windows, ... |
self-dividing-numbers | def selfDividingNumbers(left: int, right: int) -> List[int]:
"""
A self-dividing number is a number that is divisible by every digit it contains.
For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.
A self-dividing number is not allowed to contain th... |
count-different-palindromic-subsequences | def countPalindromicSubsequences(s: str) -> int:
"""
Given a string s, return the number of different non-empty palindromic subsequences in s. Since the answer may be very large, return it modulo 109 + 7.
A subsequence of a string is obtained by deleting zero or more characters from the string.
A sequen... |
flood-fill | def floodFill(image: List[List[int]], sr: int, sc: int, color: int) -> List[List[int]]:
"""
You are given an image represented by an m x n grid of integers image, where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and color. Your task is to perform a flood fill ... |
sentence-similarity | def areSentencesSimilar(sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:
"""
We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"].
Given two sentences sentence... |
asteroid-collision | def asteroidCollision(asteroids: List[int]) -> List[int]:
"""
We are given an array asteroids of integers representing asteroids in a row. The indices of the asteriod in the array represent their relative position in space.
For each asteroid, the absolute value represents its size, and the sign represents i... |
parse-lisp-expression | def evaluate(expression: str) -> int:
"""
You are given a string expression representing a Lisp-like expression to return the integer value of.
The syntax for these expressions is given as follows.
An expression is either an integer, let expression, add expression, mult expression, or an assigned v... |
sentence-similarity-ii | def areSentencesSimilarTwo(sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:
"""
We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"].
Given two sentences sente... |
monotone-increasing-digits | def monotoneIncreasingDigits(n: int) -> int:
"""
An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y.
Given an integer n, return the largest number that is less than or equal to n with monotone increasing digits.
Example 1:
>>> monot... |
daily-temperatures | def dailyTemperatures(temperatures: List[int]) -> List[int]:
"""
Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is... |
delete-and-earn | def deleteAndEarn(nums: List[int]) -> int:
"""
You are given an integer array nums. You want to maximize the number of points you get by performing the following operation any number of times:
Pick any nums[i] and delete it to earn nums[i] points. Afterwards, you must delete every element equal to nums... |
cherry-pickup | def cherryPickup(grid: List[List[int]]) -> int:
"""
You are given an n x n grid representing a field of cherries, each cell is one of three possible integers.
0 means the cell is empty, so you can pass through,
1 means the cell contains a cherry that you can pick up and pass through, or
-1 mean... |
closest-leaf-in-a-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def findClosestLeaf(root: Optional[TreeNode], k: int) -> int:
"""
Given the root of a binary tree where every node has a unique value and a tar... |
network-delay-time | def networkDelayTime(times: List[List[int]], n: int, k: int) -> int:
"""
You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a sign... |
find-smallest-letter-greater-than-target | def nextGreatestLetter(letters: List[str], target: str) -> str:
"""
You are given an array of characters letters that is sorted in non-decreasing order, and a character target. There are at least two different characters in letters.
Return the smallest character in letters that is lexicographically greater ... |
min-cost-climbing-stairs | def minCostClimbingStairs(cost: List[int]) -> int:
"""
You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.
You can either start from the step with index 0, or the step with index 1.
Return the minimum cos... |
largest-number-at-least-twice-of-others | def dominantIndex(nums: List[int]) -> int:
"""
You are given an integer array nums where the largest integer is unique.
Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.
... |
shortest-completing-word | def shortestCompletingWord(licensePlate: str, words: List[str]) -> str:
"""
Given a string licensePlate and an array of strings words, find the shortest completing word in words.
A completing word is a word that contains all the letters in licensePlate. Ignore numbers and spaces in licensePlate, and treat l... |
contain-virus | def containVirus(isInfected: List[List[int]]) -> int:
"""
A virus is spreading rapidly, and your task is to quarantine the infected area by installing walls.
The world is modeled as an m x n binary grid isInfected, where isInfected[i][j] == 0 represents uninfected cells, and isInfected[i][j] == 1 represents... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.