The distance between two array values is the number of indices between them. Given , find the minimum distance between any pair of equal elements in the array. If no such value exists, return .
There are two matching pairs of values: and . The indices of the 's are and , so their distance is . The indices of the 's are and , so their distance is . The minimum distance is .
Complete the minimumDistances function in the editor below.
minimumDistances has the following parameter(s):
The first line contains an integer , the size of array .
The second line contains space-separated integers .
Print a single integer denoting the minimum in . If no such value exists, print .
6 arr size n = 6
7 1 3 4 1 7 arr = [7, 1, 3, 4, 1, 7]
There are two pairs to consider:
The answer is .