added solution for duplicates