class Solution { public int waysToSplitArray(int[] nums) { int n=nums.length; long total_sum=Arrays.stream(nums).asLongStream().sum(); // long total_sum=0; // for(int num:nums){ // total_sum+=num; // } long cur_sum=0; int ans=0; for(int i=0;i=total_sum){ans+=1;} } return ans;
# TC= O(n) # SC=O(1) class Solution: def waysToSplitArray(self, nums: List[int]) -> int: n=len(nums) total_sum=sum(nums) cur_sum=0 ans=0 for i in range(n-1): cur_sum+=nums[i] #remainingEle_sum=total_sum-cur_sum total_sum-=nums[i] #print('i=',i,'1st i+1 ele sum=',cur_sum,'remaining ele sum=',total_sum) if(cur_sum>=total_sum): ans+=1 return ans
class Solution {
public int waysToSplitArray(int[] nums) {
int n=nums.length;
long total_sum=Arrays.stream(nums).asLongStream().sum();
// long total_sum=0;
// for(int num:nums){
// total_sum+=num;
// }
long cur_sum=0;
int ans=0;
for(int i=0;i=total_sum){ans+=1;}
}
return ans;
}
}
# TC= O(n)
# SC=O(1)
class Solution:
def waysToSplitArray(self, nums: List[int]) -> int:
n=len(nums)
total_sum=sum(nums)
cur_sum=0
ans=0
for i in range(n-1):
cur_sum+=nums[i]
#remainingEle_sum=total_sum-cur_sum
total_sum-=nums[i]
#print('i=',i,'1st i+1 ele sum=',cur_sum,'remaining ele sum=',total_sum)
if(cur_sum>=total_sum):
ans+=1
return ans