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.
publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);intn=sc.nextInt();Strings=sc.next();intnOV=0;// no of valleysintaltitude=0;// current levelfor(charc:s.toCharArray()){if(altitude==0&&c=='D')nOV++;altitude=(c=='D')?--altitude:++altitude;}System.out.println(nOV);}
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 →