DEV Community

Discussion on: Daily Coding Problem #2

Collapse
 
ascandone profile image
Alessandro Scandone

O(n) time, using division, in haskell:

f :: [Int] -> [Int]
f xs = let p = product xs in map (p `quot`) xs

O(n) time, without division, in haskell:

f :: [Int] -> [Int]
f xs = zipWith (*) l r
  where
    l = init $ scanl (*) 1 xs
    r = tail $ scanr (*) 1 xs