int main() 
{ 
   int a[]={4,3,5,2,6};  // 1 4 12 60 120
   const int n=5;
   int temp=1,i;
   int b[5]={0};
   for(i=0;i<n;i++)
   {
     b[i]=temp;
     temp*=a[i];                                
   }
   temp=1;
   for(i=n-1;i>=0;i--)
   {
     b[i]*=temp;
     temp*=a[i];                                
   }
   for(i=0;i<n;i++)
   cout<<" "<<b[i];
   }
O(n) time , O(n) space complexity
On Thursday, 29 September 2011 16:56:02 UTC+5:30, raju wrote:
>
> Given an integer array. { 1,2,3,4,5 } 
> Compute array containing elements 
> 120,60,40,30,24 (2*3*4*5,1*3*4*5, 1*2*4*5, 1*2*3*5, 1*2*3*4) 
>
> We shouldn't use division operator( / )
> Time complexity O(n) .. Space complexity O(1) 
>
>
> ~raju
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/pnuv-BqiaBUJ.
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.

Reply via email to