Problem 57545. Integer vector optimal lossless deduplication

You're given an integer vector A, a Min scalar and a Max scalar. You can assume all elements in A are in [Min,Max] range, and numel(A)<=Max-Min+1.
Your function should output also an integer vector B, whose elements are also in [Min,Max] range, and whose numel is the same as A (numel(B)==numel(A), i.e., lossless). What is different is that your B must not have duplicate values (i.e., deduplication).
There may be more than one possible Bs meeting the conditions above. You need to give the "best" one. The "best" is defined as the B making Error=sum(abs(sort(A)-sort(B))) smallest (i.e. optimal) among all possible Bs.

Solution Stats

100.0% Correct | 0.0% Incorrect
Last Solution submitted on Jan 15, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers2

Suggested Problems

More from this Author12

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!