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 ] ) NEW_LINE ans = 10 ** 9 NEW_LINE for i in range ( n ) : NEW_LINE x = a [ i ] NEW_LINE