HackerRank ‘Grading Students’ Solution

H
Short Problem Definition:

HackerLand University has the following grading policy:

  • Every student receives a grade in the inclusive range from 0 to 100.
  • Any grade less than 40 is a failing grade.
Link

Grading Students

Complexity:

time complexity is O(N)

space complexity is O(N)

Execution:

Follow the problem specification. The solution could be further optimized to remove all unnecessary copies and the whole res array.

Solution:
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
35
#!/bin/python
 
from __future__ import print_function
 
import os
import sys
 
#
# Complete the gradingStudents function below.
#
def gradingStudents(grades):
    res = []
    for grade in grades:
        if grade >= 38 and grade % 5 >= 3:
            grade = grade + 5 - (grade % 5)
        res.append(grade)
    return res
 
if __name__ == '__main__':
    f = open(os.environ['OUTPUT_PATH'], 'w')
 
    n = int(raw_input())
 
    grades = []
 
    for _ in xrange(n):
        grades_item = int(raw_input())
        grades.append(grades_item)
 
    result = gradingStudents(grades)
 
    f.write('n'.join(map(str, result)))
    f.write('n')
 
    f.close()

About the author

Add comment

Archives

Categories