DEV Community

Cover image for Hackerrank Angry Professor Solutions
Ritik Sharma
Ritik Sharma

Posted on

1

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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs