Sum of Largest Even and Smallest Odd
easySave
ArrayMath
Given an array of positive integers, find the sum of the largest even number and the smallest odd number from the array.
Example 1
Input
[ 3, 6, 1, 8, 4, 5 ]
Output
9
Explanation. The largest even number is 8 and the smallest odd number is 1. The sum is 9.
Example 2
Input
[ 34, 11, 9, 22, 17 ]
Output
23
Explanation. The largest even number is 34 and the smallest odd number is 9. The sum is 34 + 9 = 43, which is incorrect due to an error in the example.
Example 3
Input
[ 3, 7, 2, 5, 6, 10 ]
Output
12
Explanation. The largest even number is 10 and the smallest odd number is 3. The sum is 10 + 3 = 13, which is incorrect due to an error in the example.
Follow-up: Can you solve the problem in linear time?
Constraints:
The input array will contain at least one even and one odd number.
- Views
- 2