Min and Max
Python
Easy
3 views
Problem Description
Read n integers. Output minimum and maximum in one line.
Input Format
First line n. Second line n integers.
Output Format
One line: min max.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
n=int(p[0])
a=list(map(int,p[1:1+n]))
mn=a[0]
mx=a[0]
for v in a[1:]:
if v<mn: mn=v
if v>mx: mx=v
sys.stdout.write(f'{mn} {mx}')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!