We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 81f5d47 commit 3cd5313Copy full SHA for 3cd5313
1 file changed
FrogJumps.java
@@ -0,0 +1,32 @@
1
+/**
2
+ * Created by Vatsal on 15-Jul-16.
3
+ * PROBLEM: Given the current position(x) of a frog and destination(y),
4
+ * compute the number of jumps required to reach from x to y,
5
+ * if the covers D blocks in a single jump.
6
+ */
7
+
8
+class FrogJumps {
9
10
+ public int solution(int x, int y, int D){
11
+ int jumps;
12
13
+ if(x==y) return 0;
14
15
+ else{
16
+ int distance = Math.abs((y-x));
17
+ if(distance%D==0) jumps = distance/D;
18
+ else jumps = (distance/D)+1;
19
20
+ return jumps;
21
+ }
22
23
24
+ public static void main(String[] args) {
25
+ FrogJumps t = new FrogJumps();
26
+ int jumps = t.solution(0, 10, 3);
27
+ System.out.println("No. of jumps = "+jumps);
28
29
30
31
32
+}
0 commit comments