A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D.

PHOTO EMBED

Tue Apr 19 2022 19:37:14 GMT+0000 (Coordinated Universal Time)

Saved by @selvendhiran11 #java

class Solution {
    public int solution(int X, int Y, int D) {
        // write your code in Java SE 8
        // if(X > Y || X == Y) return 0;
        // int steps = 0;
        // while(Y > X)
        // {
        //     X+=D;
        //     steps++;
        // }
        // return steps;
        int iStep = 0;
        if((Y-X)%D == 0)
        {
            iStep = (Y-X)/D;
        }else{
            iStep = ((Y-X)/D)+1;
        }
        return iStep;
    }
}
content_copyCOPY

https://app.codility.com/demo/results/trainingTPD6F3-9CE/