Array Prefix Maxima and Minima
Given an array of N integers, compute two new arrays: one storing the prefix maximums and another storing the prefix minimums. The prefix maximum at index i is the maximum value among elements from index 0 to i (inclusive). Similarly, the prefix minimum at index i is the minimum value among elements from index 0 to i (inclusive). Print both arrays.
Input
The first line contains an integer N. The second line contains N space-separated integers representing the array elements.
Output
The first line should contain N space-separated integers representing the prefix maximums. The second line should contain N space-separated integers representing the prefix minimums.
Constraints
1 <= N <= 200000; -10^9 <= arr[i] <= 10^9
Example 1
5 3 1 4 2 5
3 3 4 4 5 3 1 1 1 1
Prefix maximums: [3, 3, 4, 4, 5]. Prefix minimums: [3, 1, 1, 1, 1].
Example 2
3 -1 -5 -2
-1 -1 -1 -1 -5 -5
Prefix maximums: [-1, -1, -1]. Prefix minimums: [-1, -5, -5].
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 3 1 4 2 5
3 -1 -5 -2