# Problem Statement 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. ## Constraints - `2 <= nums.length <= 2000` - `0 <= nums[i] <= 1000` # Solution Are constrains are low enough that we can just apply each operation as we loop through the list. Then we stable-sort the list to move all the zeros to the end. Since Python's built-in sorting is stable, there is little work to be done. ```python        for i in range(len(nums)-1): if nums[i] == nums[i+1]: nums[i] *= 2 nums[i+1] = 0 nums.sort(key=lambda x: not x) return nums ``` Time Complexity: O$(n\log n)$ | Space Complexity: O$(1)$