Sort by

recency

|

3994 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can find video here : https://youtu.be/fYcSakw_5-M

    vector<int> gradingStudents(vector<int> grades) {
        vector<int> result;
        for(int i = 0; i < grades.size(); i++){
            int mo = grades[i] % 5;
            if(mo < 3 || grades[i] < 38) result.push_back(grades[i]);
            else result.push_back(grades[i] - mo + 5);
        }
        return result;
    }
    
  • + 0 comments

    Python solution:

    def gradingStudents(grades):

        # Write your code here
    round_grades=[]
    for i in grades:
        if i<38:
            round_grades.append(i)
        elif (i+(5-i%5))-i < 3:
            x=i+(5-i%5)
            round_grades.append(x)
        else:
            round_grades.append(i)
    return round_grades
    
  • + 0 comments

    **java **

    public static List gradingStudents(List grades) { // Write your code here for(int i=0;i37){ int num=grades.get(i)%10; int newnum=(grades.get(i)/10)*10; if(num<5 && num>2){ grades.set(i, newnum+5); } if(num>5 && num>7){ grades.set(i, newnum+10); } } } return grades; }

  • + 0 comments

    My Solution in JavaScript / TypeScript

    function gradingStudents(grades: number[ ]): number[ ] {

    return grades.map(x => x < 38 ? x : x % 5 === 3 ? x + 2 : x % 5 === 4 ? x + 1 : x)
    

    }

  • + 0 comments

    My solution in Scala:

    def gradingStudents(grades: Array[Int]): Array[Int] = { grades.map(number => { if (number < 38) { number } else { val nextMultipleOf5 = ((number / 5) + 1) * 5 if (nextMultipleOf5 - number < 3) nextMultipleOf5 else number }}) }