Very much conceptual question


#1

Prefix Sum + Sliding Window concept are used to reduce the time complexity to O(n^2);

Otherwise, the brute force will lead to O(n^4) solution.


#2

I think its O(N^2*B^2) rather than O(N^4) and we can reduce it to O(N^2)