Check Sorted
Python
Easy
3 views
Problem Description
Read n integers. Output YES if list is non-decreasing else NO.
Input Format
First line n. Second line n integers.
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]))
ok=True
for i in range(1,n):
if a[i]<a[i-1]:
ok=False
break
sys.stdout.write('YES' if ok else 'NO')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!