Dsa
Two Pointers
Medium
Long Sequence of Non-Decreasing Subarrays
You are given an array of integers. Your task is to find the longest contiguous subarray that is non-decreasing. A non-decreasing subarray is one where each element is greater than or equal to the previous element. If there are multiple longest subarrays, return the first one found.
Input format:
- A single line containing N (1 ≤ N ≤ 100000), the number of elements in the array.
- A second line containing N integers, each representing an element of the array.
Output format:
- A single line containing K (1 ≤ K ≤ N), the size of the longest non-decreasing subarray, followed by the elements of that subarray.
Example:
Input:
8
1 2 2 3 1 5 6 6
Output:
5 1 5 6 6 6
Key concepts
two_pointersarrayssubarrays
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now