Check Array Sorted For Each Case
Programming Interview
Medium
4 views
Problem Description
Consider {x}. Each testcase has n and array. Output YES if array is non-decreasing else NO.
Input Format
First integer t. For each: n then n integers.
Output Format
t lines YES/NO.
Sample Test Case
Input:
2
5
1 2 2 5 9
4
3 2 1 1
Constraints
Sum of n over all testcases
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p:
sys.exit(0)
it=iter(p)
t=int(next(it))
out=[]
for _ in range(t):
try:
n=int(next(it))
except Exception:
n=0
prev=None
ok=True
for i in range(n):
try:
x=int(next(it))
except Exception:
x=0
if prev is not None and x<prev:
ok=False
prev=x
out.append('YES' if ok else 'NO')
sys.stdout.write('\
'.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!