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
function find ( a , b , N , K ) { for ( let i = 0 ; i < N ; i ++ ) { let count = 0 ; for ( let j = 0 ; j < N ; j ++ ) { if ( i == j ) { continue ; } let dis = Math . abs ( a [ i ] - a [ j ] ) + Math . abs ( b [ i ] - b [ j ] ) ; if ( dis <= K ) { count ++ ; } if ( count == N - 1 ) { return " " ; } } } return " " ; } let N = 5 ; let A = [ 1 , 0 , 2 , 1 , 1 ] ; let B = [ 1 , 1 , 1 , 0 , 2 ] ; let K = 1 ; document . write ( find ( A , B , N , K ) ) ;