(Adapted from: Daily Coding Problem @ 2019-08-18.)
You are given an array representing the heights of neighboring buildings on a city street, from east to west. The city assessor would like you to write an algorithm that returns how many of these buildings have a view of the setting sun, in order to properly value the street.
For example, given the array [3, 7, 8, 3, 6, 1]
, you should return 3
, since the top floors of the buildings with heights 8
, 6
, and 1
all have an unobstructed view to the west.
For bonus 🦄 points, can you solve this problem using just one forward pass through the array?
If you choose to implement your solution using Node.js, this challenge comes with a unit test suite, which can be used to verify the correctness of your solution, and can be run with npm test
or yarn test
. The unit tests expect your module named challenge.js
to export a unobstructedWestViewCount
function that takes an array of integers as its arguments and returns an integer.
Fork this repository and be ready to submit a PR with your solution when the time limit for the challenge is reached.