[LeetCode] Minimum Increment Operations to Make Array Beautiful

2919. Minimum Increment Operations to Make Array Beautiful

You are given a 0-indexed integer array nums having length n, and an integer k.

You can perform the following increment operation any number of times (including zero):

  • Choose an index i in the range [0, n - 1], and increase nums[i] by 1.

An array is considered beautiful if, for any subarray with a size of 3 or more, its maximum element is greater than or equal to k.

Return an integer denoting the minimum number of increment operations needed to make nums *beautiful.*

A subarray is a contiguous non-empty sequence of elements within an array.

Read more
[LeetCode] Minimum Equal Sum of Two Arrays After Replacing Zeros

2918. Minimum Equal Sum of Two Arrays After Replacing Zeros

You are given two arrays nums1 and nums2 consisting of positive integers.

You have to replace all the 0‘s in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.

Return the minimum equal sum you can obtain, or -1 if it is impossible.

Read more
[LeetCode] Find the K-or of an Array

2917. Find the K-or of an Array

You are given a 0-indexed integer array nums, and an integer k.

The K-or of nums is a non-negative integer that satisfies the following:

  • The ith bit is set in the K-or if and only if there are at least k elements of nums in which bit i is set.

Return the K-or of nums.

Note that a bit i is set in x if (2i AND x) == 2i, where AND is the bitwise AND operator.

Read more
[Codeforces] Lyft Level 5 Challenge 2018 - Elimination Round D. DivisorsRead more
[Codeforces] Round 513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2) E. Sergey and SubwayRead more
[Codeforces] Round 523 (Div. 2) D. TV ShowsRead more
[Codeforces] 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) C. Cloud ComputingRead more
[LeetCode] Subarrays Distinct Element Sum of Squares II

2916. Subarrays Distinct Element Sum of Squares II

You are given a 0-indexed integer array nums.

The distinct count of a subarray of nums is defined as:

  • Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].

Return the sum of the squares of distinct counts of all subarrays of nums.

Since the answer may be very large, return it modulo 109 + 7.

A subarray is a contiguous non-empty sequence of elements within an array.

Read more
[LeetCode] Length of the Longest Subsequence That Sums to Target

2915. Length of the Longest Subsequence That Sums to Target

You are given a 0-indexed array of integers nums, and an integer target.

Return the length of the longest subsequence of nums that sums up to target. If no such subsequence exists, return -1.

A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

Read more
[LeetCode] Minimum Number of Changes to Make Binary String Beautiful

2914. Minimum Number of Changes to Make Binary String Beautiful

You are given a 0-indexed binary string s having an even length.

A string is beautiful if it’s possible to partition it into one or more substrings such that:

  • Each substring has an even length.
  • Each substring contains only 1‘s or only 0‘s.

You can change any character in s to 0 or 1.

Return the minimum number of changes required to make the string s beautiful.

Read more