Codility - FrogJmp
Count the minimal number of jumps from position X to Y
FrogJmp is the third lesson number 1 out of three in the list for Time Complexity algorithm. Basically, it is an algorithm to count the number of the jump from one X location to Y location when the number of the step taken is given as Z for each single jump
public int solution(int X, int Y, int D){
int a = 0;
Y = Y - X; //setting the initial value test
if (Y >= 1){ //evaluating the Y value
a = Y/D; //setting the initial return value
if (Y % D > 0){ //evaluating the possible number of jump to add additional value
a++;
}
}
if ( a == 0 && (Y%D==0) && Y > X ){ //final check
a = 1;
}
return a;
};
Result of the code |
Code is downloadable from
Bitbucket - git clone https://masteramuk@bitbucket.org/fullstacksdev/codility-frogjmp.git
Github - https://github.com/masteramuk/codility-lessoncode.git
0 comments:
Post a Comment