task_id
stringlengths
3
79
prompt
stringlengths
255
3.9k
append-k-integers-with-minimal-sum
def minimalKSum(nums: List[int], k: int) -> int: """ You are given an integer array nums and an integer k. Append k unique positive integers that do not appear in nums to nums such that the resulting total sum is minimum. Return the sum of the k integers appended to nums. Example 1: >>> mi...
create-binary-tree-from-descriptions
# class TreeNode: # def __init__(val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def createBinaryTree(descriptions: List[List[int]]) -> Optional[TreeNode]: """ You are given a 2D integer array descriptions where descriptions...
replace-non-coprime-numbers-in-array
def replaceNonCoprimes(nums: List[int]) -> List[int]: """ You are given an array of integers nums. Perform the following steps: Find any two adjacent numbers in nums that are non-coprime. If no such numbers are found, stop the process. Otherwise, delete the two numbers and replace them with the...
number-of-single-divisor-triplets
def singleDivisorTriplet(nums: List[int]) -> int: """ You are given a 0-indexed array of positive integers nums. A triplet of three distinct indices (i, j, k) is called a single divisor triplet of nums if nums[i] + nums[j] + nums[k] is divisible by exactly one of nums[i], nums[j], or nums[k]. Return the num...
find-all-k-distant-indices-in-an-array
def findKDistantIndices(nums: List[int], key: int, k: int) -> List[int]: """ You are given a 0-indexed integer array nums and two integers key and k. A k-distant index is an index i of nums for which there exists at least one index j such that |i - j| <= k and nums[j] == key. Return a list of all k-distant ...
count-artifacts-that-can-be-extracted
def digArtifacts(n: int, artifacts: List[List[int]], dig: List[List[int]]) -> int: """ There is an n x n 0-indexed grid with some artifacts buried in it. You are given the integer n and a 0-indexed 2D integer array artifacts describing the positions of the rectangular artifacts where artifacts[i] = [r1i, c1i, r...
maximize-the-topmost-element-after-k-moves
def maximumTop(nums: List[int], k: int) -> int: """ You are given a 0-indexed integer array nums representing the contents of a pile, where nums[0] is the topmost element of the pile. In one move, you can perform either of the following: If the pile is not empty, remove the topmost element of the p...
minimum-weighted-subgraph-with-the-required-paths
def minimumWeight(n: int, edges: List[List[int]], src1: int, src2: int, dest: int) -> int: """ You are given an integer n denoting the number of nodes of a weighted directed graph. The nodes are numbered from 0 to n - 1. You are also given a 2D integer array edges where edges[i] = [fromi, toi, weighti] deno...
distance-to-a-cycle-in-undirected-graph
def distanceToCycle(n: int, edges: List[List[int]]) -> List[int]: """ You are given a positive integer n representing the number of nodes in a connected undirected graph containing exactly one cycle. The nodes are numbered from 0 to n - 1 (inclusive). You are also given a 2D integer array edges, where edges...
divide-array-into-equal-pairs
def divideArray(nums: List[int]) -> bool: """ You are given an integer array nums consisting of 2 * n integers. You need to divide nums into n pairs such that: Each element belongs to exactly one pair. The elements present in a pair are equal. Return true if nums can be divided into n ...
maximize-number-of-subsequences-in-a-string
def maximumSubsequenceCount(text: str, pattern: str) -> int: """ You are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters. You can add either pattern[0] or pattern[1] anywhere in text exactly once. Note that the character...
minimum-operations-to-halve-array-sum
def halveArray(nums: List[int]) -> int: """ You are given an array nums of positive integers. In one operation, you can choose any number from nums and reduce it to exactly half the number. (Note that you may choose this reduced number in future operations.) Return the minimum number of operations to reduce...
minimum-white-tiles-after-covering-with-carpets
def minimumWhiteTiles(floor: str, numCarpets: int, carpetLen: int) -> int: """ You are given a 0-indexed binary string floor, which represents the colors of tiles on a floor: floor[i] = '0' denotes that the ith tile of the floor is colored black. On the other hand, floor[i] = '1' denotes that the i...
count-hills-and-valleys-in-an-array
def countHillValley(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums. An index i is part of a hill in nums if the closest non-equal neighbors of i are smaller than nums[i]. Similarly, an index i is part of a valley in nums if the closest non-equal neighbors of i are larger than nums[i]....
count-collisions-on-a-road
def countCollisions(directions: str) -> int: """ There are n cars on an infinitely long road. The cars are numbered from 0 to n - 1 from left to right and each car is present at a unique point. You are given a 0-indexed string directions of length n. directions[i] can be either 'L', 'R', or 'S' denoting whe...
maximum-points-in-an-archery-competition
def maximumBobPoints(numArrows: int, aliceArrows: List[int]) -> List[int]: """ Alice and Bob are opponents in an archery competition. The competition has set the following rules: Alice first shoots numArrows arrows and then Bob shoots numArrows arrows. The points are then calculated as follows: ...
longest-substring-of-one-repeating-character
def longestRepeating(s: str, queryCharacters: str, queryIndices: List[int]) -> List[int]: """ You are given a 0-indexed string s. You are also given a 0-indexed string queryCharacters of length k and a 0-indexed array of integer indices queryIndices of length k, both of which are used to describe k queries. ...
minimum-health-to-beat-game
def minimumHealth(damage: List[int], armor: int) -> int: """ You are playing a game that has n levels numbered from 0 to n - 1. You are given a 0-indexed integer array damage where damage[i] is the amount of health you will lose to complete the ith level. You are also given an integer armor. You may use you...
find-the-difference-of-two-arrays
def findDifference(nums1: List[int], nums2: List[int]) -> List[List[int]]: """ Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where: answer[0] is a list of all distinct integers in nums1 which are not present in nums2. answer[1] is a list of all distinct integers...
minimum-deletions-to-make-array-beautiful
def minDeletion(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums. The array nums is beautiful if: nums.length is even. nums[i] != nums[i + 1] for all i % 2 == 0. Note that an empty array is considered beautiful. You can delete any number of elements from nums. ...
find-palindrome-with-fixed-length
def kthPalindrome(queries: List[int], intLength: int) -> List[int]: """ Given an integer array queries and a positive integer intLength, return an array answer where answer[i] is either the queries[i]th smallest positive palindrome of length intLength or -1 if no such palindrome exists. A palindrome is a nu...
maximum-value-of-k-coins-from-piles
def maxValueOfCoins(piles: List[List[int]], k: int) -> int: """ There are n piles of coins on a table. Each pile consists of a positive number of coins of assorted denominations. In one move, you can choose any coin on top of any pile, remove it, and add it to your wallet. Given a list piles, where pile...
maximum-sum-score-of-array
def maximumSumScore(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums of length n. The sum score of nums at an index i where 0 <= i < n is the maximum of: The sum of the first i + 1 elements of nums. The sum of the last n - i elements of nums. Return the maximum...
minimum-bit-flips-to-convert-number
def minBitFlips(start: int, goal: int) -> int: """ A bit flip of a number x is choosing a bit in the binary representation of x and flipping it from either 0 to 1 or 1 to 0. For example, for x = 7, the binary representation is 111 and we may choose any bit (including any leading zeros not shown) and fl...
find-triangular-sum-of-an-array
def triangularSum(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums, where nums[i] is a digit between 0 and 9 (inclusive). The triangular sum of nums is the value of the only element present in nums after the following process terminates: Let nums comprise of n elements. If ...
number-of-ways-to-select-buildings
def numberOfWays(s: str) -> int: """ You are given a 0-indexed binary string s which represents the types of buildings along a street where: s[i] = '0' denotes that the ith building is an office and s[i] = '1' denotes that the ith building is a restaurant. As a city official, you would lik...
sum-of-scores-of-built-strings
def sumScores(s: str) -> int: """ You are building a string s of length n one character at a time, prepending each new character to the front of the string. The strings are labeled from 1 to n, where the string with length i is labeled si. For example, for s = "abaca", s1 == "a", s2 == "ca", s3 == "aca...
minimum-number-of-operations-to-convert-time
def convertTime(current: str, correct: str) -> int: """ You are given two strings current and correct representing two 24-hour times. 24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59. In one op...
find-players-with-zero-or-one-losses
def findWinners(matches: List[List[int]]) -> List[List[int]]: """ You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match. Return a list answer of size 2 where: answer[0] is a list of all players that have not l...
maximum-candies-allocated-to-k-children
def maximumCandies(candies: List[int], k: int) -> int: """ You are given a 0-indexed integer array candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together. You are also given an integer k....
check-if-an-array-is-consecutive
def isConsecutive(nums: List[int]) -> bool: """ Given an integer array nums, return true if nums is consecutive, otherwise return false. An array is consecutive if it contains every number in the range [x, x + n - 1] (inclusive), where x is the minimum number in the array and n is the length of the array. ...
largest-number-after-digit-swaps-by-parity
def largestInteger(num: int) -> int: """ You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits). Return the largest possible value of num after any number of swaps. Example 1: >>> largestInteger(num = 12...
minimize-result-by-adding-parentheses-to-expression
def minimizeResult(expression: str) -> str: """ You are given a 0-indexed string expression of the form "+" where and represent positive integers. Add a pair of parentheses to expression such that after the addition of parentheses, expression is a valid mathematical expression and evaluates to the smalles...
maximum-product-after-k-increments
def maximumProduct(nums: List[int], k: int) -> int: """ You are given an array of non-negative integers nums and an integer k. In one operation, you may choose any element from nums and increment it by 1. Return the maximum product of nums after at most k operations. Since the answer may be very large, retu...
maximum-total-beauty-of-the-gardens
def maximumBeauty(flowers: List[int], newFlowers: int, target: int, full: int, partial: int) -> int: """ Alice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens. You are given a 0-indexed integer array flowers of size n, where flowers[i] is the number...
add-two-integers
def sum(num1: int, num2: int) -> int: """ Given two integers num1 and num2, return the sum of the two integers. Example 1: >>> sum(num1 = 12, num2 = 5) >>> 17 Explanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned. Example 2: >>> sum(num1 ...
root-equals-sum-of-children
# class TreeNode: # def __init__(val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def checkTree(root: Optional[TreeNode]) -> bool: """ You are given the root of a binary tree that consists of exactly 3 nodes: the root, its le...
count-positions-on-street-with-required-brightness
def meetRequirement(n: int, lights: List[List[int]], requirement: List[int]) -> int: """ You are given an integer n. A perfectly straight street is represented by a number line ranging from 0 to n - 1. You are given a 2D integer array lights representing the street lamp(s) on the street. Each lights[i] = [posit...
find-closest-number-to-zero
def findClosestNumber(nums: List[int]) -> int: """ Given an integer array nums of size n, return the number with the value closest to 0 in nums. If there are multiple answers, return the number with the largest value. Example 1: >>> findClosestNumber(nums = [-4,-2,1,4,8]) >>> 1 Explana...
number-of-ways-to-buy-pens-and-pencils
def waysToBuyPensPencils(total: int, cost1: int, cost2: int) -> int: """ You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to buy multiple quantiti...
maximum-score-of-a-node-sequence
def maximumScore(scores: List[int], edges: List[List[int]]) -> int: """ There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 0-indexed integer array scores of length n where scores[i] denotes the score of node i. You are also given a 2D integer array edges where edges[i] = [a...
calculate-digit-sum-of-a-string
def digitSum(s: str, k: int) -> str: """ You are given a string s consisting of digits and an integer k. A round can be completed if the length of s is greater than k. In one round, do the following: Divide s into consecutive groups of size k such that the first k characters are in the first group,...
minimum-rounds-to-complete-all-tasks
def minimumRounds(tasks: List[int]) -> int: """ You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level. Return the minimum rounds required to complete all the tasks, or -1 if it...
maximum-trailing-zeros-in-a-cornered-path
def maxTrailingZeros(grid: List[List[int]]) -> int: """ You are given a 2D integer array grid of size m x n, where each cell contains a positive integer. A cornered path is defined as a set of adjacent cells with at most one turn. More specifically, the path should exclusively move either horizontally or ve...
longest-path-with-different-adjacent-characters
def longestPath(parent: List[int], s: str) -> int: """ You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node ...
maximum-cost-of-trip-with-k-highways
def maximumCost(n: int, highways: List[List[int]], k: 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 to go fro...
intersection-of-multiple-arrays
def intersection(nums: List[List[int]]) -> List[int]: """ Given a 2D integer array nums where nums[i] is a non-empty array of distinct positive integers, return the list of integers that are present in each array of nums sorted in ascending order. Example 1: >>> intersection(nums = [[3,1,2,4,5...
count-lattice-points-inside-a-circle
def countLatticePoints(circles: List[List[int]]) -> int: """ Given a 2D integer array circles where circles[i] = [xi, yi, ri] represents the center (xi, yi) and radius ri of the ith circle drawn on a grid, return the number of lattice points that are present inside at least one circle. Note: A latt...
count-number-of-rectangles-containing-each-point
def countRectangles(rectangles: List[List[int]], points: List[List[int]]) -> List[int]: """ You are given a 2D integer array rectangles where rectangles[i] = [li, hi] indicates that ith rectangle has a length of li and a height of hi. You are also given a 2D integer array points where points[j] = [xj, yj] is a ...
number-of-flowers-in-full-bloom
def fullBloomFlowers(flowers: List[List[int]], people: List[int]) -> List[int]: """ You are given a 0-indexed 2D integer array flowers, where flowers[i] = [starti, endi] means the ith flower will be in full bloom from starti to endi (inclusive). You are also given a 0-indexed integer array people of size n, whe...
count-prefixes-of-a-given-string
def countPrefixes(words: List[str], s: str) -> int: """ You are given a string array words and a string s, where words[i] and s comprise only of lowercase English letters. Return the number of strings in words that are a prefix of s. A prefix of a string is a substring that occurs at the beginning of th...
minimum-average-difference
def minimumAverageDifference(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums of length n. The average difference of the index i is the absolute difference between the average of the first i + 1 elements of nums and the average of the last n - i - 1 elements. Both averages should be...
count-unguarded-cells-in-the-grid
def countUnguarded(m: int, n: int, guards: List[List[int]], walls: List[List[int]]) -> int: """ You are given two integers m and n representing a 0-indexed m x n grid. You are also given two 2D integer arrays guards and walls where guards[i] = [rowi, coli] and walls[j] = [rowj, colj] represent the positions of ...
escape-the-spreading-fire
def maximumMinutes(grid: List[List[int]]) -> int: """ You are given a 0-indexed 2D integer array grid of size m x n which represents a field. Each cell has one of three values: 0 represents grass, 1 represents fire, 2 represents a wall that you and fire cannot pass through. You are sit...
remove-digit-from-number-to-maximize-result
def removeDigit(number: str, digit: str) -> str: """ You are given a string number representing a positive integer and a character digit. Return the resulting string after removing exactly one occurrence of digit from number such that the value of the resulting string in decimal form is maximized. The test ...
minimum-consecutive-cards-to-pick-up
def minimumCardPickup(cards: List[int]) -> int: """ You are given an integer array cards where cards[i] represents the value of the ith card. A pair of cards are matching if the cards have the same value. Return the minimum number of consecutive cards you have to pick up to have a pair of matching cards amo...
k-divisible-elements-subarrays
def countDistinct(nums: List[int], k: int, p: int) -> int: """ Given an integer array nums and two integers k and p, return the number of distinct subarrays, which have at most k elements that are divisible by p. Two arrays nums1 and nums2 are said to be distinct if: They are of different lengths, ...
total-appeal-of-a-string
def appealSum(s: str) -> int: """ The appeal of a string is the number of distinct characters found in the string. For example, the appeal of "abbca" is 3 because it has 3 distinct characters: 'a', 'b', and 'c'. Given a string s, return the total appeal of all of its substrings. A substrin...
make-array-non-decreasing-or-non-increasing
def convertArray(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums. In one operation, you can: Choose an index i in the range 0 <= i < nums.length Set nums[i] to nums[i] + 1 or nums[i] - 1 Return the minimum number of operations to make nums non-decreasing or non-in...
largest-3-same-digit-number-in-string
def largestGoodInteger(num: str) -> str: """ You are given a string num representing a large integer. An integer is good if it meets the following conditions: It is a substring of num with length 3. It consists of only one unique digit. Return the maximum good integer as a string or an emp...
count-nodes-equal-to-average-of-subtree
# class TreeNode: # def __init__(val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def averageOfSubtree(root: TreeNode) -> int: """ Given the root of a binary tree, return the number of nodes where the value of the node is equ...
count-number-of-texts
def countTexts(pressedKeys: str) -> int: """ Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below. In order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of the letter in the key. For examp...
check-if-there-is-a-valid-parentheses-string-path
def hasValidPath(grid: List[List[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 ...
minimum-number-of-keypresses
def minimumKeypresses(s: str) -> int: """ You have a keypad with 9 buttons, numbered from 1 to 9, each mapped to lowercase English letters. You can choose which characters each button is matched to as long as: All 26 lowercase English letters are mapped to. Each character is mapped to by exactly 1 ...
find-the-k-beauty-of-a-number
def divisorSubstrings(num: int, k: int) -> int: """ The k-beauty of an integer num is defined as the number of substrings of num when it is read as a string that meet the following conditions: It has a length of k. It is a divisor of num. Given integers num and k, return the k-beauty of nu...
number-of-ways-to-split-array
def waysToSplitArray(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums of length n. nums contains a valid split at index i if the following are true: The sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - 1 elements. There is at least...
maximum-white-tiles-covered-by-a-carpet
def maximumWhiteTiles(tiles: List[List[int]], carpetLen: int) -> int: """ You are given a 2D integer array tiles where tiles[i] = [li, ri] represents that every tile j in the range li <= j <= ri is colored white. You are also given an integer carpetLen, the length of a single carpet that can be placed anywh...
substring-with-largest-variance
def largestVariance(s: str) -> int: """ The variance of a string is defined as the largest difference between the number of occurrences of any 2 characters present in the string. Note the two characters may or may not be the same. Given a string s consisting of lowercase English letters only, return the lar...
find-resultant-array-after-removing-anagrams
def removeAnagrams(words: List[str]) -> List[str]: """ You are given a 0-indexed string array words, where words[i] consists of lowercase English letters. In one operation, select any index i such that 0 < i < words.length and words[i - 1] and words[i] are anagrams, and delete words[i] from words. Keep perf...
maximum-consecutive-floors-without-special-floors
def maxConsecutive(bottom: int, top: int, special: List[int]) -> int: """ Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be special floors, used for relaxation only. You are given two integers bottom and top, which denote that ...
largest-combination-with-bitwise-and-greater-than-zero
def largestCombination(candidates: List[int]) -> int: """ The bitwise AND of an array nums is the bitwise AND of all integers in nums. For example, for nums = [1, 5, 3], the bitwise AND is equal to 1 & 5 & 3 = 1. Also, for nums = [7], the bitwise AND is 7. You are given an array of positiv...
closest-node-to-path-in-tree
def closestNode(n: int, edges: List[List[int]], query: List[List[int]]) -> List[int]: """ You are given a positive integer n representing the number of nodes in a tree, numbered from 0 to n - 1 (inclusive). You are also given a 2D integer array edges of length n - 1, where edges[i] = [node1i, node2i] denotes th...
percentage-of-letter-in-string
def percentageLetter(s: str, letter: str) -> int: """ Given a string s and a character letter, return the percentage of characters in s that equal letter rounded down to the nearest whole percent. Example 1: >>> percentageLetter(s = "foobar", letter = "o") >>> 33 Explanation: The p...
maximum-bags-with-full-capacity-of-rocks
def maximumBags(capacity: List[int], rocks: List[int], additionalRocks: int) -> int: """ You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The ith bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also given an integ...
minimum-lines-to-represent-a-line-chart
def minimumLines(stockPrices: List[List[int]]) -> int: """ You are given a 2D integer array stockPrices where stockPrices[i] = [dayi, pricei] indicates the price of the stock on day dayi is pricei. A line chart is created from the array by plotting the points on an XY plane with the X-axis representing the day ...
sum-of-total-strength-of-wizards
def totalStrength(strength: List[int]) -> int: """ As the ruler of a kingdom, you have an army of wizards at your command. You are given a 0-indexed integer array strength, where strength[i] denotes the strength of the ith wizard. For a contiguous group of wizards (i.e. the wizards' strengths form a subarra...
number-of-people-that-can-be-seen-in-a-grid
def seePeople(heights: List[List[int]]) -> List[List[int]]: """ You are given an m x n 0-indexed 2D array of positive integers heights where heights[i][j] is the height of the person standing at position (i, j). A person standing at position (row1, col1) can see a person standing at position (row2, col2) if...
check-if-number-has-equal-digit-count-and-digit-value
def digitCount(num: str) -> bool: """ You are given a 0-indexed string num of length n consisting of digits. Return true if for every index i in the range 0 <= i < n, the digit i occurs num[i] times in num, otherwise return false. Example 1: >>> digitCount(num = "1210") >>> true Ex...
sender-with-largest-word-count
def largestWordCount(messages: List[str], senders: List[str]) -> str: """ You have a chat log of n messages. You are given two string arrays messages and senders where messages[i] is a message sent by senders[i]. A message is list of words that are separated by a single space with no leading or trailing spa...
maximum-total-importance-of-roads
def maximumImportance(n: int, roads: List[List[int]]) -> int: """ You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1. You are also given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting ci...
rearrange-characters-to-make-target-string
def rearrangeCharacters(s: str, target: str) -> int: """ You are given two 0-indexed strings s and target. You can take some letters from s and rearrange them to form new strings. Return the maximum number of copies of target that can be formed by taking letters from s and rearranging them. Example...
apply-discount-to-prices
def discountPrices(sentence: str, discount: int) -> str: """ A sentence is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign '$'. A word represents a price if it is a sequence of digits preceded by a dollar sign. For example, "$100", "$2...
steps-to-make-array-non-decreasing
def totalSteps(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i - 1] > nums[i] for all 0 < i < nums.length. Return the number of steps performed until nums becomes a non-decreasing array. Example 1: >>> totalSt...
minimum-obstacle-removal-to-reach-corner
def minimumObstacles(grid: List[List[int]]) -> int: """ You are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values: 0 represents an empty cell, 1 represents an obstacle that may be removed. You can move up, down, left, or right from and to an empty cell....
maximum-profit-from-trading-stocks
def maximumProfit(present: List[int], future: List[int], budget: int) -> int: """ You are given two 0-indexed integer arrays of the same length present and future where present[i] is the current price of the ith stock and future[i] is the price of the ith stock a year in the future. You may buy each stock at mo...
min-max-game
def minMaxGame(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums whose length is a power of 2. Apply the following algorithm on nums: Let n be the length of nums. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n / 2. For eve...
partition-array-such-that-maximum-difference-is-k
def partitionArray(nums: List[int], k: int) -> int: """ You are given an integer array nums and an integer k. You may partition nums into one or more subsequences such that each element in nums appears in exactly one of the subsequences. Return the minimum number of subsequences needed such that the differe...
replace-elements-in-an-array
def arrayChange(nums: List[int], operations: List[List[int]]) -> List[int]: """ You are given a 0-indexed array nums that consists of n distinct positive integers. Apply m operations to this array, where in the ith operation you replace the number operations[i][0] with operations[i][1]. It is guaranteed tha...
jump-game-viii
def minCost(nums: List[int], costs: List[int]) -> int: """ You are given a 0-indexed integer array nums of length n. You are initially standing at index 0. You can jump from index i to index j where i < j if: nums[i] <= nums[j] and nums[k] < nums[i] for all indexes k in the range i < k < j, or nums...
strong-password-checker-ii
def strongPasswordCheckerII(password: str) -> bool: """ A password is said to be strong if it satisfies all the following criteria: It has at least 8 characters. It contains at least one lowercase letter. It contains at least one uppercase letter. It contains at least one digit. It cont...
successful-pairs-of-spells-and-potions
def successfulPairs(spells: List[int], potions: List[int], success: int) -> List[int]: """ You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the ith spell and potions[j] represents the strength of the jth potion. You are ...
match-substring-after-replacement
def matchReplacement(s: str, sub: str, mappings: List[List[str]]) -> bool: """ You are given two strings s and sub. You are also given a 2D character array mappings where mappings[i] = [oldi, newi] indicates that you may perform the following operation any number of times: Replace a character oldi of s...
count-subarrays-with-score-less-than-k
def countSubarrays(nums: List[int], k: int) -> int: """ The score of an array is defined as the product of its sum and its length. For example, the score of [1, 2, 3, 4, 5] is (1 + 2 + 3 + 4 + 5) * 5 = 75. Given a positive integer array nums and an integer k, return the number of non-empty sub...
calculate-amount-paid-in-taxes
def calculateTax(brackets: List[List[int]], income: int) -> float: """ You are given a 0-indexed 2D integer array brackets where brackets[i] = [upperi, percenti] means that the ith tax bracket has an upper bound of upperi and is taxed at a rate of percenti. The brackets are sorted by upper bound (i.e. upperi-1 ...
minimum-path-cost-in-a-grid
def minPathCost(grid: List[List[int]], moveCost: List[List[int]]) -> int: """ You are given a 0-indexed m x n integer matrix grid consisting of distinct integers from 0 to m * n - 1. You can move in this matrix from a cell to any other cell in the next row. That is, if you are in cell (x, y) such that x < m - 1...
fair-distribution-of-cookies
def distributeCookies(cookies: List[int], k: int) -> int: """ You are given an integer array cookies, where cookies[i] denotes the number of cookies in the ith bag. You are also given an integer k that denotes the number of children to distribute all the bags of cookies to. All the cookies in the same bag must ...
naming-a-company
def distinctNames(ideas: List[str]) -> int: """ You are given an array of strings ideas that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows: Choose 2 distinct names from ideas, call them ideaA and ideaB. Swap the first letters...
check-for-contradictions-in-equations
def checkContradictions(equations: List[List[str]], values: List[float]) -> bool: """ You are given a 2D array of strings equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] means that Ai / Bi = values[i]. Determine if there exists a contradiction in the equations. Ret...
greatest-english-letter-in-upper-and-lower-case
def greatestLetter(s: str) -> str: """ Given a string of English letters s, return the greatest English letter which occurs as both a lowercase and uppercase letter in s. The returned letter should be in uppercase. If no such letter exists, return an empty string. An English letter b is greater than another...
sum-of-numbers-with-units-digit-k
def minimumNumbers(num: int, k: int) -> int: """ Given two integers num and k, consider a set of positive integers with the following properties: The units digit of each integer is k. The sum of the integers is num. Return the minimum possible size of such a set, or -1 if no such set exist...