Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Product of Array Except Self
00:00
5 left

Product of Array Except Self

HardPython

Problem

Solve the “product of array except self” problem: replace each element with the product of all other elements.

Implement product_except_self(nums), returning a list where index i contains the product of every value in nums except nums[i]. Do not use division. The result array does not count toward extra space, and the input list may contain zeros and negative values.

Input: A list of integers nums.

Output: A list of integers with the same length as nums.

Constraints: 2 <= len(nums) <= 10^4; values may be negative, zero, or positive.

Constraints

  • 2 <= len(nums) <= 10^4
  • -30 <= nums[i] <= 30
  • The input may contain zero and negative values
  • Division is not allowed
  • Use O(1) extra space excluding the output list

Function Signature

def product_except_self(nums):
Interviewer

Your question is Product of Array Except Self. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.