This is a problem from hackerrank.com. It is called Counting Vallys problem. Here is the solution with javascript.
No download links available.