Programming Logic – You have been given an array and a parameter k…


You have been given an array and a parameter k. You have to output the starting index of the subarray with size k, that has the minimum sum among all subarrays of size k present in the given array.

The pseudocode for doing the same is given below.

find the cumulative sum and store that in an array named carr:
for int i = 0 to length of array
csum[i] = arr[i]
for int i = 1 to length of array
X
initialise the min_sum as csum[k-1] // first sub array
initialise the index as 0 // starting index of first sub array

for int i = k to length of array
subarray_sum = csum[i] - csum[i-k-1]
if( Y ):
update min_sum
update the index

return index

What can be used in place of X and Y to complete the pseudocode?

Related Posts

Close Bitnami banner
Bitnami