Product Array Puzzle Problem Statement
You are provided with an array of integers. You need to compute another array such that each element in this new array is the product of all elements in the original array except for the element at that index.
Input:
T – Number of test cases
For each test case:
N – Number of elements in the array
Array elements – space-separated integers
Output:
For each test case, return a line containing N space-separated integers, where each integer is the product of all the array elements except the one at the current index.
Example:
Input:
T = 1
N = 4
Array = [1, 2, 3, 4]
Output:
24 12 8 6
Explanation:
For instance, at index 0, the product is 2*3*4 = 24, similarly for index 1, the product is 1*3*4 = 12, and so on.
Constraints:
- 1 <= T <= 102
- 2 <= N <= 104
- 1 <= A[i] <= 109
- Output value should be given modulo (109 + 7)
Note:
Attempt to solve the problem without using the division operator '/', ensuring that the space complexity is constant (excluding the space used for the output array).

AnswerBot
4mo
The problem involves computing a new array where each element is the product of all elements in the original array except for the element at that index.
Iterate through the array twice to calculate the...read more
Help your peers!
Add answer anonymously...
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

