3086. Minimum Moves to Pick K Ones
You are given a 0-indexed binary array
numsof lengthn, a positive integerkand a non-negative integermaxChanges.Dylan Smith plays a game, where the goal is for Dylan to pick up
kones fromnumsusing the minimum number of moves. When the game starts, Dylan picks up any indexdylanIndexin the range[0, n - 1]and stands there. Ifnums[dylanIndex] == 1, Dylan picks up the one andnums[dylanIndex]becomes0(this does not count as a move). After this, Dylan can make any number of moves (including zero) where in each move Dylan must perform exactly one of the following actions:
- Select any index
j != dylanIndexsuch thatnums[j] == 0and setnums[j] = 1. This action can be performed at mostmaxChangestimes.- Select any two adjacent indices
xandy(|x - y| == 1) such thatnums[x] == 1,nums[y] == 0, then swap their values (setnums[y] = 1andnums[x] = 0). Ify == dylanIndex, Dylan picks up the one after this move andnums[y]becomes0.Return the minimum number of moves required by Dylan to pick exactly
kones.
3085. Minimum Deletions to Make String K-Special
You are given a string
wordand an integerk.We consider
wordto be k-special if|freq(word[i]) - freq(word[j])| <= kfor all indicesiandjin the string.Here,
freq(x)denotes the frequency of the characterxinword, and|y|denotes the absolute value ofy.Return the minimum number of characters you need to delete to make
wordk-special\.
3084. Count Substrings Starting and Ending with Given Character
You are given a string
sand a characterc. Return the total number of substrings ofsthat start and end withc.
3083. Existence of a Substring in a String and Its Reverse
Given a string
s, find any substring of length2which is also present in the reverse ofs.Return
trueif such a substring exists, andfalseotherwise.
3082. Find the Sum of the Power of All Subsequences
- User Accepted:924
- User Tried:1995
- Total Accepted:987
- Total Submissions:4186
- Difficulty:**Hard**
You are given an integer array
numsof lengthnand a positive integerk.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 may be very large, return it modulo
109 + 7.
3081. Replace Question Marks in String to Minimize Its Value
You are given a string
s.s[i]is either a lowercase English letter or'?'.For a string
thaving lengthmcontaining only lowercase English letters, we define the functioncost(i)for an indexias the number of characters equal tot[i]that appeared before it, i.e. in the range[0, i - 1].The value of
tis the sum ofcost(i)for all indicesi.For example, for the string
t = "aab":
cost(0) = 0cost(1) = 1cost(2) = 0- Hence, the value of
"aab"is0 + 1 + 0 = 1.Your task is to replace all occurrences of
'?'inswith any lowercase English letter so that the value ofsis minimized.Return a string denoting the modified string with replaced occurrences of
'?'. If there are multiple strings resulting in the minimum value, return the lexicographically smallest one.
3080. Mark Elements on Array by Performing Queries
You are given a 0-indexed array
numsof sizenconsisting of positive integers.You are also given a 2D array
queriesof sizemwherequeries[i] = [indexi, ki].Initially all elements of the array are unmarked.
You need to apply
mqueries on the array in order, where on theithquery you do the following:
- Mark the element at index
indexiif it is not already marked.- Then mark
kiunmarked elements in the array with the smallest values. If multiple such elements exist, mark the ones with the smallest indices. And if less thankiunmarked elements exist, then mark all of them.Return an array answer of size
mwhereanswer[i]is the sum of unmarked elements in the array after theithquery.
3079. Find the Sum of Encrypted Integers
You are given an integer array
numscontaining positive integers. We define a functionencryptsuch thatencrypt(x)replaces every digit inxwith the largest digit inx. For example,encrypt(523) = 555andencrypt(213) = 333.Return the sum of encrypted elements.