Window Sliding
Window Sliding technique is often used in competitive programming
It largely reduces time complexity, if used efficiently and at correct places
The pseudo code
To check the longest sequence such that the sum inside it is <= k
int ar[n]; int cur_sum=0,start=0; int length=0; for(i=0;i<n;i++) { cur_sum+=ar[i]; if(cur_sum<=k) { length=max(length,i+1-start); } else { while(start<=i) { cur_sum-=ar[start++]; if(cur_sum<=k) { length=max(length,i-start+1); break; } } } } cout<<length;