Problem:- SMRSTR
It says that we have to optimize the code snippet given in the problem. We can observe that for every value in the X array we do the same thing by dividing it repeatedly by all the elements in the D array i.e we just divide every value in the X array by the product of all elements in the D array. So, we can proceed by finding this product only once. But according to the constraints the product results in a very big number. But we can observe that if product is greater than the largest element in X array, then answer becomes zero for all of them. So, we stop calculating the product when it crosses the largest element in X array. Since, largest element in the X array satisfies our constraints, we can ensure that our product doesn’t overflow. If the product does not exceed the largest element of X array we simply find it and divide it with all the elements of the X array and print the result. This gives us a runtime of O(n) which is enough for this question.
If there is a better approach, please do comment it. Here is a link to my solution:- Click Here
If anyone did solve the second problem L-R queries, please explain me. Thanks.