Here is the problem statement- if u can login — https://bytecode.interviewstreet.com/challenges/dashboard/#problem/4f497b0018bad
otherwise — http://pastebin.ca/2121976
My approach,
Make a cumulative sum array.
Now for every index starting from 0, do binary search for k, k+mod, k + 2*mod, ..., k + 76*mod on range limited by previous max-length found, i.e. if we already have found an array of length L, which sum upto k (after doing mod) , then accordingly we have to modify the binary-search space, because we do not require a shorter-length answer.
Will this approach time-out ? As I can't submit there anymore, I need your help to see whether it is correct approach or not.
There is solution for O(max(n, m))
1. Make a cumulative sum array. A
2. Make an array
FirstTimeOccurence[0..m-1], F[i] = -1
"Beware of bugs in the above code; I have only proved it correct, not tried it." (c) Donald Knuth
Thanks.
:D
a small question, will it be
F[(A[i] - k + mod) % mod]
?Yes, you are right. There is some bugs in the above code, but you understand main idea.