Sort by

recency

|

4067 Discussions

|

  • + 0 comments
    vector<int> gradingStudents(vector<int> grades) {
        // grades already passed by value
        std::transform(grades.begin(), grades.end(), grades.begin(), 
            [] (int grade) {
                if (grade < 38)
                    return grade;
                
                int toNextMultiple = 5 - grade % 5;
                
                if (toNextMultiple < 3) {
                    grade += toNextMultiple;
                }
                
                return grade;      
            });
            
        return grades;
    }
    
  • + 0 comments

    Java:

    for(int i=0; i<grades.size(); i++){
     if(grades.get(i)<38) continue;
     else if((5 - grades.get(i)%5) < 3) 
      grades.set(i, grades.get(i)+(5 - grades.get(i)%5));
    }
    return grades;
    
  • + 0 comments

    Here’s your updated solution with twitchclip added cleanly in the docstring/comment:

    vector<int> gradingStudents(vector<int> grades) {
        vector<int> result;
    
        for (int grade : grades) {
            if (grade < 38) {
                // No rounding for failing grades
                result.push_back(grade);
            } else {
                int nextMultipleOf5 = ((grade / 5) + 1) * 5;
                if (nextMultipleOf5 - grade < 3) {
                    result.push_back(nextMultipleOf5); // round up
                } else {
                    result.push_back(grade); // no change
                }
            }
        }
    
        return result;
    }
    
  • + 0 comments
    def gradingStudents(grades):
        # Write your code here
        return [ math.ceil(g / 5) * 5 if (g >= 38 and (math.ceil(g / 5) * 5 - g) < 3) else g for g in grades ]
    
  • + 0 comments

    c#

        List<int> listResult = new List<int>();
    
        int nNumberOfStudent = 0;
        for (int i = 0; i < grades.Count; i++)
        {
            if (i == 0)
            {
                nNumberOfStudent = grades[i];
                continue;
            }
            int val = grades[i];
    
            if (val < 38)
            {
                listResult.Add(val);
            }
            else if ((5 - (val % 5)) <= 2) // 73 -> 3 -> (5-3=2)
            {
                listResult.Add(val + (5 - (val % 5)));
            }
            else if ((5 - (val % 5)) >= 3) // 67 -> 2 -> (5-2= 3)
            {
                listResult.Add(val);
            }
    
        }
    

    code is working on my VS but incorrect value here. strange