Product Of Array Except Self Problem Statement

You are provided with an integer array ARR of size N. You need to return an array PRODUCT such that PRODUCT[i] equals the product of all the elements of ARR except ARR[i].

Example:

Input:
T = 2
N = 4
ARR = [1, 2, 3, 4]
N = 3
ARR = [2, 3, 4]
Output:
[24, 12, 8, 6]
[12, 8, 6]

Constraints:

  • 1 ≤ T ≤ 100
  • 0 ≤ N ≤ 105
  • 0 ≤ ARR[i] ≤ 105
  • Time Limit: 1 sec

Note:

Each product may exceed integer limits, so take modulo MOD = 109 + 7 to keep results in bounds.

Follow Up:

Can you solve the problem using O(1) additional space?

AnswerBot
5mo

The problem requires returning an array where each element is the product of all elements in the input array except itself.

  • Iterate through the array twice to calculate the product of all elements to t...read more

Help your peers!
Select
Add answer anonymously...

Top Data Engineering Analyst Interview Questions Asked at Accenture

Q. What are parquet files?
Q. Can you explain your academic projects?
Q. Suppose there is a file with 100 columns, and you only want to load 10 specific ...read more
Data Engineering Analyst 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