MCPcopy Create free account
hub / github.com/Manvityagi/PW-Skills-Java-Course-Codes / FrogJump

Class FrogJump

Lecture 36 - Recursion 9/src/FrogJump.java:1–14  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1public class FrogJump {
2 static int best(int[] h, int n, int idx){
3 if(idx == n-1) return 0;
4 int op1 = Math.abs(h[idx] - h[idx+1]) + best(h, n, idx+1);
5 if(idx == n-2) return op1;
6 int op2 = Math.abs(h[idx] - h[idx+2]) + best(h, n, idx+2);
7 return Math.min(op1, op2);
8 }
9
10 public static void main(String[] args) {
11 int[] h = {10, 30, 40, 20};
12 System.out.println(best(h, h.length, 0));
13 }
14}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected