Sollicitatievraag bij Connected

Technical Interview: There will an algorithm written (max distance between same elements in array) this is the questions where I didn't get it right initially, after some help I got it but I guessed I missed the trick here.