01How it works
Walk the array left-to-right tracking the running maximum. Anything that breaks the non-decreasing sequence is purged — here we overwrite it with the running max so the bar chart can keep its length. The result is technically sorted, just not the same data you started with.