task_id
stringlengths
3
79
prompt
stringlengths
255
3.9k
mark-elements-on-array-by-performing-queries
def unmarkedSumArray(nums: List[int], queries: List[List[int]]) -> List[int]: """ You are given a 0-indexed array nums of size n consisting of positive integers. You are also given a 2D array queries of size m where queries[i] = [indexi, ki]. Initially all elements of the array are unmarked. You nee...
replace-question-marks-in-string-to-minimize-its-value
def minimizeStringValue(s: str) -> str: """ You are given a string s. s[i] is either a lowercase English letter or '?'. For a string t having length m containing only lowercase English letters, we define the function cost(i) for an index i as the number of characters equal to t[i] that appeared before it, i...
find-the-sum-of-the-power-of-all-subsequences
def sumOfPower(nums: List[int], k: int) -> int: """ You are given an integer array nums of length n and a positive integer k. The power of an array of integers is defined as the number of subsequences with their sum equal to k. Return the sum of power of all subsequences of nums. Since the answer ma...
existence-of-a-substring-in-a-string-and-its-reverse
def isSubstringPresent(s: str) -> bool: """ Given a string s, find any substring of length 2 which is also present in the reverse of s. Return true if such a substring exists, and false otherwise. Example 1: >>> isSubstringPresent(s = "leetcode") >>> true Explanation: Substring "ee...
count-substrings-starting-and-ending-with-given-character
def countSubstrings(s: str, c: str) -> int: """ You are given a string s and a character c. Return the total number of substrings of s that start and end with c. Example 1: >>> countSubstrings(s = "abada", c = "a") >>> 6 Explanation: Substrings starting and ending with "a" are: "abada"...
minimum-deletions-to-make-string-k-special
def minimumDeletions(word: str, k: int) -> int: """ You are given a string word and an integer k. We consider word to be k-special if |freq(word[i]) - freq(word[j])| <= k for all indices i and j in the string. Here, freq(x) denotes the frequency of the character x in word, and |y| denotes the absolute v...
minimum-moves-to-pick-k-ones
def minimumMoves(nums: List[int], k: int, maxChanges: int) -> int: """ You are given a binary array nums of length n, a positive integer k and a non-negative integer maxChanges. Alice plays a game, where the goal is for Alice to pick up k ones from nums using the minimum number of moves. When the game start...
make-string-anti-palindrome
def makeAntiPalindrome(s: str) -> str: """ We call a string s of even length n an anti-palindrome if for each index 0 <= i < n, s[i] != s[n - i - 1]. Given a string s, your task is to make s an anti-palindrome by doing any number of operations (including zero). In one operation, you can select two chara...
maximum-length-substring-with-two-occurrences
def maximumLengthSubstring(s: str) -> int: """ Given a string s, return the maximum length of a substring such that it contains at most two occurrences of each character. Example 1: >>> maximumLengthSubstring(s = "bcbbbcba") >>> 4 Explanation: The following substring has a length o...
apply-operations-to-make-sum-of-array-greater-than-or-equal-to-k
def minOperations(k: int) -> int: """ You are given a positive integer k. Initially, you have an array nums = [1]. You can perform any of the following operations on the array any number of times (possibly zero): Choose any element in the array and increase its value by 1. Duplicate any element...
most-frequent-ids
def mostFrequentIDs(nums: List[int], freq: List[int]) -> List[int]: """ The problem involves tracking the frequency of IDs in a collection that changes over time. You have two integer arrays, nums and freq, of equal length n. Each element in nums represents an ID, and the corresponding element in freq indicates...
longest-common-suffix-queries
def stringIndices(wordsContainer: List[str], wordsQuery: List[str]) -> List[int]: """ You are given two arrays of strings wordsContainer and wordsQuery. For each wordsQuery[i], you need to find a string from wordsContainer that has the longest common suffix with wordsQuery[i]. If there are two or more strin...
shortest-subarray-with-or-at-least-k-i
def minimumSubarrayLength(nums: List[int], k: int) -> int: """ You are given an array nums of non-negative integers and an integer k. An array is called special if the bitwise OR of all of its elements is at least k. Return the length of the shortest special non-empty subarray of nums, or return -1 if n...
minimum-levels-to-gain-more-points
def minimumLevels(possible: List[int]) -> int: """ You are given a binary array possible of length n. Alice and Bob are playing a game that consists of n levels. Some of the levels in the game are impossible to clear while others can always be cleared. In particular, if possible[i] == 0, then the ith level ...
shortest-subarray-with-or-at-least-k-ii
def minimumSubarrayLength(nums: List[int], k: int) -> int: """ You are given an array nums of non-negative integers and an integer k. An array is called special if the bitwise OR of all of its elements is at least k. Return the length of the shortest special non-empty subarray of nums, or return -1 if n...
find-the-sum-of-subsequence-powers
def sumOfPowers(nums: List[int], k: int) -> int: """ You are given an integer array nums of length n, and a positive integer k. The power of a subsequence is defined as the minimum absolute difference between any two elements in the subsequence. Return the sum of powers of all subsequences of nums which...
harshad-number
def sumOfTheDigitsOfHarshadNumber(x: int) -> int: """ An integer divisible by the sum of its digits is said to be a Harshad number. You are given an integer x. Return the sum of the digits of x if x is a Harshad number, otherwise, return -1. Example 1: >>> sumOfTheDigitsOfHarshadNumber(x = 18)...
water-bottles-ii
def maxBottlesDrunk(numBottles: int, numExchange: int) -> int: """ You are given two integers numBottles and numExchange. numBottles represents the number of full water bottles that you initially have. In one operation, you can perform one of the following operations: Drink any number of full water...
count-alternating-subarrays
def countAlternatingSubarrays(nums: List[int]) -> int: """ You are given a binary array nums. We call a subarray alternating if no two adjacent elements in the subarray have the same value. Return the number of alternating subarrays in nums. Example 1: >>> countAlternatingSubarrays(num...
minimize-manhattan-distances
def minimumDistance(points: List[List[int]]) -> int: """ You are given an array points representing integer coordinates of some points on a 2D plane, where points[i] = [xi, yi]. The distance between two points is defined as their Manhattan distance. Return the minimum possible value for maximum distance...
find-longest-self-contained-substring
def maxSubstringLength(s: str) -> int: """ Given a string s, your task is to find the length of the longest self-contained substring of s. A substring t of a string s is called self-contained if t != s and for every character in t, it doesn't exist in the rest of s. Return the length of the longest self...
longest-strictly-increasing-or-strictly-decreasing-subarray
def longestMonotonicSubarray(nums: List[int]) -> int: """ You are given an array of integers nums. Return the length of the longest subarray of nums which is either strictly increasing or strictly decreasing. Example 1: >>> longestMonotonicSubarray(nums = [1,4,3,3,2]) >>> 2 Explanation...
lexicographically-smallest-string-after-operations-with-constraint
def getSmallestString(s: str, k: int) -> str: """ You are given a string s and an integer k. Define a function distance(s1, s2) between two strings s1 and s2 of the same length n as: The sum of the minimum distance between s1[i] and s2[i] when the characters from 'a' to 'z' are placed in a cyclic o...
minimum-operations-to-make-median-of-array-equal-to-k
def minOperationsToMakeMedianK(nums: List[int], k: int) -> int: """ You are given an integer array nums and a non-negative integer k. In one operation, you can increase or decrease any element by 1. Return the minimum number of operations needed to make the median of nums equal to k. The median of an ar...
minimum-cost-walk-in-weighted-graph
def minimumCost(n: int, edges: List[List[int]], query: List[List[int]]) -> List[int]: """ There is an undirected weighted graph with n vertices labeled from 0 to n - 1. You are given the integer n and an array edges, where edges[i] = [ui, vi, wi] indicates that there is an edge between vertices ui and vi wi...
find-the-index-of-permutation
def getPermutationIndex(perm: List[int]) -> int: """ Given an array perm of length n which is a permutation of [1, 2, ..., n], return the index of perm in the lexicographically sorted array of all of the permutations of [1, 2, ..., n]. Since the answer may be very large, return it modulo 109 + 7. E...
score-of-a-string
def scoreOfString(s: str) -> int: """ You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters. Return the score of s. Example 1: >>> scoreOfString(s = "hello") >>> 13 Explanation: The ASCII...
minimum-rectangles-to-cover-points
def minRectanglesToCoverPoints(points: List[List[int]], w: int) -> int: """ You are given a 2D integer array points, where points[i] = [xi, yi]. You are also given an integer w. Your task is to cover all the given points with rectangles. Each rectangle has its lower end at some point (x1, 0) and its upper e...
minimum-time-to-visit-disappearing-nodes
def minimumTime(n: int, edges: List[List[int]], disappear: List[int]) -> List[int]: """ There is an undirected graph of n nodes. You are given a 2D array edges, where edges[i] = [ui, vi, lengthi] describes an edge between node ui and node vi with a traversal time of lengthi units. Additionally, you are give...
find-the-number-of-subarrays-where-boundary-elements-are-maximum
def numberOfSubarrays(nums: List[int]) -> int: """ You are given an array of positive integers nums. Return the number of subarrays of nums, where the first and the last elements of the subarray are equal to the largest element in the subarray. Example 1: >>> numberOfSubarrays(nums = [1,4,...
latest-time-you-can-obtain-after-replacing-characters
def findLatestTime(s: str) -> str: """ You are given a string s representing a 12-hour format time where some of the digits (possibly none) are replaced with a "?". 12-hour times are formatted as "HH:MM", where HH is between 00 and 11, and MM is between 00 and 59. The earliest 12-hour time is 00:00, and the...
maximum-prime-difference
def maximumPrimeDifference(nums: List[int]) -> int: """ You are given an integer array nums. Return an integer that is the maximum distance between the indices of two (not necessarily different) prime numbers in nums. Example 1: >>> maximumPrimeDifference(nums = [4,2,9,5,3]) >>> 3 ...
kth-smallest-amount-with-single-denomination-combination
def findKthSmallest(coins: List[int], k: int) -> int: """ You are given an integer array coins representing coins of different denominations and an integer k. You have an infinite number of coins of each denomination. However, you are not allowed to combine coins of different denominations. Return the k...
minimum-sum-of-values-by-dividing-array
def minimumValueSum(nums: List[int], andValues: List[int]) -> int: """ You are given two arrays nums and andValues of length n and m respectively. The value of an array is equal to the last element of that array. You have to divide nums into m disjoint contiguous subarrays such that for the ith subarray...
maximum-number-of-potholes-that-can-be-fixed
def maxPotholes(road: str, budget: int) -> int: """ You are given a string road, consisting only of characters "x" and ".", where each "x" denotes a pothole and each "." denotes a smooth road, and an integer budget. In one repair operation, you can repair n consecutive potholes for a price of n + 1. Ret...
count-the-number-of-special-characters-i
def numberOfSpecialChars(word: str) -> int: """ You are given a string word. A letter is called special if it appears both in lowercase and uppercase in word. Return the number of special letters in word. Example 1: >>> numberOfSpecialChars(word = "aaAbcBC") >>> 3 Explanation: ...
count-the-number-of-special-characters-ii
def numberOfSpecialChars(word: str) -> int: """ You are given a string word. A letter c is called special if it appears both in lowercase and uppercase in word, and every lowercase occurrence of c appears before the first uppercase occurrence of c. Return the number of special letters in word. Exam...
minimum-number-of-operations-to-satisfy-conditions
def minimumOperations(grid: List[List[int]]) -> int: """ You are given a 2D matrix grid of size m x n. In one operation, you can change the value of any cell to any non-negative number. You need to perform some operations such that each cell grid[i][j] is: Equal to the cell below it, i.e. grid[i][j] ==...
find-edges-in-shortest-paths
def findAnswer(n: int, edges: List[List[int]]) -> List[bool]: """ You are given an undirected weighted graph of n nodes numbered from 0 to n - 1. The graph consists of m edges represented by a 2D array edges, where edges[i] = [ai, bi, wi] indicates that there is an edge between nodes ai and bi with weight wi. ...
maximum-number-that-makes-result-of-bitwise-and-zero
def maxNumber(n: int) -> int: """ Given an integer n, return the maximum integer x such that x <= n, and the bitwise AND of all the numbers in the range [x, n] is 0. Example 1: >>> maxNumber(n = 7) >>> 3 Explanation: The bitwise AND of [6, 7] is 6. The bitwise AND of [5, 6, 7] ...
make-a-square-with-the-same-color
def canMakeSquare(grid: List[List[str]]) -> bool: """ You are given a 2D matrix grid of size 3 x 3 consisting only of characters 'B' and 'W'. Character 'W' represents the white color, and character 'B' represents the black color. Your task is to change the color of at most one cell so that the matrix has a ...
right-triangles
def numberOfRightTriangles(grid: List[List[int]]) -> int: """ You are given a 2D boolean matrix grid. A collection of 3 elements of grid is a right triangle if one of its elements is in the same row with another element and in the same column with the third element. The 3 elements may not be next to each ot...
find-all-possible-stable-binary-arrays-i
def numberOfStableArrays(zero: int, one: int, limit: int) -> int: """ You are given 3 positive integers zero, one, and limit. A binary array arr is called stable if: The number of occurrences of 0 in arr is exactly zero. The number of occurrences of 1 in arr is exactly one. Each subarray of...
find-all-possible-stable-binary-arrays-ii
def numberOfStableArrays(zero: int, one: int, limit: int) -> int: """ You are given 3 positive integers zero, one, and limit. A binary array arr is called stable if: The number of occurrences of 0 in arr is exactly zero. The number of occurrences of 1 in arr is exactly one. Each subarray of...
find-the-integer-added-to-array-i
def addedInteger(nums1: List[int], nums2: List[int]) -> int: """ You are given two arrays of equal length, nums1 and nums2. Each element in nums1 has been increased (or decreased in the case of negative) by an integer, represented by the variable x. As a result, nums1 becomes equal to nums2. Two arrays ...
find-the-integer-added-to-array-ii
def minimumAddedInteger(nums1: List[int], nums2: List[int]) -> int: """ You are given two integer arrays nums1 and nums2. From nums1 two elements have been removed, and all other elements have been increased (or decreased in the case of negative) by an integer, represented by the variable x. As a result...
minimum-array-end
def minEnd(n: int, x: int) -> int: """ You are given two integers n and x. You have to construct an array of positive integers nums of size n where for every 0 <= i < n - 1, nums[i + 1] is greater than nums[i], and the result of the bitwise AND operation between all elements of nums is x. Return the minimum...
find-the-median-of-the-uniqueness-array
def medianOfUniquenessArray(nums: List[int]) -> int: """ You are given an integer array nums. The uniqueness array of nums is the sorted array that contains the number of distinct elements of all the subarrays of nums. In other words, it is a sorted array consisting of distinct(nums[i..j]), for all 0 <= i <= j ...
equalize-strings-by-adding-or-removing-characters-at-ends
def minOperations(initial: str, target: str) -> int: """ Given two strings initial and target, your task is to modify initial by performing a series of operations to make it equal to target. In one operation, you can add or remove one character only at the beginning or the end of the string initial. Ret...
valid-word
def isValid(word: str) -> bool: """ A word is considered valid if: It contains a minimum of 3 characters. It contains only digits (0-9), and English letters (uppercase and lowercase). It includes at least one vowel. It includes at least one consonant. You are given a string word. ...
minimum-number-of-operations-to-make-word-k-periodic
def minimumOperationsToMakeKPeriodic(word: str, k: int) -> int: """ You are given a string word of size n, and an integer k such that k divides n. In one operation, you can pick any two indices i and j, that are divisible by k, then replace the substring of length k starting at i with the substring of lengt...
minimum-length-of-anagram-concatenation
def minAnagramLength(s: str) -> int: """ You are given a string s, which is known to be a concatenation of anagrams of some string t. Return the minimum possible length of the string t. An anagram is formed by rearranging the letters of a string. For example, "aab", "aba", and, "baa" are anagrams of "aa...
minimum-cost-to-equalize-array
def minCostToEqualizeArray(nums: List[int], cost1: int, cost2: int) -> int: """ You are given an integer array nums and two integers cost1 and cost2. You are allowed to perform either of the following operations any number of times: Choose an index i from nums and increase nums[i] by 1 for a cost of co...
maximum-hamming-distances
def maxHammingDistances(nums: List[int], m: int) -> List[int]: """ Given an array nums and an integer m, with each element nums[i] satisfying 0 <= nums[i] < 2m, return an array answer. The answer array should be of the same length as nums, where each element answer[i] represents the maximum Hamming distance bet...
check-if-grid-satisfies-conditions
def satisfiesConditions(grid: List[List[int]]) -> bool: """ You are given a 2D matrix grid of size m x n. You need to check if each cell grid[i][j] is: Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists). Different from the cell to its right, i.e. grid[i][j] != grid[i][j + ...
maximum-points-inside-the-square
def maxPointsInsideSquare(points: List[List[int]], s: str) -> int: """ You are given a 2D array points and a string s where, points[i] represents the coordinates of point i, and s[i] represents the tag of point i. A valid square is a square centered at the origin (0, 0), has edges parallel to the axes, and ...
minimum-substring-partition-of-equal-character-frequency
def minimumSubstringsInPartition(s: str) -> int: """ Given a string s, you need to partition it into one or more balanced substrings. For example, if s == "ababcc" then ("abab", "c", "c"), ("ab", "abc", "c"), and ("ababcc") are all valid partitions, but ("a", "bab", "cc"), ("aba", "bc", "c"), and ("ab", "abcc")...
permutation-difference-between-two-strings
def findPermutationDifference(s: str, t: str) -> int: """ You are given two strings s and t such that every character occurs at most once in s and t is a permutation of s. The permutation difference between s and t is defined as the sum of the absolute difference between the index of the occurrence of each ...
taking-maximum-energy-from-the-mystic-dungeon
def maximumEnergy(energy: List[int], k: int) -> int: """ In a mystic dungeon, n magicians are standing in a line. Each magician has an attribute that gives you energy. Some magicians can give you negative energy, which means taking energy from you. You have been cursed in such a way that after absorbing ene...
maximum-difference-score-in-a-grid
def maxScore(grid: List[List[int]]) -> int: """ You are given an m x n matrix grid consisting of positive integers. You can move from a cell in the matrix to any other cell that is either to the bottom or to the right (not necessarily adjacent). The score of a move from a cell with the value c1 to a cell with t...
find-the-minimum-cost-array-permutation
def findPermutation(nums: List[int]) -> List[int]: """ You are given an array nums which is a permutation of [0, 1, 2, ..., n - 1]. The score of any permutation of [0, 1, 2, ..., n - 1] named perm is defined as: score(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[...
special-array-i
def isArraySpecial(nums: List[int]) -> bool: """ An array is considered special if the parity of every pair of adjacent elements is different. In other words, one element in each pair must be even, and the other must be odd. You are given an array of integers nums. Return true if nums is a special array, ot...
special-array-ii
def isArraySpecial(nums: List[int], queries: List[List[int]]) -> List[bool]: """ An array is considered special if every pair of its adjacent elements contains two numbers with different parity. You are given an array of integer nums and a 2D integer matrix queries, where for queries[i] = [fromi, toi] your ...
sum-of-digit-differences-of-all-pairs
def sumDigitDifferences(nums: List[int]) -> int: """ You are given an array nums consisting of positive integers where all integers have the same number of digits. The digit difference between two integers is the count of different digits that are in the same position in the two integers. Return the sum...
find-number-of-ways-to-reach-the-k-th-stair
def waysToReachStair(k: int) -> int: """ You are given a non-negative integer k. There exists a staircase with an infinite number of stairs, with the lowest stair numbered 0. Alice has an integer jump, with an initial value of 0. She starts on stair 1 and wants to reach stair k using any number of operation...
maximum-number-of-upgradable-servers
def maxUpgrades(count: List[int], upgrade: List[int], sell: List[int], money: List[int]) -> List[int]: """ You have n data centers and need to upgrade their servers. You are given four arrays count, upgrade, sell, and money of length n, which show: The number of servers The cost of upgrading a ...
find-the-level-of-tree-with-minimum-sum
# class TreeNode: # def __init__(val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def minimumLevel(root: Optional[TreeNode]) -> int: """ Given the root of a binary tree root where each node has a value, return the level of th...
find-the-xor-of-numbers-which-appear-twice
def duplicateNumbersXOR(nums: List[int]) -> int: """ You are given an array nums, where each number in the array appears either once or twice. Return the bitwise XOR of all the numbers that appear twice in the array, or 0 if no number appears twice. Example 1: >>> duplicateNumbersXOR(nums ...
find-occurrences-of-an-element-in-an-array
def occurrencesOfElement(nums: List[int], queries: List[int], x: int) -> List[int]: """ You are given an integer array nums, an integer array queries, and an integer x. For each queries[i], you need to find the index of the queries[i]th occurrence of x in the nums array. If there are fewer than queries[i] o...
find-the-number-of-distinct-colors-among-the-balls
def queryResults(limit: int, queries: List[List[int]]) -> List[int]: """ You are given an integer limit and a 2D array queries of size n x 2. There are limit + 1 balls with distinct labels in the range [0, limit]. Initially, all balls are uncolored. For every query in queries that is of the form [x, y], you...
block-placement-queries
def getResults(queries: List[List[int]]) -> List[bool]: """ There exists an infinite number line, with its origin at 0 and extending towards the positive x-axis. You are given a 2D array queries, which contains two types of queries: For a query of type 1, queries[i] = [1, x]. Build an obstacle at d...
find-the-number-of-good-pairs-i
def numberOfPairs(nums1: List[int], nums2: List[int], k: int) -> int: """ You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k. A pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1). Ret...
string-compression-iii
def compressedString(word: str) -> str: """ Given a string word, compress it using the following algorithm: Begin with an empty string comp. While word is not empty, use the following operation: Remove a maximum length prefix of word made of a single character c repeating at most 9 times....
find-the-number-of-good-pairs-ii
def numberOfPairs(nums1: List[int], nums2: List[int], k: int) -> int: """ You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k. A pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1). Ret...
maximum-sum-of-subsequence-with-non-adjacent-elements
def maximumSumSubsequence(nums: List[int], queries: List[List[int]]) -> int: """ You are given an array nums consisting of integers. You are also given a 2D array queries, where queries[i] = [posi, xi]. For query i, we first set nums[posi] equal to xi, then we calculate the answer to query i which is the ma...
better-compression-of-string
def betterCompression(compressed: str) -> str: """ You are given a string compressed representing a compressed version of a string. The format is a character followed by its frequency. For example, "a3b1a1c2" is a compressed version of the string "aaabacc". We seek a better compression with the following co...
minimum-number-of-chairs-in-a-waiting-room
def minimumChairs(s: str) -> int: """ You are given a string s. Simulate events at each second i: If s[i] == 'E', a person enters the waiting room and takes one of the chairs in it. If s[i] == 'L', a person leaves the waiting room, freeing up a chair. Return the minimum number of chairs ne...
count-days-without-meetings
def countDays(days: int, meetings: List[List[int]]) -> int: """ You are given a positive integer days representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array meetings of size n where, meetings[i] = [start_i, end_i] represents the starting and ...
lexicographically-minimum-string-after-removing-stars
def clearStars(s: str) -> str: """ You are given a string s. It may contain any number of '*' characters. Your task is to remove all '*' characters. While there is a '*', do the following operation: Delete the leftmost '*' and the smallest non-'*' character to its left. If there are several smalles...
find-subarray-with-bitwise-or-closest-to-k
def minimumDifference(nums: List[int], k: int) -> int: """ You are given an array nums and an integer k. You need to find a subarray of nums such that the absolute difference between k and the bitwise OR of the subarray elements is as small as possible. In other words, select a subarray nums[l..r] such that |k ...
bitwise-or-of-adjacent-elements
def orArray(nums: List[int]) -> List[int]: """ Given an array nums of length n, return an array answer of length n - 1 such that answer[i] = nums[i] | nums[i + 1] where | is the bitwise OR operation. Example 1: >>> orArray(nums = [1,3,7,15]) >>> [3,7,15] Example 2: >>> or...
clear-digits
def clearDigits(s: str) -> str: """ You are given a string s. Your task is to remove all digits by doing this operation repeatedly: Delete the first digit and the closest non-digit character to its left. Return the resulting string after removing all digits. Note that the operation can...
find-the-first-player-to-win-k-games-in-a-row
def findWinningPlayer(skills: List[int], k: int) -> int: """ A competition consists of n players numbered from 0 to n - 1. You are given an integer array skills of size n and a positive integer k, where skills[i] is the skill level of player i. All integers in skills are unique. All players are standing...
find-the-maximum-length-of-a-good-subsequence-i
def maximumLength(nums: List[int], k: int) -> int: """ You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1]. Return the maximum possible length of a good su...
find-the-maximum-length-of-a-good-subsequence-ii
def maximumLength(nums: List[int], k: int) -> int: """ You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1]. Return the maximum possible length of a good su...
find-the-child-who-has-the-ball-after-k-seconds
def numberOfChild(n: int, k: int) -> int: """ You are given two positive integers n and k. There are n children numbered from 0 to n - 1 standing in a queue in order from left to right. Initially, child 0 holds a ball and the direction of passing the ball is towards the right direction. After each second, t...
find-the-n-th-value-after-k-seconds
def valueAfterKSeconds(n: int, k: int) -> int: """ You are given two integers n and k. Initially, you start with an array a of n integers where a[i] = 1 for all 0 <= i <= n - 1. After each second, you simultaneously update each element to be the sum of all its preceding elements plus the element itself. For...
maximum-total-reward-using-operations-i
def maxTotalReward(rewardValues: List[int]) -> int: """ You are given an integer array rewardValues of length n, representing the values of rewards. Initially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times: Choose an u...
maximum-total-reward-using-operations-ii
def maxTotalReward(rewardValues: List[int]) -> int: """ You are given an integer array rewardValues of length n, representing the values of rewards. Initially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times: Choose an u...
the-number-of-ways-to-make-the-sum
def numberOfWays(n: int) -> int: """ You have an infinite number of coins with values 1, 2, and 6, and only 2 coins with value 4. Given an integer n, return the number of ways to make the sum of n with the coins you have. Since the answer may be very large, return it modulo 109 + 7. Note that the or...
count-pairs-that-form-a-complete-day-i
def countCompleteDayPairs(hours: List[int]) -> int: """ Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day. A complete day is defined as a time duration that is an exact multiple of 24 hours. ...
count-pairs-that-form-a-complete-day-ii
def countCompleteDayPairs(hours: List[int]) -> int: """ Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day. A complete day is defined as a time duration that is an exact multiple of 24 hours. ...
maximum-total-damage-with-spell-casting
def maximumTotalDamage(power: List[int]) -> int: """ A magician has various spells. You are given an array power, where each element represents the damage of a spell. Multiple spells can have the same damage value. It is a known fact that if a magician decides to cast a spell with a damage of power[i], ...
peaks-in-array
def countOfPeaks(nums: List[int], queries: List[List[int]]) -> List[int]: """ A peak in an array arr is an element that is greater than its previous and next element in arr. You are given an integer array nums and a 2D integer array queries. You have to process queries of two types: queries[i] ...
minimum-moves-to-get-a-peaceful-board
def minMoves(rooks: List[List[int]]) -> int: """ Given a 2D array rooks of length n, where rooks[i] = [xi, yi] indicates the position of a rook on an n x n chess board. Your task is to move the rooks 1 cell at a time vertically or horizontally (to an adjacent cell) such that the board becomes peaceful. A bo...
find-minimum-operations-to-make-all-elements-divisible-by-three
def minimumOperations(nums: List[int]) -> int: """ You are given an integer array nums. In one operation, you can add or subtract 1 from any element of nums. Return the minimum number of operations to make all elements of nums divisible by 3. Example 1: >>> minimumOperations(nums = [1,2,3,...
minimum-operations-to-make-binary-array-elements-equal-to-one-i
def minOperations(nums: List[int]) -> int: """ You are given a binary array nums. You can do the following operation on the array any number of times (possibly zero): Choose any 3 consecutive elements from the array and flip all of them. Flipping an element means changing its value from 0 ...
minimum-operations-to-make-binary-array-elements-equal-to-one-ii
def minOperations(nums: List[int]) -> int: """ You are given a binary array nums. You can do the following operation on the array any number of times (possibly zero): Choose any index i from the array and flip all the elements from index i to the end of the array. Flipping an element means...
count-the-number-of-inversions
def numberOfPermutations(n: int, requirements: List[List[int]]) -> int: """ You are given an integer n and a 2D array requirements, where requirements[i] = [endi, cnti] represents the end index and the inversion count of each requirement. A pair of indices (i, j) from an integer array nums is called an inve...
minimum-average-of-smallest-and-largest-elements
def minimumAverage(nums: List[int]) -> float: """ You have an array of floating point numbers averages which is initially empty. You are given an array nums of n integers where n is even. You repeat the following procedure n / 2 times: Remove the smallest element, minElement, and the largest elemen...