largest element which is smaller than the current element in the next row must be just before smallest element which is greater than or equal to the current element because rows are sorted .
if ( p - 1 >= 0 ) ans = min ( ans , abs ( arr [ i + 1 ] [ p - 1 ] - arr [ i ] [ j ] ) ) ; } } return ans ; }