In the first case, the “correct case”, you’re looking at the return values from the
In the second case, the “incorrect case”, you’re looking at what happens to the original
list each time you pass it into the
heap_add_or_replace function, you copy the input
list the first time you do a sort. The result of that sort, and everything that’s done after that isn’t reflected in the original list. So the original list you passed in doesn’t ever get sorted or filtered for duplicates. That’s why the two cases are different.
CLICK HERE to find out more related problems solutions.