Go Passing Cars
func passingCars(a []int) int {
passing, eastbound := 0, 0
for _, v := range a {
if v == 0 {
eastbound++
} else if eastbound > 0 {
passing += eastbound
if passing > 1000000000 {
return -1
}
}
}
return passing
}
This counts eastbound cars as it scans, then adds them whenever a westbound car appears.