A Discrete Mathematics professor has a class of students. Frustrated with their lack of discipline, the professor decides to cancel a class if fewer than some students are present when class starts. Arrival times go from on time () to arrived late ().
Given the arrival time of each student and a threshold number of attendees, determine if the class is canceled.
Example:
Input: n=4, k=3,arr[]={-1,-3,4,2}
Output: YES
Approach
Java
public class AngryProfessor {public static void main(String[] args) {int n = 4, k = 3;int[] a = { -1, -3, 4, 2 };System.out.println(angryProfessor(k, a));}private static String angryProfessor(int k, int[] a) {int m = 0;int n = a.length;for (int j = 0; j < n; j++) {if (a[j] <= 0) {m++;}}if (m < k) {return "YES";} else {return "NO";}}}
C++
#include <bits/stdc++.h>using namespace std;string angryProfessor(int k, vector<int> a){int m = 0;int n = a.size();for (int j = 0; j < n; j++){if (a[j] <= 0){m++;}}if (m < k){return "YES";}else{return "NO";}}int main(){int n = 4, k = 3;vector<int> a = {-1, -3, 4, 2};cout << angryProfessor(k, a);return 0;}
No comments:
Post a Comment