Productsofarrayexceptself

Table of Contents

Explaination Source: https://www.youtube.com/watch?v=bNvIQI2wAjk

Python script: products_of_array_except_self.py

1. Problem

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.
  • You must write an algorithm that runs in O(n) time and without using the division operation.

1.1. Example:

Input: nums = [1,2,3,4] Output: [24,12,8,6]

1.2. demonstration:

[ 1 * 2 * 3 * 4 = 24, 1 * 2 * 3 * 4 = 12, 1 * 2 * 3 * 4 = 8, 1 * 2 * 3 * 4 = 6 ]

Author: Nyll

Created: 2022-08-10 Wed 13:05