challengerco.de — challenge yourself [BETA]
Login - Sign up

main / east-west-pairs

Count pairs of cars going East and West

The Challenge

Write a function solve(array) that will count the number of pairs of cars, one going East (0) and another later going West (1). Given an array: [0, 1, 0, 1, 1] it should count the pairs: for the car at (1): (1, 2), (1, 4), (1, 5); and then for the car at (3): (3, 4), (3, 5). The result should be 5. Note: if the result is higher than 1,000,000,000 the function should return -1

Ready for It?

Published under the GPLv3 license
Fork challenger-code. Issues?