MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / waysToSplitArray

Method waysToSplitArray

NumberOfWaysToSplitArray.java:3–19  ·  view source on GitHub ↗
(int[] nums)

Source from the content-addressed store, hash-verified

1
2class Solution {
3 public int waysToSplitArray(int[] nums) {
4 long right = 0;
5 long left = 0;
6 for(int num : nums){
7 right += num;
8 }
9 int n = nums.length;
10 int count=0;
11 for(int i=0;i<n-1;i++){
12 left += nums[i];
13 right -= nums[i];
14 if(left >= right){
15 count++;
16 }
17 }
18 return count;
19 }
20}
21
22//only left sum

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected