Pergunta de entrevista da empresa Holiday Tribe

Again a dsa question, In a given array find the first and last repeated element, Again i given them the solution but i was unable to optimise it properly, i shared what i'm thinking for the optimisation but that was not enough for them.