Question bank › Two Pointers
Dsa Two Pointers Medium

Maximize Distance Between Duplicates

You are given an array of integers, which can contain duplicates. Your goal is to maximize the distance between duplicates in the array. The distance is defined as the difference of indices of two same integers in the array. Your task is to return the maximum distance found. If there are no duplicates, return -1. Input format: - A single line containing N (1 ≤ N ≤ 100000), the number of elements in the array. - A second line containing N integers, each representing an element of the array. Output format: - A single integer indicating the maximum distance between duplicates, or -1 if no duplicates exist. Example: Input: 7 1 3 5 1 2 3 5 Output: 3

Key concepts

two_pointershashinggreedy

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.