Codeforces Round 731 (Div. 3) F. Array Stabilization (GCD version)
2772. Apply Operations to Make All Array Elements Equal to Zero
You are given a 0-indexed integer array
numsand a positive integerk.You can apply the following operation on the array any number of times:
- Choose any subarray of size
kfrom the array and decrease all its elements by1.Return
trueif you can make all the array elements equal to0, orfalseotherwise.A subarray is a contiguous non-empty part of an array.
2771. Longest Non-decreasing Subarray From Two Arrays
You are given two 0-indexed integer arrays
nums1andnums2of lengthn.Let’s define another 0-indexed integer array,
nums3, of lengthn. For each indexiin the range[0, n - 1], you can assign eithernums1[i]ornums2[i]tonums3[i].Your task is to maximize the length of the longest non-decreasing subarray in
nums3by choosing its values optimally.Return an integer representing the length of the longest non-decreasing subarray in
nums3.Note: A subarray is a contiguous non-empty sequence of elements within an array.
2770. Maximum Number of Jumps to Reach the Last Index
You are given a 0-indexed array
numsofnintegers and an integertarget.You are initially positioned at index
0. In one step, you can jump from indexito any indexjsuch that:
0 <= i < j < n-target <= nums[j] - nums[i] <= targetReturn the maximum number of jumps you can make to reach index
n - 1.If there is no way to reach index
n - 1, return-1.
2769. Find the Maximum Achievable Number
You are given two integers,
numandt.An integer
xis called achievable if it can become equal tonumafter applying the following operation no more thanttimes:
- Increase or decrease
xby1, and simultaneously increase or decreasenumby1.Return the maximum possible achievable number. It can be proven that there exists at least one achievable number.
You are given two integers
mandnrepresenting the dimensions of a 0-indexedm x ngrid.You are also given a 0-indexed 2D integer matrix
coordinates, wherecoordinates[i] = [x, y]indicates that the cell with coordinates[x, y]is colored black. All cells in the grid that do not appear incoordinatesare white.A block is defined as a
2 x 2submatrix of the grid. More formally, a block with cell[x, y]as its top-left corner where0 <= x < m - 1and0 <= y < n - 1contains the coordinates[x, y],[x + 1, y],[x, y + 1], and[x + 1, y + 1].Return a 0-indexed integer array
arrof size5such thatarr[i]is the number of blocks that contains exactlyi*black cells*.
2767. Partition String Into Minimum Beautiful Substrings
Given a binary string
s, partition the string into one or more substrings such that each substring is beautiful.A string is beautiful if:
- It doesn’t contain leading zeros.
- It’s the binary representation of a number that is a power of
5.Return the minimum number of substrings in such partition. If it is impossible to partition the string
sinto beautiful substrings, return-1.A substring is a contiguous sequence of characters in a string.