3072. Distribute Elements Into Two Arrays II
You are given a 1-indexed array of integers
numsof lengthn.We define a function
greaterCountsuch thatgreaterCount(arr, val)returns the number of elements inarrthat are strictly greater thanval.You need to distribute all the elements of
numsbetween two arraysarr1andarr2usingnoperations. In the first operation, appendnums[1]toarr1. In the second operation, appendnums[2]toarr2. Afterwards, in theithoperation:
- If
greaterCount(arr1, nums[i]) > greaterCount(arr2, nums[i]), appendnums[i]toarr1.- If
greaterCount(arr1, nums[i]) < greaterCount(arr2, nums[i]), appendnums[i]toarr2.- If
greaterCount(arr1, nums[i]) == greaterCount(arr2, nums[i]), appendnums[i]to the array with a lesser number of elements.- If there is still a tie, append
nums[i]toarr1.The array
resultis formed by concatenating the arraysarr1andarr2. For example, ifarr1 == [1,2,3]andarr2 == [4,5,6], thenresult = [1,2,3,4,5,6].Return the integer array
result.
3071. Minimum Operations to Write the Letter Y on a Grid
You are given a 0-indexed
n x ngrid wherenis odd, andgrid[r][c]is0,1, or2.We say that a cell belongs to the Letter Y if it belongs to one of the following:
- The diagonal starting at the top-left cell and ending at the center cell of the grid.
- The diagonal starting at the top-right cell and ending at the center cell of the grid.
- The vertical line starting at the center cell and ending at the bottom border of the grid.
The Letter Y is written on the grid if and only if:
- All values at cells belonging to the Y are equal.
- All values at cells not belonging to the Y are equal.
- The values at cells belonging to the Y are different from the values at cells not belonging to the Y.
Return the minimum number of operations needed to write the letter Y on the grid given that in one operation you can change the value at any cell to
0,1, or2.