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.
Jumping on the Clouds
Jumping on the Clouds
+ 0 comments int minJump = 0; int currIndex = 0; int itr = 0; while (currIndex < c.size() & itr < c.size()) { while (currIndex < c.size()-2 && c.get(currIndex+2) == 0) { currIndex = currIndex + 2; minJump++; // System.out.println(currIndex); } while (currIndex < c.size()-1 && c.get(currIndex+1) == 0) { currIndex = currIndex + 1; minJump++; // System.out.println(currIndex); } itr++; } // System.out.println(minJump); return minJump;
+ 0 comments public static int jumpingOnClouds(List c) { // Write your code here int count=0,i=0;
while(i<c.size()){ if(i+2<c.size()&&c.get(i+2)!=1){ count++; System.out.println(i+" "+count); i=i+2; } else{ count++; System.out.println(i+" "+count); i=i+1; } } return count-1; }
+ 0 comments My python3 solution
def jumpingOnClouds(c): # Write your code here count = 0 i = 0 while i < len(c)-1: if (i + 2 < len(c)) and c[i+2] == 0: count += 1 i += 2 else: count += 1 i += 1 return count
+ 0 comments Clojure solution:
(defn jumpingOnClouds [c] (let [cc (dec (count c))] (loop [i 0 j 0] (cond (>= i cc) j (= i (dec cc)) (inc j) true (recur (+ i (if (pos? (nth c (+ i 2))) 1 2)) (inc j))))))
+ 0 comments def jumpingOnClouds(c): # Write your code here count_jumps = 0 i=0 while i < len(c)-1: count_jumps+=1 i+= 2 if i+2<len(c) and not c[i+2] else 1 return count_jumps
Load more conversations
Sort 3041 Discussions, By:
Please Login in order to post a comment