[LeetCode] Apply Operations to an Array

2460. Apply Operations to an Array

You are given a 0-indexed array nums of size n consisting of non-negative integers.

You need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith element of nums:

  • If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation.

After performing all the operations, shift all the 0’s to the end of the array.

  • For example, the array [1,0,2,0,0,1] after shifting all its 0’s to the end, is [1,2,1,0,0,0].

Return the resulting array.

Note that the operations are applied sequentially, not all at once.

Read more
[CodeChef] Greatest Dumpling FightRead more
[CodeChef] Add to SubsequenceRead more
[CodeChef] Maximum ValueRead more
[CodeChef] Chefina and SwapRead more
[CodeChef] Penalty Shoot-Out IIRead more
[Codeforces] Educational Round 98 (Rated for Div. 2) D. Radio TowersRead more
[Codeforces] Educational Round 99 (Rated for Div. 2) D. Sequence and SwapsRead more
[Codeforces] Round #691 (Div. 1) A. Row GCDRead more
[Codeforces] Round #689 (Div. 2, based on Zed Code Competition) D. Divide and SummarizeRead more