Skip to content

Commit

Permalink
Fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
rsrbk committed May 21, 2024
1 parent 5628de6 commit 96fe615
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions product_of_array_except_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ def product_except_self(nums):
n = len(nums)
result = [1] * n

left_product = [1] * n
right_product = [1] * n

for i in range(1, n):
left_product[i] = left_product[i - 1] * nums[i - 1]

for i in range(n - 2, -1, -1):
right_product[i] = right_product[i + 1] * nums[i + 1]

for i in range(n):
for j in range(n):
if i != j:
result[i] *= nums[j]

result[i] = left_product[i] * right_product[i]

return result

# Test the function with the example input
Expand Down

0 comments on commit 96fe615

Please sign in to comment.