Min, Max, and Range
Python
Medium
2 views
Problem Description
Read n integers, output min, max, and (max-min). Use variables, one pass.
Input Format
Line1: n. Line2: n integers.
Output Format
One line: min max range.
Official Solution
import sys
a=sys.stdin.read().strip().split()
if not a: sys.exit(0)
n=int(a[0])
nums=list(map(int,a[1:1+n]))
mn=nums[0]; mx=nums[0]
for v in nums[1:]:
if v<mn: mn=v
if v>mx: mx=v
sys.stdout.write(f"{mn} {mx} {mx-mn}")
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!