JavaEasyArrays10 min
Find the minimum and maximum in an array
Print the minimum and maximum separated by a space. Follow the stated ordering and edge-case conventions exactly. Interviewers use this task to probe algorithm selection, invariants, and boundary handling.
Input
n followed by n integers.
Output
Print the minimum and maximum separated by a space.
Constraints
1 <= n <= 100000; values between -1000000000 and 1000000000.
Example
Input
5 3 -2 9 9 0
Output
-2 9
Example 2 input
2 0 1
Output
0 1
This example exercises a further boundary or ordering case.
Public test cases (2)
Input
5 3 -2 9 9 0
Expected output
-2 9
Input
1 7
Expected output
7 7
Hints (2)
- Identify the state needed to avoid recomputing work for each element.
- Maintain the smallest and largest values in a single streaming pass.
Target complexity: time O(n) · space O(1)
