In this HackerRank Angry Professor problem you have Given the arrival time of each student and a threshold number of attendees, determine if the class is canceled.

hackerrank angry professor problem solution


Problem solution in Python programming.

T = int(input())
for _ in range(T):
    N, K = input().split()
    N = int(N)
    K = int(K)
    students = 0
    arrivals = input().split()
    for i in arrivals:
        if int(i) <= 0:
            students += 1
    if students < K:
        print("YES")
    else:
        print("NO")


Problem solution in Java Programming.

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

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner scan=new Scanner(System.in);
		int T= scan.nextInt();
		for(int i=0; i<T; i++){
			int numofstudents=0;
			int N=scan.nextInt();
			int K=scan.nextInt();
			for(int j=0;j<N; j++){
				int a= scan.nextInt();
				if( a<=0) numofstudents++;
			}
			if(numofstudents < K) System.out.println("YES");
			else System.out.println("NO");
    }
}
}


Problem solution in C++ programming.

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a; cin >> a;
    for (int g=0; g<a; g++)
    {
        int b,c; cin >> b >> c;
        int num=0; 
        for (int g=0; g<b; g++)
        {
            int d; cin >> d;
            if (d<=0) num++; 
        }
        if (num>=c)
        {
            cout << "NO" << '\n'; 
        }
        else cout << "YES" << '\n';
    }
    return 0; 
}


Problem solution in C programming.

#include<stdio.h>
#include<stdlib.h>

int main(){
	int i, j , T, N, K, t, counter;
	scanf("%d",&T);
	for(i=0; i<T; i++){
		counter= 0;
		scanf("%d %d",&N,&K);
		//t = malloc(sizeof(int)*N);
		for(j=0; j<N; j++){
			scanf("%d",&t);
			if(t<=0) counter++;
		}
		if(counter < K)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


Problem solution in JavaScript programming.

function processData(input) {
    //Enter your code here
    var res = "No";
    var lines = input.split('\n');
    lines.shift(1);
    for(var i = 0; i < lines.length; i += 2) {
      var currentLine = lines[i].split(" ");
      var nextLine = lines[i+1].split(" ");
      var latePeople = 0;
      if(nextLine.length != currentLine[0]){
        process.stdout.write("NO\n");
      } else {
          for(var j = 0; j < nextLine.length; j++) {
              if(nextLine[j] > 0) {
                  latePeople++;
              }
          }
          if((currentLine[0] - latePeople) >= currentLine[1]){
                  process.stdout.write("NO\n");
          } else {
                  process.stdout.write("YES\n");
          }
      }
    } 

} 

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});