How to figure out if an array is first increasing, then decreasing [C++]

Revision en2, by Qualified, 2020-07-18 18:21:00

Given an integer $$$n$$$, $$$1 <= n <= 10^5$$$, and an array $$$a$$$ consisting of $$$n$$$ elements, figure out if the array is a good array. A good array is defined to be first increasing, then decreasing. Note that an increasing array or decreasing array is a good array. An increasing array is an array such that every next element of every element(that is not the last) has to be greater than or equal to that element. A decreasing array is an array such that every next element of every element(that is not the last) has to be less than or equal to that element.

Example:

Input:

5 1 2 4 3 1

Output: YES

Input:

3 3 2 1

Output: YES

Input:

5 1 2 3 4 4

Output: YES

Input:

5 5 4 2 1 1

Output: YES

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Qualified 2020-07-18 18:21:00 5 Tiny change: 'nOutput:\nNO\n\nInput:' -> 'nOutput:\nYES\n\nInput:'
en1 English Qualified 2020-07-18 18:00:30 799 Initial revision (published)