# Grading Students Solution in Kotlin -HackerRank

**Problem**

HackerLand University has the following grading policy :

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

Sam is a professor at the university and likes to round each student’s ** grade **according to these rules:

- If the diﬀerence between the
and the next multiple of 5 is less than 3, round*grade*up to the next multiple of 5.*grade* - If the value of
is less than 38, no rounding occurs as the result will still be a failing grade.*grade*

**Examples**

= 84*grade*round to 85 (85–84 is less than 3)*grade**= 29*do not round (result is less than 40)*grade**= 57*do not round (60–57 is 3 or higher)

Given the initial value of ** grade** for each of Sam’s

**students, write code to automate the rounding process.**

*n***Function Description**

Complete the function gradingStudents in the editor below.

gradingStudents has the following parameter(s):

- int grades[n]: the grades before rounding

**Returns**

- int[n]: the grades after rounding as appropriate

**Input Format**

The ﬁrst line contains a single integer, ** n**, the number of students. Each line of

**the**

*i***subsequent lines contains a single integer,**

*n***.**

*grade[i]***Sample Input**

`4 `

73

67

38

33

**Sample Output**

`75 `

67

40

33

**ANSWER**

fun gradingStudents(grades: Array<Int>): Array<Int> {var gradeList : MutableList<Int> = ArrayList() grades.forEach() { item -> if (item >= 38 && item % 5 > 2 ) {

val total = item + (5 - item % 5)

gradeList.add(total)

} else {

gradeList.add(item)

} }return gradeList.toTypedArray()

}

**Explanation**

1. Student 1 received a 73, and the next multiple of 5 from 73 is 75 . Since 75–73 < 3, the student’s grade is rounded to 75.

2. Student 2 received a 67, and the next multiple of 5 from 67 is 70. Since 70–67 = 3, the grade will not be modiﬁed and the student’s ﬁnal grade is 67.

3. Student 3 received a 38, and the next multiple of 5 from 38 is 40. Since 40–38 < 3, the student’s grade will be rounded to 40.

4. Student 4 received a grade below 38, so the grade will not be modiﬁed and the student’s ﬁnal grade is 33.