Hackerrank – Counting Valleys

Hackerrank – Problem Statement

A description of the problem can be found on Hackerrank.

Solution

I loop throught all steps and remeber the level from the sea (level). If it is D, I decrement by 1, if U increment by 1.
When such situation happen that actual sea level is 0 and current step is U, then I found new valley and increate the count of valley variable.

I created solution in:

All solutions are also available on my GitHub profile.

Scala

Java

Javascript

Leave a Reply

Your email address will not be published. Required fields are marked *