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
3d

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!
Add answer anonymously...
Accenture Data Engineering Analyst 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