I have to write a method that counts the highest left and highest
right heights of the current index.
Let's say we have the array {1,4,7,3,2}, so for index 1 ( height 4) - the `maxLeftHeight=1`

, `maxRightHeight=7`

and for index 2(height 7) - `maxLeftHeight=4`

, `maxRightHeight=3`

and so on...

The first and the last indexes don't count so the array starts counting at 1 and finishes counting at `array.length-1`

I tried to write a code for this and this is what I got:

```
public String getCurrentMaxHeights(int[] height)
{
int maxLeft = 0;
int maxRight = 0;
String st = "";
for (int i = 1; i < height.length - 1; i++)
{
maxRight = Math.max(height[i + 1], height[height.length - 1]);
maxLeft = Math.max(height[i - 1], height[0]);
st += "The max left height for " + height[i] + " is " + maxLeft +
" the max right height is " + maxRight + " \n";
}
return st;
}
```

**output:**

The max left height for 1 is 2 the max right height is 3 The max left height for 1 is 2 the max right height is 4 The max left height for 4 is 2 the max right height is 3 The max left height for 1 is 4 the max right height is 3 The max left height for 1 is 2 the max right height is 3 The max left height for 2 is 2 the max right height is 3

This is wrong, how can I fix it to be right?

Try this

`selectedIndex`

is the`index`

you start from, Moreover, add check if there is values on the`left`

or the`right`

or notAnother way with complete example if you want it with

`int array`

not`Integer`

: