JS Essentials Exam 6 august 2019 Find the Special Subsequence
Здравейте,колеги!
Някой може ли да сподели решение на 2 задача от този изпит. Ето условието:
Problem 2. Find the Special Subsequence
Your task is to find the longest special subsequence in the given array.
The special subsequence is a sequence, which contains negative-positive-negative or positive-negative-positive numbers in that order. If there are 2 special sequences with equal length get the first one.
Input
An array - contains the given numbers from the sequence.
Output
If there is no special subsequence print: "In {sequence} no special sequence is found"
Otherwise show each of the elements in that sequence separated with comma and single space (", ")
"The longest sequence is {sequence}"
Note:
0 (zero) is neither positive nor negative number, so it always breaks the sequence
Examples
Input Output Comment
[1, -2, 1, -1, 2, 1, -1] The longest sequence is 1, -2, 1, -1, 2 There are 2 special subsequences. The first contains 5 numbers, the second containes 2 numbers, so we print the length of the first one.
[-1, -1, -1, 1, -1] The longest sequence is -1, 1, -1
[1, 2, 3, 4, 5] In 1, 2, 3, 4, 5 no special sequence is found
Благодаря!
Заповядайте, моето решение https://pastebin.com/crCQGzaK.
Тествано е в judge и дава максималния брой точки.