Finding smallest subarray lengths for given multiple queries

Viewed 271

You are given an array of integers A[], of max length N, up to 10^6 and then M number of queries. While querying you will be given an integer X and you have to return minimum length of sub array whose sum is greater or equal to X. Problem is the number of such queries M can be up to 10^6.

any clue to solve it efficiently within contest time.

Note: When M is very small we can solve with O(M*N) but when M is huge I guess there must be different approach.

Note: There is a way to solve the problem here in O(N), when M =~ 1.

0 Answers
Related