Product of the others
A free medium coding practice problem. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.
- Difficulty
- Medium
- Type
- Function
- Languages
- JavaScript, TypeScript or Python
Problem
Return an array where element i is the product of every element of nums except nums[i]. Try it without division — zeros make division tricky.
Function signature
// JavaScript
function productExceptSelf(nums)
// TypeScript
function productExceptSelf(nums: any): any
// Python
def product_except_self(nums):Examples
productExceptSelf([1,2,3,4])→[24,12,8,6]productExceptSelf([-1,1,0,-3,3])→[0,0,9,0,0]
How checking works
Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.