Popular Posts

Sunday, July 17, 2011

Product of numbers in an array

Problem:

Given an integer array. 
e.g. 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)


Solution:
              Find the product by first finding all its left part then find right part and multiply both the results to get the output.

Complexity:   O(n) TC and O(n) SC


Code:



No comments:

Post a Comment