task_id
stringlengths
3
79
prompt
stringlengths
255
3.93k
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
from typing import List 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 ex...
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
from typing import List 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 i...
find-the-longest-equal-subarray
from typing import List 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 e...
maximal-range-that-each-element-is-maximum-in-it
from typing import List 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 m...
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
from typing import List 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 t...
maximize-value-of-function-in-a-ball-passing-game
from typing import List 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 receiv...
maximum-coins-heroes-can-collect
from typing import List 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...
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
from typing import List 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 ...
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
from typing import List 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 followi...
minimum-edge-weight-equilibrium-queries-in-a-tree
from typing import List 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 th...
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
from typing import List 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 poin...
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
from typing import List 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 singl...
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
from typing import List 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 ce...
minimum-right-shifts-to-sort-the-array
from typing import List 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...
minimum-array-length-after-pair-removals
from typing import List 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 an...
count-pairs-of-points-with-distance-k
from typing import Any, List 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 ...
minimum-edge-reversals-so-every-node-is-reachable
from typing import List 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, v...
sum-of-values-at-indices-with-k-set-bits
from typing import List 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 bi...
happy-students
from typing import List 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 ...
maximum-number-of-alloys
from typing import List 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 mach...
maximum-element-sum-of-a-complete-subset-of-indices
from typing import List 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 ...
maximum-length-of-semi-decreasing-subarrays
from typing import List 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 n...
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
from typing import List 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-d...
beautiful-towers-ii
from typing import List 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 b...
count-valid-paths-in-a-tree
from typing import List 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...
the-wording-game
from typing import List 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 l...
minimum-operations-to-collect-elements
from typing import List 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 elemen...
minimum-number-of-operations-to-make-array-empty
from typing import List 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. ...
split-array-into-maximum-number-of-subarrays
from typing import List 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...
maximum-number-of-k-divisible-components
from typing import List 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...
maximum-value-of-an-ordered-triplet-i
from typing import List 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...
maximum-value-of-an-ordered-triplet-ii
from typing import List 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...
minimum-size-subarray-in-infinite-array
from typing import List 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 i...
count-visited-nodes-in-a-directed-graph
from typing import List 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...
minimizing-array-after-replacing-pairs-with-their-product
from typing import List 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 ...
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
from typing import List 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 us...
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
from typing import List 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]...
maximum-linear-stock-score
from typing import List 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-i...
last-visited-integers
from typing import List 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 a...
longest-unequal-adjacent-groups-subsequence-i
from typing import List 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 subseq...
longest-unequal-adjacent-groups-subsequence-ii
from typing import List 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...
count-of-sub-multisets-with-bounded-sum
from typing import List 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...
find-indices-with-index-and-value-difference-i
from typing import List 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 -...
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
from typing import List 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 -...
construct-product-matrix
from typing import List 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 a...
maximum-profitable-triplets-with-increasing-prices-i
from typing import List 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: ...
minimum-sum-of-mountain-triplets-i
from typing import List 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 ...
minimum-sum-of-mountain-triplets-ii
from typing import List 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 ...
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
from typing import List 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...
subarrays-distinct-element-sum-of-squares-i
from typing import List 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 numbe...
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
from typing import List 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 i...
subarrays-distinct-element-sum-of-squares-ii
from typing import List 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 numbe...
find-the-k-or-of-an-array
from typing import List 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. Retu...
minimum-equal-sum-of-two-arrays-after-replacing-zeros
from typing import List 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 t...
minimum-increment-operations-to-make-array-beautiful
from typing import List 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], ...
maximum-points-after-collecting-coins-from-all-nodes
from typing import List 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...
maximum-profitable-triplets-with-increasing-prices-ii
from typing import List 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: ...
find-champion-i
from typing import List 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...
find-champion-ii
from typing import List 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] i...
maximum-score-after-applying-operations-on-a-tree
from typing import List, Set 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...
maximum-balanced-subsequence-sum
from typing import List 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 i...
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
from typing import List 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...
maximum-strong-pair-xor-i
from typing import List 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 str...
high-access-employees
from typing import List 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 tim...
minimum-operations-to-maximize-last-elements-in-arrays
from typing import List 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] a...
maximum-strong-pair-xor-ii
from typing import List 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 str...
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
from typing import List 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...
maximum-gcd-sum-of-a-subarray
from typing import List 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. ...
find-words-containing-character
from typing import List 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. Examp...
maximize-area-of-square-hole-in-grid
from typing import List 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...
minimum-number-of-coins-for-fruits
from typing import List 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 a...
find-maximum-non-decreasing-array-length
from typing import List 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...
matrix-similarity-after-cyclic-shifts
from typing import List 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. ...
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
from typing import List 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]| <= li...