Longest Sorted SubsegmentMedium

Longest Sorted Subsegment

MediumPractice library · +20 XPtwo pointersarrayssliding window

Given an array of N integers, find the length of the longest contiguous subsegment that is sorted in non-decreasing order. If there are multiple such subsegments of the maximum length, return the length of the first one encountered.

Input

The first line contains an integer N. The second line contains N space-separated integers representing the array elements.

Output

Print a single integer, the length of the longest non-decreasing subsegment.

Constraints

1 <= N <= 200000 -10^9 <= array elements <= 10^9

Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests

Example 1

Input
5
1 2 2 1 3
Output
3

The longest non-decreasing subsegments are [1, 2, 2] (length 3) and [1, 3] (length 2). The longest is 3.

Example 2

Input
7
3 1 4 1 5 9 2
Output
3

The longest non-decreasing subsegment is [1, 4] or [1, 5, 9]. The subsegment [1, 5, 9] has length 3.

Hints