-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathResult.java
More file actions
34 lines (27 loc) · 1.09 KB
/
Result.java
File metadata and controls
34 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package hackrank.algorithm.implement.angryprof;
import java.util.List;
/**
* @see <a href="https://www.hackerrank.com/challenges/angry-professor">Angry Professor</a>
*/
public class Result {
/**
* @param k Minimum number of on time students required to not cancel class.
* @param a List of student arrival times. Negative or equal to zero is on time. Positive number implies late.
* @return "YES" if professor is angry at lack of punctual students and cancels class. Otherwise, "NO".
*/
public static String angryProfessor(int k, List<Integer> a) {
// start out as always angry - professor should really see somebody about that
boolean angryCancelClass = true;
int numberStudentsOnTime = 0;
for (int arrivalTime : a) {
if (arrivalTime <= 0) {
numberStudentsOnTime++;
}
if (numberStudentsOnTime >= k) {
angryCancelClass = false; // enough students are on time; don't cancel class
break;
}
}
return angryCancelClass ? "YES" : "NO";
}
}