find shortest distance for given number x,y in the array