 C++ || Prefix Sum || Number of Ways to Split Array - Solution Explanation || O(n) Time
IntuitionTo determine the number of valid splits in the array, we need to check whether the sum of elements in the left part (up to index i) is greater than or
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
To determine the number of valid splits in the array, we need to check whether the sum of elements in the left part (up to index i) is greater than or equal to the sum of elements in the right part (from index i+1 onward). Using prefix sums allows us to compute these sums efficiently.

# Approach
<!-- Describe your approach to solving the problem. -->
1. **Prefix Sum Calculation**:
   -  First, calculate the prefix sum of the array. This array stores the cumulative sum up to each index.
   - For example, for nums = [10, 4, -8, 7], the prefix sum would be [10, 14, 6, 13].

2. **Iterate Through Possible Splits**:
   - Loop through the array up to `n-1` (to ensure there is at least one element in the right part).
   - For each index `i`:
     - The sum of the left part is the prefix sum at index `i` (`prefixSum[i]`).
     - The sum of the right part is the total sum of the array (`prefixSum[n-1]`) minus the prefix sum at index `i` (`prefixSum[i]`).
   - Check if the left sum is greater than or equal to the right sum. If so, increment the count of valid splits.

3. **Return the Count**:
   - After iterating through all possible splits, return the count of valid splits.



# Complexity
- **Time Complexity**:  
  - Calculating the prefix sum takes $$O(n)$$ time.  
  - Iterating through the array to count valid splits also takes $$O(n)$$ time.  
  - Overall, the time complexity is $$O(n)$$.

- **Space Complexity**:  
  - The prefix sum array requires $$O(n)$$ space.  
  - Thus, the space complexity is $$O(n)$$.

# Code
```cpp []
class Solution {
public:
    int waysToSplitArray(vector<int>& nums) {
        int n = nums.size();
        vector<long long> prefixSum(n);
        int count = 0;

        // calculate prefix sum
        prefixSum[0] = nums[0];
        for(int i=1; i<n; i++){
            prefixSum[i] = prefixSum[i-1] + nums[i];
        }


        for(int i=0; i<n-1; i++){
            long long leftSum = prefixSum[i];
            long long rightSum = prefixSum[n-1] - prefixSum[i];

            if(leftSum >= rightSum) count++;
        }

        return count;
    }
};
```
['C++']