Arrays & Hashing • Medium
Product Except Self
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]`. You must write an algorithm that runs in `O(n)` time and without using the division operation.
The Challenge
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]`. You must write an algorithm that runs in `O(n)` time and without using the division operation.
Pro-tip: Use prefix and suffix product arrays to compute the products before and after each element.
Solution.swift Tests.swift
Output
Ready to run.