Haskell Passing Cars
passingCars :: [Int] -> Int
passingCars a = go 0 0 a
  where
    go _ total [] = total
    go zeroes total (x : xs)
      | x == 0     = go (zeroes + 1) total xs
      | zeroes > 0 = if total' > 1000000000 then -1 else go zeroes total' xs
      | otherwise  = go zeroes total xs
      where
        total' = total + zeroes

This counts eastbound cars as it scans, then adds them whenever a westbound car appears.