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