Lendscape interview question

Problem similar to remove duplicates on Leetcode