Tuesday, May 3, 2011

Pubmatic Question: Average of the elements of an array

Only Problem in this question is to tackle integer overflow. Instead of doing
(a[0] + a[1] + ....a [n-1])  /  n
do as following --
a[0]  / n + a[1]  /  n + ..... a[n-1]  /  n