"""
// Time Complexity :O(n2) Iterating over array twice
// Space Complexity :O(1) Extra space for the list
// Did this code successfully run on Leetcode :NA
// Any problem you faced while coding this :NA

//Explanation:
//BF approach:
Iterate through array twice and store the multiplication
in a auxiliary array. By the end, replace the original array by auxiliary
array

//Optimized solution
Use temp and rproduct-> leftpass and rightpass
rp*=rp*temp
temp=nums[l/r]
"""
from typing import List
class Solution:
    def productExceptSelf(self, nums: List[int]) -> List[int]:
      rproduct, temp = 1,1
      result = []

      #left pass
      for l in range(len(nums)):
        rproduct *= temp
        result.append(rproduct)
        temp = nums[l]

      #right pass
      rproduct, temp = 1,1
      for r in range(len(nums)-1,-1,-1):
        rproduct *= temp
        result[r] *= rproduct
        temp = nums[r]
      return result

# Brute force
array=[1,2,3,4]
m=1
res=[]

for i in range(len(array)):
  m = 1
  for j in range(len(array)):
   if array[i]==array[j]:
     pass
   else:
     m*=array[j]
  print(m)
  res.append(m)

array=res
print(array)

4c112fc9aaf1214fdbc4e6a7e31eeb390a9d4517
<mask token>


class Solution:

    def productExceptSelf(self, nums: List[int]) ->List[int]:
        rproduct, temp = 1, 1
        result = []
        for l in range(len(nums)):
            rproduct *= temp
            result.append(rproduct)
            temp = nums[l]
        rproduct, temp = 1, 1
        for r in range(len(nums) - 1, -1, -1):
            rproduct *= temp
            result[r] *= rproduct
            temp = nums[r]
        return result


<mask token>

<mask token>


class Solution:

    def productExceptSelf(self, nums: List[int]) ->List[int]:
        rproduct, temp = 1, 1
        result = []
        for l in range(len(nums)):
            rproduct *= temp
            result.append(rproduct)
            temp = nums[l]
        rproduct, temp = 1, 1
        for r in range(len(nums) - 1, -1, -1):
            rproduct *= temp
            result[r] *= rproduct
            temp = nums[r]
        return result


<mask token>
for i in range(len(array)):
    m = 1
    for j in range(len(array)):
        if array[i] == array[j]:
            pass
        else:
            m *= array[j]
    print(m)
    res.append(m)
<mask token>
print(array)

<mask token>


class Solution:

    def productExceptSelf(self, nums: List[int]) ->List[int]:
        rproduct, temp = 1, 1
        result = []
        for l in range(len(nums)):
            rproduct *= temp
            result.append(rproduct)
            temp = nums[l]
        rproduct, temp = 1, 1
        for r in range(len(nums) - 1, -1, -1):
            rproduct *= temp
            result[r] *= rproduct
            temp = nums[r]
        return result


array = [1, 2, 3, 4]
m = 1
res = []
for i in range(len(array)):
    m = 1
    for j in range(len(array)):
        if array[i] == array[j]:
            pass
        else:
            m *= array[j]
    print(m)
    res.append(m)
array = res
print(array)

<mask token>
from typing import List


class Solution:

    def productExceptSelf(self, nums: List[int]) ->List[int]:
        rproduct, temp = 1, 1
        result = []
        for l in range(len(nums)):
            rproduct *= temp
            result.append(rproduct)
            temp = nums[l]
        rproduct, temp = 1, 1
        for r in range(len(nums) - 1, -1, -1):
            rproduct *= temp
            result[r] *= rproduct
            temp = nums[r]
        return result


array = [1, 2, 3, 4]
m = 1
res = []
for i in range(len(array)):
    m = 1
    for j in range(len(array)):
        if array[i] == array[j]:
            pass
        else:
            m *= array[j]
    print(m)
    res.append(m)
array = res
print(array)

"""
// Time Complexity :O(n2) Iterating over array twice
// Space Complexity :O(1) Extra space for the list
// Did this code successfully run on Leetcode :NA
// Any problem you faced while coding this :NA

//Explanation:
//BF approach:
Iterate through array twice and store the multiplication
in a auxiliary array. By the end, replace the original array by auxiliary
array

//Optimized solution
Use temp and rproduct-> leftpass and rightpass
rp*=rp*temp
temp=nums[l/r]
"""
from typing import List
class Solution:
    def productExceptSelf(self, nums: List[int]) -> List[int]:
      rproduct, temp = 1,1
      result = []

      #left pass
      for l in range(len(nums)):
        rproduct *= temp
        result.append(rproduct)
        temp = nums[l]

      #right pass
      rproduct, temp = 1,1
      for r in range(len(nums)-1,-1,-1):
        rproduct *= temp
        result[r] *= rproduct
        temp = nums[r]
      return result

# Brute force
array=[1,2,3,4]
m=1
res=[]

for i in range(len(array)):
  m = 1
  for j in range(len(array)):
   if array[i]==array[j]:
     pass
   else:
     m*=array[j]
  print(m)
  res.append(m)

array=res
print(array)
