2. LeftRight Sum #

Created Sunday 03 May 2020

We are given an array. We have to store the product of all the elements to the left, and the right in Ai. Time (O(n)) and space complexity should be constant. Division is not allowed. Algorithm

  1. We store the left product in a variable.
  2. We calculate the right product and multiply it with left. Before doing this, store the current element in a variable.
  3. Contiue till the end.

Space O(1), Time O(n)