C# Solution for Number of Ways To Split Array Problem
IntuitionThe goal is to determine how many valid splits exist in the array, where the sum of the left subarray is greater than or equal to the sum of the right
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The goal is to determine how many valid splits exist in the array, where the sum of the left subarray is greater than or equal to the sum of the right subarray. The intuition is to avoid recalculating subarray sums repeatedly by leveraging cumulative sums:
•	Use a running total (leftSum) for the left subarray.
•	Derive the right subarray sum dynamically as rightSum = totalSum - leftSum.

# Approach
<!-- Describe your approach to solving the problem. -->
1.	Calculate Total Sum:
	•	Compute the total sum of the array in a single pass. This allows us to derive the sum of the right subarray dynamically.
2.	Iterate Over Splits:
	•	Iterate through the array from index 0 to n-2 to ensure the right subarray always contains at least one element.
3.	Track Left and Right Sums:
	•	Maintain a leftSum variable to track the cumulative sum of elements in the left subarray.
	•	Use the formula rightSum = totalSum - leftSum to compute the right subarray sum dynamically.
4.	Check Valid Splits:
	•	For each split index, check if leftSum >= rightSum. If true, increment the count of valid splits.
5.	Return Result:
	•	After the loop, return the count of valid splits.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
1.	Total Sum Calculation:
	•	Calculating the total sum of the array takes O(n).
2.	Split Iteration:
	•	Iterating through the array to check splits also takes O(n).

Overall Time Complexity: O(n) + O(n) = O(n)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
1.	Auxiliary Space:
	•	The solution uses a constant amount of additional space, including variables like totalSum, leftSum, and validSplits.

Overall Space Complexity: O(1)

# Code
```csharp []
public class Solution {
    public int WaysToSplitArray(int[] nums) {
        int n = nums.Length;

        long totalSum = 0;
        foreach (int num in nums) {
            totalSum += num;
        }

        long leftSum = 0;
        int validSplits = 0;
        for (int i = 0; i < n - 1; i++) {
            leftSum += nums[i];
            long rightSum = totalSum - leftSum;

            if (leftSum >= rightSum) {
                validSplits++;
            }
        }

        return validSplits;
    }
}
```
['C#']