FrogJmp

Count a minimal number of jumps from position X to Y.


Solution:

Solution to Codility's Frog Jump problem which is from the Codility Lesson 3: Time Complexity and, is solved in Java 8 with 100% performance and correctness scores. The goal here is to count a minimal number of jumps from position x to y. You can find the question of this FrogJmp problem in the Codility website.


package Codility.Lesson3;

public class FrogJump {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int result = solution(10, 85, 30);
		System.out.println (result);
	}
	
	public static int solution(int X, int Y, int D) {
        // write your code in Java SE 8
	int remJump  = Y-X;
        int CountJump = (int)remJump/D;
        int rem = remJump%D;
        if (rem!=0) {
        	CountJump++;
        }
        return CountJump;
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *