Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Sort Sorted Groups by ssk8
def sorted_groups(items: list[int]) -> list[int]:
groups, group = [], []
for item in items:
if (new:=group + [item]) in (sorted(new), sorted(new, reverse=True)):
group = new
else:
groups.append(group)
group = [item]
groups.append(group)
return [i for s in sorted(groups) for i in s]
Sept. 13, 2022
Comments: