Simplest Code🚀 || Beat 100% || Complete Explanation
Upvote if you find this helpful! 👍IntuitionThe problem involves finding the number of valid splits of an array such that the sum of the left part is greater tha
# **Upvote if you find this helpful! 👍**

# Intuition
The problem involves finding the number of valid splits of an array such that the sum of the left part is greater than or equal to the sum of the right part. To achieve this, we can calculate prefix sums and suffix sums for efficient comparisons at each split point.

---


# Approach
1. **Prefix Sum Calculation**: Compute a cumulative sum from the start of the array (`sumFromStart`). This allows us to quickly calculate the sum of elements from the beginning to any index.
2. **Suffix Sum Calculation**: Similarly, compute a cumulative sum from the end of the array (`sumFromEnd`). This allows us to calculate the sum of elements from any index to the end.
3. **Validation of Splits**: Iterate through the array (excluding the last element) and compare the prefix sum at index `i` with the suffix sum starting at `i + 1`. If the prefix sum is greater than or equal, it represents a valid split.
4. **Count Valid Splits**: Maintain a counter to keep track of the number of valid splits.

---


# Complexity
- **Time complexity**:  
  The time complexity is $$O(n)$$ since we iterate over the array multiple times (once for prefix sums, once for suffix sums, and once to count valid splits).
  
- **Space complexity**:  
  The space complexity is $$O(n)$$ because we use two auxiliary vectors to store prefix and suffix sums.

---


# Code
```cpp
class Solution {
public:
    int waysToSplitArray(vector<int>& nums) {
        vector<long long int>sumFromStart(nums.size());
        vector<long long int>sumFromEnd(nums.size());
        sumFromStart[0] = nums[0];
        for(int i=1;i<nums.size();i++){
            sumFromStart[i] = nums[i] + sumFromStart[i-1];
        }
        sumFromEnd[nums.size()-1] = nums[nums.size()-1];
        for(int i = nums.size()-2;i>=0;i--){
            sumFromEnd[i] = nums[i] + sumFromEnd[i+1];
        }
        long long int ans=0;
        for(int i=0;i<nums.size()-1;i++){
            if(sumFromStart[i] >= sumFromEnd[i+1]) ans++;
        }
        return ans;
    }
};
['Array', 'Math', 'Prefix Sum', 'C++']