Problem
Ask
Submissions

Problem: Product of Array Except Self

Medium
30 min
Explore how to compute an array where each element is the product of all other elements except itself. Learn to develop an O(n) time, O(1) space algorithm without division. This lesson helps you deepen your coding interview skills by practicing an essential pattern used in many challenges.

Statement

You’re given an integer array, arr. Return a resultant array so that res[i] is equal to the product of all the elements of arr except arr[i].

Write an algorithm that runs in O(n)O(n) time without using the division operation.

Constraints:

  • 22 \leq arr.length 103\leq 10^3
  • 30-30 \leq arr[i] 30\leq 30
  • The product of any prefix or suffix of arr is guaranteed to fit in a 32-bit integer.
Problem
Ask
Submissions

Problem: Product of Array Except Self

Medium
30 min
Explore how to compute an array where each element is the product of all other elements except itself. Learn to develop an O(n) time, O(1) space algorithm without division. This lesson helps you deepen your coding interview skills by practicing an essential pattern used in many challenges.

Statement

You’re given an integer array, arr. Return a resultant array so that res[i] is equal to the product of all the elements of arr except arr[i].

Write an algorithm that runs in O(n)O(n) time without using the division operation.

Constraints:

  • 22 \leq arr.length 103\leq 10^3
  • 30-30 \leq arr[i] 30\leq 30
  • The product of any prefix or suffix of arr is guaranteed to fit in a 32-bit integer.