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.
publicstaticintcountingValleys(intsteps,Stringpath){// Write your code hereintdifference=0;booleanisValley=false;intcount=0;for(inti=0;i<path.length();i++){if(difference==0&&isValley){count++;}if(path.charAt(i)=='U'){if(difference==0){isValley=false;}difference++;}else{if(difference==0){isValley=true;}difference--;}}if(isValley&&difference==0){count++;}returncount;}
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 →