Pergunta de entrevista da empresa Walmart

Find the first duplicate in the array having the numbers upto length n. Input: [1,3,5,2,4] Output: No Duplicate Input: [1,4,2,4,5,2] Output: 4 Without extra space