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).

Be the first one to answer
Add answer anonymously...
OPERA Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter