DEV Community

Cover image for Hackerrank Angry Professor Solutions
Ritik Sharma
Ritik Sharma

Posted on

Hackerrank Angry Professor Solutions

A Discrete Mathematics professor has a class of students. Frustrated with their lack of discipline, the professor
decides to cancel class if fewer than some number of students are present when class starts. Arrival times go
from on time (arrivalTime 0) to arrived late (arrivalTime > 0).
Given the arrival time of each student and a threshhold number of attendees, determine if the class is
cancelled.

Python

def angryProfessor(k, a):
    students = 0
    for i in a:
        if i <= 0: students += 1
    if students < k: print("YES")
    else: print("NO")

angryProfessor(3,[-1,-3,4,2])
Enter fullscreen mode Exit fullscreen mode

JavaScript

function angryProfessor(k, a) {
  let students = 0;
  for (let i = 0; i < a.length; i++) {
    if (a[i] <= 0) {
      students++;
    }
  }
  if (students < k) {
    console.log("YES");
  } else {
    console.log("NO");
  }
}

Enter fullscreen mode Exit fullscreen mode

C++

#include <iostream>
using namespace std;

void angryProfessor(int k, int a[], int n) {
  int students = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 0) {
      students++;
    }
  }
  if (students < k) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)