Ad
  • Custom User Avatar

    But isn't the check performed at the start of the expression? Array length will always be greater than or equal to zero. If the value of n is negative then the function returns -1 in this solution.

    Edit:
    Okay, I'm dumb :D

  • Custom User Avatar

    @vasyl.shevchuk.78 yes you are right. It would be better to test for it. But the Kata description was a bit vague about the possible values of n and since that case is never tested so I assumed n >= 0 always.

  • Custom User Avatar

    Read about "?" operator in java.