SUFFPR02 - Editorial

Problem Link - Count Suffixes with Sum Greater Than X

Problem Statement:

Given an array arr[] of size n and a value X, count how many suffixes of the array have a sum greater than X.

Approach:

To count suffixes with a sum greater than X, we calculate suffix sums starting from the end of the array. Starting with a suffixSum of zero, we iterate from the last element to the first, adding each element to suffixSum. After each addition, we check if suffixSum is greater than X and, if so, increment a counter. This way, we efficiently check each suffix without recalculating any sums.

Time Complexity:

O(n), as we iterate through the array once from the end to the beginning.

Space Complexity:

O(1), as we only use a constant amount of additional space for variables like suffixSum and count.