Home > Net >  Do hackerrank challenge(s) treat first element specially?
Do hackerrank challenge(s) treat first element specially?

Time:09-11

I'm doing enter image description here enter image description here

Fine. But if I run that same code locally, I add main method

public static void main(String[] args) {
    List<Integer> grades = Arrays.asList(4,73,67,38,33);
    System.out.println(gradingStudents(grades));
}

...and get [4, 75, 67, 40, 33]. Wrong answer.

On the other hand, if I edit the for loop to start at 1: for (int i=1;i<grades.size();i ) {, locally I get [75, 67, 40, 33]. Correct answer.

It seems like I should start at 1 since the first list element is not a grade.

For instances where hackerrank is used as a code test for an interview, this is unnerving. Am I looking at this wrong? Doesn't looping from 1 make more sense? Why does looping from zero work, and looping from 1 not work?

CodePudding user response:

The text of the code challenge says:

The first line contains a single integer,

  • Related