dev-resources.site
for different kinds of informations.
No of ways to split Array
Published at
1/3/2025
Categories
rangequeries
dsa
leetcode
prefixsum
Author
Prashant Mishra
TC: O(n) for calculating prefix sum, and O(n) for iterating over the prefix sum for calculating valid splits
class Solution {
public int waysToSplitArray(int[] nums) {
long prefix[] = new long[nums.length];
long current = 0;
for(int i=0;i<nums.length;i++){
current+=nums[i];
prefix[i] = current;
}
int count =0;
for(int i =0;i<nums.length-1;i++){
long left = prefix[i];
long right = prefix[nums.length-1];
if(left>=right-left) count++;
}
return count;
}
}
Articles
12 articles in total
Minimize XOR
read article
Count prefix and suffix I and II
read article
Rabin Karp (hashing) String pattern matching
read article
Min no. of operations to move all balls to each box
read article
Find all anagrams in the string[Fixed Window pattern]
read article
No of ways to split Array
currently reading
Range sum query 2D - Immutable
read article
Count vowel strings in ranges
read article
Range Sum Query - Immutable
read article
Job Scheduling Problem with Max Profit
read article
Non overlapping intervals
read article
Minimum No. of arrows to burst balloons
read article
Featured ones: