o(n) soln
Lets say A is the array of length N.
Create an array "sum" of length N and initialize it to 0.
Create an array "product" of length N and initialize it to 1.
now sum[i]=sum[i-1]+A[i]; sum[0]=A[0];
product[i]=product[i-1]+A[I] product[0]=A[0];
make a two hash table for product and sum array ;
in product arrary traverse i=0 to n ;
divide result=product[i]/P and check result is present in hash table or not
if yes then get index of result .
suppose k then check absolute(sum[i]-sum[k])==S if yes then we got sub
array.
else ..keep do this untill array end ;
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.