Beginner Friendly Solution - Core Logic Building approach. Java | Python | C++
IntuitionThe problem involves splitting the array into two non-empty parts and comparing their sums. Instead of recalculating sums repeatedly for every split, w
# Intuition
The problem involves splitting the array into two non-empty parts and comparing their sums. Instead of recalculating sums repeatedly for every split, we can use a prefix sum array to efficiently compute the left and right sums for each split.

# Approach
1. Compute the prefix sum array, where `prefixSum[i]` stores the sum of elements from the start of the array to index `i`. This allows us to calculate the sum of any subarray in constant time.
2. Calculate the total sum of the array using the last value of the prefix sum array.
3. Iterate through the array, checking for all valid splits:
   - The left sum is `prefixSum[i]`.
   - The right sum is `total_sum - prefixSum[i]`.
   - Increment the count if the left sum is greater than or equal to the right sum.
4. Return the count of valid splits.

# Complexity
- Time complexity:  
  The prefix sum calculation and the iteration through the array are both \(O(n)\), so the total time complexity is **$$O(n)$$**.

- Space complexity:  
  We use an additional array of size \(n\) for storing the prefix sums, so the space complexity is **$$O(n)$$**.


# Code
```python3 []
class Solution:
    def waysToSplitArray(self, nums: List[int]) -> int:
        n = len(nums)
        cnt = 0
        pSum = [0]*n
        pSum[0] = nums[0]

        for i in range(1, n):
            pSum[i] = pSum[i - 1] + nums[i]

        full = pSum[-1]
        for i in range(n - 1):
            l = pSum[i]
            r = full - l
            if l >= r:
                cnt += 1

        return cnt 
```
```java []
class Solution {
    public int waysToSplitArray(int[] nums) {
    int n = nums.length;
    long[] prefixSum = new long[n];
    prefixSum[0] = nums[0];
    
    for (int i = 1; i < n; i++) {
        prefixSum[i] = prefixSum[i - 1] + nums[i];
    }
    
    long totalSum = prefixSum[n - 1];
    int count = 0;

    for (int i = 0; i < n - 1; i++) {
        long left = prefixSum[i];
        long right = totalSum - left;
        if (left >= right) {
            count++;
        }
    }
    
    return count;

    }
}
```
``` C++ []

class Solution {
public:
    int waysToSplitArray(vector<int>& nums) {
        int n = nums.size();
        vector<long long> prefixSum(n);
        prefixSum[0] = nums[0];

        for (int i = 1; i < n; i++) {
            prefixSum[i] = prefixSum[i - 1] + nums[i];
        }
        
        long long totalSum = prefixSum[n - 1];
        int count = 0;

        for (int i = 0; i < n - 1; i++) {
            long long left = prefixSum[i];
            long long right = totalSum - left;
            if (left >= right) {
                count++;
            }
        }
        
        return count;        
    }
};

```
['Python3']