This particular problem has been coming up a lot lately; you might take some inspiration from this thread which seems to be solving the next part of the problem (removing duplicates).
If this is for the eYRC then IMO posting the problem statement in a forum and saying “plz help me” is not doing your own work.