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!
Select
Add answer anonymously...
OPERA Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits