You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array
code
of length ofn
and a keyk
.To decrypt the code, you must replace every number. All the numbers are replaced simultaneously.
- If
k > 0
, replace theith
number with the sum of the nextk
numbers.- If
k < 0
, replace theith
number with the sum of the previousk
numbers.- If
k == 0
, replace theith
number with0
.As
code
is circular, the next element ofcode[n-1]
iscode[0]
, and the previous element ofcode[0]
iscode[n-1]
.Given the circular array
code
and 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
arr
is called k-even if there are exactlyk
indices 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
n
where 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 innums
are missing and are denoted by -1.You can choose a pair of positive integers
(x, y)
exactly once and replace each missing element with eitherx
ory
.You need to minimize the maximum absolute difference between adjacent elements of
nums
after replacements.Return the minimum possible difference.
3356. Zero Array Transformation II
You are given an integer array
nums
of lengthn
and a 2D arrayqueries
wherequeries[i] = [li, ri, vali]
.Each
queries[i]
represents the following action onnums
:
- Decrement the value at each index in the range
[li, ri]
innums
by 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 firstk
queries in sequence,nums
becomes a Zero Array. If no suchk
exists, return -1.
3355. Zero Array Transformation I
You are given an integer array
nums
of lengthn
and 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
true
if it is possible to transformnums
into 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
curr
such thatnums[curr] == 0
, and choose a movement direction of either left or right.After that, you repeat the following process:
If
curr
is out of the range[0, n - 1]
, this process ends.If
nums[curr] == 0
, move in the current direction by incrementingcurr
if you are moving right, or decrementingcurr
if 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
curr
and movement direction is considered valid if every element innums
becomes 0 by the end of the process.Return the number of possible valid selections.