My issue
There are NN players standing between Gi-Hun and Ali in a straight line
- The i^{\text{th}}ith player having height H_iHi.
- Gi-Hun and Ali both have the same height, KK.
Gi-Hun wants to know the minimum number of players who need to be removed from the line so that Ali is visible in his line of sight given the following information
- Line of sight is a straight line drawn between the topmost point of two objects.
Ali is visible to Gi-Hun if nobody between them crosses this line. - Even if there are some players who have the same height as that of Gi-Hun and Ali, Ali will be visible in Gi-Hun’s line of sight.
My code
// Update the code below to solve the problem
#include <stdio.h>
int main() {
int N, K;
scanf("%d %d", &N, &K);
int heights[N];
for (int i = 0; i < N; ++i) {
scanf("%d", &heights[i]);
}
int visible_players = 1; // Gi-Hun is always visible
for (int i = K - 1; i < N; ++i) {
if (heights[i] <= 0 || heights[i] < K) {
break; // Player obstructs Ali, stop counting
} else {
++visible_players;
}
}
printf("%d\n", visible_players);
return 0;
}
Learning course: Solve Programming problems using C
Problem Link: CodeChef: Practical coding for everyone