Definitions
- A subsequence may not be contiguous, e.g.
[1, 1, 1]
is a subsequence of[1, 2, 1, 2, 1]
. - An equal subsequence is a subsequence in which every element is equal.
- The longest equal subsequence may not be unique, e.g.
[1, 1]
and[2, 2]
are both longest equal subsequences of[2, 1, 1, 2]
.
Input
A non-empty list of positive integers in one of the format below:
- as the native implementation of an array of positive integers in your language
- as a string of newline-separated integers in decimal
- as a string of newline-separated integers in unary
- any other reasonable formats
Output
All of the longest equal subsequences in any order in one of the formats below:
- as a 2D nested array in your language (if the input is an array)
- as a flattened array with the equal elements being contiguous
- any other reasonable format
Scoring
Although we are looking for something long, the code used should be as short as possible in terms of number of bytes, since this is code-golf
Testcases
Inputs:
[1, 2, 3]
[1, 2, 2, 1]
[1, 2, 3, 2, 1]
[1, 2, 1, 2, 3, 4, 1]
Outputs:
[[1], [2], [3]]
[[1, 1], [2, 2]]
[[1, 1], [2, 2]]
[[1, 1, 1]]
Note that for the outputs above, any order is valid.
A flattened array is also valid, as long as the equal elements are contiguous.
1 2 3
,1 1 2 2
,1 1 2 2
,1 1 1
? \$\endgroup\$