You are viewing a single comment's thread. Return to all comments →
Java solution
public static String solve(long n) { // Write your code here int steps = (int)getStepsToReachBlock(n); if (steps != -1) { return "Go On Bob " + steps; } else { return "Better Luck Next Time"; } } public static int getStepsToReachBlock(long n) { /// a[i] = n = k(k+1) / 2 /// 2n == k(k+1) /// k^ 2 <k(k+1) == 2n < (k+1)^2 long k = (long) (Math.sqrt(2*n)); if(2*n == k*(k+1)){ return (int)k; } return -1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Stepping Stones Game
You are viewing a single comment's thread. Return to all comments →
Java solution