53. Is the Array Sorted?
Foundation1000 ms256 MBSolved by 0%
Print Yes if the array is sorted in non-decreasing order, each element
is greater than or equal to the one before it, and No otherwise.
Equal neighbours are fine. [1, 2, 2, 3] is sorted.
Constraints - `1 ≤ n ≤ 100000` - `-1000000 ≤ a[i] ≤ 1000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
Output
Print exactly one word: Yes or No.
Input5
1 2 3 4 5
OutputYes
Noteis strictly ascending
Input4
1 3 2 4
OutputNo
Notehas one pair out of order in the middle
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.