Sort by

recency

|

4070 Discussions

|

  • + 0 comments
    vector<int> gradingStudents(vector<int> grades)
    {
        for(int i = 0; i < grades.size(); i++)
        {
            if(grades[i] >= 38)
            {
                int diff = abs((grades[i]%5)-5);
                if(diff < 3)
                {
                    grades[i] += diff;
                }
            }
        }
        return grades;
    }
    
  • + 0 comments
    function gradingStudents(grades) {
        // less than 38 is automatically failed
        // if the difference b/w original marks and rounded original marks by closest multiple of 5
        // is less than 3, then round off to rounded marks. If not, original marks remain the same.
        let minMarks = 38;
        let lengthOfGrades = grades.length;
        let finalArray = [];
        let mult5 = 0;
        console.log(grades);
        // assuming grades -> [73,67,38,33]
        for(let i = 0; i < lengthOfGrades; i++ ){
            // fail because grades LT 38
            if( grades[i] < minMarks ){
                finalArray.push(grades[i]);
            }else {
                // grades are GTE 38
                // finding the multiples of 5
                mult5 = Math.ceil(grades[i]/5); // 73/5 => 14.6 => ceil(14.6) => 15
                mult5 *= 5; // to get the multiple of 5 closest to grade 15*5=>75
                if( mult5 - grades[i] < 3 ){
                    finalArray.push(mult5);
                }else{
                    finalArray.push(grades[i]);
                }
            }
        } 
        return finalArray;
    }
    

    ` undefined

  • + 1 comment

    I have submitted the solution and all of the hackerrank tests are passing. Still the submission is failing with error "We could not process your problem. Please submit the problem again." I keep getting it even for multiple submissions. I also tried to solve other problems and it's still the same. Has anyone else faced such an issue? Any suggestions?

  • + 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;