Given a 0-indexed integer array nums, return an array answer of the same length where answer[i] = |leftSum[i] - rightSum[i]|. leftSum[i] is the sum of the elements to the left of index i, and rightSum[i] is the sum of the elements to the right of index i. A side with no elements sums to 0.
Given a 0-indexed integer array nums, return an array answer of the same length where answer[i] = |leftSum[i] - rightSum[i]|. leftSum[i] is the sum of the elements to the left of index i, and rightSum[i] is the sum of the elements to the right of index i. A side with no elements sums to 0.
Example 1:
Input: {"nums":[10,4,8,3]}
Output: [15,1,11,22]
Constraints:
1≤nums.length≤1000
1≤nums[i]≤105
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[10,4,8,3]}
Start with nothing on the left (left = 0) and everything on the right (right = 25).