From: Jab Date: 2008-06-20T15:19:22+09:00 Subject: Re: little problem (google hiring puzzle) I believe this works in O(n). (I believe reverse, and zip are O(n)) It is very similar to other solutions, but I like the each_with_index method. data=[4, 3, 2, 1, 2] front=[1]; back=[1] data.each_with_index{|val, index| front[index + 1] = front[index] * val} data.reverse.each_with_index {|val, index| back[index+1] = back[index] * val} front.pop back.pop data=[] front.zip(back.reverse){|a, b| data.push a * b} p data -jacob