Last active
September 6, 2020 09:47
-
-
Save Shaddyjr/fefac6a5b1714ec5600a9279d240d624 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.hackerrank.com/challenges/angry-professo | |
function angryProfessor(k, a) { | |
// establishing constants | |
const YES = "YES"; | |
const NO = "NO"; | |
let inClassCount = 0; // keeping running total | |
for(const arrivalTime of a){ // looping through each arrivalTime; O(n) | |
inClassCount += arrivalTime <= 0; // get boolean (true/false) if student is late or on time, adding (1/0) to total | |
if(inClassCount >= k) return NO; // before loop is done, if the total count is past threshold, stop and return NO | |
} | |
return YES; // loop finished without issue, reutrn YES; Time Complexity = O(n) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment