Previous Next
0 / 21
Module DEMO-32-106DEMO-C-32

Check if Array is Sorted

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a C program to check if a 1D array is sorted in ascending order. The array is sorted if every element is less than or equal to the next element. Output "YES" if sorted, otherwise "NO".

Example 1

Input:

5 1 2 3 4 5

Output:

YES

Example 2

Input:

5 1 3 2 4 5

Output:

NO

Constraints

1 <= n <= 100

Input Format

n followed by elements

Output Format

YES or NO

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
5
1 2 3 4 5
YES
Strictly ascending.
Sample #2
Public sample
5
1 3 2 4 5
NO
3 > 2, so not sorted.
Sample #3
Public sample
1
100
YES
Single element is trivially sorted.
Sample #4
Public sample
5
1 1 1 1 1
YES
Duplicates allow equality.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings