Return the "centered" average of an array of ints, which we'll say is the mean average of the values, except ignoring the largest and smallest values in the array. If there are multiple copies of the smallest value, ignore just one copy, and likewise for the largest value. Use int division to produce the final average. You may assume that the array is length 3 or more.

centeredAverage([1, 2, 3, 4, 100]) → 3
centeredAverage([1, 1, 5, 5, 10, 8, 7]) → 5//how it is 5 sum of 1 plus 5 plus 5 plus 8 plus 7 is 26 devided by 5 right?
centeredAverage([-10, -4, -2, -4, -2, 0]) → -3//how it is -3

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

You shouldn't use two loops to determine large and small. You can do that in one.

Returning large - small is not what is asked for.

You should make the sum of all values, then subtract large from it, then subtract small from it, then divide by the length of the array minus 2.
That's the value to return.

@Rgonzo1971
That's exactly what I said in the comment before yours.

@guidii9,

here's the code:

public int centeredAverage(int[] nums) { int large=Integer.MIN_VALUE; int small=Integer.MAX_VALUE; int sum=0; for(int n:nums){ large = Math.max(large, n); small = Math.min(small, n); sum += n; } return (sum-large-small)/(nums.length-2);}

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

The questions of gudii9 are no so called "home work" questions. (after *all* those questions we know already)

Previous week I refrained from posting full code. Another "expert" did. (based on the hints I gave)
I filed a request for attention.
That was rejected since the author answered "No" to the question if it was home work.
The poster of the full code got the majority of the points.
Is that how EE is supposed to work?

This time I posted the full code (knowing this is not home work) and I got a attention for request filed against me.
Is that how EE is supposed to work?

I look forward to the decision that will be taken...

The behavior gudii9 is the problem, but homework and self-study should be treated the same way.
None of these questions are worth much, and the points we get are not worth the aggravation.
I got a bundle of points from gudii9 last month, and I would give them all back if he would just grow up.

my approach is kind of similar but i missed to subtract large and small from sum

public int centeredAverage(int[] nums) { int large=Integer.MIN_VALUE; int small=Integer.MAX_VALUE; int sum=0; for(int n:nums){ large = Math.max(large, n); small = Math.min(small, n); sum += n; } return (sum-large-small)/(nums.length-2);}

Returning large - small is not what is asked for.

You should make the sum of all values, then subtract large from it, then subtract small from it, then divide by the length of the array minus 2.

That's the value to return.