[Hacker Earth] Candy Distribution 3Read more
[Hacker Earth] XOR in SequenceRead more
[Hacker Earth] Count NumbersRead more
[Codeforces] Educational Round 44 (Rated for Div. 2) E. Pencils and BoxesRead more
[Codeforces] Round 486 (Div. 3) E. Divisibility by 25Read more
[Codeforces] Round 486 (Div. 3) F. Rain and UmbrellasRead more
[Codeforces] Educational Round 45 (Rated for Div. 2) E. Post LampsRead more
[Codeforces] Round 489 (Div. 2) D. Nastya and a GameRead more
[LeetCode] Distribute Elements Into Two Arrays II

3072. Distribute Elements Into Two Arrays II

You are given a 1-indexed array of integers nums of length n.

We define a function greaterCount such that greaterCount(arr, val) returns the number of elements in arr that are strictly greater than val.

You need to distribute all the elements of nums between two arrays arr1 and arr2 using n operations. In the first operation, append nums[1] to arr1. In the second operation, append nums[2] to arr2. Afterwards, in the ith operation:

  • If greaterCount(arr1, nums[i]) > greaterCount(arr2, nums[i]), append nums[i] to arr1.
  • If greaterCount(arr1, nums[i]) < greaterCount(arr2, nums[i]), append nums[i] to arr2.
  • If greaterCount(arr1, nums[i]) == greaterCount(arr2, nums[i]), append nums[i] to the array with a lesser number of elements.
  • If there is still a tie, append nums[i] to arr1.

The array result is formed by concatenating the arrays arr1 and arr2. For example, if arr1 == [1,2,3] and arr2 == [4,5,6], then result = [1,2,3,4,5,6].

Return the integer array result.

Read more
[LeetCode] Minimum Operations to Write the Letter Y on a Grid

3071. Minimum Operations to Write the Letter Y on a Grid

You are given a 0-indexed n x n grid where n is odd, and grid[r][c] is 0, 1, or 2.

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, or 2.

Read more