# Given an array of n integers where n > 1, nums,
# return an array output such that output[i] is equal to the product of all the elements of nums
# except nums[i].
#
# Solve it without division and in O(n).
#
# For example, given [1,2,3,4], return [24,12,8,6].
#
# Follow up:
# Could you solve it with constant space complexity? (Note: The output array does not count as extra space
# for the purpose of space complexity analysis.)


class Solution(object):
    def productExceptSelf(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """

        output = [1] * len(nums)

        product = 1

        for i in range(len(nums)):
            output[i] = product
            product *= nums[i]

        product = 1

        for i in range(len(nums) - 1, -1, -1):
            output[i] *= product
            product *= nums[i]

        return output
a78e97ffe11c639e789d7ded10589712e350ee6d
<mask token>

class Solution(object):
    <mask token>

class Solution(object):

    def productExceptSelf(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        output = [1] * len(nums)
        product = 1
        for i in range(len(nums)):
            output[i] = product
            product *= nums[i]
        product = 1
        for i in range(len(nums) - 1, -1, -1):
            output[i] *= product
            product *= nums[i]
        return output

# Given an array of n integers where n > 1, nums,
# return an array output such that output[i] is equal to the product of all the elements of nums
# except nums[i].
#
# Solve it without division and in O(n).
#
# For example, given [1,2,3,4], return [24,12,8,6].
#
# Follow up:
# Could you solve it with constant space complexity? (Note: The output array does not count as extra space
# for the purpose of space complexity analysis.)


class Solution(object):
    def productExceptSelf(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """

        output = [1] * len(nums)

        product = 1

        for i in range(len(nums)):
            output[i] = product
            product *= nums[i]

        product = 1

        for i in range(len(nums) - 1, -1, -1):
            output[i] *= product
            product *= nums[i]

        return output