It seems to me this should be the solution:

```
public int[] notAlone(int[] nums, int val) {
int[] result = new int[nums.length] ;
for (int i = 0 ; i < nums.length ; i++) {
boolean isAlone = (i > 0 && i < nums.length-1) && (nums[i-1] != nums[i]) && (nums[i+1] != nums[i]) ;
int value = isAlone ? Math.max(nums[i-1], nums[i+1]) : nums[i] ;
result[i] = value ;
}
return result ;
}
```

But this code passes all the tests:

```
public int[] notAlone(int[] nums, int val) {
int[] result = new int[nums.length] ;
for (int i = 0 ; i < nums.length ; i++) {
boolean isAlone = (i > 0 && i < nums.length-1) && (nums[i-1] != nums[i]) && (nums[i+1] != nums[i]) ;
int value = isAlone ? Math.max(nums[i-1], nums[i+1]) : nums[i] ;
result[i] = Math.max(nums[i],value) ; // This line is different
}
return result ;
}
```

And just like in your solution, I don't use the "val" parameter passed in. Which in itself is very odd.

I hope you can see how this translates from the way the problem is described into code - each step of the problem is one line inside the loop.

Your solution is modifying the array as it goes, which also may be fine but does change the problem (if you start with 1,2,3 and modify "1" to become "5" (e.g.) then when you test "2" its neighbors will be 5,3 instead of 1,3).

It's hard for me to give you advice since I don't really understand why their test answers are correct. I must be misreading their problem statement somehow.

I'd like to see what other experts think of this and what's going on here :)

Doug