Tap here to switch tabs
Problem
Submissions

Problem: Apply Operations to an Array

med
30 min
Try to solve the Apply Operations to an Array problem.

Statement

You are given a 00-indexed integer array nums of size nn.

You need to apply n−1n - 1 operations sequentially to the array. In the ithi^{th} operation, where 0≤i<n−10 \leq i < n - 1:

  • If nums[i] == nums[i + 1], multiply nums[i] by 22 and set nums[i + 1] to 00.

  • Otherwise, skip this operation.

After performing all operations, shift all 00’s to the end of the array while maintaining the relative order of the non-zero elements.

Return the modified array.

Constraints:

  • 2≤2 \leq nums.length ≤2000\leq 2000

  • 0≤0 \leq nums[i] ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Apply Operations to an Array

med
30 min
Try to solve the Apply Operations to an Array problem.

Statement

You are given a 00-indexed integer array nums of size nn.

You need to apply n−1n - 1 operations sequentially to the array. In the ithi^{th} operation, where 0≤i<n−10 \leq i < n - 1:

  • If nums[i] == nums[i + 1], multiply nums[i] by 22 and set nums[i + 1] to 00.

  • Otherwise, skip this operation.

After performing all operations, shift all 00’s to the end of the array while maintaining the relative order of the non-zero elements.

Return the modified array.

Constraints:

  • 2≤2 \leq nums.length ≤2000\leq 2000

  • 0≤0 \leq nums[i] ≤1000\leq 1000