Skip to content

Instantly share code, notes, and snippets.

@Shaddyjr
Last active September 6, 2020 09:47
Show Gist options
  • Save Shaddyjr/fefac6a5b1714ec5600a9279d240d624 to your computer and use it in GitHub Desktop.
Save Shaddyjr/fefac6a5b1714ec5600a9279d240d624 to your computer and use it in GitHub Desktop.
// 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