[LeetCode] Relocate Marbles

2766. Relocate Marbles

You are given a 0-indexed integer array nums representing the initial positions of some marbles. You are also given two 0-indexed integer arrays moveFrom and moveTo of equal length.

Throughout moveFrom.length steps, you will change the positions of the marbles. On the ith step, you will move all marbles at position moveFrom[i] to position moveTo[i].

After completing all the steps, return the sorted list of occupied positions.

Notes:

  • We call a position occupied if there is at least one marble in that position.
  • There may be multiple marbles in a single position.
Read more
[LeetCode] Longest Alternating Subarray

2765. Longest Alternating Subarray

You are given a 0-indexed integer array nums. A subarray s of length m is called alternating if:

  • m is greater than 1.
  • s1 = s0 + 1.
  • The 0-indexed subarray s looks like [s0, s1, s0, s1,...,s(m-1) % 2]. In other words, s1 - s0 = 1, s2 - s1 = -1, s3 - s2 = 1, s4 - s3 = -1, and so on up to s[m - 1] - s[m - 2] = (-1)m.

Return the maximum length of all alternating subarrays present in nums or -1 if no such subarray exists**.

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

Read more
[Codeforces] Educational Round 113 (Rated for Div. 2) D. Inconvenient PairsRead more
[Codeforces] Technocup 2022 - Elimination Round 3 D. Yet Another Sorting ProblemRead more
[Codeforces] Round 748 (Div. 3) D2. Half of SameRead more
[Codeforces] Bubble Cup 14 - Finals Online Mirror (Unrated, ICPC Rules, Teams Preferred, Div. 2) E. Array GameRead more
[Codeforces] Round 751 (Div. 1) B. Frog TravelerRead more
[CS Academy] Reverse SubarrayRead more
[CS Academy] Subarray PartitionRead more
[CS Academy] Squarish RectangleRead more