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.
functioncountingValleys($steps,$path){// Write your code here$altitude=0;$valleys=0;foreach(str_split($path)as$step){if($altitude==0&&$step=='D'){$valleys++;}if($step=='U'){$altitude++;}else{$altitude--;}}return$valleys;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Valleys
You are viewing a single comment's thread. Return to all comments →
Here's my own PHP solution.