You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array
codeof length ofnand a keyk.To decrypt the code, you must replace every number. All the numbers are replaced simultaneously.
- If
k > 0, replace theithnumber with the sum of the nextknumbers.- If
k < 0, replace theithnumber with the sum of the previousknumbers.- If
k == 0, replace theithnumber with0.As
codeis circular, the next element ofcode[n-1]iscode[0], and the previous element ofcode[0]iscode[n-1].Given the circular array
codeand an integer keyk, return the decrypted code to defuse the bomb!
3339. Find the Number of K-Even Arrays
You are given three integers
n,m, andk.An array
arris called k-even if there are exactlykindices such that, for each of these indicesi(0 <= i < n - 1):
(arr[i] * arr[i + 1]) - arr[i] - arr[i + 1]is even.Return the number of possible k-even arrays of size
nwhere all elements are in the range[1, m].Since the answer may be very large, return it modulo
109 + 7.
3357. Minimize the Maximum Adjacent Element Difference
You are given an array of integers
nums. Some values innumsare missing and are denoted by -1.You can choose a pair of positive integers
(x, y)exactly once and replace each missing element with eitherxory.You need to minimize the maximum absolute difference between adjacent elements of
numsafter replacements.Return the minimum possible difference.
3356. Zero Array Transformation II
You are given an integer array
numsof lengthnand a 2D arrayquerieswherequeries[i] = [li, ri, vali].Each
queries[i]represents the following action onnums:
- Decrement the value at each index in the range
[li, ri]innumsby at mostvali.- The amount by which each value is decremented can be chosen independently for each index.
A Zero Array is an array with all its elements equal to 0.
Return the minimum possible non-negative value of
k, such that after processing the firstkqueries in sequence,numsbecomes a Zero Array. If no suchkexists, return -1.
3355. Zero Array Transformation I
You are given an integer array
numsof lengthnand a 2D arrayqueries, wherequeries[i] = [li, ri].For each
queries[i]:
- Select a subset of indices within the range
[li, ri]innums.- Decrement the values at the selected indices by 1.
A Zero Array is an array where all elements are equal to 0.
Return
trueif it is possible to transformnumsinto a Zero Array after processing all the queries sequentially, otherwise returnfalse.A subset of an array is a selection of elements (possibly none) of the array.
3354. Make Array Elements Equal to Zero
You are given an integer array
nums.Start by selecting a starting position
currsuch thatnums[curr] == 0, and choose a movement direction of either left or right.After that, you repeat the following process:
If
curris out of the range[0, n - 1], this process ends.If
nums[curr] == 0, move in the current direction by incrementingcurrif you are moving right, or decrementingcurrif you are moving left.Else if
nums[curr] > 0:
- Decrement
nums[curr]by 1.- Reverse your movement direction (left becomes right and vice versa).
- Take a step in your new direction.
A selection of the initial position
currand movement direction is considered valid if every element innumsbecomes 0 by the end of the process.Return the number of possible valid selections.