Problem

3/3

Maximum and minimum not from all

Theory Click to read/hide

In this task, you need to calculate:
– the number of even and odd elements;
– maximum even element;
– maximum odd element;
If you analyze the program code that is given, you can see that 4 variables are given. 
We will use one to organize the cycle (i). For other calculations, 4 more variables are needed, and we have only 3 left (j, k, m)!. 
In this case, we are looking for values ​​that we can calculate, knowing other values.
You can see that knowing the number of even elements, you can find the number of odd ones as N minus the number of even ones.
Another issue that needs to be addressed is the initial values ​​of the maximums.
In this case, since we know that all elements are non-negative, we can take initial values ​​equal to zero or any negative number.
Try to find all values ​​in one pass through the array

Problem

Given an array containing non-negative integers. Output: – maximum even element, if the number of even elements is not less than odd ones; – the maximum odd element if the number of odd elements is greater than the number of even elements. For example, for an array of six elements equal to 4, 6, 12, 17, 3, 8, respectively, the answer is 12 – largest even number, since there are more even numbers in this array.