Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Hi

I am trying below challenge

http://codingbat.com/prob/p167430

I was not sure on how to proceed. please advise

I am trying below challenge

http://codingbat.com/prob/p167430

I was not sure on how to proceed. please advise

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

return true if the array contains any of

2, 7, -1

or

2, 7, 0

or

2, 7, 1

or

2, 7, 2

or

2, 7, 3

I have to check in sequence and in pattern right. please advise

```
public boolean has271(int[] nums) {
int i=nums.length;
if(i>=3){
for(int j=0;j<i-1;j++)
{
if(nums[j]==2 && nums[j]==7 && nums[j]==1)
return true;
}
}
return false;
}
```

i wrote like above. passing in some test cases and failing in others

```
Expected Run
has271({1, 2, 7, 1}) â†’ true false X
has271({1, 2, 8, 1}) â†’ false false OK
has271({2, 7, 1}) â†’ true false X
has271({3, 8, 2}) â†’ true false X
has271({2, 7, 3}) â†’ true false X
has271({2, 7, 4}) â†’ false false OK
has271({2, 7, -1}) â†’ true false X
has271({2, 7, -2}) â†’ false false OK
has271({4, 5, 3, 8, 0}) â†’ true false X
has271({2, 7, 5, 10, 4}) â†’ true false X
has271({2, 7, -2, 4, 9, 3}) â†’ true false X
has271({2, 7, 5, 10, 1}) â†’ false false OK
has271({2, 7, -2, 4, 10, 2}) â†’ false false OK
```

please advise

```
public boolean has271(int[] nums) {
for(int i=0;i<xxxxxxxxxxxxx;i++){
if(nums[i+1]==xxxxxxxxx)
if (Math.xxx((numsxxxxx)-nums[i+2])<=x){return true;}
}
return false;
}
```

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialCan you see why

nums[j]==2 && nums[j]==7 && nums[j]==1

can never be true?

i see your point now. I improved as below my success rate in test cases but not 100% yet. Please advise

```
public boolean has271(int[] nums) {
int i=nums.length;
if(i>=3){
for(int j=0;j<i-1;j++)
{
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==1)
return true;
}
}
return false;
}
```

```
Expected Run
has271({1, 2, 7, 1}) â†’ true true OK
has271({1, 2, 8, 1}) â†’ false false OK
has271({2, 7, 1}) â†’ true true OK
has271({3, 8, 2}) â†’ true false X
has271({2, 7, 3}) â†’ true false X
has271({2, 7, 4}) â†’ false false OK
has271({2, 7, -1}) â†’ true false X
has271({2, 7, -2}) â†’ false false OK
has271({4, 5, 3, 8, 0}) â†’ true false X
has271({2, 7, 5, 10, 4}) â†’ true false X
has271({2, 7, -2, 4, 9, 3}) â†’ true false X
has271({2, 7, 5, 10, 1}) â†’ false false OK
has271({2, 7, -2, 4, 10, 2}) â†’ false false OK
```

```
has271({2, 7, 5, 10, 4}) â†’ true false X
has271({2, 7, -2, 4, 9, 3}) â†’ true false X
```

I wonder how above two test cases supposed to be true according to below code challenge description

Given an array of ints, return true if it contains a 2, 7, 1 pattern -- a value, followed by the value plus 5, followed by the value minus 1. Additionally the 271 counts even if the "1" differs by 2 or less from the correct value.

has271({1, 2, 7, 1}) â†’ true

has271({1, 2, 8, 1}) â†’ false

has271({2, 7, 1}) â†’ true

5 and -2 are never 'near differ by 2' from 1 right?

please advise

a value (5), followed by the value plus 5 (10), followed by the value minus 1 (4).

