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
Problem Comments
3 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers3
Suggested Problems
-
3480 Solvers
-
3818 Solvers
-
Back to basics 21 - Matrix replicating
1788 Solvers
-
575 Solvers
-
Help the Patriots get to the Super Bowl
185 Solvers
More from this Author14
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Hello, the problem could be solved by hard-coding the values of the test cases.
Can you add test case(s) to take care of the issue? Let me know if you need help in doing that.
Of course you can do hard-coding, but that will also make you far away from the smallest solution size. There are always cheaters in this community and you can never take care of all of them.
@Dyuman Joshi
Also I don't know how to get the best error of a randomly generated test case without leaking the algorithm to get the best error.