0ms || Beats 100% || Efficient & Easy C++ Solution || Full Explained
IntuitionThe goal is to find the number of ways to split the array into two non-empty parts such that the sum of the left part is greater than or equal to the s
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The goal is to find the number of ways to split the array into two non-empty parts such that the sum of the left part is greater than or equal to the sum of the right part.

If we know the total sum of the array, we can calculate the sum of the right part dynamically as we iterate through the array, by subtracting the running sum of the left part from the total sum.This approach avoids recalculating the sums for each split, making it efficient.

# Approach
<!-- Describe your approach to solving the problem. -->
**Step 1: Compute the Total Sum**
Calculate the total sum of the array. This will help compute the right part's sum efficiently during the split-checking phase.

**Step 2: Iterate Through the Array**
As we iterate through the array:
Maintain a running sum (leftSum) for the left part.
Calculate the right part's sum dynamically as 

            rightSum = totalSum - leftSum.

**Step 3: Check the Split Condition**
For each index i: Check if 

            leftSum >= rightSum.
If the condition holds, increment the count of valid splits.
Return the Result: After processing all indices, return the count of valid splits.

# Complexity
- Time complexity:O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int waysToSplitArray(vector<int>& nums) {
        long long leftSideSum = 0, rightSideSum = 0;
        for (int num : nums) {
            rightSideSum += num;
        }
        int validSplits = 0;
        for (int i = 0; i < nums.size() - 1; i++) {
            leftSideSum += nums[i];
            rightSideSum -= nums[i];
            if (leftSideSum >= rightSideSum) {
                validSplits++;
            }
        }
        return validSplits;
    }
};
```
['Array', 'Prefix Sum', 'C++']