HackerRank 'AngryProfessor' Solution

Martin Kysel · March 11, 2015

Short Problem Definition:

The professor is conducting a course on Discrete Mathematics to a class of N students. He is angry at the lack of their discipline, and he decides to cancel the class if there are less than K students present after the class starts.

Given the arrival time of each student, your task is to find out if the class gets cancelled or not.

Angry Professor


time complexity is O(N)

space complexity is O(1)


Just count all students with arrival time <= 0.


if __name__ == '__main__':
    t = input()
    for _ in xrange(t):
        n, m = map(int, raw_input().split())
        A = map(int, raw_input().split())
        for x in A:
            if x <= 0:
                m -= 1
        if m <= 0:
            print "NO"
            print "YES"

Twitter, Facebook