Second Best

The extreme grades on a test might be outliers. You decide you want to ignore the extremes and look at the next grade in a given array of grades.

Challenge

You will be given an array `ar` with at least 3 elements. Find the sum of the following 3 elements in an `ar`:

• The 2nd
• The 2nd-to-last
• The middle element. If `ar` has an even number of elements, the middle element is the last element in the 1st half.

If an element belongs to more than one category, it should only be counted once. For example, when given `{1,2,3,4}`, you should print `5`, the sum of 2 and 3. (`2` should not be double-counted even though its both the 2nd and middle element.)

• Peter Lacres

Other output is incorrect. Is it possible to show me which one is incorrect? That way i can adjust my code accordingly. Now i'm just guessing, thx!

• zkvarz

It works perfectly, thanks for brain teasing!)

• kevintaw

a little intresting

a solution:

my code

• Bolke

Yes, I don't understand why no answers are given. If you are unable to solve, you'll keep guessing, and if you ARE able to solve, you may have found something really clunky and ugly, and you really want to know what is a better way of doing it.

• Learneroo

You can view featured answers to many problems after you get it correct. We may also allow one to use the "cheat" option to view these answers even earlier.