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 ‘1’ 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 0.
Constraints:
1<=n, k<=10
1<=height[i] <=100
Input:
The first line contains two integers 'n' and 'k', the number of hurdles, and the maximum height the character can jump naturally.
The second line contains 'n' space-separated integers height[i] where 0<=i<n.
Output:
Print the No: of 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 0.
Explanation:
height = [ 1, 2, 3, 3, 2] k=1
The character can jump 1 unit high initially and must take 3-1=2 doses of potion to be able to jump all of the hurdles.
#include <stdio.h> #include <stdlib.h> int main() { int *h; int i,n,k,max=0; scanf("%d%d",&n,&k); h=(int *)malloc(n*sizeof(int)); for(i=0;i<n;i++) { scanf("%d", h); if(max < *h) max = *h; h++; } printf("%d",max-k); return 0; }
INPUT_1:
10 4
1 6 3 5 2 8 7 9 4 2
OUTPUT:
5
INPUT_2:
5 5
2 15 4 5 2
OUTPUT:
10
INPUT_3:
8 3
2 2 5 10 2 3 5 6
OUTPUT:
7
ILLUSTRATION
![](http://www.fcukthecode.com/wp-content/uploads/2022/01/Screenshot-from-2022-01-14-16-46-17.png)
Morae Q!
- Find the length of the array’s longest increasing sub-sequence.
- Arrange numbers in a circle so that any two neighbouring numbers differ by 1.
- Find partial names and count the total numbers.
- Find the minimized sum of non-deleted elements of the array after the end of the game.
- Find the maximum number of good sleeping times optimally.
- Sort the elements of the array in the order in which they are required.
- Find the minimum number of flats, monkey needs to visit to catch ninjas.
- Convert the square matrix to matrix in Z form.
- Shift the K elements of each row to right of the matrix.
- Find maximum possible number of students in a balanced team with skills.
- Find the Maximum number of pairs of points you can match with each other.
- Calculate the number of non-empty good subarrays of given array.
- Transform the binary string A into the string B using finite operations.
- Find the number of potion must the character take to jump the hurdles.
- Count the total number of vowels and consonants.
- Return all elements of the matrix in spiral order.
- Return all palindromic paths of the matrix.
- Write the code to change the display in reverse order using pointer.
- Find the number of days the expedition can last.
- Find the minimum size of the sub-segment to make the array pairwise distinct.