solved greedy sorting