💡 C++ | O(N) | Very Easy Sol | Simple Logic | With Full Explanation ✏
IntuitionWe have to find the count of the left subarrays having sum >= the right subarraysApproach
We will store the sum of the whole array in the rs
Then we wi
# Intuition
We have to find the count of the left subarrays having sum >= the right subarrays

# Approach
- We will store the sum of the whole array in the `rs`
- Then we will traverse the array and use sliding window concept and store the element sum in the `ls` and subtract it from the `rs`
- Run the check if the `ls` >= `rs`. If yes then we will increment the ans

# Complexity
- Time complexity:
```O(n)```

- Space complexity:
```O(1)```

# Code
```cpp []
class Solution {
public:
    int waysToSplitArray(vector<int>& nums) {
        int ans=0;
        long long ls=0;
        long long rs=0;
        for(int i:nums)rs+=i;
        for(int j=0;j<nums.size()-1;j++){
            ls+=nums.at(j);
            rs-=nums.at(j);
            if(ls>=rs) ans++;
        }
        return ans;
    }
};
```


![anonupvote.jpeg](https://assets.leetcode.com/users/images/bf7ce48f-1a34-404c-8610-410d43112c2c_1720413559.1746094.jpeg)
# Ask any doubt !!!
Reach out to me 😊👇
🔗 https://tushar-bhardwaj.vercel.app/
['Array', 'Math', 'Sliding Window', 'Prefix Sum', 'C++']