We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hey folks,
In this problem, the only confusion part is,
if the level is 0 and the step is 'D'(that is down), why we are incrementing the valley count?
The answer is we are pretty much looking for the valley. In this case, valley is step down and the sea level is 0. So from the sea level to enters into valley is taken as count one, then because of the problem statement, the hiker definitely needs to reach the sea level after some steps later. Here is the solution in javascript,
Counting Valleys
You are viewing a single comment's thread. Return to all comments →
Hey folks, In this problem, the only confusion part is, if the level is 0 and the step is 'D'(that is down), why we are incrementing the valley count? The answer is we are pretty much looking for the valley. In this case, valley is step down and the sea level is 0. So from the sea level to enters into valley is taken as count one, then because of the problem statement, the hiker definitely needs to reach the sea level after some steps later. Here is the solution in javascript,