Sort by

recency

|

4006 Discussions

|

  • + 0 comments

    I tested my solution in VSCode and results are correct, but i cannot submit as I get message the results are wrong. Could you check please?

    function gradingStudents( grades ) {

    const rounded = []; const gradesOnly = [...grades]; gradesOnly.shift(); for( let grade of gradesOnly ) if( grade < 38 || grade % 5 === 0 ) rounded.push(grade); else if( Math.floor(grade / 5) * 5 + 5 - grade < 3) rounded.push(Math.floor(grade / 5) * 5 + 5); else rounded.push(grade); return rounded;
    }

  • + 0 comments

    I confess that, at first, I tried to round the value directly, but then I remembered that Math.ceil only works for floats, so:

    Divide the number by the multiple (5):

    value / 5 = X

    Since we're rounding up, we'll round it to the next whole number, which is Y.

    Now, multiply Y by multiple (5) to find the nearest multiple of 5 that's greater than the "value"

    function gradingStudents(grades: number[]): number[] {
    	const response = grades.reduce((acc, value, index) => {
    		const next = Math.ceil(value / 5) * 5;
    		const factor = Math.abs(next - value);
    		acc[index] = value;
    		if (factor < 3 && value >= 38) {
    			acc[index] = next;
    		}
    		return acc;
    	}, [] as number[]);
    	return response;
    }
    
  • + 0 comments

    This is my solution, how are things?

    vector gradingStudents(vector grades) { for(int i = 0; i < grades.size(); i++){

    if(grades[i] > 37){
      if((grades[i]+1)%5 == 0)
        grades[i] += 1;
      else if((grades[i]+2)%5 == 0)
        grades[i] += 2;    
    }
    

    } return grades; }

  • + 0 comments

    There is an issue with the question. It assumes the input to have the first element as the number of students (not a grade). However, my code only worked when considering the first element (grades[0] in python)..

    Code

    def complement(x, m): return (m - (x % m)) % m

    def gradingStudents(grades): result = [] # Create a new list instead of modifying grades

    for grade in grades:
        if grade < 38 or grade % 5 < 3:
            result.append(grade)  # No rounding needed
        else:
            result.append(grade + complement(grade, 5))  #  Round up properly    
    return result  #  Return a new list
    
  • + 0 comments

    Here is my solution in python:

    Write your code here

    grade_1=[]
    for i in grades:
        if i>=38:
            if (math.ceil(i/5)*5)-i < 3:
                grade_1.append(((math.ceil(i/5)*5)))
            else:
                grade_1.append(i)
        else:
            grade_1.append(i)
    return grade_1