[Codeforces] Round 818 (Div. 2) D. Madoka and The Corruption SchemeRead more
[LeetCode] Sum of Imbalance Numbers of All Subarrays

6894. Sum of Imbalance Numbers of All Subarrays

The imbalance number of a 0-indexed integer array arr of length n is defined as the number of indices in sarr = sorted(arr) such that:

  • 0 <= i < n - 1, and
  • sarr[i+1] - sarr[i] > 1

Here, sorted(arr) is the function that returns the sorted version of arr.

Given a 0-indexed integer array nums, return the sum of imbalance numbers of all its subarrays.

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

Read more
[LeetCode] Continuous Subarrays

6911. Continuous Subarrays

You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:

  • Let i, i + 1, …, j be the indices in the subarray. Then, for each pair of indices i <= i1, i2 <= j, 0 <= |nums[i1] - nums[i2]| <= 2.

Return the total number of continuous subarrays.

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

Read more
[LeetCode] Prime Pairs With Target Sum

6916. Prime Pairs With Target Sum

You are given an integer n. We say that two integers x and y form a prime number pair if:

  • 1 <= x <= y <= n
  • x + y == n
  • x and y are prime numbers

Return the 2D sorted list of prime number pairs [xi, yi]. The list should be sorted in increasing order of xi. If there are no prime number pairs at all, return an empty array.

Note: A prime number is a natural number greater than 1 with only two factors, itself and 1.

Read more
[LeetCode] Longest Even Odd Subarray With Threshold

6909. Longest Even Odd Subarray With Threshold

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

Find the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following conditions:

  • nums[l] % 2 == 0
  • For all indices i in the range [l, r - 1], nums[i] % 2 != nums[i + 1] % 2
  • For all indices i in the range [l, r], nums[i] <= threshold

Return an integer denoting the length of the longest such subarray.

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

Read more
[Codeforces] Round 867 (Div. 3) G2. Magic Triples (Hard Version)Read more
[Codeforces] Round 867 (Div. 3) G1. Magic Triples (Easy Version)Read more
[Codeforces] Round 867 (Div. 3) F. Gardening FriendsRead more
[Codeforces] Global Round 22 D. Permutation AddictsRead more
[Codeforces] Educational Round 136 (Rated for Div. 2) D. Reset K EdgesRead more