Skip to main content
1 of 4
Cristian Lupascu
  • 8.7k
  • 2
  • 25
  • 52

Haskell, 67 bytes

(q:r)!x|null q||last q<=x=(q++[x]):r|1<2=q:r!x
_!x=[[x]]
foldl(!)[]

Try it online.

Cristian Lupascu
  • 8.7k
  • 2
  • 25
  • 52