WildSequence
TCO19 SRM 758 · 2019-05-09 · by misof
Problem Statement
A sequence of distinct integers is called wild if it has the following properties:
- It never increases twice in a row.
- It never decreases twice in a row.
For example, {4, 7, 3, 9, 1, 5, 2} is a wild sequence but {4, 7, 3, 6, 9, 1, 5, 2} is not, as it increases twice in a row: from 3 to 6 and then from 6 to 9.
You are given the
Constraints
- head will be between 0 and 10^6, inclusive.
- rest will contain between 0 and 49 elements, inclusive.
- Each element of rest will be between 0 and 10^6, inclusive.
- The elements of rest will be distinct.
- head will be distinct from all elements of rest.
20
{10, 30}
Returns: {20, 10, 30 }
Both {20, 10, 30} and {20, 30, 10} are correct answers. You may return either of them.
20
{10, 30, 40}
Returns: {20, 10, 40, 30 }
This time, there are three correct answers: {20, 10, 40, 30}, {20, 30, 10, 40}, and {20, 40, 10, 30}. You may return any one of these sequences.
4
{1, 2, 3, 6, 7, 5}
Returns: {4, 7, 5, 6, 1, 3, 2 }
10
{}
Returns: {10 }
10
{20}
Returns: {10, 20 }
Submissions are judged against all 150 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class WildSequence with a public method vector<int> construct(int head, vector<int> rest) · 150 test cases · 2 s / 256 MB per case