Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Hi,

i am trying below challenge

http://codingbat.com/prob/p110019

I have not understood on problem statement when they say like

i wrote as below

some test cases are failing as below

Expected Run

array667({6, 6, 2}) → 1 1 OK

array667({6, 6, 2, 6}) → 1 1 OK

array667({6, 7, 2, 6}) → 1 0 X

array667({6, 6, 2, 6, 7}) → 2 1 X

array667({1, 6, 3}) → 0 0 OK

array667({6, 1}) → 0 0 OK

array667({}) → 0 0 OK

array667({3, 6, 7, 6}) → 1 0 X

array667({3, 6, 6, 7}) → 2 1 X

array667({6, 3, 6, 6}) → 1 1 OK

array667({6, 7, 6, 6}) → 2 1 X

array667({1, 2, 3, 5, 6}) → 0 0 OK

array667({1, 2, 3, 6, 6}) → 1 1 OK

please advise

i am trying below challenge

http://codingbat.com/prob/p110019

I have not understood on problem statement when they say like

count instances where the second "6" is actually a 7.

i wrote as below

```
public int array667(int[] nums) {
int count=0;
for(int i=0;i<nums.length-1;i++)
{
if(nums[i]==nums[i+1])
count++;
}
return count;
}
```

some test cases are failing as below

Expected Run

array667({6, 6, 2}) → 1 1 OK

array667({6, 6, 2, 6}) → 1 1 OK

array667({6, 7, 2, 6}) → 1 0 X

array667({6, 6, 2, 6, 7}) → 2 1 X

array667({1, 6, 3}) → 0 0 OK

array667({6, 1}) → 0 0 OK

array667({}) → 0 0 OK

array667({3, 6, 7, 6}) → 1 0 X

array667({3, 6, 6, 7}) → 2 1 X

array667({6, 3, 6, 6}) → 1 1 OK

array667({6, 7, 6, 6}) → 2 1 X

array667({1, 2, 3, 5, 6}) → 0 0 OK

array667({1, 2, 3, 6, 6}) → 1 1 OK

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.

So your code would detect

6,6 (which is correct)

but also

3,3 (which is not)

Also the instructions say you need to find pairs like this:

6,6

or

6,7

So you want code something like this:

```
public int array667(int[] nums) {
int count=0;
for(int i=0;i<nums.length-1;i++)
{
if(nums[i]==6 && nums[i+1] == 7)
count++;
}
return count;
}
```

which would detect one of those pairs - the 6,7 combination.So you need to add code to make it also recognize the 6,6 combination.

```
public int array667(int[] nums) {
int count=0;
for(int i=0;i<nums.length-1;i++)
{
if(nums[i]==nums[i+1]|| nums[i]==6&&nums[i+1]==7)
count++;
}
return count;
}
```

i wrote as above . It pass all the tests.does it looks ok?

array667({1,1})

```
if (nums[i]==nums[i+1] ... )
```

in the test as that's just checking if two numbers in the sequence are identical.

The problem is asking for specifically checking for 6s and 7s, not any two numbers.

Doug

, you don't really want this

By removing that as below

```
public int array667(int[] nums) {
int count=0;
for(int i=0;i<nums.length-1;i++)
{
if(nums[i]==6&&nums[i+1]==7)
count++;
}
return count;
}
```

i am failing test cases as below

```
Expected Run
array667({6, 6, 2}) → 1 0 X
array667({6, 6, 2, 6}) → 1 0 X
array667({6, 7, 2, 6}) → 1 1 OK
array667({6, 6, 2, 6, 7}) → 2 1 X
array667({1, 6, 3}) → 0 0 OK
array667({6, 1}) → 0 0 OK
array667({}) → 0 0 OK
array667({3, 6, 7, 6}) → 1 1 OK
array667({3, 6, 6, 7}) → 2 1 X
array667({6, 3, 6, 6}) → 1 0 X
array667({6, 7, 6, 6}) → 2 1 X
array667({1, 2, 3, 5, 6}) → 0 0 OK
array667({1, 2, 3, 6, 6}) → 1 0 X
```

Please advise

return the number of times that two 6's are next to each other

how to incorporate above in to if condition . please advise

```
if(nums[i]==6&&nums[i+1]==7)
```

as of now i am able to check 6 and 7 are adjacent. Since i am using 6 in this condition not sure how to check if another 6 also adjacent. Not able to think. Also i wonder why thinking is hard sometimes. please advise

you can then come back to http://codingbat.com/prob/p110019 with a new idea.

```
if(nums[i]==6 && (nums[i+1] == 6 || nums[i+1] == 7))
```

And how we can use it in the whole method like this?

```
public int array667(int[] nums) {
int count=0;
for(int i=0;i<nums.length-1;i++)
{
if(nums[i]==6 && (nums[i+1] == 6 || nums[i+1] == 7))
count++;
}
return count;
}
```

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 trial```
public int array667(int[] nums) {
int count=0;
for(int i=0;i<nums.length-1;i++)
{
if(nums[i]==6 && (nums[i+1] == 6 || nums[i+1] == 7))
count++;
}
return count;
}
```

i like above solution where we can check same index for 2 different values 6 as well as 7. This is new perspective opened for me.

This is new perspective opened for me.Excellent. That's the whole point of expert's exchange :)

Glad you've got this now.

Doug

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.