Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Become a Premium Member and unlock a new, free course in leading technologies each month.

Solved

Posted on 2016-08-26

Hi,

I am working on below challenge

http://codingbat.com/prob/p179487

Pseudo Code:

1. loop through given array

2. find elemt a i position and i+1 position.

3. check their equality.

4. if equal return true

5. if not equal reurn false

I wrote my code as below

I am not passing all tests

How to improve my psedo code, approach, code? please advise

I am working on below challenge

http://codingbat.com/prob/p179487

Pseudo Code:

1. loop through given array

2. find elemt a i position and i+1 position.

3. check their equality.

4. if equal return true

5. if not equal reurn false

I wrote my code as below

```
public boolean scores100(int[] scores) {
boolean result=true;
int len=scores.length;
for(int i=0;i<len-1;i++){
if(scores[i]!=100&&scores[i+1]!=100){
// i=i+1;
result=false;
return result;
}
}
return result;
}
```

Expected Run

scores100([1, 100, 100]) → true true OK

scores100([1, 100, 99, 100]) → false true X

scores100([100, 1, 100, 100]) → true true OK

scores100([100, 1, 100, 1]) → false true X

scores100([1, 2, 3, 4, 5]) → false false OK

scores100([1, 2, 100, 4, 5]) → false false OK

other tests

OK

I am not passing all tests

How to improve my psedo code, approach, code? please advise

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

- Help others & share knowledge
- Earn cash & points
- Learn & ask questions

3 Comments

```
public boolean scores100(int[] scores) {
boolean result=false;
int len=scores.length;
for(int i=0;i<len-1;i++){
if(scores[i]==100&&scores[i+1]==100){
// i=i+1;
result=true;
return result;
}
}
return result;
}
//Your pseudo code looks OK to me, your code doesn't match. Assume that there
//are no 2 scores of 100 next to each other, set your flag to true once you've found one.
```

above passes all tests.

any improvements?

```
public boolean scores100(int[] scores) {
for (int i = 0;i < scores.length - 1; i++) {
if (scores[i] == 100 && scores[i+1] == 100) {
return true;
}
}
return false;
}
```

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

Earn Certification

HTML5 Specialist - Certification

Free withPremium

Course of the Month10 days, 8 hours left to enroll

Join the community of 500,000 technology professionals and ask your questions.