---
# System prepended metadata

title: 2574. Left and Right Sum Differences
tags: [Leetcode, Easy, Prefix Sum]

---

# 2574. Left and Right Sum Differences
###### tags: `Leetcode` `Easy` `Prefix Sum`
Link: https://leetcode.com/problems/left-and-right-sum-differences/description/
## Code
$O(N)$ $O(1)$
```python=
class Solution:
    def leftRightDifference(self, nums: List[int]) -> List[int]:
        leftSum, rightSum = 0, 0
        for i in range(1, len(nums)):
            rightSum += nums[i]
        ans = []
        for i in range(len(nums)):
            if i!=0: 
                rightSum -= nums[i]
                leftSum += nums[i-1]
            ans.append(abs(rightSum-leftSum))
        return ans
```