A video player plays a game in which the character competes in a hurdle race. Hurdles are of varying heights, and the characters have a maximum height they can jump. There is a magic potion they can take that will increase their maximum jump height by unit for each dose. How many doses of the potion must the character take to be able to jump all of the hurdles. If the character can already clear all of the hurdles, return . Example The character can jump unit high initially and must take doses of potion to be able to jump all of the hurdles. Function Description Complete the hurdleRace function in the editor below. hurdleRace has the following parameter(s): int k: the height the character can jump naturally int height[n]: the heights of each hurdle Returns int: the minimum number of doses required, always or more Input Format The first line contains two space-separated integers and , the number of hurdles and the maximum height the character can jump naturally. The second line contains space-separated integers where . Constraints Sample Input 0 5 41 6 3 5 2 Sample Output 0 2 Explanation 0 Dan's character can jump a maximum of units, but the tallest hurdle has a height of : To be able to jump all the hurdles, Dan must drink doses. Sample Input 1 5 72 5 4 5 2 Sample Output 1 0 Explanation 1 Dan's character can jump a maximum of units, which is enough to cross all the hurdles: Because he can already jump all the hurdles, Dan needs to drink doses.
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
A video player plays a game in which the character competes in a hurdle race. Hurdles are of varying heights, and the characters have a maximum height they can jump. There is a magic potion they can take that will increase their maximum jump height by unit for each dose. How many doses of the potion must the character take to be able to jump all of the hurdles. If the character can already clear all of the hurdles, return .
Example
The character can jump unit high initially and must take doses of potion to be able to jump all of the hurdles.
Function Description
Complete the hurdleRace function in the editor below.
hurdleRace has the following parameter(s):
- int k: the height the character can jump naturally
- int height[n]: the heights of each hurdle
Returns
- int: the minimum number of doses required, always or more
Input Format
The first line contains two space-separated integers and , the number of hurdles and the maximum height the character can jump naturally.
The second line contains space-separated integers where .
Constraints
Sample Input 0
Sample Output 0
Explanation 0
Dan's character can jump a maximum of units, but the tallest hurdle has a height of :
To be able to jump all the hurdles, Dan must drink doses.
Sample Input 1
Sample Output 1
Explanation 1
Dan's character can jump a maximum of units, which is enough to cross all the hurdles:
Because he can already jump all the hurdles, Dan needs to drink doses.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images