In the given unsorted array, which may also contain duplicates, find the minimum distance between 2 different numbers in the given array.
Distance between 2 numbers in an array: absolute difference between the indices + 1
Input array be
Time Complexity: O(n^2) , Order is O(n^2) because of the 2 loops.
- Use two loops, one loop finds any one of the element and second loop finds the other element in the same way.
- Subtract the indices we get the distance between them.
- Do this until we get the minimum distance.