task_id
stringlengths
3
79
prompt
stringlengths
255
3.9k
maximum-sum-of-an-hourglass
def maxSum(grid: List[List[int]]) -> int: """ You are given an m x n integer matrix grid. We define an hourglass as a part of the matrix with the following form: Return the maximum sum of the elements of an hourglass. Note that an hourglass cannot be rotated and must be entirely contained withi...
minimize-xor
def minimizeXor(num1: int, num2: int) -> int: """ Given two positive integers num1 and num2, find the positive integer x such that: x has the same number of set bits as num2, and The value x XOR num1 is minimal. Note that XOR is the bitwise XOR operation. Return the integer x. The test...
maximum-deletions-on-a-string
def deleteString(s: str) -> int: """ You are given a string s consisting of only lowercase English letters. In one operation, you can: Delete the entire string s, or Delete the first i letters of s if the first i letters of s are equal to the following i letters in s, for any i in the range 1 <= i ...
maximize-total-tastiness-of-purchased-fruits
def maxTastiness(price: List[int], tastiness: List[int], maxAmount: int, maxCoupons: int) -> int: """ You are given two non-negative integer arrays price and tastiness, both arrays have the same length n. You are also given two non-negative integers maxAmount and maxCoupons. For every integer i in range [0,...
the-employee-that-worked-on-the-longest-task
def hardestWorker(n: int, logs: List[List[int]]) -> int: """ There are n employees, each with a unique id from 0 to n - 1. You are given a 2D integer array logs where logs[i] = [idi, leaveTimei] where: idi is the id of the employee that worked on the ith task, and leaveTimei is the time at whic...
find-the-original-array-of-prefix-xor
def findArray(pref: List[int]) -> List[int]: """ You are given an integer array pref of size n. Find and return the array arr of size n that satisfies: pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]. Note that ^ denotes the bitwise-xor operation. It can be proven that the answer is unique. ...
using-a-robot-to-print-the-lexicographically-smallest-string
def robotWithString(s: str) -> str: """ You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty: Remove the first character of a string s and give it to the robot. The robot will append this character to the string ...
paths-in-matrix-whose-sum-is-divisible-by-k
def numberOfPaths(grid: List[List[int]], k: int) -> int: """ You are given a 0-indexed m x n integer matrix grid and an integer k. You are currently at position (0, 0) and you want to reach position (m - 1, n - 1) moving only down or right. Return the number of paths where the sum of the elements on the pat...
minimum-split-into-subarrays-with-gcd-greater-than-one
def minimumSplits(nums: List[int]) -> int: """ You are given an array nums consisting of positive integers. Split the array into one or more disjoint subarrays such that: Each element of the array belongs to exactly one subarray, and The GCD of the elements of each subarray is strictly greater ...
number-of-valid-clock-times
def countTime(time: str) -> int: """ You are given a string of length 5 called time, representing the current time on a digital clock in the format "hh:mm". The earliest possible time is "00:00" and the latest possible time is "23:59". In the string time, the digits represented by the ? symbol are unknown, ...
range-product-queries-of-powers
def productQueries(n: int, queries: List[List[int]]) -> List[int]: """ Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in non-decreasing order, and there is only one way to form the array. You are also...
minimize-maximum-of-array
def minimizeArrayValue(nums: List[int]) -> int: """ You are given a 0-indexed array nums comprising of n non-negative integers. In one operation, you must: Choose an integer i such that 1 <= i < n and nums[i] > 0. Decrease nums[i] by 1. Increase nums[i - 1] by 1. Return the minimum...
create-components-with-same-value
def componentValue(nums: List[int], edges: List[List[int]]) -> int: """ There is an undirected tree with n nodes labeled from 0 to n - 1. You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also given a 2D integer array edges of length n - 1 w...
largest-positive-integer-that-exists-with-its-negative
def findMaxK(nums: List[int]) -> int: """ Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array. Return the positive integer k. If there is no such integer, return -1. Example 1: >>> findMaxK(nums = [-1,2,-3,3...
count-number-of-distinct-integers-after-reverse-operations
def countDistinctIntegers(nums: List[int]) -> int: """ You are given an array nums consisting of positive integers. You have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers in nums. Return the number of d...
sum-of-number-and-its-reverse
def sumOfNumberAndReverse(num: int) -> bool: """ Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise. Example 1: >>> sumOfNumberAndReverse(num = 443) >>> true Explanation: 172 + 271 = 443 so we...
count-subarrays-with-fixed-bounds
def countSubarrays(nums: List[int], minK: int, maxK: int) -> int: """ You are given an integer array nums and two integers minK and maxK. A fixed-bound subarray of nums is a subarray that satisfies the following conditions: The minimum value in the subarray is equal to minK. The maximum value i...
number-of-nodes-with-value-one
def numberOfNodes(n: int, queries: List[int]) -> int: """ There is an undirected connected tree with n nodes labeled from 1 to n and n - 1 edges. You are given the integer n. The parent node of a node with a label v is the node with the label floor (v / 2). The root of the tree is the node with the label 1. ...
determine-if-two-events-have-conflict
def haveConflict(event1: List[str], event2: List[str]) -> bool: """ You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where: event1 = [startTime1, endTime1] and event2 = [startTime2, endTime2]. Event times are valid 24...
number-of-subarrays-with-gcd-equal-to-k
def subarrayGCD(nums: List[int], k: int) -> int: """ Given an integer array nums and an integer k, return the number of subarrays of nums where the greatest common divisor of the subarray's elements is k. A subarray is a contiguous non-empty sequence of elements within an array. The greatest common divi...
minimum-cost-to-make-array-equal
def minCost(nums: List[int], cost: List[int]) -> int: """ You are given two 0-indexed arrays nums and cost consisting each of n positive integers. You can do the following operation any number of times: Increase or decrease any element of the array nums by 1. The cost of doing one operatio...
minimum-number-of-operations-to-make-arrays-similar
def makeSimilar(nums: List[int], target: List[int]) -> int: """ You are given two positive integer arrays nums and target, of the same length. In one operation, you can choose any two distinct indices i and j where 0 <= i, j < nums.length and: set nums[i] = nums[i] + 2 and set nums[j] = nums[j]...
number-of-distinct-binary-strings-after-applying-operations
def countDistinctStrings(s: str, k: int) -> int: """ You are given a binary string s and a positive integer k. You can apply the following operation on the string any number of times: Choose any substring of size k from s and flip all its characters, that is, turn all 1's into 0's, and all 0's into...
odd-string-difference
def oddString(words: List[str]) -> str: """ You are given an array of equal-length strings words. Assume that the length of each string is n. Each string words[i] can be converted into a difference integer array difference[i] of length n - 1 where difference[i][j] = words[i][j+1] - words[i][j] where 0 <= j ...
words-within-two-edits-of-dictionary
def twoEditWords(queries: List[str], dictionary: List[str]) -> List[str]: """ You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length. In one edit you can take a word from queries, and change any letter in it to any othe...
destroy-sequential-targets
def destroyTargets(nums: List[int], space: int) -> int: """ You are given a 0-indexed array nums consisting of positive integers, representing targets on a number line. You are also given an integer space. You have a machine which can destroy targets. Seeding the machine with some nums[i] allows it to destr...
next-greater-element-iv
def secondGreaterElement(nums: List[int]) -> List[int]: """ You are given a 0-indexed array of non-negative integers nums. For each integer in nums, you must find its respective second greater integer. The second greater integer of nums[i] is nums[j] such that: j > i nums[j] > nums[i] There...
average-value-of-even-numbers-that-are-divisible-by-three
def averageValue(nums: List[int]) -> int: """ Given an integer array nums of positive integers, return the average value of all even integers that are divisible by 3. Note that the average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer. Example 1: ...
most-popular-video-creator
def mostPopularCreator(creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: """ You are given two string arrays creators and ids, and an integer array views, all of length n. The ith video on a platform was created by creators[i], has an id of ids[i], and has views[i] views. The popula...
minimum-addition-to-make-integer-beautiful
def makeIntegerBeautiful(n: int, target: int) -> int: """ You are given two positive integers n and target. An integer is considered beautiful if the sum of its digits is less than or equal to target. Return the minimum non-negative integer x such that n + x is beautiful. The input will be generated suc...
height-of-binary-tree-after-subtree-removal-queries
# class TreeNode: # def __init__(val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def treeQueries(root: Optional[TreeNode], queries: List[int]) -> List[int]: """ You are given the root of a binary tree with n nodes. Each node...
sort-array-by-moving-items-to-empty-space
def sortArray(nums: List[int]) -> int: """ You are given an integer array nums of size n containing each element from 0 to n - 1 (inclusive). Each of the elements from 1 to n - 1 represents an item, and the element 0 represents an empty space. In one operation, you can move any item to the empty space. nums...
apply-operations-to-an-array
def applyOperations(nums: List[int]) -> List[int]: """ You are given a 0-indexed array nums of size n consisting of non-negative integers. You need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith element of nums: If nums[i] ==...
maximum-sum-of-distinct-subarrays-with-length-k
def maximumSubarraySum(nums: List[int], k: int) -> int: """ You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions: The length of the subarray is k, and All the elements of the subarray are distinct. ...
total-cost-to-hire-k-workers
def totalCost(costs: List[int], k: int, candidates: int) -> int: """ You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker. You are also given two integers k and candidates. We want to hire exactly k workers according to the following rules: You will run ...
minimum-total-distance-traveled
def minimumTotalDistance(robot: List[int], factory: List[List[int]]) -> int: """ There are some robots and factories on the X-axis. You are given an integer array robot where robot[i] is the position of the ith robot. You are also given a 2D integer array factory where factory[j] = [positionj, limitj] indicates...
minimum-subarrays-in-a-valid-split
def validSubarraySplit(nums: List[int]) -> int: """ You are given an integer array nums. Splitting of an integer array nums into subarrays is valid if: the greatest common divisor of the first and last elements of each subarray is greater than 1, and each element of nums belongs to exactly one ...
number-of-distinct-averages
def distinctAverages(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums of even length. As long as nums is not empty, you must repetitively: Find the minimum number in nums and remove it. Find the maximum number in nums and remove it. Calculate the average of the two ...
count-ways-to-build-good-strings
def countGoodStrings(low: int, high: int, zero: int, one: int) -> int: """ Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following: Append the character '0' zero times. Append the character '1' on...
most-profitable-path-in-a-tree
def mostProfitablePath(edges: List[List[int]], bob: int, amount: List[int]) -> int: """ There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in ...
split-message-based-on-limit
def splitMessage(message: str, limit: int) -> List[str]: """ You are given a string, message, and a positive integer, limit. You must split message into one or more parts based on limit. Each resulting part should have the suffix "", where "b" is to be replaced with the total number of parts and "a" is to b...
convert-the-temperature
def convertTemperature(celsius: float) -> List[float]: """ You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius. You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit]. Return...
number-of-subarrays-with-lcm-equal-to-k
def subarrayLCM(nums: List[int], k: int) -> int: """ Given an integer array nums and an integer k, return the number of subarrays of nums where the least common multiple of the subarray's elements is k. A subarray is a contiguous non-empty sequence of elements within an array. The least common multiple ...
minimum-number-of-operations-to-sort-a-binary-tree-by-level
# class TreeNode: # def __init__(val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def minimumOperations(root: Optional[TreeNode]) -> int: """ You are given the root of a binary tree with unique values. In one operation, y...
maximum-number-of-non-overlapping-palindrome-substrings
def maxPalindromes(s: str, k: int) -> int: """ You are given a string s and a positive integer k. Select a set of non-overlapping substrings from the string s that satisfy the following conditions: The length of each substring is at least k. Each substring is a palindrome. Return the m...
minimum-cost-to-buy-apples
def minCost(n: int, roads: List[List[int]], appleCost: List[int], k: int) -> List[int]: """ You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads, where roads[i] = [ai, bi, costi] indicates that there is a bidirectional road between cities ai and bi w...
number-of-unequal-triplets-in-array
def unequalTriplets(nums: List[int]) -> int: """ You are given a 0-indexed array of positive integers nums. Find the number of triplets (i, j, k) that meet the following conditions: 0 <= i < j < k < nums.length nums[i], nums[j], and nums[k] are pairwise distinct. In other words, nums[i] !=...
closest-nodes-queries-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 closestNodes(root: Optional[TreeNode], queries: List[int]) -> List[List[int]]: """ You are given the root of a binary search tree and an ar...
minimum-fuel-cost-to-report-to-the-capital
def minimumFuelCost(roads: List[List[int]], seats: int) -> int: """ There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exactly n - 1 roads. The capital city is city 0. You are given a 2D integer array roads where roa...
number-of-beautiful-partitions
def beautifulPartitions(s: str, k: int, minLength: int) -> int: """ You are given a string s that consists of the digits '1' to '9' and two integers k and minLength. A partition of s is called beautiful if: s is partitioned into k non-intersecting substrings. Each substring has a length of at l...
maximum-xor-of-two-non-overlapping-subtrees
def maxXor(n: int, edges: List[List[int]], values: List[int]) -> int: """ There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. The...
minimum-cuts-to-divide-a-circle
def numberOfCuts(n: int) -> int: """ A valid cut in a circle can be: A cut that is represented by a straight line that touches two points on the edge of the circle and passes through its center, or A cut that is represented by a straight line that touches one point on the edge of the circle and its...
difference-between-ones-and-zeros-in-row-and-column
def onesMinusZeros(grid: List[List[int]]) -> List[List[int]]: """ You are given a 0-indexed m x n binary matrix grid. A 0-indexed m x n difference matrix diff is created with the following procedure: Let the number of ones in the ith row be onesRowi. Let the number of ones in the jth column be ...
minimum-penalty-for-a-shop
def bestClosingTime(customers: str) -> int: """ You are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y': if the ith character is 'Y', it means that customers come at the ith hour whereas 'N' indicates that no customers com...
count-palindromic-subsequences
def countPalindromes(s: str) -> int: """ Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 109 + 7. Note: A string is palindromic if it reads the same forward and backward. A subsequence is a stri...
find-the-pivot-integer
def pivotInteger(n: int) -> int: """ Given a positive integer n, find the pivot integer x such that: The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively. Return the pivot integer x. If no such integer exists, return -1. It is guarantee...
append-characters-to-string-to-make-subsequence
def appendCharacters(s: str, t: str) -> int: """ You are given two strings s and t consisting of only lowercase English letters. Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s. A subsequence is a string that can be derived from anoth...
remove-nodes-from-linked-list
# class ListNode: # def __init__(val=0, next=None): # self.val = val # self.next = next class Solution: def removeNodes(head: Optional[ListNode]) -> Optional[ListNode]: """ You are given the head of a linked list. Remove every node which has a node with a greater value anywhere to th...
count-subarrays-with-median-k
def countSubarrays(nums: List[int], k: int) -> int: """ You are given an array nums of size n consisting of distinct integers from 1 to n and a positive integer k. Return the number of non-empty subarrays in nums that have a median equal to k. Note: The median of an array is the middle element ...
number-of-substrings-with-fixed-ratio
def fixedRatio(s: str, num1: int, num2: int) -> int: """ You are given a binary string s, and two integers num1 and num2. num1 and num2 are coprime numbers. A ratio substring is a substring of s where the ratio between the number of 0's and the number of 1's in the substring is exactly num1 : num2. ...
circular-sentence
def isCircularSentence(sentence: str) -> bool: """ A sentence is a list of words that are separated by a single space with no leading or trailing spaces. For example, "Hello World", "HELLO", "hello world hello world" are all sentences. Words consist of only uppercase and lowercase English lett...
divide-players-into-teams-of-equal-skill
def dividePlayers(skill: List[int]) -> int: """ You are given a positive integer array skill of even length n where skill[i] denotes the skill of the ith player. Divide the players into n / 2 teams of size 2 such that the total skill of each team is equal. The chemistry of a team is equal to the product of ...
minimum-score-of-a-path-between-two-cities
def minScore(n: int, roads: List[List[int]]) -> int: """ You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei] indicates that there is a bidirectional road between cities ai and bi with a distance equal to distance...
divide-nodes-into-the-maximum-number-of-groups
def magnificentSets(n: int, edges: List[List[int]]) -> int: """ You are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n. You are also given a 2D integer array edges, where edges[i] = [ai, bi] indicates that there is a bidirectional edge b...
number-of-subarrays-having-even-product
def evenProduct(nums: List[int]) -> int: """ Given a 0-indexed integer array nums, return the number of subarrays of nums having an even product. Example 1: >>> evenProduct(nums = [9,6,7,13]) >>> 6 Explanation: There are 6 subarrays with an even product: - nums[0..1] = 9 * 6 = 54. ...
maximum-value-of-a-string-in-an-array
def maximumValue(strs: List[str]) -> int: """ The value of an alphanumeric string can be defined as: The numeric representation of the string in base 10, if it comprises of digits only. The length of the string, otherwise. Given an array strs of alphanumeric strings, return the maximum val...
maximum-star-sum-of-a-graph
def maxStarSum(vals: List[int], edges: List[List[int]], k: int) -> int: """ There is an undirected graph consisting of n nodes numbered from 0 to n - 1. You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the ith node. You are also given a 2D integer array edges where...
frog-jump-ii
def maxJump(stones: List[int]) -> int: """ You are given a 0-indexed integer array stones sorted in strictly increasing order representing the positions of stones in a river. A frog, initially on the first stone, wants to travel to the last stone and then return to the first stone. However, it can jump to a...
minimum-total-cost-to-make-arrays-unequal
def minimumTotalCost(nums1: List[int], nums2: List[int]) -> int: """ You are given two 0-indexed integer arrays nums1 and nums2, of equal length n. In one operation, you can swap the values of any two indices of nums1. The cost of this operation is the sum of the indices. Find the minimum total cost of ...
delete-greatest-value-in-each-row
def deleteGreatestValue(grid: List[List[int]]) -> int: """ You are given an m x n matrix grid consisting of positive integers. Perform the following operation until grid becomes empty: Delete the element with the greatest value from each row. If multiple such elements exist, delete any of them. ...
longest-square-streak-in-an-array
def longestSquareStreak(nums: List[int]) -> int: """ You are given an integer array nums. A subsequence of nums is called a square streak if: The length of the subsequence is at least 2, and after sorting the subsequence, each element (except the first element) is the square of the previous number....
maximum-number-of-points-from-grid-queries
def maxPoints(grid: List[List[int]], queries: List[int]) -> List[int]: """ You are given an m x n integer matrix grid and an array queries of size k. Find an array answer of size k such that for each integer queries[i] you start in the top left cell of the matrix and repeat the following process: I...
bitwise-or-of-all-subsequence-sums
def subsequenceSumOr(nums: List[int]) -> int: """ Given an integer array nums, return the value of the bitwise OR of the sum of all possible subsequences in the array. A subsequence is a sequence that can be derived from another sequence by removing zero or more elements without changing the order of the re...
count-pairs-of-similar-strings
def similarPairs(words: List[str]) -> int: """ You are given a 0-indexed string array words. Two strings are similar if they consist of the same characters. For example, "abca" and "cba" are similar since both consist of characters 'a', 'b', and 'c'. However, "abacba" and "bcfd" are not similar...
smallest-value-after-replacing-with-sum-of-prime-factors
def smallestValue(n: int) -> int: """ You are given a positive integer n. Continuously replace n with the sum of its prime factors. Note that if a prime factor divides n multiple times, it should be included in the sum as many times as it divides n. Return the smallest value n will take on...
add-edges-to-make-degrees-of-all-nodes-even
def isPossible(n: int, edges: List[List[int]]) -> bool: """ There is an undirected graph consisting of n nodes numbered from 1 to n. You are given the integer n and a 2D array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi. The graph can be disconnected. You can add ...
cycle-length-queries-in-a-tree
def cycleLengthQueries(n: int, queries: List[List[int]]) -> List[int]: """ You are given an integer n. There is a complete binary tree with 2n - 1 nodes. The root of that tree is the node with the value 1, and every node with a value val in the range [1, 2n - 1 - 1] has two children where: The left nod...
check-if-there-is-a-path-with-equal-number-of-0s-and-1s
def isThereAPath(grid: List[List[int]]) -> bool: """ You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1). Return true if there is a path from (0, 0) to (m - 1, n - 1) that visits an equal number of 0's and 1's. Otherwis...
maximum-enemy-forts-that-can-be-captured
def captureForts(forts: List[int]) -> int: """ You are given a 0-indexed integer array forts of length n representing the positions of several forts. forts[i] can be -1, 0, or 1 where: -1 represents there is no fort at the ith position. 0 indicates there is an enemy fort at the ith position. 1 ...
reward-top-k-students
def topStudents(positive_feedback: List[str], negative_feedback: List[str], report: List[str], student_id: List[int], k: int) -> List[int]: """ You are given two string arrays positive_feedback and negative_feedback, containing the words denoting positive and negative feedback, respectively. Note that no word i...
minimize-the-maximum-of-two-arrays
def minimizeSet(divisor1: int, divisor2: int, uniqueCnt1: int, uniqueCnt2: int) -> int: """ We have two arrays arr1 and arr2 which are initially empty. You need to add positive integers to them such that they satisfy all the following conditions: arr1 contains uniqueCnt1 distinct positive integers, eac...
shortest-distance-to-target-string-in-a-circular-array
def closestTarget(words: List[str], target: str, startIndex: int) -> int: """ You are given a 0-indexed circular string array words and a string target. A circular array means that the array's end connects to the array's beginning. Formally, the next element of words[i] is words[(i + 1) % n] and the pr...
take-k-of-each-character-from-left-and-right
def takeCharacters(s: str, k: int) -> int: """ You are given a string s consisting of the characters 'a', 'b', and 'c' and a non-negative integer k. Each minute, you may take either the leftmost character of s, or the rightmost character of s. Return the minimum number of minutes needed for you to take at l...
maximum-tastiness-of-candy-basket
def maximumTastiness(price: List[int], k: int) -> int: """ You are given an array of positive integers price where price[i] denotes the price of the ith candy and a positive integer k. The store sells baskets of k distinct candies. The tastiness of a candy basket is the smallest absolute difference of the p...
number-of-great-partitions
def countPartitions(nums: List[int], k: int) -> int: """ You are given an array nums consisting of positive integers and an integer k. Partition the array into two ordered groups such that each element is in exactly one group. A partition is called great if the sum of elements of each group is greater than ...
count-the-number-of-k-big-indices
def kBigIndices(nums: List[int], k: int) -> int: """ You are given a 0-indexed integer array nums and a positive integer k. We call an index i k-big if the following conditions are satisfied: There exist at least k different indices idx1 such that idx1 < i and nums[idx1] < nums[i]. There exist ...
count-the-digits-that-divide-a-number
def countDigits(num: int) -> int: """ Given an integer num, return the number of digits in num that divide num. An integer val divides nums if nums % val == 0. Example 1: >>> countDigits(num = 7) >>> 1 Explanation: 7 divides itself, hence the answer is 1. Example 2: ...
distinct-prime-factors-of-product-of-array
def distinctPrimeFactors(nums: List[int]) -> int: """ Given an array of positive integers nums, return the number of distinct prime factors in the product of the elements of nums. Note that: A number greater than 1 is called prime if it is divisible by only 1 and itself. An integer val1 is a fa...
partition-string-into-substrings-with-values-at-most-k
def minimumPartition(s: str, k: int) -> int: """ You are given a string s consisting of digits from 1 to 9 and an integer k. A partition of a string s is called good if: Each digit of s is part of exactly one substring. The value of each substring is less than or equal to k. Return the...
closest-prime-numbers-in-range
def closestPrimes(left: int, right: int) -> List[int]: """ Given two positive integers left and right, find the two integers num1 and num2 such that: left <= num1 < num2 <= right . Both num1 and num2 are prime numbers. num2 - num1 is the minimum amongst all other pairs satisfying the above cond...
categorize-box-according-to-criteria
def categorizeBox(length: int, width: int, height: int, mass: int) -> str: """ Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box. The box is "Bulky" if: Any of the dimensio...
find-xor-beauty-of-array
def xorBeauty(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums. The effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]). The xor-beauty of the array is the XORing of the effective values of all the possible triplets of indices (i, j, k) whe...
maximize-the-minimum-powered-city
def maxPower(stations: List[int], r: int, k: int) -> int: """ You are given a 0-indexed integer array stations of length n, where stations[i] represents the number of power stations in the ith city. Each power station can provide power to every city in a fixed range. In other words, if the range is denoted ...
maximum-count-of-positive-integer-and-negative-integer
def maximumCount(nums: List[int]) -> int: """ Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers. In other words, if the number of positive integers in nums is pos and the number of negative integers is neg,...
maximal-score-after-applying-k-operations
def maxKelements(nums: List[int], k: int) -> int: """ You are given a 0-indexed integer array nums and an integer k. You have a starting score of 0. In one operation: choose an index i such that 0 <= i < nums.length, increase your score by nums[i], and replace nums[i] with ceil(nums[i] / 3)...
make-number-of-distinct-characters-equal
def isItPossible(word1: str, word2: str) -> bool: """ You are given two 0-indexed strings word1 and word2. A move consists of choosing two indices i and j such that 0 <= i < word1.length and 0 <= j < word2.length and swapping word1[i] with word2[j]. Return true if it is possible to get the number of dis...
time-to-cross-a-bridge
def findCrossingTime(n: int, k: int, time: List[List[int]]) -> int: """ There are k workers who want to move n boxes from the right (old) warehouse to the left (new) warehouse. You are given the two integers n and k, and a 2D integer array time of size k x 4 where time[i] = [righti, picki, lefti, puti]. The...
number-of-good-binary-strings
def goodBinaryStrings(minLength: int, maxLength: int, oneGroup: int, zeroGroup: int) -> int: """ You are given four integers minLength, maxLength, oneGroup and zeroGroup. A binary string is good if it satisfies the following conditions: The length of the string is in the range [minLength, maxLength...
time-taken-to-cross-the-door
def timeTaken(arrival: List[int], state: List[int]) -> List[int]: """ There are n persons numbered from 0 to n - 1 and a door. Each person can enter or exit through the door once, taking one second. You are given a non-decreasing integer array arrival of size n, where arrival[i] is the arrival time of the i...
difference-between-element-sum-and-digit-sum-of-an-array
def differenceOfSum(nums: List[int]) -> int: """ You are given a positive integer array nums. The element sum is the sum of all the elements in nums. The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums. Return the absolute difference between the elemen...