Java and C++, Easy Solution
IntuitionThe problem asks for the number of valid splits of an array, where the sum of the left part is greater than or equal to the sum of the right part. This
# Intuition
The problem asks for the number of valid splits of an array, where the sum of the left part is greater than or equal to the sum of the right part. This can be efficiently solved using prefix sums.
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
1. First, calculate the total sum of the array, totalSum, which represents the sum of all elements.
2. Use a variable leftSum to keep track of the sum of the left part as we iterate through the array.
3. For every index i, compute the sum of the right part as:
rightSum=totalSum−leftSum

<!-- Describe your approach to solving the problem. -->

# 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
```java []
class Solution {
    public int waysToSplitArray(int[] nums) {
        long totalSum = 0, leftSum = 0;
        int count = 0;

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

        for (int i = 0; i < nums.length - 1; i++) {
            leftSum += nums[i];
            long rightSum = totalSum - leftSum;

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

        return count;
    }
}
```
```cpp []
class Solution {
public:
    int waysToSplitArray(vector<int>& nums) {
        long long totalSum = 0, leftSum = 0;
        int count = 0;

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

        for (int i = 0; i < nums.size() - 1; ++i) {
            leftSum += nums[i];
            long long rightSum = totalSum - leftSum;

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

        return count;
    }
};

```
['C++']