✅ Beginner Friendly | Easy to Understand | 100% Faster | Prefix Sum | Java | Video Explanation 🔥
IntuitionTo solve this problem, the key observation is that for any split of the array into two non-empty parts, the left part's sum (psum) must be greater than
# Intuition
To solve this problem, the key observation is that for any split of the array into two non-empty parts, the left part's sum (`psum`) must be greater than or equal to the right part's sum (`sum - psum`). By iterating through the array and maintaining a running prefix sum, we can efficiently check this condition for every potential split.

# Approach
1. **Calculate the Total Sum:** First, compute the total sum of the array, as it will help determine the sum of the right part for any split.
2. **Iterate Through the Array:** Use a loop to traverse the array up to the second last element. For each iteration:
   - Update the prefix sum (`psum`) by adding the current element.
   - Compare the prefix sum with the right part's sum (`sum - psum`). If `psum` is greater than or equal, count it as a valid split.
3. **Return the Result:** Finally, return the count of valid splits.

This approach ensures that we check each possible split in a single pass of the array.

# Complexity
- **Time complexity:**  
  $$O(n)$$  
  The algorithm involves a single traversal of the array to calculate the total sum, followed by another traversal to check the condition for valid splits. Thus, it is linear in time complexity.

- **Space complexity:**  
  $$O(1)$$  
  The solution uses a constant amount of extra space, as we only maintain variables for the total sum, prefix sum, and the count of valid splits.


# Code
```java []
class Solution {
    public int waysToSplitArray(int[] nums) {
        // Calculate the total sum of the array
        long sum = 0;
        for(int num : nums) {
            sum += num;
        }

        // Initialize prefix sum (psum) and answer (ans)
        long psum = 0;
        int ans = 0;

        // Iterate through the array up to the second last element
        for(int i = 0; i < nums.length - 1; i++) {
            // Add the current element to the prefix sum
            psum += nums[i];

            // Check if the prefix sum is greater than or equal to the remaining sum
            if(psum >= (sum - psum)) {
                // Increment the count of valid splits
                ans++;
            }
        }

        // Return the total number of valid splits
        return ans;
    }
}

```

LeetCode 2270 Number of Ways to Split Array | Prefix Sum | Asked in Amazon
https://youtu.be/icKP3DC9Gq8
['Array', 'Prefix Sum', 'Java']