Counting Valid Splits in an Array Based on Sum Comparison
IntuitionThe problem asks us to determine the number of valid splits in the array such that the sum of the left subarray is greater than or equal to the sum of
# Intuition
The problem asks us to determine the number of valid splits in the array such that the sum of the left subarray is greater than or equal to the sum of the right subarray. A straightforward approach involves computing prefix sums and comparing them for each potential split.

# Approach
**1. Calculate Total Sum:**
- First, compute the total sum of the array to help calculate the right sum efficiently for any split.

**2. Iterate Over Possible Splits:**
- Maintain a ```left_sum``` variable to track the cumulative sum of the left subarray as we iterate through the array.
- For each index *i* (up to the second-to-last element), compute the right sum as ```total_sum - left_sum```.
- Check if ```left_sum >= right_sum```. If true, it's a valid split, so increment the counter.

**3. Return the Count:**
- At the end of the iteration, return the count of valid splits.

# Complexity
- Time complexity:
*O(n)*, where *n* is the size of the array. We iterate through the array twice: once to compute the total sum and once to check for valid splits.

- Space complexity:
*O(1)*, as we only use a few additional variables (```total_sum```, ```left_sum```, and ```right_sum```).

# Code
```cpp []
class Solution {
public:
    int waysToSplitArray(vector<int>& nums) {
        int valid_splits = 0;
        long long total_sum = 0;

        for (int num : nums){
            total_sum += num;
        }

        // To keep track of the cumulative sum of the left part
        long long left_sum = 0;

        // Iterating through the array up to the second-to-last element
        for (int i = 0; i < nums.size() - 1; i++) {
            left_sum += nums[i];

            // Calculating right sum as the remaining elements
            long long right_sum = total_sum - left_sum;

            if (left_sum >= right_sum) {
                valid_splits++;
            }
        }

        return valid_splits;
    }
};

```
['Prefix Sum', 'C++']