Misleading output

Misleading output for test case [2, 2, 2, 11]

Type your question above this line.

Hello everyone,

I’ve just checked the provided solution and found out that with the test case [2, 2, 2, 11] the output result is [2, 11, 2, 11] instead of the expected [2, 11, 2, 2] if I’m not mistaken. My proposal is to add swapping of the elements. Any clarification or feedback is highly appreciated.


Hi @Dmitry,

When we remove all the duplicate values from the list, we will get [2, 11] whose length is 2.

For test case

When we remove all duplicate values from the list, again, we will get [2, 11] whose length is 2.

So both of the test cases give us the same result.

I hope I have answered your query; please let me know if you still have any confusion.

Thank You :blush:

Hi @Abdul_Mateen , thank you for your explanation. Doesn’t matter what elements go after all the unique elements, that’s why [2, 11, 2, 11] and [2, 11, 2, 2] both have the same result - 2 unique elements at the beginning.
In the problem’s test cases explanation also says about removing the duplicates:

Input: [2, 2, 2, 11]
Output: 2
Explanation: The first two elements after removing the duplicates will be [2, 11].

The reason I asked was the line “move all duplicates at the end of the array” in the problem statement. I thought I was necessary to move all the duplicates at the end of the array as the algorithm does this sorting in place. This line may substituted with “move all unique elements to the beginning of the array” for better understanding, but it’s a subtle detail. Everything is clear for me now.

1 Like