#K68462. Product of Array Except Self
Product of Array Except Self
Product of Array Except Self
You are given an array of n integers (nums) where (n>1). Your task is to construct an output array such that each element at index (i) is equal to the product of all the elements in the input array except (nums[i]).
Note that you must solve the problem without using division and in (O(n)) time complexity. This problem requires careful handling of zeros and negative numbers as well.
inputFormat
The first line of input contains an integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers representing the array (nums).
outputFormat
Output a single line containing (n) integers separated by a space, where the (i^{th}) integer is the product of all the numbers in the array except (nums[i]).## sample
4
1 2 3 4
24 12 8 6