Sort by

recency

|

3956 Discussions

|

  • + 0 comments

    Java:

    // Write your code here

    List<Integer> result = new ArrayList();
    
        for(Integer grade : grades) {
            if(grade%5 > 2 && grade > 37) {
                result.add(5 * (grade/5 +1));
            } else {
                result.add(grade);
            }
        }
    
        return result;
    
  • + 0 comments
    public static List<Integer> gradingStudents(List<Integer> grades) {
            return grades.stream().map(elem -> {
                int module = 5 - (elem % 5);
                return elem >= 38 && module < 3 ? elem + module : elem;
            }).collect(Collectors.toList());
        }
    
  • + 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

    Also python

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

    for python

    def gradingStudents(grades):
        for idx in range(len(grades)):
            if grades[idx]>=38:
                if (grades[idx]//5+1)*5-grades[idx]<3:
                    grades[idx] = (grades[idx]//5+1)*5
        return grades