Apply Operations to an Array Problem
Apply Operations to an Array Problem — ExecCode Easy DSA Practice
Solve the Apply Operations to an Array problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a 0-indexed array nums of size n consisting of non-negative integers. Your task is to compute the required answer and return the resulting array. You need to apply n - 1 operations to this array where, in the i^th operation (0-indexed), you will apply the following on the i^th 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.
Examples
Input {"nums": [1, 2, 2, 1, 1, 0]}; Output [1, 4, 2, 0, 0, 0]. Input {"nums": [0, 1]}; Output [1, 0]
Constraints
2 <= nums.length <= 2000 0 <= nums[i] <= 1000
Practice Apply Operations to an Array free on ExecCode. Browse DSA problems, topic map, and placement guides.