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
Peter Lacres
Jan 10, 5:12 AMOther 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!
Victoria Holland
Feb 7, 5:35 AMAn important thing to remember when creating else-if blocks with multiple conditions: always test the more restrictive conditions first, or the less restrictive ones will match both cases and the wrong statement may be run.
zkvarz
Feb 14, 10:40 AMIt works perfectly, thanks for brain teasing!)
kevintaw
Jun 13, 10:46 PMa little intresting
thales
Jul 18, 10:32 AMa solution:
my code
Bolke
Sep 20, 6:05 PMYes, 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
Sep 20, 6:22 PMYou 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.