DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Array

Product of Array Except Self

**Problem Statement:** Given an integer array `nums`, return an array `answer` such that `answer[i]` is equal to the product of all the elements of `nums` except `nums[i]`. The product of any prefix or suffix of `nums` is guaranteed to fit in a 32-bit integer. **Hint / Expected Approach:** Left-pass × right-pass without division **Edge Cases to Consider:** - (1) Array contains zeros (one vs two zeros) - (2) Two-element array - (3) All ones

Examples

Example 1
Input: [1,2,3,4]
Output: [24,12,8,6]
Example 2
Input: [-1,1,0,-3,3]
Output: [0,0,9,0,0]
Example 3
Input: [1,1]
Output: [1,1]

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪Array contains zeros (one vs two zeros)
  • ▪Two-element array
  • ▪All ones
Frequently Asked At
GoogleAmazonMicrosoftMetaAppleAdobeFlipkart