From: steve ross Date: 2010-04-24T09:08:10+09:00 Subject: Re: Best way to write this method? On Apr 23, 2010, at 3:31 PM, Robert Dober wrote: > > On Fri, Apr 23, 2010 at 6:53 PM, Derek Cannon > wrote: > > Hmm? Do I miss something here? > > def arys_distinct? aa, ba > (aa.map(&:to_a).flatten & ba.map(&:to_a).flatten).empty? > end > def overlaps? a, b > a.any?{ |aday, ar| > b.any?{ |bday, br| > aday == bday && !arys_distinct?(ar, br) > } > } > end The algorithm I proposed for overlaps? is (by my count) at worst O(2). This one looks like at least O(n*m). Maybe I'm wrong about that. In any case, a good puzzle.