Introduction
Let's observe the following array:
[1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1]
A group consists of the same digits next to each other. In the above array, there are 5 different groups:
[1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1]
1, 1, 1
2, 2
1, 1, 1, 1
2, 2, 2
1, 1, 1
The smallest group of these is [2, 2]
, so we output [2, 2]
.
Let's take another example:
[3, 3, 3, 4, 4, 4, 4, 5, 5, 4, 4, 3, 3, 4, 4]
3, 3, 3
4, 4, 4, 4
5, 5
4, 4
3, 3
4, 4
You can see that there are multiple groups with the same length. The smallest groups are:
[3, 3], [4, 4], [4, 4] and [5, 5].
So we just output [3, 3], [4, 4], [4, 4], [5, 5]
in any reasonable format. You may output these in any order.
The Task
Given an array consisting of only positive integers, output the smallest group(s) from the array. You can assume that the array will contain at least 1 integer.
Test cases
Input: [1, 1, 2, 2, 3, 3, 4]
Output: [4]
Input: [1]
Output: [1]
Input: [1, 1, 10, 10, 10, 100, 100]
Output: [1, 1], [100, 100]
This is code-golf, so the submission with the least amount of bytes wins!
11101010100100
doesn't seem correct for input :p. \$\endgroup\$