A Discrete Mathematics professor has a class of students. Frustrated with their lack of discipline, he decides to cancel class if fewer than some number of students are present when class starts. Arrival times go from on time () to arrived late ().
Given the arrival time of each student and a threshhold number of attendees, determine if the class is canceled.
Description
It must return YES if class is canceled, or
NO
otherwise.
angry professor has the following parameter(s):
- k: the threshold number of students
- a: an array of integers representing arrival times
Question from hackerrank.
Solution in C# -
class Solution {
static string angryProfessor(int k, int[] a) {
int total = 0;
for(int i=0; i<a.Length; i++)
if(a[i] <= 0)
total++;
if(total >= k)
return "NO";
else
return "YES";
}
static void Main(string[] args) {
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
int t = Convert.ToInt32(Console.ReadLine());
for (int tItr = 0; tItr < t; tItr++) {
string[] nk = Console.ReadLine().Split(' ');
int n = Convert.ToInt32(nk[0]);
int k = Convert.ToInt32(nk[1]);
int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), aTemp => Convert.ToInt32(aTemp));
string result = angryProfessor(k, a);
textWriter.WriteLine(result);
}
textWriter.Flush();
textWriter.Close();
}
}
Post a Comment