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
Problem Comments
-
3 Comments
Dyuman Joshi
on 14 Jan 2023
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.
埃博拉酱
on 15 Jan 2023
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.
埃博拉酱
on 15 Jan 2023
@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.
Solution Comments
Show commentsProblem Recent Solvers2
Suggested Problems
-
2476 Solvers
-
287 Solvers
-
302 Solvers
-
615 Solvers
-
419 Solvers
More from this Author12
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!