HackerEarth | Log In

I have tried solving this but I am getting pass just the first test case. Can anyone help with this? Thank You…

1 Like

Make 2 arrays pre and post. Pre will store the prefix product and post will store suffix product with modulo taken. Now to answer the query for ith index the answer will be pre[i - 1] * post[i + 1] % m

1 Like

Thank you for replying. I am new to problem solving.
My approach was- 1. found out product of all the elements of the array
2. divided the product by the required array element. took modulus and printed.

Can you please tell me what is the mistake in this approach?

The numbers are of order 10^9 and total numbers are 10^5. Product of all the numbers would be tremendously huge. Forget about C++ which can store maximum 10^18. Even with python and Java you will get TLE. Because even multiplying the numbers will take time.