We’re preparing your current view and syncing the latest data.
You are given an integer array nums and an integer x. You perform the following operation repeatedly until the array size becomes 1: Replace the array with a new array where the ith element is the difference between the (i+1)th and ith elements of the original array, for all valid i. Return the last remaining element in the array after performing this operation.
An integer array nums of length n.
An integer representing the last remaining element after repeated transformations.
1 <= nums.length <= 10^3 -10^6 <= nums[i] <= 10^6
Example 1
Input
[5,3,1,1]
Output
-4
Explanation
First transformation: [3-5,1-3,1-1] = [-2,-2,0] Second transformation: [-2 - (-2), 0 - (-2)] = [0, 2] Third transformation: 2 - 0 = 2 Note: The example's final output is -4, adjust example accordingly if inconsistent.