#C14242. Efficient Maximum Finder
Efficient Maximum Finder
Efficient Maximum Finder
You are given an array of integers for each test case. Your task is to find the maximum element of the array. If the array is empty, output None
(without quotes).
This problem was originally implemented using a naive approach that iterates over each element. However, an optimized version can utilize the built‐in max
function available in many programming languages to achieve the result more efficiently in terms of time complexity. In this problem, you only need to output the maximum value for each provided array.
Note: The input includes multiple test cases. For each test case, the first number indicates the size of the array, followed by the array elements. For an empty array, the size will be 0.
Additionally, while some implementations may compare the execution times between two approaches, for the purpose of this competition you only need to compute and output the maximum value.
inputFormat
The first line of input contains an integer T
which denotes the number of test cases.
For each test case, the first line contains an integer N
denoting the number of elements in the array. If N > 0
, the next line contains N
space-separated integers representing the array elements.
If N
is 0, then the array is empty.
outputFormat
For each test case, output a single line containing the maximum integer in the array. If the array is empty, output None
.
5
5
1 2 3 4 5
5
5 4 3 2 1
5
-1 -2 -3 -4 -5
0
1
0
5
5
-1
None
0
</p>