Easy to understand Prefix Sum with O(1) space || C++ beats 100% Time Complexity.
IntuitionThe problem requires splitting an array into two parts such that the sum of the left part is greater than or equal to the sum of the right part. This c
# Intuition
The problem requires splitting an array into two parts such that the sum of the left part is greater than or equal to the sum of the right part. This can be solved by maintaining a running sum or using a prefix sum array for efficient computation of sums.

# Approach 1: Using Running Sums
1. **Calculate Total Sum**: Start by calculating the total sum of the array to compute the right sum dynamically.
2. **Iterate Through the Array**: Use a loop to evaluate all possible split points up to the second-to-last element.
3. **Track Left and Right Sums**: Maintain a running sum for the left part. Compute the right part as `rightSum = totalSum - leftSum`.
4. **Check Valid Splits**: For each split point, check if `leftSum >= rightSum`. If true, increment the result counter.
5. **Return Result**: Return the total count of valid splits.

# Approach 2: Using Prefix Sum
1. **Calculate Prefix Sums**: Build a prefix sum array, where `prefix[i]` stores the sum of the array elements from the start up to index `i`.
2. **Iterate Through the Array**: Iterate through the array up to the second-to-last index.
3. **Compare Sums**: For each index, check if the left sum (`prefix[idx]`) is greater than or equal to the right sum (`prefix[n-1] - prefix[idx]`).
4. **Update Result**: Increment the counter if the condition is met.
5. **Return Result**: Return the count of valid splits.

# Complexity for Both Approaches
### Approach 1
- **Time Complexity**:  
  $$O(n)$$ — One pass to calculate the total sum and another pass to check valid splits.
- **Space Complexity**:  
  $$O(1)$$ — Only variables for tracking sums and the result are used.

### Approach 2
- **Time Complexity**:  
  $$O(n)$$ — One pass to calculate the prefix sum array and another pass to evaluate splits.
- **Space Complexity**:  
  $$O(n)$$ — The prefix sum array requires additional space proportional to the input size.

# Code
### Approach 1: Using Running Sums
```cpp
class Solution {
public:
    int waysToSplitArray(vector<int>& nums) {
        int n = nums.size();
        int res = 0;
        long totalSum = 0, leftSum = 0;

        // Calculate the total sum of the array
        for (int num : nums) {
            totalSum += num;
        }

        // Iterate through the array and check valid splits
        for (int i = 0; i < n - 1; i++) {
            leftSum += nums[i];
            long rightSum = totalSum - leftSum;

            if (leftSum >= rightSum) {
                res++;
            }
        }

        return res;
    }
};
```
### Approach 2: Using Prefix Sum
```cpp
class Solution {
public:
    int waysToSplitArray(vector<int>& nums) {
        int n = nums.size(), res = 0;
        vector<long> prefix(n, 0);

        // Build the prefix sum array
        for (int i = 0; i < n; i++) {
            prefix[i] = i > 0 ? prefix[i - 1] + nums[i] : nums[i];
        }

        // Check valid splits using prefix sums
        for (int idx = 0; idx < n - 1; idx++) {
            if (prefix[idx] >= prefix[n - 1] - prefix[idx]) {
                res++;
            }
        }

        return res;
    }
};
```

['C++']