 📌100% || C++ || Python || Prefix Sum ||🌟Beginner-Friendly
IntuitionTo solve this problem, we need to find the valid split points in the array where the sum of the first part is greater than or equal to the sum of the s
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
To solve this problem, we need to find the valid split points in the array where the sum of the first part is greater than or equal to the sum of the second part. By iterating through the array and maintaining a running total for both parts, we can efficiently check each split point.
# Approach
<!-- Describe your approach to solving the problem. -->
1. Calculate Total Sum: First, we calculate the total sum of the array, which we will use to initialize the sum of the second part (b).
2. Iterate through the Array: As we iterate through the array, we maintain two running sums: a for the first part and b for the second part.
3. Update Sums: At each index i, update a by adding nums[i] and b by subtracting nums[i].
4. Check Condition: If at any point a >= b, it means we have a valid split. We increment our count of valid splits.
5. Return Result: Finally, return the count of valid splits
# Complexity
- Time complexity: $$𝑂(𝑛)$$ We iterate through the array twice: once for calculating the total sum and once for checking the valid splits. This results in linear time complexity.
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$𝑂(1)$$ We use a fixed amount of extra space for the variables a, b, and cou, making the space complexity constant.
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int waysToSplitArray(vector<int>& nums) {
        long long a=0,b=0;
        for(auto& i:nums) b=b+i;
        int n=nums.size(),cou=0;
        for(auto i=0;i<n-1;i++){
            a+=nums[i];
            b-=nums[i];
            if(a>=b) cou++;
        }
        return cou;
    }
};
```
``` python []
class Solution:
    def waysToSplitArray(self, nums: List[int]) -> int:
        a = 0 
        b = sum(nums) 
        n = len(nums) 
        cou = 0 
        for i in range(n - 1): 
            a += nums[i] 
            b -= nums[i] 
            if a >= b: 
                cou += 1 
        return cou
```
['Array', 'Prefix Sum', 'C++', 'Python3']