Simple prefixSum solution✅✅
IntuitionThe task is to find the number of ways to split an array nums nums such that:
Both parts are non-empty.
The sum of the left part (prefixSum) is greater
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The task is to find the number of ways to split an array nums nums such that:
1. Both parts are non-empty.
1. The sum of the left part (prefixSum) is greater than or equal to the sum of the right part (suffixSum).

By observing:
- prefixSum+suffixSum=totalSum,
- we can compute suffixSum=totalSum−prefixSum.

As we iterate through the array and keep track of prefixSum, suffixSum can be calculated directly. The problem reduces to checking whether prefixSum ≥ suffixSum for valid splits.




# Approach
<!-- Describe your approach to solving the problem. -->
1. Calculate Total Sum:

    - Compute the total sum of the array once using a single pass.  This will help in deriving suffixSum later.

1. Initialize Prefix Sum:

    - Start with prefixSum=0.
    - Use a variable count=0 to keep track of valid splits.

1. Iterate Through the Array:

    - For each element (except the last one to ensure non-empty right part):
        1. Update prefixSum by adding the current element.
        1. Derive suffixSum as totalSum−prefixSum.
        1. Check the condition prefixSum≥suffixSum:
            - If true, increment the count.

1. Return Result:

    - After iterating through the array, return count.


# 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) {
        int n=nums.size();
        long long totalSum = 0;
        for (int num : nums) {
            totalSum+=num;
        }

        long long prefixSum=0;
        int count=0;

        for(int i=0;i<n-1;i++){
            prefixSum+=nums[i];
            long long suffixSum=totalSum-prefixSum;

            if(prefixSum>=suffixSum) count++;
        }
        return count;
    }
};
```
['Array', 'Prefix Sum', 'C++']