Pack Consecutive Duplicates Into Sublists

Problem Given a list, group runs of consecutive equal elements into sublists (run-length grouping). Only adjacent equal elements are grouped; a value that reappears after a different value starts a new run.

Input / Output

  • Input: a list xs of comparable elements.
  • Output: a list of sublists, each holding one maximal run of consecutive equal elements, in original order.

Constraints

  • 0 ≤ n ≤ 10^4.
  • An empty input yields an empty list.
  • Equality is by element value.

Example

  • [a,a,b,c,c,c] → [[a,a],[b],[c,c,c]].
  • [a,b,a] → [[a],[b],[a]] — the second a is a new run, not merged with the first.
added …
LeaderboardSalaryAccount