task_id stringlengths 3 79 | prompt stringlengths 255 3.9k |
|---|---|
minimum-number-of-food-buckets-to-feed-the-hamsters | def minimumBuckets(hamsters: str) -> int:
"""
You are given a 0-indexed string hamsters where hamsters[i] is either:
'H' indicating that there is a hamster at index i, or
'.' indicating that index i is empty.
You will add some number of food buckets at the empty indices in order to feed th... |
minimum-cost-homecoming-of-a-robot-in-a-grid | def minCost(startPos: List[int], homePos: List[int], rowCosts: List[int], colCosts: List[int]) -> int:
"""
There is an m x n grid, where (0, 0) is the top-left cell and (m - 1, n - 1) is the bottom-right cell. You are given an integer array startPos where startPos = [startrow, startcol] indicates that initially... |
count-fertile-pyramids-in-a-land | def countPyramids(grid: List[List[int]]) -> int:
"""
A farmer has a rectangular grid of land with m rows and n columns that can be divided into unit cells. Each cell is either fertile (represented by a 1) or barren (represented by a 0). All cells outside the grid are considered barren.
A pyramidal plot of l... |
find-target-indices-after-sorting-array | def targetIndices(nums: List[int], target: int) -> List[int]:
"""
You are given a 0-indexed integer array nums and a target element target.
A target index is an index i such that nums[i] == target.
Return a list of the target indices of nums after sorting nums in non-decreasing order. If there are no ta... |
k-radius-subarray-averages | def getAverages(nums: List[int], k: int) -> List[int]:
"""
You are given a 0-indexed array nums of n integers, and an integer k.
The k-radius average for a subarray of nums centered at some index i with the radius k is the average of all elements in nums between the indices i - k and i + k (inclusive). If t... |
removing-minimum-and-maximum-from-array | def minimumDeletions(nums: List[int]) -> int:
"""
You are given a 0-indexed array of distinct integers nums.
There is an element in nums that has the lowest value and an element that has the highest value. We call them the minimum and maximum respectively. Your goal is to remove both these elements from the... |
find-all-people-with-secret | def findAllPeople(n: int, meetings: List[List[int]], firstPerson: int) -> List[int]:
"""
You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [xi, yi, timei] indicates that person xi and person yi have a m... |
minimum-cost-to-reach-city-with-discounts | def minimumCost(n: int, highways: List[List[int]], discounts: int) -> int:
"""
A series of highways connect n cities numbered from 0 to n - 1. You are given a 2D integer array highways where highways[i] = [city1i, city2i, tolli] indicates that there is a highway that connects city1i and city2i, allowing a car t... |
finding-3-digit-even-numbers | def findEvenNumbers(digits: List[int]) -> List[int]:
"""
You are given an integer array digits, where each element is a digit. The array may contain duplicates.
You need to find all the unique integers that follow the given requirements:
The integer consists of the concatenation of three elements f... |
delete-the-middle-node-of-a-linked-list | # class ListNode:
# def __init__(val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def deleteMiddle(head: Optional[ListNode]) -> Optional[ListNode]:
"""
You are given the head of a linked list. Delete the middle node, and return the head of the modified linked list.
... |
step-by-step-directions-from-a-binary-tree-node-to-another | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def getDirections(root: Optional[TreeNode], startValue: int, destValue: int) -> str:
"""
You are given the root of a binary tree with n nodes. ... |
valid-arrangement-of-pairs | def validArrangement(pairs: List[List[int]]) -> List[List[int]]:
"""
You are given a 0-indexed 2D integer array pairs where pairs[i] = [starti, endi]. An arrangement of pairs is valid if for every index i where 1 <= i < pairs.length, we have endi-1 == starti.
Return any valid arrangement of pairs.
Note:... |
subsequence-of-size-k-with-the-largest-even-sum | def largestEvenSum(nums: List[int], k: int) -> int:
"""
You are given an integer array nums and an integer k. Find the largest even sum of any subsequence of nums that has a length of k.
Return this sum, or -1 if such a sum does not exist.
A subsequence is an array that can be derived from another array... |
find-subsequence-of-length-k-with-the-largest-sum | def maxSubsequence(nums: List[int], k: int) -> List[int]:
"""
You are given an integer array nums and an integer k. You want to find a subsequence of nums of length k that has the largest sum.
Return any such subsequence as an integer array of length k.
A subsequence is an array that can be derived from... |
find-good-days-to-rob-the-bank | def goodDaysToRobBank(security: List[int], time: int) -> List[int]:
"""
You and a gang of thieves are planning on robbing a bank. You are given a 0-indexed integer array security, where security[i] is the number of guards on duty on the ith day. The days are numbered starting from 0. You are also given an integ... |
detonate-the-maximum-bombs | def maximumDetonation(bombs: List[List[int]]) -> int:
"""
You are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the center as the location of the bomb.
The bombs are represented by a 0-indexed 2D integer array bombs... |
rings-and-rods | def countPoints(rings: str) -> int:
"""
There are n rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from 0 to 9.
You are given a string rings of length 2n that describes the n rings that are placed onto the rods. Every two characters in rings forms a colo... |
sum-of-subarray-ranges | def subArrayRanges(nums: List[int]) -> int:
"""
You are given an integer array nums. The range of a subarray of nums is the difference between the largest and smallest element in the subarray.
Return the sum of all subarray ranges of nums.
A subarray is a contiguous non-empty sequence of elements within... |
watering-plants-ii | def minimumRefill(plants: List[int], capacityA: int, capacityB: int) -> int:
"""
Alice and Bob want to water n plants in their garden. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i.
Each plant needs a specific amount of water. Ali... |
maximum-fruits-harvested-after-at-most-k-steps | def maxTotalFruits(fruits: List[List[int]], startPos: int, k: int) -> int:
"""
Fruits are available at some positions on an infinite x-axis. You are given a 2D integer array fruits where fruits[i] = [positioni, amounti] depicts amounti fruits at the position positioni. fruits is already sorted by positioni in a... |
number-of-unique-flavors-after-sharing-k-candies | def shareCandies(candies: List[int], k: int) -> int:
"""
You are given a 0-indexed integer array candies, where candies[i] represents the flavor of the ith candy. Your mom wants you to share these candies with your little sister by giving her k consecutive candies, but you want to keep as many flavors of candie... |
find-first-palindromic-string-in-the-array | def firstPalindrome(words: List[str]) -> str:
"""
Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string "".
A string is palindromic if it reads the same forward and backward.
Example 1:
>>> firstPalindrome(word... |
adding-spaces-to-a-string | def addSpaces(s: str, spaces: List[int]) -> str:
"""
You are given a 0-indexed string s and a 0-indexed integer array spaces that describes the indices in the original string where spaces will be added. Each space should be inserted before the character at the given index.
For example, given s = "Enjoy... |
number-of-smooth-descent-periods-of-a-stock | def getDescentPeriods(prices: List[int]) -> int:
"""
You are given an integer array prices representing the daily price history of a stock, where prices[i] is the stock price on the ith day.
A smooth descent period of a stock consists of one or more contiguous days such that the price on each day is lower t... |
minimum-operations-to-make-the-array-k-increasing | def kIncreasing(arr: List[int], k: int) -> int:
"""
You are given a 0-indexed array arr consisting of n positive integers, and a positive integer k.
The array arr is called K-increasing if arr[i-k] <= arr[i] holds for every index i, where k <= i <= n-1.
For example, arr = [4, 1, 5, 2, 6, 2] is K-in... |
elements-in-array-after-removing-and-replacing-elements | def elementInNums(nums: List[int], queries: List[List[int]]) -> List[int]:
"""
You are given a 0-indexed integer array nums. Initially on minute 0, the array is unchanged. Every minute, the leftmost element in nums is removed until no elements remain. Then, every minute, one element is appended to the end of nu... |
maximum-number-of-words-found-in-sentences | def mostWordsFound(sentences: List[str]) -> int:
"""
A sentence is a list of words that are separated by a single space with no leading or trailing spaces.
You are given an array of strings sentences, where each sentences[i] represents a single sentence.
Return the maximum number of words that appear in... |
find-all-possible-recipes-from-given-supplies | def findAllRecipes(recipes: List[str], ingredients: List[List[str]], supplies: List[str]) -> List[str]:
"""
You have information about n different recipes. You are given a string array recipes and a 2D string array ingredients. The ith recipe has the name recipes[i], and you can create it if you have all the ne... |
check-if-a-parentheses-string-can-be-valid | def canBeValid(s: str, locked: str) -> bool:
"""
A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true:
It is ().
It can be written as AB (A concatenated with B), where A and B are valid parentheses strings.
It can be w... |
abbreviating-the-product-of-a-range | def abbreviateProduct(left: int, right: int) -> str:
"""
You are given two positive integers left and right with left <= right. Calculate the product of all integers in the inclusive range [left, right].
Since the product may be very large, you will abbreviate it following these steps:
Count all tr... |
a-number-after-a-double-reversal | def isSameAfterReversals(num: int) -> bool:
"""
Reversing an integer means to reverse all its digits.
For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained.
Given an integer num, reverse num to get reversed1, then reverse reversed1 to get rever... |
execution-of-all-suffix-instructions-staying-in-a-grid | def executeInstructions(n: int, startPos: List[int], s: str) -> List[int]:
"""
There is an n x n grid, with the top-left cell at (0, 0) and the bottom-right cell at (n - 1, n - 1). You are given the integer n and an integer array startPos where startPos = [startrow, startcol] indicates that a robot is initially... |
intervals-between-identical-elements | def getDistances(arr: List[int]) -> List[int]:
"""
You are given a 0-indexed array of n integers arr.
The interval between two elements in arr is defined as the absolute difference between their indices. More formally, the interval between arr[i] and arr[j] is |i - j|.
Return an array intervals of lengt... |
recover-the-original-array | def recoverArray(nums: List[int]) -> List[int]:
"""
Alice had a 0-indexed array arr consisting of n positive integers. She chose an arbitrary positive integer k and created two new 0-indexed integer arrays lower and higher in the following manner:
lower[i] = arr[i] - k, for every index i where 0 <= i <... |
minimum-operations-to-remove-adjacent-ones-in-matrix | def minimumOperations(grid: List[List[int]]) -> int:
"""
You are given a 0-indexed binary matrix grid. In one operation, you can flip any 1 in grid to be 0.
A binary matrix is well-isolated if there is no 1 in the matrix that is 4-directionally connected (i.e., horizontal and vertical) to another 1.
Ret... |
check-if-all-as-appears-before-all-bs | def checkString(s: str) -> bool:
"""
Given a string s consisting of only the characters 'a' and 'b', return true if every 'a' appears before every 'b' in the string. Otherwise, return false.
Example 1:
>>> checkString(s = "aaabbb")
>>> true
Explanation:
The 'a's are at indices 0, 1... |
number-of-laser-beams-in-a-bank | def numberOfBeams(bank: List[str]) -> int:
"""
Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array bank representing the floor plan of the bank, which is an m x n 2D matrix. bank[i] represents the ith row, consisting of '0's and '1's. '0' means the cell is empt... |
destroying-asteroids | def asteroidsDestroyed(mass: int, asteroids: List[int]) -> bool:
"""
You are given an integer mass, which represents the original mass of a planet. You are further given an integer array asteroids, where asteroids[i] is the mass of the ith asteroid.
You can arrange for the planet to collide with the asteroi... |
maximum-employees-to-be-invited-to-a-meeting | def maximumInvitations(favorite: List[int]) -> int:
"""
A company is organizing a meeting and has a list of n employees, waiting to be invited. They have arranged for a large circular table, capable of seating any number of employees.
The employees are numbered from 0 to n - 1. Each employee has a favorite ... |
remove-all-ones-with-row-and-column-flips | def removeOnes(grid: List[List[int]]) -> bool:
"""
You are given an m x n binary matrix grid.
In one operation, you can choose any row or column and flip each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's).
Return true if it is possible to remove all 1's from grid using ... |
capitalize-the-title | def capitalizeTitle(title: str) -> str:
"""
You are given a string title consisting of one or more words separated by a single space, where each word consists of English letters. Capitalize the string by changing the capitalization of each word such that:
If the length of the word is 1 or 2 letters, ch... |
maximum-twin-sum-of-a-linked-list | # class ListNode:
# def __init__(val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def pairSum(head: Optional[ListNode]) -> int:
"""
In a linked list of size n, where n is even, the ith node (0-indexed) of the linked list is known as the twin of the (n-1-i)th node, i... |
longest-palindrome-by-concatenating-two-letter-words | def longestPalindrome(words: List[str]) -> int:
"""
You are given an array of strings words. Each element of words consists of two lowercase English letters.
Create the longest possible palindrome by selecting some elements from words and concatenating them in any order. Each element can be selected at most... |
stamping-the-grid | def possibleToStamp(grid: List[List[int]], stampHeight: int, stampWidth: int) -> bool:
"""
You are given an m x n binary matrix grid where each cell is either 0 (empty) or 1 (occupied).
You are then given stamps of size stampHeight x stampWidth. We want to fit the stamps such that they follow the given rest... |
check-if-every-row-and-column-contains-all-numbers | def checkValid(matrix: List[List[int]]) -> bool:
"""
An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive).
Given an n x n integer matrix matrix, return true if the matrix is valid. Otherwise, return false.
Example 1:
>>> checkValid(m... |
minimum-swaps-to-group-all-1s-together-ii | def minSwaps(nums: List[int]) -> int:
"""
A swap is defined as taking two distinct positions in an array and swapping the values in them.
A circular array is defined as an array where we consider the first element and the last element to be adjacent.
Given a binary circular array nums, return the minimu... |
count-words-obtained-after-adding-a-letter | def wordCount(startWords: List[str], targetWords: List[str]) -> int:
"""
You are given two 0-indexed arrays of strings startWords and targetWords. Each string consists of lowercase English letters only.
For each string in targetWords, check if it is possible to choose a string from startWords and perform a ... |
earliest-possible-day-of-full-bloom | def earliestFullBloom(plantTime: List[int], growTime: List[int]) -> int:
"""
You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of lengt... |
pour-water-between-buckets-to-make-water-levels-equal | def equalizeWater(buckets: List[int], loss: int) -> float:
"""
You have n buckets each containing some gallons of water in it, represented by a 0-indexed integer array buckets, where the ith bucket contains buckets[i] gallons of water. You are also given an integer loss.
You want to make the amount of water... |
divide-a-string-into-groups-of-size-k | def divideString(s: str, k: int, fill: str) -> List[str]:
"""
A string s can be partitioned into groups of size k using the following procedure:
The first group consists of the first k characters of the string, the second group consists of the next k characters of the string, and so on. Each element ca... |
minimum-moves-to-reach-target-score | def minMoves(target: int, maxDoubles: int) -> int:
"""
You are playing a game with integers. You start with the integer 1 and you want to reach the integer target.
In one move, you can either:
Increment the current integer by one (i.e., x = x + 1).
Double the current integer (i.e., x = 2 * x).
... |
solving-questions-with-brainpower | def mostPoints(questions: List[List[int]]) -> int:
"""
You are given a 0-indexed 2D integer array questions where questions[i] = [pointsi, brainpoweri].
The array describes the questions of an exam, where you have to process the questions in order (i.e., starting from question 0) and make a decision whether... |
maximum-running-time-of-n-computers | def maxRunTime(n: int, batteries: List[int]) -> int:
"""
You have n computers. You are given the integer n and a 0-indexed integer array batteries where the ith battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously using the given batteries.
Initia... |
choose-numbers-from-two-arrays-in-range | def countSubranges(nums1: List[int], nums2: List[int]) -> int:
"""
You are given two 0-indexed integer arrays nums1 and nums2 of length n.
A range [l, r] (inclusive) where 0 <= l <= r < n is balanced if:
For every i in the range [l, r], you pick either nums1[i] or nums2[i].
The sum of the numbe... |
minimum-cost-of-buying-candies-with-discount | def minimumCost(cost: List[int]) -> int:
"""
A shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free.
The customer can choose any candy to take away for free as long as the cost of the chosen candy is less than or equal to the minimum cost of the two candie... |
count-the-hidden-sequences | def numberOfArrays(differences: List[int], lower: int, upper: int) -> int:
"""
You are given a 0-indexed array of n integers differences, which describes the differences between each pair of consecutive integers of a hidden sequence of length (n + 1). More formally, call the hidden sequence hidden, then we have... |
k-highest-ranked-items-within-a-price-range | def highestRankedKItems(grid: List[List[int]], pricing: List[int], start: List[int], k: int) -> List[List[int]]:
"""
You are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop. The integers in the grid represent the following:
0 represents a wall that you... |
number-of-ways-to-divide-a-long-corridor | def numberOfWays(corridor: str) -> int:
"""
Along a long library corridor, there is a line of seats and decorative plants. You are given a 0-indexed string corridor of length n consisting of letters 'S' and 'P' where each 'S' represents a seat and each 'P' represents a plant.
One room divider has already be... |
count-elements-with-strictly-smaller-and-greater-elements | def countElements(nums: List[int]) -> int:
"""
Given an integer array nums, return the number of elements that have both a strictly smaller and a strictly greater element appear in nums.
Example 1:
>>> countElements(nums = [11,7,2,15])
>>> 2
Explanation: The element 7 has the element 2... |
rearrange-array-elements-by-sign | def rearrangeArray(nums: List[int]) -> List[int]:
"""
You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers.
You should return the array of nums such that the the array follows the given conditions:
Every consecutive pair of inte... |
find-all-lonely-numbers-in-the-array | def findLonely(nums: List[int]) -> List[int]:
"""
You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.
Return all lonely numbers in nums. You may return the answer in any order.
Example 1:
>... |
maximum-good-people-based-on-statements | def maximumGood(statements: List[List[int]]) -> int:
"""
There are two types of persons:
The good person: The person who always tells the truth.
The bad person: The person who might tell the truth and might lie.
You are given a 0-indexed 2D integer array statements of size n x n that repre... |
minimum-number-of-lines-to-cover-points | def minimumLines(points: List[List[int]]) -> int:
"""
You are given an array points where points[i] = [xi, yi] represents a point on an X-Y plane.
Straight lines are going to be added to the X-Y plane, such that every point is covered by at least one line.
Return the minimum number of straight lines nee... |
keep-multiplying-found-values-by-two | def findFinalValue(nums: List[int], original: int) -> int:
"""
You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.
You then do the following steps:
If original is found in nums, multiply it by two (i.e., se... |
all-divisions-with-the-highest-score-of-a-binary-array | def maxScoreIndices(nums: List[int]) -> List[int]:
"""
You are given a 0-indexed binary array nums of length n. nums can be divided at index i (where 0 <= i <= n) into two arrays (possibly empty) numsleft and numsright:
numsleft has all the elements of nums between index 0 and i - 1 (inclusive), while ... |
find-substring-with-given-hash-value | def subStrHash(s: str, power: int, modulo: int, k: int, hashValue: int) -> str:
"""
The hash of a 0-indexed string s of length k, given integers p and m, is computed using the following function:
hash(s, p, m) = (val(s[0]) * p0 + val(s[1]) * p1 + ... + val(s[k-1]) * pk-1) mod m.
Where val(s[i]... |
groups-of-strings | def groupStrings(words: List[str]) -> List[int]:
"""
You are given a 0-indexed array of strings words. Each string consists of lowercase English letters only. No letter occurs more than once in any string of words.
Two strings s1 and s2 are said to be connected if the set of letters of s2 can be obtained fr... |
amount-of-new-area-painted-each-day | def amountPainted(paint: List[List[int]]) -> List[int]:
"""
There is a long and thin painting that can be represented by a number line. You are given a 0-indexed 2D integer array paint of length n, where paint[i] = [starti, endi]. This means that on the ith day you need to paint the area between starti and endi... |
minimum-sum-of-four-digit-number-after-splitting-digits | def minimumSum(num: int) -> int:
"""
You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits found in num must be used.
For example, given num =... |
partition-array-according-to-given-pivot | def pivotArray(nums: List[int], pivot: int) -> List[int]:
"""
You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:
Every element less than pivot appears before every element greater than pivot.
Every element equal to piv... |
minimum-cost-to-set-cooking-time | def minCostSetTime(startAt: int, moveCost: int, pushCost: int, targetSeconds: int) -> int:
"""
A generic microwave supports cooking times for:
at least 1 second.
at most 99 minutes and 99 seconds.
To set the cooking time, you push at most four digits. The microwave normalizes what you push... |
minimum-difference-in-sums-after-removal-of-elements | def minimumDifference(nums: List[int]) -> int:
"""
You are given a 0-indexed integer array nums consisting of 3 * n elements.
You are allowed to remove any subsequence of elements of size exactly n from nums. The remaining 2 * n elements will be divided into two equal parts:
The first n elements be... |
sort-even-and-odd-indices-independently | def sortEvenOdd(nums: List[int]) -> List[int]:
"""
You are given a 0-indexed integer array nums. Rearrange the values of nums according to the following rules:
Sort the values at odd indices of nums in non-increasing order.
For example, if nums = [4,1,2,3] before this step, it becomes [4,... |
smallest-value-of-the-rearranged-number | def smallestNumber(num: int) -> int:
"""
You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.
Return the rearranged number with minimal value.
Note that the sign of the number does not change after rearranging the digits.
... |
minimum-time-to-remove-all-cars-containing-illegal-goods | def minimumTime(s: str) -> int:
"""
You are given a 0-indexed binary string s which represents a sequence of train cars. s[i] = '0' denotes that the ith car does not contain illegal goods and s[i] = '1' denotes that the ith car does contain illegal goods.
As the train conductor, you would like to get rid of... |
unique-substrings-with-equal-digit-frequency | def equalDigitFrequency(s: str) -> int:
"""
Given a digit string s, return the number of unique substrings of s where every digit appears the same number of times.
Example 1:
>>> equalDigitFrequency(s = "1212")
>>> 5
Explanation: The substrings that meet the requirements are "1", "2", ... |
count-operations-to-obtain-zero | def countOperations(num1: int, num2: int) -> int:
"""
You are given two non-negative integers num1 and num2.
In one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.
For example, if num1 = 5 and num2 = 4, subtract num2 from num1, thus obtaining num1 = ... |
minimum-operations-to-make-the-array-alternating | def minimumOperations(nums: List[int]) -> int:
"""
You are given a 0-indexed array nums consisting of n positive integers.
The array nums is called alternating if:
nums[i - 2] == nums[i], where 2 <= i <= n - 1.
nums[i - 1] != nums[i], where 1 <= i <= n - 1.
In one operation, you can ch... |
removing-minimum-number-of-magic-beans | def minimumRemoval(beans: List[int]) -> int:
"""
You are given an array of positive integers beans, where each integer represents the number of magic beans found in a particular magic bag.
Remove any number of beans (possibly none) from each bag such that the number of beans in each remaining non-empty bag ... |
maximum-and-sum-of-array | def maximumANDSum(nums: List[int], numSlots: int) -> int:
"""
You are given an integer array nums of length n and an integer numSlots such that 2 * numSlots >= n. There are numSlots slots numbered from 1 to numSlots.
You have to place all n integers into the slots such that each slot contains at most two nu... |
remove-all-ones-with-row-and-column-flips-ii | def removeOnes(grid: List[List[int]]) -> int:
"""
You are given a 0-indexed m x n binary matrix grid.
In one operation, you can choose any i and j that meet the following conditions:
0 <= i < m
0 <= j < n
grid[i][j] == 1
and change the values of all cells in row i and column j to z... |
count-equal-and-divisible-pairs-in-an-array | def countPairs(nums: List[int], k: int) -> int:
"""
Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) where 0 <= i < j < n, such that nums[i] == nums[j] and (i * j) is divisible by k.
Example 1:
>>> countPairs(nums = [3,1,2,2,2,1,3], k = 2)
... |
find-three-consecutive-integers-that-sum-to-a-given-number | def sumOfThree(num: int) -> List[int]:
"""
Given an integer num, return three consecutive integers (as a sorted array) that sum to num. If num cannot be expressed as the sum of three consecutive integers, return an empty array.
Example 1:
>>> sumOfThree(num = 33)
>>> [10,11,12]
Explana... |
maximum-split-of-positive-even-integers | def maximumEvenSplit(finalSum: int) -> List[int]:
"""
You are given an integer finalSum. Split it into a sum of a maximum number of unique positive even integers.
For example, given finalSum = 12, the following splits are valid (unique positive even integers summing up to finalSum): (12), (2 + 10), (2 ... |
count-good-triplets-in-an-array | def goodTriplets(nums1: List[int], nums2: List[int]) -> int:
"""
You are given two 0-indexed arrays nums1 and nums2 of length n, both of which are permutations of [0, 1, ..., n - 1].
A good triplet is a set of 3 distinct values which are present in increasing order by position both in nums1 and nums2. In ot... |
count-integers-with-even-digit-sum | def countEven(num: int) -> int:
"""
Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even.
The digit sum of a positive integer is the sum of all its digits.
Example 1:
>>> countEven(num = 4)
>>> 2
Explanation:
T... |
merge-nodes-in-between-zeros | # class ListNode:
# def __init__(val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def mergeNodes(head: Optional[ListNode]) -> Optional[ListNode]:
"""
You are given the head of a linked list, which contains a series of integers separated by 0's. The beginning and end... |
construct-string-with-repeat-limit | def repeatLimitedString(s: str, repeatLimit: int) -> str:
"""
You are given a string s and an integer repeatLimit. Construct a new string repeatLimitedString using the characters of s such that no letter appears more than repeatLimit times in a row. You do not have to use all characters from s.
Return the l... |
count-array-pairs-divisible-by-k | def countPairs(nums: List[int], k: int) -> int:
"""
Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) such that:
0 <= i < j <= n - 1 and
nums[i] * nums[j] is divisible by k.
Example 1:
>>> countPairs(nums = [1,2,3,4,5], k = 2... |
number-of-ways-to-build-sturdy-brick-wall | def buildWall(height: int, width: int, bricks: List[int]) -> int:
"""
You are given integers height and width which specify the dimensions of a brick wall you are building. You are also given a 0-indexed array of unique integers bricks, where the ith brick has a height of 1 and a width of bricks[i]. You have an... |
counting-words-with-a-given-prefix | def prefixCount(words: List[str], pref: str) -> int:
"""
You are given an array of strings words and a string pref.
Return the number of strings in words that contain pref as a prefix.
A prefix of a string s is any leading contiguous substring of s.
Example 1:
>>> prefixCount(words = [... |
minimum-number-of-steps-to-make-two-strings-anagram-ii | def minSteps(s: str, t: str) -> int:
"""
You are given two strings s and t. In one step, you can append any character to either s or t.
Return the minimum number of steps to make s and t anagrams of each other.
An anagram of a string is a string that contains the same characters with a different (or the... |
minimum-time-to-complete-trips | def minimumTime(time: List[int], totalTrips: int) -> int:
"""
You are given an array time where time[i] denotes the time taken by the ith bus to complete one trip.
Each bus can make multiple trips successively; that is, the next trip can start immediately after completing the current trip. Also, each bus op... |
minimum-time-to-finish-the-race | def minimumFinishTime(tires: List[List[int]], changeTime: int, numLaps: int) -> int:
"""
You are given a 0-indexed 2D integer array tires where tires[i] = [fi, ri] indicates that the ith tire can finish its xth successive lap in fi * ri(x-1) seconds.
For example, if fi = 3 and ri = 2, then the tire wou... |
number-of-ways-to-build-house-of-cards | def houseOfCards(n: int) -> int:
"""
You are given an integer n representing the number of playing cards you have. A house of cards meets the following conditions:
A house of cards consists of one or more rows of triangles and horizontal cards.
Triangles are created by leaning two cards against eac... |
most-frequent-number-following-key-in-an-array | def mostFrequent(nums: List[int], key: int) -> int:
"""
You are given a 0-indexed integer array nums. You are also given an integer key, which is present in nums.
For every unique integer target in nums, count the number of times target immediately follows an occurrence of key in nums. In other words, count... |
sort-the-jumbled-numbers | def sortJumbled(mapping: List[int], nums: List[int]) -> List[int]:
"""
You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.
The mapped value of an integer is the new integer ob... |
all-ancestors-of-a-node-in-a-directed-acyclic-graph | def getAncestors(n: int, edges: List[List[int]]) -> List[List[int]]:
"""
You are given a positive integer n representing the number of nodes of a Directed Acyclic Graph (DAG). The nodes are numbered from 0 to n - 1 (inclusive).
You are also given a 2D integer array edges, where edges[i] = [fromi, toi] denot... |
minimum-number-of-moves-to-make-palindrome | def minMovesToMakePalindrome(s: str) -> int:
"""
You are given a string s consisting only of lowercase English letters.
In one move, you can select any two adjacent characters of s and swap them.
Return the minimum number of moves needed to make s a palindrome.
Note that the input will be generated ... |
cells-in-a-range-on-an-excel-sheet | def cellsInRange(s: str) -> List[str]:
"""
A cell (r, c) of an excel sheet is represented as a string "" where:
denotes the column number c of the cell. It is represented by alphabetical letters.
For example, the 1st column is denoted by 'A', the 2nd by 'B', the 3rd by 'C', and so on.
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.