Your question is Merge Adjacent Equal Numbers. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Given an array, you can merge two adjacent equal numbers into one; return the smallest final array after applying operations optimally.
A merge replaces equal adjacent values x, x with 2 * x. Choose the operations that produce the shortest final array; if several results have the same length, return the lexicographically smallest one. For signed values, a value created from a negative pair is not merged again.
Implement merge_equal_adjacent(nums), which accepts a list of integers and returns the resulting list.
Constraints:
1 <= len(nums) <= 200-10^9 <= nums[i] <= 10^9def merge_equal_adjacent(nums):