abhinas raj wrote:i was doing it like first store it in set (since set does not allow duplicate value to be stored), but if i do like that the order of the elements will be changed. so we cant
That's not necessaily true. A LinkedHashSet
does preserve addition order.
second method i was trying that match each element with all the previous elements if equal then delete this .. but that also does not look optimized. i want some optimized solution that's why i posted only question
If this is another interview question, did they
ask you to produce an optimized solution? If not, don't worry about it.
Winston