Comments on: Max Distance between two occurrences of the same element https://demo.ritambhara.in/max-distance-between-two-occurrences-of-the-same-element/ Coding / System Design Interviews Tue, 06 Oct 2020 03:21:21 +0000 hourly 1 https://wordpress.org/?v=6.7.2 By: trsingh https://demo.ritambhara.in/max-distance-between-two-occurrences-of-the-same-element/#comment-4637 Tue, 06 Oct 2020 03:21:21 +0000 https://www.ritambhara.in/?p=11068#comment-4637 This is incorrect. We need to do hash.put(arr[I]), i) in else case too.
else
{
int dist = i – hash.get(arr[i]);
if(dist > maxDistance)
maxDistance = dist;
}

]]>