Given an array A
of N
integers . I need to find X
such that the difference between the following 2 values (A[1] * A[2] * ... * A[X])
and (A[X+1] * A[X+2] * ... * A[N])
is minimum possible i.e. I need to minimize | (A[1] * A[2] * ... * A[X]) - (A[X+1] * A[X+2] * ... * A[N]) |
and if there are multiple such values of X, print the smallest one.
Constraints:-
1 <=
N
<= 10^51 <=
A[i]
<= 10^18.
I am not able to find the approach to solve this problem in efficient way. What should be the best approach to solve this problem. Is there any special algorithm for multiplying large quantity of numbers.