Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.
Become a Premium Member and unlock a new, free course in leading technologies each month.
public boolean scoresIncreasing(int[] scores) {
boolean result=false;
int len=scores.length;
for(int i=0;i<len;i++){
if(scores[i+1]>scores[i]&&scores[i+2]>scores[i+1]){
result=true;
return result;
}
}
return result;
}
Expected Run
scoresIncreasing([1, 3, 4]) → true true OK
scoresIncreasing([1, 3, 2]) → false Exception:java.lang.ArrayIndexOutOfB oundsExcep tion: 3 (line number:5) X
scoresIncreasing([1, 1, 4]) → true Exception:java.lang.ArrayIndexOutOfB oundsExcep tion: 3 (line number:5) X
scoresIncreasing([1, 1, 2, 4, 4, 7]) → true true OK
scoresIncreasing([1, 1, 2, 4, 3, 7]) → false true X
scoresIncreasing([-5, 4, 11]) → true true OK
Your progress graph for this problem
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
public boolean scoresIncreasing(int[] scores) {
boolean result=true;
int len=scores.length;
for(int i=0;i<len-2;i++){
if(scores[i+1]<scores[i]||scores[i+2]<scores[i+1]){
result=false;
return result;
}
}
return result;
}
public boolean scoresIncreasing(int[] scores) {
boolean result=true;
int len=scores.length;
for(int i=0;i<len-1;i++){
if(scores[i+1]<scores[i]){
result=false;
return result;
}
}
return result;
}
public boolean scoresIncreasing(int[] scores) {
int[] sorted = scores.clone();
Arrays.sort(sorted);
return Arrays.equals(scores, sorted);
}
public boolean scoresIncreasing(int[] scores) {
for (int i = 0; i < scores.length - 1; i++) {
if (scores[i+1] < scores[i]) {
return false;
}
}
return true;
}
public boolean scoresIncreasing(int[] scores) {
for (int i = 0; i < scores.length - 1; i++) {
if (scores[i+1] < scores[i]) {
return false;
}
}
return true;
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.