if duplicates are found , b [ x ] is replaced with minimum of the previous and current position 's  shortest distance
b . put ( x , Math . min ( d , b . get ( x ) ) ) ; } } int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int x = a [ i ] ;