FrogJmp

Solution

This java solution to codility problem FrogJmp scored 100%

Logic: Find the distance between X and Y, then divide that distance by the hop size that is D. If there is remainder then one more hop is needed so add 1 to the hops. Return the hops. Can you make this better?

public class FrogJump {

    //Detected time complexity : 0(1)
    public int solution(int X, int Y, int D){
        int distance = Y - X;
        int hops = distance/D;

        if (distance%D >0) {
            hops++;
        }
        return hops;
    }

}