task_id stringlengths 3 79 | prompt stringlengths 255 3.9k |
|---|---|
number-of-beautiful-integers-in-the-range | def numberOfBeautifulIntegers(low: int, high: int, k: int) -> int:
"""
You are given positive integers low, high, and k.
A number is beautiful if it meets both of the following conditions:
The count of even digits in the number is equal to the count of odd digits.
The number is divisible by k.
... |
check-if-a-string-is-an-acronym-of-words | def isAcronym(words: List[str], s: str) -> bool:
"""
Given an array of strings words and a string s, determine if s is an acronym of words.
The string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, "ab" can be forme... |
determine-the-minimum-sum-of-a-k-avoiding-array | def minimumSum(n: int, k: int) -> int:
"""
You are given two integers, n and k.
An array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.
Return the minimum possible sum of a k-avoiding array of length n.
Example 1:
... |
maximize-the-profit-as-the-salesman | def maximizeTheProfit(n: int, offers: List[List[int]]) -> int:
"""
You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.
Additionally, you are given a 2D integer array offers where offers[i] = [starti, endi, goldi], indicating that ith buyer wants to buy al... |
find-the-longest-equal-subarray | def longestEqualSubarray(nums: List[int], k: int) -> int:
"""
You are given a 0-indexed integer array nums and an integer k.
A subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.
Return the length of the longest possible equal subarray after dele... |
maximal-range-that-each-element-is-maximum-in-it | def maximumLengthOfRanges(nums: List[int]) -> List[int]:
"""
You are given a 0-indexed array nums of distinct integers.
Let us define a 0-indexed array ans of the same length as nums in the following way:
ans[i] is the maximum length of a subarray nums[l..r], such that the maximum element in that s... |
furthest-point-from-origin | def furthestDistanceFromOrigin(moves: str) -> int:
"""
You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.
In the ith move, you can choose one of the following directions:
move to ... |
find-the-minimum-possible-sum-of-a-beautiful-array | def minimumPossibleSum(n: int, target: int) -> int:
"""
You are given positive integers n and target.
An array nums is beautiful if it meets the following conditions:
nums.length == n.
nums consists of pairwise distinct positive integers.
There doesn't exist two distinct indices, i and j, i... |
minimum-operations-to-form-subsequence-with-target-sum | def minOperations(nums: List[int], target: int) -> int:
"""
You are given a 0-indexed array nums consisting of non-negative powers of 2, and an integer target.
In one operation, you must apply the following changes to the array:
Choose any element of the array nums[i] such that nums[i] > 1.
Rem... |
maximize-value-of-function-in-a-ball-passing-game | def getMaxFunctionValue(receiver: List[int], k: int) -> int:
"""
You are given an integer array receiver of length n and an integer k. n players are playing a ball-passing game.
You choose the starting player, i. The game proceeds as follows: player i passes the ball to player receiver[i], who then passes i... |
maximum-coins-heroes-can-collect | def maximumCoins(heroes: List[int], monsters: List[int], coins: List[int]) -> List[int]:
"""
There is a battle and n heroes are trying to defeat m monsters. You are given two 1-indexed arrays of positive integers heroes and monsters of length n and m, respectively. heroes[i] is the power of ith hero, and monste... |
check-if-strings-can-be-made-equal-with-operations-i | def canBeEqual(s1: str, s2: str) -> bool:
"""
You are given two strings s1 and s2, both of length 4, consisting of lowercase English letters.
You can apply the following operation on any of the two strings any number of times:
Choose any two indices i and j such that j - i = 2, then swap the two ch... |
check-if-strings-can-be-made-equal-with-operations-ii | def checkStrings(s1: str, s2: str) -> bool:
"""
You are given two strings s1 and s2, both of length n, consisting of lowercase English letters.
You can apply the following operation on any of the two strings any number of times:
Choose any two indices i and j such that i < j and the difference j - ... |
maximum-sum-of-almost-unique-subarray | def maxSum(nums: List[int], m: int, k: int) -> int:
"""
You are given an integer array nums and two positive integers m and k.
Return the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0.
A subarray of nums is almost unique if it contains at least ... |
count-k-subsequences-of-a-string-with-maximum-beauty | def countKSubsequencesWithMaxBeauty(s: str, k: int) -> int:
"""
You are given a string s and an integer k.
A k-subsequence is a subsequence of s, having length k, and all its characters are unique, i.e., every character occurs once.
Let f(c) denote the number of times the character c occurs in s.
Th... |
count-symmetric-integers | def countSymmetricIntegers(low: int, high: int) -> int:
"""
You are given two positive integers low and high.
An integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x. Numbers with an odd number of digits are never symmetric.
... |
minimum-operations-to-make-a-special-number | def minimumOperations(num: str) -> int:
"""
You are given a 0-indexed string num representing a non-negative integer.
In one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.
Return the minimum number of operations required to make num ... |
count-of-interesting-subarrays | def countInterestingSubarrays(nums: List[int], modulo: int, k: int) -> int:
"""
You are given a 0-indexed integer array nums, an integer modulo, and an integer k.
Your task is to find the count of subarrays that are interesting.
A subarray nums[l..r] is interesting if the following condition holds:
... |
minimum-edge-weight-equilibrium-queries-in-a-tree | def minOperationsQueries(n: int, edges: List[List[int]], queries: List[List[int]]) -> List[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] = [ui, vi, wi] indicates that there is an edge between n... |
smallest-number-with-given-digit-product | def smallestNumber(n: int) -> str:
"""
Given a positive integer n, return a string representing the smallest positive integer such that the product of its digits is equal to n, or "-1" if no such number exists.
Example 1:
>>> smallestNumber(n = 105)
>>> "357"
Explanation: 3 * 5 * 7 = 1... |
points-that-intersect-with-cars | def numberOfPoints(nums: List[List[int]]) -> int:
"""
You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti, endi] where starti is the starting point of the ith car and endi is the ending point of the ith car.
Re... |
determine-if-a-cell-is-reachable-at-a-given-time | def isReachableAtTime(sx: int, sy: int, fx: int, fy: int, t: int) -> bool:
"""
You are given four integers sx, sy, fx, fy, and a non-negative integer t.
In an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.
Return true if you can reach cell (fx,... |
minimum-moves-to-spread-stones-over-grid | def minimumMoves(grid: List[List[int]]) -> int:
"""
You are given a 0-indexed 2D integer matrix grid of size 3 * 3, representing the number of stones in each cell. The grid contains exactly 9 stones, and there can be multiple stones in a single cell.
In one move, you can move a single stone from its current... |
string-transformation | def numberOfWays(s: str, t: str, k: int) -> int:
"""
You are given two strings s and t of equal length n. You can perform the following operation on the string s:
Remove a suffix of s of length l where 0 < l < n and append it at the start of s.
For example, let s = 'abcd' then in one operation you... |
sum-of-remoteness-of-all-cells | def sumRemoteness(grid: List[List[int]]) -> int:
"""
You are given a 0-indexed matrix grid of order n * n. Each cell in this matrix has a value grid[i][j], which is either a positive integer or -1 representing a blocked cell.
You can move from a non-blocked cell to any non-blocked cell that shares an edge.
... |
minimum-right-shifts-to-sort-the-array | def minimumRightShifts(nums: List[int]) -> int:
"""
You are given a 0-indexed array nums of length n containing distinct positive integers. Return the minimum number of right shifts required to sort nums and -1 if this is not possible.
A right shift is defined as shifting the element at index i to index (i ... |
minimum-array-length-after-pair-removals | def minLengthAfterRemovals(nums: List[int]) -> int:
"""
Given an integer array num sorted in non-decreasing order.
You can perform the following operation any number of times:
Choose two indices, i and j, where nums[i] < nums[j].
Then, remove the elements at indices i and j from nums. The remai... |
count-pairs-of-points-with-distance-k | def countPairs(coordinates: List[List[int]], k: int) -> int:
"""
You are given a 2D integer array coordinates and an integer k, where coordinates[i] = [xi, yi] are the coordinates of the ith point in a 2D plane.
We define the distance between two points (x1, y1) and (x2, y2) as (x1 XOR x2) + (y1 XOR y2) whe... |
minimum-edge-reversals-so-every-node-is-reachable | def minEdgeReversals(n: int, edges: List[List[int]]) -> List[int]:
"""
There is a simple directed graph with n nodes labeled from 0 to n - 1. The graph would form a tree if its edges were bi-directional.
You are given an integer n and a 2D integer array edges, where edges[i] = [ui, vi] represents a directed... |
sum-of-values-at-indices-with-k-set-bits | def sumIndicesWithKSetBits(nums: List[int], k: int) -> int:
"""
You are given a 0-indexed integer array nums and an integer k.
Return an integer that denotes the sum of elements in nums whose corresponding indices have exactly k set bits in their binary representation.
The set bits in an integer are the... |
happy-students | def countWays(nums: List[int]) -> int:
"""
You are given a 0-indexed integer array nums of length n where n is the total number of students in the class. The class teacher tries to select a group of students so that all the students remain happy.
The ith student will become happy if one of these two conditi... |
maximum-number-of-alloys | def maxNumberOfAlloys(n: int, k: int, budget: int, composition: List[List[int]], stock: List[int], cost: List[int]) -> int:
"""
You are the owner of a company that creates alloys using various types of metals. There are n different types of metals available, and you have access to k machines that can be used to... |
maximum-element-sum-of-a-complete-subset-of-indices | def maximumSum(nums: List[int]) -> int:
"""
You are given a 1-indexed array nums. Your task is to select a complete subset from nums where every pair of selected indices multiplied is a perfect square,. i. e. if you select ai and aj, i * j must be a perfect square.
Return the sum of the complete subset with... |
maximum-length-of-semi-decreasing-subarrays | def maxSubarrayLength(nums: List[int]) -> int:
"""
You are given an integer array nums.
Return the length of the longest semi-decreasing subarray of nums, and 0 if there are no such subarrays.
A subarray is a contiguous non-empty sequence of elements within an array.
A non-empty array is semi-d... |
maximum-odd-binary-number | def maximumOddBinaryNumber(s: str) -> str:
"""
You are given a binary string s that contains at least one '1'.
You have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.
Return a string representing the maximu... |
beautiful-towers-i | def maximumSumOfHeights(heights: List[int]) -> int:
"""
You are given an array heights of n integers representing the number of bricks in n consecutive towers. Your task is to remove some bricks to form a mountain-shaped tower arrangement. In this arrangement, the tower heights are non-decreasing, reaching a ma... |
beautiful-towers-ii | def maximumSumOfHeights(maxHeights: List[int]) -> int:
"""
You are given a 0-indexed array maxHeights of n integers.
You are tasked with building n towers in the coordinate line. The ith tower is built at coordinate i and has a height of heights[i].
A configuration of towers is beautiful if the followin... |
count-valid-paths-in-a-tree | def countPaths(n: int, edges: List[List[int]]) -> int:
"""
There is an undirected tree with n nodes labeled from 1 to n. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree.
Return the number ... |
the-wording-game | def canAliceWin(a: List[str], b: List[str]) -> bool:
"""
Alice and Bob each have a lexicographically sorted array of strings named a and b respectively.
They are playing a wording game with the following rules:
On each turn, the current player should play a word from their list such that the new wo... |
minimum-operations-to-collect-elements | def minOperations(nums: List[int], k: int) -> int:
"""
You are given an array nums of positive integers and an integer k.
In one operation, you can remove the last element of the array and add it to your collection.
Return the minimum number of operations needed to collect elements 1, 2, ..., k.
... |
minimum-number-of-operations-to-make-array-empty | def minOperations(nums: List[int]) -> int:
"""
You are given a 0-indexed array nums consisting of positive integers.
There are two types of operations that you can apply on the array any number of times:
Choose two elements with equal values and delete them from the array.
Choose three elements... |
split-array-into-maximum-number-of-subarrays | def maxSubarrays(nums: List[int]) -> int:
"""
You are given an array nums consisting of non-negative integers.
We define the score of subarray nums[l..r] such that l <= r as nums[l] AND nums[l + 1] AND ... AND nums[r] where AND is the bitwise AND operation.
Consider splitting the array into one or more ... |
maximum-number-of-k-divisible-components | def maxKDivisibleComponents(n: int, edges: List[List[int]], values: List[int], k: 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 a... |
maximum-value-of-an-ordered-triplet-i | def maximumTripletValue(nums: List[int]) -> int:
"""
You are given a 0-indexed integer array nums.
Return the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.
The value of a triplet of indices (i, j, k) is equal to (nums[i] -... |
maximum-value-of-an-ordered-triplet-ii | def maximumTripletValue(nums: List[int]) -> int:
"""
You are given a 0-indexed integer array nums.
Return the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.
The value of a triplet of indices (i, j, k) is equal to (nums[i] -... |
minimum-size-subarray-in-infinite-array | def minSizeSubarray(nums: List[int], target: int) -> int:
"""
You are given a 0-indexed array nums and an integer target.
A 0-indexed array infinite_nums is generated by infinitely appending the elements of nums to itself.
Return the length of the shortest subarray of the array infinite_nums with a sum ... |
count-visited-nodes-in-a-directed-graph | def countVisitedNodes(edges: List[int]) -> List[int]:
"""
There is a directed graph consisting of n nodes numbered from 0 to n - 1 and n directed edges.
You are given a 0-indexed array edges where edges[i] indicates that there is an edge from node i to node edges[i].
Consider the following process on th... |
minimizing-array-after-replacing-pairs-with-their-product | def minArrayLength(nums: List[int], k: int) -> int:
"""
Given an integer array nums and an integer k, you can perform the following operation on the array any number of times:
Select two adjacent elements of the array like x and y, such that x * y <= k, and replace both of them with a single element wi... |
divisible-and-non-divisible-sums-difference | def differenceOfSums(n: int, m: int) -> int:
"""
You are given positive integers n and m.
Define two integers as follows:
num1: The sum of all integers in the range [1, n] (both inclusive) that are not divisible by m.
num2: The sum of all integers in the range [1, n] (both inclusive) that are d... |
minimum-processing-time | def minProcessingTime(processorTime: List[int], tasks: List[int]) -> int:
"""
You have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors. Each task must be assigned to a unique core, and each core can only be used once.
You are giv... |
apply-operations-to-make-two-strings-equal | def minOperations(s1: str, s2: str, x: int) -> int:
"""
You are given two 0-indexed binary strings s1 and s2, both of length n, and a positive integer x.
You can perform any of the following operations on the string s1 any number of times:
Choose two indices i and j, and flip both s1[i] and s1[j]. ... |
apply-operations-on-array-to-maximize-sum-of-squares | def maxSum(nums: List[int], k: int) -> int:
"""
You are given a 0-indexed integer array nums and a positive integer k.
You can do the following operation on the array any number of times:
Choose any two distinct indices i and j and simultaneously update the values of nums[i] to (nums[i] AND nums[j]... |
maximum-linear-stock-score | def maxScore(prices: List[int]) -> int:
"""
Given a 1-indexed integer array prices, where prices[i] is the price of a particular stock on the ith day, your task is to select some of the elements of prices such that your selection is linear.
A selection indexes, where indexes is a 1-indexed integer array of ... |
last-visited-integers | def lastVisitedIntegers(nums: List[int]) -> List[int]:
"""
Given an integer array nums where nums[i] is either a positive integer or -1. We need to find for each -1 the respective positive integer, which we call the last visited integer.
To achieve this goal, let's define two empty arrays: seen and ans.
... |
longest-unequal-adjacent-groups-subsequence-i | def getLongestSubsequence(words: List[str], groups: List[int]) -> List[str]:
"""
You are given a string array words and a binary array groups both of length n, where words[i] is associated with groups[i].
Your task is to select the longest alternating subsequence from words. A subsequence of words is altern... |
longest-unequal-adjacent-groups-subsequence-ii | def getWordsInLongestSubsequence(words: List[str], groups: List[int]) -> List[str]:
"""
You are given a string array words, and an array groups, both arrays having length n.
The hamming distance between two strings of equal length is the number of positions at which the corresponding characters are differen... |
count-of-sub-multisets-with-bounded-sum | def countSubMultisets(nums: List[int], l: int, r: int) -> int:
"""
You are given a 0-indexed array nums of non-negative integers, and two integers l and r.
Return the count of sub-multisets within nums where the sum of elements in each subset falls within the inclusive range of [l, r].
Since the answer ... |
find-indices-with-index-and-value-difference-i | def findIndices(nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:
"""
You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.
Your task is to find two indices i and j, both in the range [0, n - 1], that satisfy the fo... |
shortest-and-lexicographically-smallest-beautiful-string | def shortestBeautifulSubstring(s: str, k: int) -> str:
"""
You are given a binary string s and a positive integer k.
A substring of s is beautiful if the number of 1's in it is exactly k.
Let len be the length of the shortest beautiful substring.
Return the lexicographically smallest beautiful subst... |
find-indices-with-index-and-value-difference-ii | def findIndices(nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:
"""
You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.
Your task is to find two indices i and j, both in the range [0, n - 1], that satisfy the fo... |
construct-product-matrix | def constructProductMatrix(grid: List[List[int]]) -> List[List[int]]:
"""
Given a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following condition is met:
Each element p[i][j] is calculated as the product of all ele... |
maximum-profitable-triplets-with-increasing-prices-i | def maxProfit(prices: List[int], profits: List[int]) -> int:
"""
Given the 0-indexed arrays prices and profits of length n. There are n items in an store where the ith item has a price of prices[i] and a profit of profits[i].
We have to pick three items with the following condition:
prices[i] < pri... |
minimum-sum-of-mountain-triplets-i | def minimumSum(nums: List[int]) -> int:
"""
You are given a 0-indexed array nums of integers.
A triplet of indices (i, j, k) is a mountain if:
i < j < k
nums[i] < nums[j] and nums[k] < nums[j]
Return the minimum possible sum of a mountain triplet of nums. If no such triplet exists, ret... |
minimum-sum-of-mountain-triplets-ii | def minimumSum(nums: List[int]) -> int:
"""
You are given a 0-indexed array nums of integers.
A triplet of indices (i, j, k) is a mountain if:
i < j < k
nums[i] < nums[j] and nums[k] < nums[j]
Return the minimum possible sum of a mountain triplet of nums. If no such triplet exists, ret... |
minimum-changes-to-make-k-semi-palindromes | def minimumChanges(s: str, k: int) -> int:
"""
Given a string s and an integer k, partition s into k substrings such that the letter changes needed to make each substring a semi-palindrome are minimized.
Return the minimum number of letter changes required.
A semi-palindrome is a special type of string ... |
number-of-ways-to-reach-destination-in-the-grid | def numberOfWays(n: int, m: int, k: int, source: List[int], dest: List[int]) -> int:
"""
You are given two integers n and m which represent the size of a 1-indexed grid. You are also given an integer k, a 1-indexed integer array source and a 1-indexed integer array dest, where source and dest are in the form [x... |
subarrays-distinct-element-sum-of-squares-i | def sumCounts(nums: List[int]) -> int:
"""
You are given a 0-indexed integer array nums.
The distinct count of a subarray of nums is defined as:
Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in ... |
minimum-number-of-changes-to-make-binary-string-beautiful | def minChanges(s: str) -> int:
"""
You are given a 0-indexed binary string s having an even length.
A string is beautiful if it's possible to partition it into one or more substrings such that:
Each substring has an even length.
Each substring contains only 1's or only 0's.
You can cha... |
length-of-the-longest-subsequence-that-sums-to-target | def lengthOfLongestSubsequence(nums: List[int], target: int) -> int:
"""
You are given a 0-indexed array of integers nums, and an integer target.
Return the length of the longest subsequence of nums that sums up to target. If no such subsequence exists, return -1.
A subsequence is an array that can be d... |
subarrays-distinct-element-sum-of-squares-ii | def sumCounts(nums: List[int]) -> int:
"""
You are given a 0-indexed integer array nums.
The distinct count of a subarray of nums is defined as:
Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in ... |
find-the-k-or-of-an-array | def findKOr(nums: List[int], k: int) -> int:
"""
You are given an integer array nums, and an integer k. Let's introduce K-or operation by extending the standard bitwise OR. In K-or, a bit position in the result is set to 1 if at least k numbers in nums have a 1 in that position.
Return the K-or of nums.
... |
minimum-equal-sum-of-two-arrays-after-replacing-zeros | def minSum(nums1: List[int], nums2: List[int]) -> int:
"""
You are given two arrays nums1 and nums2 consisting of positive integers.
You have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.
Return the minimum equal sum you... |
minimum-increment-operations-to-make-array-beautiful | def minIncrementOperations(nums: List[int], k: int) -> int:
"""
You are given a 0-indexed integer array nums having length n, and an integer k.
You can perform the following increment operation any number of times (including zero):
Choose an index i in the range [0, n - 1], and increase nums[i] by ... |
maximum-points-after-collecting-coins-from-all-nodes | def maximumPoints(edges: List[List[int]], coins: List[int], k: int) -> int:
"""
There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. 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 the ... |
maximum-profitable-triplets-with-increasing-prices-ii | def maxProfit(prices: List[int], profits: List[int]) -> int:
"""
Given the 0-indexed arrays prices and profits of length n. There are n items in an store where the ith item has a price of prices[i] and a profit of profits[i].
We have to pick three items with the following condition:
prices[i] < pri... |
find-champion-i | def findChampion(grid: List[List[int]]) -> int:
"""
There are n teams numbered from 0 to n - 1 in a tournament.
Given a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 <= i, j <= n - 1 and i != j team i is stronger than team j if grid[i][j] == 1, otherwise, team j is stronger than team i... |
find-champion-ii | def findChampion(n: int, edges: List[List[int]]) -> int:
"""
There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG.
You are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [ui, vi] indicates that there is a... |
maximum-score-after-applying-operations-on-a-tree | def maximumScoreAfterOperations(edges: List[List[int]], values: List[int]) -> int:
"""
There is an undirected tree with n nodes labeled from 0 to n - 1, and 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... |
maximum-balanced-subsequence-sum | def maxBalancedSubsequenceSum(nums: List[int]) -> int:
"""
You are given a 0-indexed integer array nums.
A subsequence of nums having length k and consisting of indices i0 < i1 < ... < ik-1 is balanced if the following holds:
nums[ij] - nums[ij-1] >= ij - ij-1, for every j in the range [1, k - 1].
... |
distribute-candies-among-children-iii | def distributeCandies(n: int, limit: int) -> int:
"""
You are given two positive integers n and limit.
Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.
Example 1:
>>> distributeCandies(n = 5, limit = 2)
>>> 3
... |
distribute-candies-among-children-i | def distributeCandies(n: int, limit: int) -> int:
"""
You are given two positive integers n and limit.
Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.
Example 1:
>>> distributeCandies(n = 5, limit = 2)
>>> 3
... |
distribute-candies-among-children-ii | def distributeCandies(n: int, limit: int) -> int:
"""
You are given two positive integers n and limit.
Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.
Example 1:
>>> distributeCandies(n = 5, limit = 2)
>>> 3
... |
number-of-strings-which-can-be-rearranged-to-contain-substring | def stringCount(n: int) -> int:
"""
You are given an integer n.
A string s is called good if it contains only lowercase English characters and it is possible to rearrange the characters of s such that the new string contains "leet" as a substring.
For example:
The string "lteer" is good because... |
maximum-spending-after-buying-items | def maxSpending(values: List[List[int]]) -> int:
"""
You are given a 0-indexed m * n integer matrix values, representing the values of m * n different items in m different shops. Each shop has n items where the jth item in the ith shop has a value of values[i][j]. Additionally, the items in the ith shop are sor... |
maximum-strong-pair-xor-i | def maximumStrongPairXor(nums: List[int]) -> int:
"""
You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:
|x - y| <= min(x, y)
You need to select two integers from nums such that they form a strong pair and their bitwi... |
high-access-employees | def findHighAccessEmployees(access_times: List[List[str]]) -> List[str]:
"""
You are given a 2D 0-indexed array of strings, access_times, with size n. For each i where 0 <= i <= n - 1, access_times[i][0] represents the name of an employee, and access_times[i][1] represents the access time of that employee. All ... |
minimum-operations-to-maximize-last-elements-in-arrays | def minOperations(nums1: List[int], nums2: List[int]) -> int:
"""
You are given two 0-indexed integer arrays, nums1 and nums2, both having length n.
You are allowed to perform a series of operations (possibly none).
In an operation, you select an index i in the range [0, n - 1] and swap the values of nu... |
maximum-strong-pair-xor-ii | def maximumStrongPairXor(nums: List[int]) -> int:
"""
You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:
|x - y| <= min(x, y)
You need to select two integers from nums such that they form a strong pair and their bitwi... |
make-three-strings-equal | def findMinimumOperations(s1: str, s2: str, s3: str) -> int:
"""
You are given three strings: s1, s2, and s3. In one operation you can choose one of these strings and delete its rightmost character. Note that you cannot completely empty a string.
Return the minimum number of operations required to make the ... |
separate-black-and-white-balls | def minimumSteps(s: str) -> int:
"""
There are n balls on a table, each ball has a color black or white.
You are given a 0-indexed binary string s of length n, where 1 and 0 represent black and white balls, respectively.
In each step, you can choose two adjacent balls and swap them.
Return the minim... |
maximum-xor-product | def maximumXorProduct(a: int, b: int, n: int) -> int:
"""
Given three integers a, b, and n, return the maximum value of (a XOR x) * (b XOR x) where 0 <= x < 2n.
Since the answer may be too large, return it modulo 109 + 7.
Note that XOR is the bitwise XOR operation.
Example 1:
>>> maxim... |
find-building-where-alice-and-bob-can-meet | def leftmostBuildingQueries(heights: List[int], queries: List[List[int]]) -> List[int]:
"""
You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the ith building.
If a person is in building i, they can move to any other building j if and only if i < j and h... |
maximum-gcd-sum-of-a-subarray | def maxGcdSum(nums: List[int], k: int) -> int:
"""
You are given an array of integers nums and an integer k.
The gcd-sum of an array a is calculated as follows:
Let s be the sum of all the elements of a.
Let g be the greatest common divisor of all the elements of a.
The gcd-sum of a is equa... |
find-words-containing-character | def findWordsContaining(words: List[str], x: str) -> List[int]:
"""
You are given a 0-indexed array of strings words and a character x.
Return an array of indices representing the words that contain the character x.
Note that the returned array may be in any order.
Example 1:
>>> findW... |
maximize-area-of-square-hole-in-grid | def maximizeSquareHoleArea(n: int, m: int, hBars: List[int], vBars: List[int]) -> int:
"""
You are given the two integers, n and m and two integer arrays, hBars and vBars. The grid has n + 2 horizontal and m + 2 vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from 1.
You can remove s... |
minimum-number-of-coins-for-fruits | def minimumCoins(prices: List[int]) -> int:
"""
You are given an 0-indexed integer array prices where prices[i] denotes the number of coins needed to purchase the (i + 1)th fruit.
The fruit market has the following reward for each fruit:
If you purchase the (i + 1)th fruit at prices[i] coins, you c... |
find-maximum-non-decreasing-array-length | def findMaximumLength(nums: List[int]) -> int:
"""
You are given a 0-indexed integer array nums.
You can perform any number of operations, where each operation involves selecting a subarray of the array and replacing it with the sum of its elements. For example, if the given array is [1,3,5,6] and you selec... |
matrix-similarity-after-cyclic-shifts | def areSimilar(mat: List[List[int]], k: int) -> bool:
"""
You are given an m x n integer matrix mat and an integer k. The matrix rows are 0-indexed.
The following proccess happens k times:
Even-indexed rows (0, 2, 4, ...) are cyclically shifted to the left.
Odd-indexed rows (1, 3... |
count-beautiful-substrings-i | def beautifulSubstrings(s: str, k: int) -> int:
"""
You are given a string s and a positive integer k.
Let vowels and consonants be the number of vowels and consonants in a string.
A string is beautiful if:
vowels == consonants.
(vowels * consonants) % k == 0, in other terms the multiplicat... |
make-lexicographically-smallest-array-by-swapping-elements | def lexicographicallySmallestArray(nums: List[int], limit: int) -> List[int]:
"""
You are given a 0-indexed array of positive integers nums and a positive integer limit.
In one operation, you can choose any two indices i and j and swap nums[i] and nums[j] if |nums[i] - nums[j]| <= limit.
Return the lexi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.