We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Sherlock and Queries
Sherlock and Queries
Sort by
recency
|
62 Discussions
|
Please Login in order to post a comment
One more hint. If B[i]==1, you need to multiply every A on all C's product. It can be done in O(N+M).
I am getting timeout in four testcases, 9, 10, 12, 13...any suggestions. My code https://www.hackerrank.com/challenges/sherlock-and-queries/submissions/code/33184473
I will give a hint to other people trying to get through this by themselves: it's a trivial improvement of the algorithm that one immediately sees, followed by a sanitization of the input. The second part is less obvious, as some people - including myself - don't see it as part of the initial algorithm.
Great question. I first tried this problem months ago but was note able to solve it completely. Now I did. :-)
if j % B[i] == 0 then
Shouldn't this be:
if A[j] % B[i] == 0 then
I get the expected output only when I make that change