Remove duplicates after satisfying additional conditions

 

Â