3030. Find the Grid of Region Average
You are given a 0-indexed
m x ngridimagewhich represents a grayscale image, whereimage[i][j]represents a pixel with intensity in the range[0..255]. You are also given a non-negative integerthreshold.Two pixels
image[a][b]andimage[c][d]are said to be adjacent if|a - c| + |b - d| == 1.A region is a
3 x 3subgrid where the absolute difference in intensity between any two adjacent pixels is less than or equal tothreshold.All pixels in a region belong to that region, note that a pixel can belong to multiple regions.
You need to calculate a 0-indexed
m x ngridresult, whereresult[i][j]is the average intensity of the region to whichimage[i][j]belongs, rounded down to the nearest integer. Ifimage[i][j]belongs to multiple regions,result[i][j]is the average of the rounded down average intensities of these regions, rounded down to the nearest integer. Ifimage[i][j]does not belong to any region,result[i][j]is equal toimage[i][j].Return the grid
result.
3031. Minimum Time to Revert Word to Initial State II
You are given a 0-indexed string
wordand an integerk.At every second, you must perform the following operations:
- Remove the first
kcharacters ofword.- Add any
kcharacters to the end ofword.Note that you do not necessarily need to add the same characters that you removed. However, you must perform both operations at every second.
Return the minimum time greater than zero required for
wordto revert to its initial state.
3029. Minimum Time to Revert Word to Initial State I
You are given a 0-indexed string
wordand an integerk.At every second, you must perform the following operations:
- Remove the first
kcharacters ofword.- Add any
kcharacters to the end ofword.Note that you do not necessarily need to add the same characters that you removed. However, you must perform both operations at every second.
Return the minimum time greater than zero required for
wordto revert to its initial state.
An ant is on a boundary. It sometimes goes left and sometimes right.
You are given an array of non-zero integers
nums. The ant starts readingnumsfrom the first element of it to its end. At each step, it moves according to the value of the current element:
- If
nums[i] < 0, it moves left by-nums[i]units.- If
nums[i] > 0, it moves right bynums[i]units.Return the number of times the ant returns to the boundary.
Notes:
- There is an infinite space on both sides of the boundary.
- We check whether the ant is on the boundary only after it has moved
|nums[i]|units. In other words, if the ant crosses the boundary during its movement, it does not count.