Sort by

recency

|

4060 Discussions

|

  • + 0 comments

    def gradingStudents(grades): """ Round grades according to the following rules: 1. If grade < 38, no rounding (failing grade) 2. If difference between grade and next multiple of 5 is < 3, round up 3. Otherwise, keep original grade """ result = []

    for grade in grades:
        if grade < 38:
            # Failing grades are not rounded
            result.append(grade)
        else:
            # Find the next multiple of 5
            next_multiple = math.ceil(grade / 5) * 5
            difference = next_multiple - grade
    
            if difference < 3:
                # Round up to next multiple of 5
                result.append(next_multiple)
            else:
                # Keep original grade
                result.append(grade)
    
    return result
    
  • + 0 comments

    Python Solution:`

        result = []
        for grade in grades:
            if(grade<38):
                result.append(grade)
            else:
                next_mutliple = grade-(grade%5)+5
                if (next_mutliple-grade<3):
                    grade=next_mutliple
                    result.append(grade)
                else:
                    result.append(grade)          
            
        return result
    
  • + 0 comments

    C++ solution

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

    Java Solution

    public static List<Integer> gradingStudents(List<Integer> grades) {
        int i=0;
        for(int a:grades){
            if(a<38){
                grades.set(i,a);
            }else{
                int nextMultipleOf5=((a/5)+1)*5;
            if((nextMultipleOf5-a)<3){
                grades.set(i,nextMultipleOf5);
            }else{
                grades.set(i,a);
            }
            }
    
            i++;
        }
    return grades;
    
    
    
    
    }
    

    }

  • + 0 comments

    java 8 Solution

    public static List<Integer> gradingStudents(List<Integer> grades) {
    int i = 0;
    for(int x : grades)
    {
        int remValue = x % 5;
        if (remValue >= 3 && x > 37) {
                grades.set(i,(x+5-remValue));
            }
        i++;
    }
    
    return grades;
    
    }