Given an array of integers, return an array where each position contains the product of all elements except the element at that index. Implement def product_except_self(nums): and return an array with the same length as nums. Aim for O(n) time and O(1) extra space, excluding the returned array. Do not use division, and correctly handle arrays containing zero.
def product_except_self(nums):