You are viewing a single comment's thread. Return to all comments →
public static int countingValleys(int steps, String path) { // Write your code here String[] s=path.split(""); int i=0; int k=0,l=0; int j=0; for(int p=0;p<s.length;p++){ if(s[p].equalsIgnoreCase("u")){ k=j; j=i; i++; } else{ k=j; j=i; i--; if((k==1||k==0||k==-1)&&j==0&&i==-1){ l++; } } } return l; }
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 →