Tariq, the Kangaroo, is trying to reach a flag that's flagHeight
units above the ground. In his attempt to reach the flag, Tariq can make any number of jumps up the rock wall where it's mounted; however, he can only move up the wall (meaning he cannot overshoot the flag and move down to reach it). There are 2 types of jumps:
- A jump of height 1.
- A jump of height
jumpHeight
.
Tariq wants your help determining the minimum number of jumps it will take him to collect the flag. Complete the jumps function in your editor. It has 2 parameters:
- An integer,
flagHeight
, the height of the flag. - An integer,
jumpHeight
, the number of units he ascends in a jump of type 2.
It must return an integer denoting the minimum number of times Tariq must jump to collect the flag.
public int jumps(int flagHeight, int jumpHeight) {
}
Constraints
1 ≤ flagHeight ≤ 109
1 ≤ jumpHeight ≤ 109
Output Format
Your function must return an integer denoting the minimum number of jumps Tariq must make to collect the flag.
// Should assert to true
Jumper jumper = new Jumper();
Integer expected = jumper.jumps(3,1);
Integer actual = 3;
Assert.assertEquals(expected, actual);
- Explanation
- As Tariq can only jump 1 unit or
jumpHeight
units andjumpHeight = 1
, Tariq can only ever make 1-unit jumps. This means that it will take him 3 steps to reach the flag, so we return 3.
- As Tariq can only jump 1 unit or
// Should assert to true
Jumper jumper = new Jumper();
Integer expected = jumper.jumps(3,2);
Integer actual = 2;
Assert.assertEquals(expected, actual);
- Explanation
- Tariq will jump
jumpHeight = 2
units, and then jump 1 more unit to reach the flag. Thus, we return 2.
- Tariq will jump
// Should assert to true
Jumper jumper = new Jumper();
Integer expected = jumper.jumps(3,3);
Integer actual = 1;
Assert.assertEquals(expected, actual);
- Explanation
- Tariq will make a single jump
jumpHeight = 3
units up the rock wall and reach the flag, so we return 1.
- Tariq will make a single jump