Check if any point exists in a plane whose Manhattan distance is at most K from N given points | Function to check if there exists any point with at most K distance from N given points ; Traverse the given n points ; Stores the count of pairs of coordinates having Manhattan distance <= K ; For the same coordinate ; Calculate Manhattan distance ; If Manhattan distance <= K ; If all coordinates can meet ; If all coordinates can 't meet ; Driver code
def find ( a , b , N , K ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT count = 0 NEW_LINE for j in range ( N ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT continue NEW_LINE DEDENT dis = abs ( a [ i ] - a [ j ] ) + abs ( b [ i ] - b [ j ] ) NEW_LINE if ( dis <= K ) : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT if ( count == N - 1 ) : NEW_LINE INDENT return " Yes " NEW_LINE DEDENT DEDENT return " No " NEW_LINE DEDENT DEDENT N = 5 NEW_LINE A = [ 1 , 0 , 2 , 1 , 1 ] NEW_LINE B = [ 1 , 1 , 1 , 0 , 2 ] NEW_LINE K = 1 NEW_LINE print ( find ( A , B , N , K ) ) NEW_LINE