Smallest groups in an array

Mathematica, 24 bytes

MinimalBy[Length]@*Split

This is a composition of two functions that can be applied to a list. Split takes all groups of consecutive numbers, and MinimalBy[Length] selects those with minimal length.


Pyth, 14 12 11

mM_MmhbrQ8

Test Suite

2 bytes thanks to Jakube! And 1 byte thanks to isaacg!

Unfortunately, run length decoding doesn't quite do what we want it to do, but it will work with a minor workaround, but that makes it slightly longer than the manual implementation:

mr]d9.mhbrQ8

Credit to Jakube for finding this out.


Haskell, 38 bytes

import Data.Lists
argmins length.group

Usage example: argmins length.group $ [3,3,3,4,4,4,4,5,5,4,4,3,3,4,4] -> [[4,4],[3,3],[4,4],[5,5]].

Build groups of equal elements and find those with minimal length.