Rakuten interview question

Deduplication of table Basic solution and efficient one