Check in all four possible directions
temp1 = Distance ( arr , i + 1 , j ) NEW_LINE temp2 = Distance ( arr , i - 1 , j ) NEW_LINE temp3 = Distance ( arr , i , j + 1 ) NEW_LINE temp4 = Distance ( arr , i , j - 1 ) NEW_LINE