educative.io

Misleading problem statement

Problem statement:

Given an array of sorted numbers, remove all duplicates from it. You should not use any extra space ; after removing the duplicates in-place return the length of the subarray that has no duplicate in it.

In the solution, elements are not removed from the array, they just shifted to the end of the array. I think, either the problem statement should be different (e.g. “…shift all duplicates to the end…”) or the solution should be modified to actually remove duplicates.

3 Likes

that’s right, its misleading problem statement. Problems statement tells to return the length of the subarray with no duplicates. So, when I returned arr.size(), it resulted in a error.
Solution code doesn’t handle deletion of last few blocks.

Agreed. Duplicates are not removed with this solution, despite the problem statement explicitly calling for it.

Hi @Stanislav_Dzhus,

Thank you for pointing this out. The problem statement should instead be:
Given an array of sorted numbers, shift all duplicates to the right. You should not use any extra space ; after shifting the duplicates in-place return the length of the subarray that has no duplicate in it.

We will correct this shortly.

when will you correct it?

2 Likes

The structure of the problem reminds me more of idiomatic C than of Python. Since we can only have one return value in C and we need to keep track of the length of the array, it is common to pass a pointer to an array into a function and return the length of the array.

Inspired by C style, along with Python slices, we could modify main() as shown below. The proposed solution will work with the given problem statement, while providing the given time and space complexity performance.

def main():
    arr = [2, 3, 3, 3, 6, 9, 9]
    new_len = remove_duplicates(arr)
    arr = arr[:new_len]
    print(f'len: {new_len} no_dups: {arr}')

It’s been almost a year since this issue was raised. Can this be fixed?

I have no idea how such a simple course charges such a high premium and yet consistently has these errors in the material.

3 Likes

The problem still hasn’t been updated. The problem statement says to remove duplicates and your solution doesn’t remove the duplicates.

This issue was called out almost 2 years ago and a simple text change still hasn’t been updated. Please correct this.

3 Likes

@Aiyan_Tufail, the problem statement is still a bit misleading; I’m a new platform member and love the content so far.

this issue is damn near 2 years old now and no one can be bothered to fix it. this is the perfect example of the state of modern software development. backlogs are literally black holes. issues get put on the backlog never to be seen again.

Thanks for pointing this out.
Move all the unique elements at the beginning of the array and after moving return the length of the subarray that has no duplicate in it. This line clarifies it.