Best test for duplicate values?

Pages: 12
After uniquefy is called, the value at those positions are no longer duplicates. Does it retain the same value? Yes. Does it violate the constraints? No.

I want to replace either the first or the second duplicate value


Does not say "I want to sometimes replace the first and sometimes replace the second duplicate value."

Even if it did, simply reversing the order the array was traversed every other call would still keep the execution time considerably faster than yours.
> Does not say "I want to sometimes replace the first and sometimes replace the second duplicate value."

Has said that consistently right through.

In the very first post in this thread.
Example:
input vector has values {1,12,8,1,7,15,20,9,12}
output vector after function {17,12,8,1,7,15,20,9,2}

where the boldfaced number have been randomly modified.



> simply reversing the order the array was traversed every other call would
> still keep the execution time considerably faster than yours.

Yes it will 'keep the execution time considerably faster than yours'

As would this: inline void ems_uniqueify(std::vector<int>& v) {}

Neither would meet the requirements.

'Every other call' is naive; there is nothing random about it. Even if that was randomly decided, if a value appears thrice, the first or the last would be replaced with a probability of 50%, the middle one would be replaced with a probability of 100%.


I'm not going to pursue this increasingly meaningless discussion any more. I've have been satiated.

Last edited on
You know, going back through the posts, I think you're probably right about what the OP wanted, however I wouldn't call his wording unambiguous with regards to that constraint anywhere he mentioned it.

Every other call is naive. Randomly choosing the initial start point for iterating through the vector would be less so. It would certainly withstand casual scrutiny by most users, and it would retain the speed advantage.


Topic archived. No new replies allowed.
Pages: 12