Problem
Input format
The first line contains `n`. The second line contains `n` integers separated by spaces. - `1 <= n <= 1000` - `-1000 <= v[i] <= 1000` - a single nonzero element forms an alternating-sign run of length `1`
Output format
The first line contains a single natural number: the length of the longest alternating-sign run. The second line contains the elements of that run, separated by spaces.
Example
8 3 -1 4 -2 5 5 -6 7
5 3 -1 4 -2 5
Stuck?
Use the Get Hint button in the action bar to reveal a guided hint.
💬 Discussion
Loading...No comments yet. Be the first to start the discussion!
Sample cases (from the problem)
Sample Case 1
8 3 -1 4 -2 5 5 -6 7
5 3 -1 4 -2 5
Solve it your way first
Community solutions unlock after you submit a passing solution. Don't peek.
Ready to solve this challenge?
Create a free account to write code, submit solutions, and track your progress.