has271({2, 7, -2,

a value (4), followed by the value plus 5 (9), followed by the value minus 1 (3).

The final "value" you have to aim at, can be within a tolerance of 2 from "

You are looking for a pattern somewhere in these ints. The search - or "thinking" - you have to do and are asked to carry out is :

* You are "told" that the first int is the "pattern setter" let's call it. They have used the word "value" actually.

* You are also "told" that you are looking for a "pattern" involving just 3 of the ints you are given. You might be given more than 3 ints, you might be given fewer than 3, and you could be given exactly 3 ints. So however many ints you are given, you must ensure that you look at all of them (the entire [] ) to see if 3 of them follow the pattern that you have been asked to find. For this to happen, you obviously need to have in the back of your mind that the use of a loop could well come into the solution.

* THE "PATTERN" (the task is) "are there 3 consecutive ints like this : 1) pattern-setter (first) value, followed by 2) pattern-setter PLUS 5, followed by (in the third position) 3) a value which is NOT MORE THAN 2 different from the pattern-setter after 1 has been taken away from the pattern-setter"?

If your ints are for example 8,13,5 then would the pattern have been found in these ints or not???

Well - 8 is our pattern-setter, so that is a given (we accept that no matter what else we are thinking about). Right, so we know that we are asked to discover whether the next int is equal to pattern-setter plus 5. Is it? Yes it is, it's 13. 8 + 5 = 13. Right, now we need to know whether the 3rd int is equal to the pattern-setter minus 1 (which is 8-1 =7) and then ALSO BE not more than 2 away from 7. So is 5 more than two away from 7? No it IS 2 away from 7, so it satisfies our third criterion. Now we have evaluated 3 ints and found that they satisfy the question, we can return true. We found the pattern.

8,13,5 was ok. 8,13,6 would have been too. 8,13,7 would have been also. Can you see the meta here now? If so, go back to the code and match it up with the above explanatory steps, and go over it until you see it flow.

Can you see why

nums[j]==2 && nums[j]==7 && nums[j]==1

can never be true?

above is never true because at same index of array 3 numbers cannot be there.

My solution as below is true for some cases but false for some other

```
public boolean has271(int[] nums) {
int i=nums.length;
if(i>=3){
for(int j=0;j<i-1;j++)
{
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==1)
return true;
}
}
return false;
}
```

please advise

```
Expected Run
has271({1, 2, 7, 1}) â†’ true true OK
has271({1, 2, 8, 1}) â†’ false false OK
has271({2, 7, 1}) â†’ true true OK
has271({3, 8, 2}) â†’ true false X
has271({2, 7, 3}) â†’ true false X
has271({2, 7, 4}) â†’ false false OK
has271({2, 7, -1}) â†’ true false X
has271({2, 7, -2}) â†’ false false OK
has271({4, 5, 3, 8, 0}) â†’ true false X
has271({2, 7, 5, 10, 4}) â†’ true false X
has271({2, 7, -2, 4, 9, 3}) â†’ true false X
has271({2, 7, 5, 10, 1}) â†’ false false OK
has271({2, 7, -2, 4, 10, 2}) â†’ false
```

```
public boolean has271(int[] nums) {
int i=nums.length;
if(i>=3){
for(int j=0;j<i-1;j++)
{
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==1){
return true;
}
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==2){
return true;
}
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==3){
return true;
}
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==0){
return true;
}
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==-1){
return true;
}
}
}
return false;
}
```

i updated my code and passed more tests as below

```
Expected Run
has271({1, 2, 7, 1}) â†’ true true OK
has271({1, 2, 8, 1}) â†’ false false OK
has271({2, 7, 1}) â†’ true true OK
has271({3, 8, 2}) â†’ true false X
has271({2, 7, 3}) â†’ true true OK
has271({2, 7, 4}) â†’ false false OK
has271({2, 7, -1}) â†’ true true OK
has271({2, 7, -2}) â†’ false false OK
has271({4, 5, 3, 8, 0}) â†’ true false X
has271({2, 7, 5, 10, 4}) â†’ true false X
has271({2, 7, -2, 4, 9, 3}) â†’ true false X
has271({2, 7, 5, 10, 1}) â†’ false false OK
has271({2, 7, -2, 4, 10, 2}) â†’ false false OK
```

stil failing on 4 test cases. please advise
If so, can you add conditions to handle them?

Instead, you have hard-wired your code to look at "271". I said in my above comment, that IT DOES NOT MATTER what those 3 ints are - they COULD BE ANYTHING - "0,1,2", "7,9,11" . . . you name it.

Re-read my quoted comment, and think again.

---------

That relationship HAS to be :

1st int = anything

2nd int = 1st int plus 5

3rd int = 1st int -1

If you are given more than 3 ints, then move along the array one place (leaving the first int out of it) and include the next int in the triplet. This is where you need the for loop.

```
has271({3, 8, 2}) â†’ true false X
has271({4, 5, 3, 8, 0}) â†’ true false X
has271({2, 7, 5, 10, 4}) â†’ true false X
has271({2, 7, -2, 4, 9, 3}) â†’ true false X
```

i am failing above four.3rd int = 1st int -1 give or take 2 (so if 1st int is "4", third int can only be : 3, 2 or 1 (going down from 4), or 4 or 5 going upwards from 3.you mean it should be as below right

3rd int = 1st int -1 give or take 2 (so if 1st int is "4", third int can only be : 3, 2 or 1 (going down from 4), or 4 or 5 going upwards from4.

1st int = anythingabove is clear

2nd int = 1st int plus 5

Below is not clear. I am trying to re read again and again to understand it

If you are given more than 3 ints, then move along the array one place (leaving the first int out of it) and include the next int in the triplet. This is where you need the for loop.

```
public class Test34 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
/*has271({3, 8, 2}) â†’ true false X
has271({4, 5, 3, 8, 0}) â†’ true false X
has271({2, 7, 5, 10, 4}) â†’ true false X
has271({2, 7, -2, 4, 9, 3}) â†’ true false X*/
has271({3, 8, 2});
}
public static boolean has271(int[] nums) {
int i=nums.length;
if(i>=3){
for(int j=0;j<i-1;j++)
{
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==1){
return true;
}
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==2){
return true;
}
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==3){
return true;
}
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==0){
return true;
}
if(nums[j]==2 && nums[j+1]==7 && nums[j+2]==-1){
return true;
}
}
}
return false;
}
}
```

i am getting error. please advies

you mean it should be as below right

3rd int = 1st int -1 give or take 2 (so if 1st int is "4", third int can only be : 3, 2 or 1 (going down from 4), or 4 or 5 going upwards from 4.

No. Going upwards from 3. Because 3 would be the "expected" value - because that's 4-1, which is 3. So 3 is in a sense the "correct" value BUT the rules say that you can deviate by 2 or less from that "correct" value, so you can have 3+1 (4) or 3+2 (5) going up.

Going down - if your 1st int is 4 - then the "correct" third int SHOULD be 3, but it COULD also be 2 or 1.

* get the first int

* see if the next int is equal to the first int +5 and if it is then :

* see if the third int is equal to the first int minus 1, or is 2 away from the first int-1 IN EITHER DIRECTION.

and if you are given more than 3 ints, then put the above into a for loop, and move along the array.

```
public class Test34 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[]={1,8,2};
System.out.println("value is--->"+has271(arr));
}
public static boolean has271(int[] nums) {
/** get the first int
* see if the next int is equal to the first int +5 and if it is then :
* see if the third int is equal to the first int minus 1, or is 2 away from the first int-1 IN EITHER DIRECTION.
and if you are given more than 3 ints, then put the above into a for loop, and move along the array.*/
int i=nums.length;
if(i>=3){
for(int j=0;j<i-1;)
{
if(nums[1]==nums[0]+5 && nums[2]==nums[0]-1);
j=j+2;
return true;
}
}
return false;
}
}
```

i wrote as aboe to check second and third value of the array based on first. I see i am getting true no matter what i pass as belowvalue is--->true

Once i make above working i will think about adding additionally

or is 2 away from the first int-1 IN EITHER DIRECTION.please advise

```
Expected Run
has271({1, 2, 7, 1}) â†’ true true OK
has271({1, 2, 8, 1}) â†’ false true X
has271({2, 7, 1}) â†’ true true OK
has271({3, 8, 2}) â†’ true true OK
has271({2, 7, 3}) â†’ true true OK
has271({2, 7, 4}) â†’ false true X
has271({2, 7, -1}) â†’ true true OK
has271({2, 7, -2}) â†’ false true X
has271({4, 5, 3, 8, 0}) â†’ true true OK
has271({2, 7, 5, 10, 4}) â†’ true true OK
has271({2, 7, -2, 4, 9, 3}) â†’ true true OK
has271({2, 7, 5, 10, 1}) â†’ false true X
has271({2, 7, -2, 4, 10, 2}) â†’ false true X
```

i am failing some test cases as above
```
public class Test34 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[]={1,8,2};
System.out.println("value is--->"+has271(arr));
}
public static boolean has271(int[] nums) {
/** get the first int
* see if the next int is equal to the first int +5 and if it is then :
* see if the third int is equal to the first int minus 1, or is 2 away from the first int-1 IN EITHER DIRECTION.
and if you are given more than 3 ints, then put the above into a for loop, and move along the array.*/
int i=nums.length;
if(i>=3){
for(int j=0;j<i-1;)
{
if(nums[1]==nums[0]+5 && (nums[2]==nums[0]-1||nums[2]==nums[0]-2||nums[2]==nums[0]+1||nums[2]==nums[0]+2));
j=j+2;
return true;
}
}
return false;
}
}
```

i updated my code as above still failing 5 test cases

I feel i am getting close

```
Expected Run
has271({1, 2, 7, 1}) â†’ true true OK
has271({1, 2, 8, 1}) â†’ false true X
has271({2, 7, 1}) â†’ true true OK
has271({3, 8, 2}) â†’ true true OK
has271({2, 7, 3}) â†’ true true OK
has271({2, 7, 4}) â†’ false true X
has271({2, 7, -1}) â†’ true true OK
has271({2, 7, -2}) â†’ false true X
has271({4, 5, 3, 8, 0}) â†’ true true OK
has271({2, 7, 5, 10, 4}) â†’ true true OK
has271({2, 7, -2, 4, 9, 3}) â†’ true true OK
has271({2, 7, 5, 10, 1}) â†’ false true X
has271({2, 7, -2, 4, 10, 2}) â†’ false true X
```

please advise

```
public boolean has271(int[] nums) {
int i=nums.length;
if(i>=3){
for(int j=0;j<i-1;)
{
if(nums[j+1]==nums[j]+5 &&(nums[j+2]==nums[j]-1||nums[j+2]==nums[j]-2||nums[j+2]==nums[j]+1||nums[j+2]==nums[j]+2));
j=j+2;
return true;
}
}
return false;
}
```

i updated further still above 5 test cases failing. please advise

1st int is . ..........................

Right.

2nd int is ..........................

Is 103 + 5 = to 109 ? No. So that means the test already flunked. Return false.

How about .......... 1st int = 90.

2nd int = 95.

Is 90 + 5 = to 95??????????????????????. Answer = YES, it is. Right. So that's one "if statement out of the way!"

3rd int = 92

Is 92 = to (95-1), give or take 2?????????????????????????

YES!!!!!!!!!!!!!!!!!!!!!!!

2nd if statisfied. WE HAVE A SATISFACTORY int triplet here!. Return TRUE!

--------------------------

Now . . . . the places where you see 90, 95 and 92 above :

PUT ANY INTEGERS YOU LIKE, AND GO THROUGH THE STEPS JUST LIKE WE WENT THROUGH THEM ABOVE - EXACTLY THE SAME LOGIC, BUT USING YOUR NEW NUMBERS. SO WHEN YOU ADD 5, YOU ADD 5 TO THE FIRST NUMBER. WHEN YOU SEE -1, YOU TAKE ONE AWAY FROM YOUR FIRST INT. WHEN YOU DECIDE WHETHER THE 3RD INT YOU CHOSE IS OK, ASK YOUSELF IF IT IS NOT MORE THAN 2 DIFFERENT FROM THE FIRST INT-1.

public boolean has271(int[] nums) {

int i=nums.length;

for(int j=0;j<i-2;j++)

{

if(nums[j+1]==nums[j]+5 &&(nums[j+2]==nums[j]-1||nums[j+2]== nums[j]-2| |nums[j+2] ==nums[j]+ 1||nums[j+ 2]==nums[j ]+2));

j=j+2;

return true;

}

return false;

}

i modifiede as above. passed few more test cases but still not 100% correct

```
Expected Run
has271({1, 2, 7, 1}) â†’ true true OK
has271({1, 2, 8, 1}) â†’ false true X
has271({2, 7, 1}) â†’ true true OK
has271({3, 8, 2}) â†’ true true OK
has271({2, 7, 3}) â†’ true true OK
has271({2, 7, 4}) â†’ false true X
has271({2, 7, -1}) â†’ true true OK
has271({2, 7, -2}) â†’ false true X
has271({4, 5, 3, 8, 0}) â†’ true true OK
has271({2, 7, 5, 10, 4}) â†’ true true OK
has271({2, 7, -2, 4, 9, 3}) â†’ true true OK
has271({2, 7, 5, 10, 1}) â†’ false true X
has271({2, 7, -2, 4, 10, 2}) â†’ false true X
```

Sorry that i am not able to completely follow on this challenge(since it seems bit stretch for me). Please advise how to fix and improve my code
```
public boolean has271(int[] nums) {
int i=nums.length;
for(int j=0;j<i-2;j++)
{
if(nums[j+1]==nums[j]+5 &&(nums[j+2]==nums[j]-1||nums[j+2]==nums[j]-2||nums[j+2]==nums[j]+1||nums[j+2]==nums[j]+2));
return true;
}
return false;
}
```

i modified furthwer now only 4 test cases failing instead of 5 compared to earlier comment

```
has271({1, 2, 8, 1}) â†’ false true X
has271({2, 7, 5, 10, 1}) â†’ false true X
has271({2, 7, -2, 4, 10, 2}) â†’ false true X
has271({2, 7, 4}) â†’ false true X
```

({2, 7, 5, 10, 1}) . . . so 2 + 5 =7, so we are ok so far. But 5 is more than 2 away from 2-1 (which is 1), so that's a fail. So now 7 +5 is 12, not 10, so that's a fail. Then finally, 5 +5 IS 10, but again 5-1 (which is 4) is more than 2 away from 1, so the whole thing fails again to false.

has271({2, 7, -2, 4, 10, 2}) .... so 2+5 = 7, but 2-1 (which is 1) is not 2 away from -2, so fail. Now 7+5 isn't -2, so another fail. Now -2 +5 isn't 4, so another fail. Finally 4+5 isn't 10, so there's another fail, and no need to even look at the last 2 in that sequence.

has271({2, 7, 4}) . . . so 2+5 is 7, so that's ok, and so is 2-1 (which is 1) 2 or less away from 4? No, so another fail to false.

if ( 2nd int = 1st int plus 5 ) {we are ok so far; now test the third int; is the 3rd int

{else return false;}

Keep doing this until you can't test 3 sequential ints from the series you are given because you've already moved along the series too far.

is the 3rd int AT MOST 2 different from the 1st int-1? If it is ( return true; );}

i mistakenly thought as below instead till now

is the 3rd int AT MOST 2 different from the 1st int? If it is ( return true; );}

Given an array of ints, return true if it contains a 2, 7, 1 pattern -- a value, followed by the value plus 5, followed by the value minus 1. Additionally the 271 counts even if the "1" differs by 2 or less from the correct value.

```
public boolean has271(int[] nums) {
int i=nums.length;
for(int j=0;j<i-2;j++)
{
if(nums[j+1]==nums[j]+5 &&(nums[j+2]==nums[j]-1||nums[j+2]==nums[j]-2||nums[j+2]==nums[j]-3||nums[j+2]==nums[j]||nums[j+2]==nums[j]+1));
return true;
}
return false;
}
```

i wrote as above still 5 failing

I am not sure that any more help will do you any good here. The task is simple.

You get a series of ints.

The SECOND int has to be EXACTLY equal to the first int + 5.

If that test is passed, then the third int has to be equal to the first int -1, OR equal to the first int -1,GIVE OR TAKE 2.

1,2,32,33,45,766,12,2,7,1

only the last 3 ints will pass the test and return true. There are 8, repeat 8 sets of possible 3 ints you have to evaluate :

1,2,32

2,32,33

32,33,45

33,45,766

45,766,12

766,12,2

12,2,7

and

2,7,1.

1,2,32,33,45,766,12,2,7,-1

would that series return true or false??

Don't write code - just look at the series with your eyes.

```
public boolean has271(int[] nums) {
if(nums.length>2){
for(int i=0;i<nums.length-1;i++)
{
if((nums[i+1]==(nums[i]+5))&& (Math.abs(nums[i]-nums[i+2])<=3))
{
return true;
}
```

}

}

return false;

}

i kind of modified and failing in 2 instead

```
Expected Run
has271({1, 2, 7, 1}) â†’ true true OK
has271({1, 2, 8, 1}) â†’ false false OK
has271({2, 7, 1}) â†’ true true OK
has271({3, 8, 2}) â†’ true true OK
has271({2, 7, 3}) â†’ true true OK
has271({2, 7, 4}) â†’ false true X
has271({2, 7, -1}) â†’ true true OK
has271({2, 7, -2}) â†’ false false OK
has271({4, 5, 3, 8, 0}) â†’ true true OK
has271({2, 7, 5, 10, 4}) â†’ true true OK
has271({2, 7, -2, 4, 9, 3}) â†’ true true OK
has271({2, 7, 5, 10, 1}) â†’ false true X
has271({2, 7, -2, 4, 10, 2}) â†’ false false OK
```

The SECOND int has to be EXACTLY equal to the first int + 5.100% clear

then the third int has to be equal to the first int -1, OR equal to the first int -1,GIVE OR TAKE 2.still clear 50%

1,2,32,33,45,766,12,2,7,1

only the last 3 ints will pass the test and return true. There are 8, repeat 8 sets of possible 3 ints you have to evaluate :

1,2,32

2,32,33

32,33,45

33,45,766

45,766,12

766,12,2

12,2,7

and

2,7,1.

. . . . so given the same set of ints as I just used above, with one change :

1,2,32,33,45,766,12,2,7,-1

would that series return true or false??

based on the challenge it should be true

followed by the value minusabove highlighted one is in 2,7,1 or the one italicized above?1.Additionally the 271 counts even if the"1"differs by 2 or less from the correct value.

basically 3rd=2nd plus/minus atmost 2(or may be 3) right?

2nd = 1st +5. End of story.

3rd = (1st-1) give or take 2.

```
3rd = (1st-1) give or take 2.
```

i got it

```
public boolean has271(int[] nums) {
if(nums.length>2){
for(int i=0;i<nums.length-2;i++)
{
if((nums[i+1]==(nums[i]+5))&& (Math.abs(nums[i+2]-(nums[i]-1))<=2))
{
return true;
}
}
}
return false;
}
```

above passed fine

if i think pattern numbers as x y z

y=x+5

z=(x-1) plus or minus 2

followed by the value minus 1. Additionally the 271 counts even if the "1" differs by 2 or less from the correct value.

above highlighted one is in 2,7,1 or the one italicized above?

I am having trouble getting my head around what you are asking here. But let me try :

"followed by the value minus 1" means : an int in the 3rd position which is equal to the 1st int -1.

" Additionally the 271 counts even if the "1" differs by 2 or less from the correct value" means : the int in the position that the 1 is in, in the 271 above, should return true EVEN IF the value in that position (always the third position of the 3 ints) is "OUT" by as much as 2 from the correct value, and by "correct value", codingbat means "the 1st int" - in other words, the 2 in the 271 above.

See how much shorter your code is now you understand the challenge. :) Well done.

int in the position that the 1 is in

challenge should have mentioned as above instead of saying "1"

```
"OUT" by as much as 2 from the correct value, and by "correct value", codingbat means "the 1st int"
```

i was thinking above should be as below instead

```
"OUT" by as much as 2 from the correct value, and by "correct value", codingbat means "the 1st int - 1"
```

please correct me if i am wrong
So

codingbat means "the 1st int" - in other words, the 2 in the 271 above.

should indeed read :

codingbat means "the 1st int" - in other words, the 2 in the 271 above - BUT MINUS ONE IOW, whatever the first int is, but minus 1.

Anyway, you understood it all already, so don't start overthinking things now. Your own xyz explanation was what did the trick for you I think.

Java

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

2, 7, -1

or

2, 7, 0

or

2, 7, 1

or

2, 7, 2

or

2, 7, 3