4 ms·
Checking that the output is sorted is the easy part. Checking that the output is a (optionally stable) permutation of the input is the hard part. You can't do
by fdupress 6y ago
Checking that the output is sorted is the easy part.
Checking that the output is a (optionally stable) permutation of the input is the hard part. You can't do that dynamically if you have, for example, overwritten your input by sorting in place. And making a copy of your input is only going to be affordable in very specific and small instances on which you might as well just run a well-understood algorithm.
- ogogmad 6y agoIt looks like their algorithm can only modify the input list by swapping elements. This is guaranteed to result in a permutation.