[LeetCode] Construct Uniform Parity Array I

3875. Construct Uniform Parity Array I

You are given an array nums1 of n distinct integers.

You want to construct another array nums2 of length n such that the elements in nums2 are either all odd or all even.

For each index i, you must choose exactly one of the following (in any order):

  • nums2[i] = nums1[i]
  • nums2[i] = nums1[i] - nums1[j], for an index j != i

Return true if it is possible to construct such an array, otherwise, return false.

Read more
[LeetCode] Count Commas in Range II

3871. Count Commas in Range II

You are given an integer n.

Return the total number of commas used when writing all integers from [1, n] (inclusive) in standard number formatting.

In standard formatting:

  • A comma is inserted after every three digits from the right.
  • Numbers with fewer than 4 digits contain no commas.
Read more
[LeetCode] Longest Arithmetic Sequence After Changing At Most One Element

3872. Longest Arithmetic Sequence After Changing At Most One Element

You are given an integer array nums.

A subarray is arithmetic if the difference between consecutive elements in the subarray is constant.

You can replace at most one element in nums with any integer. Then, you select an arithmetic subarray from nums.

Return an integer denoting the maximum length of the arithmetic subarray you can select.

Read more
[LeetCode] Maximum Points Activated with One Addition

3873. Maximum Points Activated with One Addition

You are given a 2D integer array points, where points[i] = [x_i, y_i] represents the coordinates of the i^th point. All coordinates in points are distinct.

If a point is activated, then all points that have the same x-coordinate or y-coordinate become activated as well.

Activation continues until no additional points can be activated.

You may add one additional point at any integer coordinate (x, y) not already present in points. Activation begins by activating this newly added point.

Return an integer denoting the maximum number of points that can be activated, including the newly added point.

Read more
[LeetCode] Construct Uniform Parity Array II

3876. Construct Uniform Parity Array II

You are given an array nums1 of n distinct integers.

You want to construct another array nums2 of length n such that the elements in nums2 are either all odd or all even.

For each index i, you must choose exactly one of the following (in any order):

  • nums2[i] = nums1[i]​​​​​​​
  • nums2[i] = nums1[i] - nums1[j], for an index j != i, such that nums1[i] - nums1[j] >= 1

Return true if it is possible to construct such an array, otherwise return false.

Read more
[LeetCode] Count Good Subarrays

3878. Count Good Subarrays

You are given an integer array nums.

A subarray is called good if the bitwise OR of all its elements is equal to at least one element present in that subarray.

Return the number of good subarrays in nums.

Here, the bitwise OR of two integers a and b is denoted by a | b.

Read more
[LeetCode] Minimum Absolute Difference Between Two Values

3880. Minimum Absolute Difference Between Two Values

You are given an integer array nums consisting only of 0, 1, and 2.

A pair of indices (i, j) is called valid if nums[i] == 1 and nums[j] == 2.

Return the minimum absolute difference between i and j among all valid pairs. If no valid pair exists, return -1.

The absolute difference between indices i and j is defined as abs(i - j).

Read more
[LeetCode] Minimum Removals to Achieve Target XOR

3877. Minimum Removals to Achieve Target XOR

You are given an integer array nums and an integer target.

You may remove any number of elements from nums (possibly zero).

Return the minimum number of removals required so that the bitwise XOR of the remaining elements equals target. If it is impossible to achieve target, return -1.

The bitwise XOR of an empty array is 0.

Read more
[LeetCode] Count Non Decreasing Arrays With Given Digit Sums

3883. Count Non Decreasing Arrays With Given Digit Sums

You are given an integer array digitSum of length n.

An array arr of length n is considered valid if:

  • 0 <= arr[i] <= 5000
  • it is non-decreasing.
  • the sum of the digits of arr[i] equals digitSum[i].

Return an integer denoting the number of distinct valid arrays. Since the answer may be large, return it modulo 10^9 + 7.

An array is said to be non-decreasing if each element is greater than or equal to the previous element, if it exists.

Read more
[LeetCode] Direction Assignments with Exactly K Visible People

3881. Direction Assignments with Exactly K Visible People

You are given three integers n, pos, and k.

There are n people standing in a line indexed from 0 to n - 1. Each person independently chooses a direction:

  • 'L': visible only to people on their right
  • 'R': visible only to people on their left

pos

  • A person i < pos is visible if and only if they choose 'L'.
  • A person i > pos is visible if and only if they choose 'R'.

Return the number of possible direction assignments such that the person at index pos sees exactly k people.

Since the answer may be large, return it modulo 10^9 + 7.

Read more