#9.  Product of Array Except Self

https://leetcode.com/problems/product-of-array-except-self/

Not a fan of this question 🙂

It is a bit tricky to code up the first time – but there is nothing logically difficult about it, so not really sure why a company might choose to ask it in an interview.

If we could use ‘/’ operator, the solution would be straightforward -> result[i] = (total_product)/a[i].

One possible appraoch -> result[i] = left_product[i] * right_product[i].

We could achieve this by creating two arrays one for left_product and another for right_product, but this could also be solved in O(1) space (not considering the memory required for returned array) by using a single array that first stores right_products and then overwrites the same array with final answer.

Leave a comment