Second Best


Premium Content - Free Preview

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.)


End of Free Content Preview. Please Sign in or Sign up to buy premium content.

Comments

  • 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!

  • It works perfectly, thanks for brain teasing!)

  • a little intresting

  • 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.

  • 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.

Contact Us
Sign in or email us at [email protected]