https://www.hackerrank.com/challenges/angry-professor
A Discrete Mathematics professor has a class of students. Frustrated with their lack of discipline, he decides to cancel class if fewer than students are present when class starts.
Given the arrival time of each student, determine if the class is canceled.
The first line of input contains , the number of test cases.
Each test case consists of two lines. The first line has two space-separated integers, (students in the class) and (the cancelation threshold).
The second line contains space-separated integers () describing the arrival times for each student.
The second line contains space-separated integers () describing the arrival times for each student.
Note: Non-positive arrival times () indicate the student arrived early or on time; positive arrival times () indicate the student arrived minutes late.
Scanner sc = new Scanner(System.in);
//no of test cases
int T = Integer.parseInt(sc.nextLine());
for(int count=0;count<T;count++)
{
String[] constraints = sc.nextLine().split(" ");
//n and k
int N =Integer.parseInt(constraints[0]);
int K =Integer.parseInt(constraints[1]);
//count no of students inside the class
int noOfStuds =0;
//all the students times are stored in string array
String[] students = sc.nextLine().split(" ");
for(int i=0;i<N;i++)
{
int stud = Integer.parseInt(students[i]);
// if it is negative or zero the student arrived before the class
if(stud<=0)
noOfStuds++;
//k students are present in the class so no need to cancel the class, so NO
if(noOfStuds>=K)
{
System.out.println("NO");
break;
}
}
// if K students are not there in the class the class is cancelled so YES
if(noOfStuds<K)
System.out.println("YES");
}