Grading Students

Sort by

recency

|

211 Discussions

|

  • + 0 comments

    C++

    int NextMultipleOfFive(int n)
    {
        return (((100 - n) % 5) + n);
    }
    
    vector<int> gradingStudents(vector<int> grades) {
        for(int i = 0; i < grades.size(); ++i)
        {
            if(38 > grades[i])
            {
                continue;
            }
            else
            {
                int round = NextMultipleOfFive(grades[i]);
                if( 3 > (round - grades[i]))
                {
                    grades[i] = round;
                }
            }
        }
        return grades;
    }
    
  • + 0 comments
    function gradingStudents(grades) {
        let result=[],i;
        for(i=0; i<grades.length; i++){
            if(grades[i]<38){
                result.push(grades[i]);
            }
            else{
                let mutipal5 = parseInt((grades[i]/5+1))*5;
                let lessthen3 = mutipal5 -grades[i];
                if(lessthen3<3){
                  result.push(mutipal5) ; 
                }
                else{
                    result.push(grades[i]);
                }
                
                }
        }
        return result
    }
    
  • + 0 comments

    Python

    def gradingStudents(grades):
        final_grades = []
        for grade in grades:
            if grade < 38:
                final_grades.append(grade)
            else:
                nextMulitpleOf5 = 5 * ((grade//5) + 1)
                if (nextMulitpleOf5 - grade) < 3:
                    final_grades.append(nextMulitpleOf5)
                else:
                    final_grades.append(grade)
                    
        return final_grades
    
  • + 0 comments

    Jva 15 solution public static List gradingStudents(List grades) { // Write your code here List roundedLst = new ArrayList();

    for(Integer grade:grades){
        int tmp=0;
        if(grade>=38){
          tmp = grade%5;
          if(5-tmp <3){
            grade = grade + (5-tmp);          
          } 
        } 
        roundedLst.add(grade);
    }
    
    
    return roundedLst;
    }
    
  • + 0 comments

    Rust best solution

    If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions

    pub fn grading_students(grades: &[i32]) -> Vec<i32> {
        //Time complexity: O(n)
        //Space complexity (ignoring input): O(n)
        let mut new_grades = Vec::new();
    
        for &grade in grades {
            if (grade < 37) && ((grade % 5) > 2) {
                new_grades.push(grade + 5 - (grade % 5));
            } else {
                new_grades.push(grade);
            }
        }
    
        new_grades
    }