DEV Community

Discussion on: Product of array except self, a mind-boggling Google Interview question

Collapse
akhilpokle profile image
Akhil Author

It works, but your algorithm works in O(n^2). The solution in article works in O(n).

Collapse
bitdweller profile image
Pedro Pimenta

Yeah I get it now. I'm not a programmer by education, so I don't know many of these concepts. I guess O(n) means going through the array only once, right? I go through the array as many times as elements are in the array, hence O(n^2). This is not performant, your solution (and the one asked for, actually) is resolved quicker and with less processing power. Hey, I learned something, right? :D Thanks!

Thread Thread
akhilpokle profile image
Akhil Author

Spot on! I will add your solution too so that people like you can get a better idea about performance :D