Duplicate remover not working properly. | SoloLearn: Learn to code for FREE!

+1

Duplicate remover not working properly.

https://code.sololearn.com/ctlfewg3nRgb/?ref=app

c++

7/25/2020 9:31:33 AM

Tricker

3 Answers

New Answer

+1

You're accessing the same array which you are iterating based on its index. So, if you erase one element and reduce the size, you fulfill the stop condition, but you'll also skip one element: 122322 Erase x = 1, new array 12322 Next x = 2, value 3 Next x = 3, value 2 Erase x = 3, new array 1232 Next x = 4 < size So you are missing the number of elements, which you reduced the size for at the end of each array.

+2

See here, a possible solution: https://code.sololearn.com/cZy6Kj8iqLU7/?ref=app

+1

Sandra Meyer thanks for pointing out the error. That helped me to come up with a solution: https://code.sololearn.com/c2968L8hLXCc/?ref=app