304 North Cardinal St.
Dorchester Center, MA 02124

# Red Light, Green Light CodeChef Solution

## Problem – Red Light, Green Light CodeChef Solution

“You won’t get caught if you hide behind someone.”

Sang-Woo advises Gi-Hun to hide behind someone to avoid getting shot.

Gi-Hun follows Sang-Woo’s advice and hides behind Ali, who saved his life earlier. Gi-Hun and Ali both have the same height, K. Many players saw this trick and also started hiding behind Ali.

Now, there are N players standing between Gi-Hun and Ali in a straight line, with the i^th player having height Hi​. Gi-Hun wants to know the minimum number of players who need to get shot so that Ali is visible in his line of sight.

Note:

• 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.
• Gi-Hun and Ali have the same height.

### Input Format

• The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
• The first line of each test case contains two space-separated integers N and K, denoting the total number of players between Gi-Hun and Ali and the height of both of them respectively.
• The second line of each test case contains N space-separated integers, denoting the heights of the players between Gi-Hun and Ali.

### Output Format

For each test case, output in a single line the minimum number of players who need to get shot so that Ali is visible in Gi-Hun’s line of sight.

### Constraints

• 1≤T≤10^5
• 1≤N≤10^5
• 1≤K≤10^6
• 1≤Hi​≤10^6 for every 1≤iN.
• The sum of N across all test cases does not exceed 5⋅10^5.

### Sample 1:

``````Input:
3
4 10
2 13 4 16
5 8
9 3 8 8 4
4 6
1 2 3 4
Output:
2
1
0``````

### Explanation:

Test Case 1: Gi-Hun and Ali have height 10. For Ali to be visible to Gi-Hun, the second person (with height 13) and the fourth person (with height 16) need to get shot. Hence, the minimum number of players who need to get shot is 2.

Test Case 2: Gi-Hun and Ali have height 8. For Ali to be visible to Gi-Hun, the first person (with height 9) needs to get shot. Hence, the minimum number of players who need to get shot is 1.

Test Case 3: Nobody needs to get shot because everyone is shorter than Gi-Hun and Ali.

## Red Light, Green Light CodeChef Solution in Pyth 3

``````# cook your dish here
case = int(input())
for i in range(case):
x,y = input().split()
num = 0
l = list(map(int,input().split()))
for i in l:
if i > int(y):
num += 1
print(num)``````

## Red Light, Green Light CodeChef Solution in C++17

``````#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
int n,k,count=0;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>k)count++;
}
cout<<count<<endl;
}
return 0;
}
``````

## Red Light, Green Light CodeChef Solution in Java

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner s= new  Scanner(System.in);
int T= s.nextInt();
for(int j=0;j<T;j++){
int a= s.nextInt();
int b= s.nextInt();
int[] c= new int[a];
int m=0;
for(int i=0;i<a;i++){
c[i]=s.nextInt();
}
for(int i=0;i<a;i++){
if(c[i]>b){
m++;
}
}
System.out.println(m);
}
}
}
``````
##### Red Light, Green Light CodeChef Solution Review:

In our experience, we suggest you solve this Red Light, Green Light CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Red Light, Green Light CodeChef Solution

Find on CodeChef

##### Conclusion:

I hope this Red Light, Green Light CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions