Count number of coordinates from an array satisfying the given conditions | Function to count the number of coordinates from a given set that satisfies the given conditions ; Stores the count of central points ; Find all possible pairs ; Initialize variables c1 , c2 , c3 , c4 to define the status of conditions ; Stores value of each point ; Check the conditions for each point by generating all possible pairs ; If arr [ j ] [ 0 ] > x and arr [ j ] [ 1 ] == y ; If arr [ j ] [ 0 ] < x and arr [ j ] [ 1 ] = = y ; If arr [ j ] [ 1 ] > y and arr [ j ] [ 0 ] == x ; If arr [ j ] [ 1 ] < y and arr [ j ] [ 0 ] = = x ; If all conditions satisfy then point is central point ; Increment the count by 1 ; Return the count ; Driver Code
def centralPoints ( arr , N ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT c1 = 0 NEW_LINE c2 = 0 NEW_LINE c3 = 0 NEW_LINE c4 = 0 NEW_LINE x = arr [ i ] [ 0 ] NEW_LINE y = arr [ i ] [ 1 ] NEW_LINE for j in range ( N ) : NEW_LINE INDENT if ( arr [ j ] [ 0 ] > x and arr [ j ] [ 1 ] == y ) : NEW_LINE INDENT c1 = 1 NEW_LINE DEDENT if ( arr [ j ] [ 1 ] > y and arr [ j ] [ 0 ] == x ) : NEW_LINE INDENT c2 = 1 NEW_LINE DEDENT if ( arr [ j ] [ 0 ] < x and arr [ j ] [ 1 ] == y ) : NEW_LINE INDENT c3 = 1 NEW_LINE DEDENT if ( arr [ j ] [ 1 ] < y and arr [ j ] [ 0 ] == x ) : NEW_LINE INDENT c4 = 1 NEW_LINE DEDENT DEDENT if ( c1 + c2 + c3 + c4 == 4 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ [ 1 , 0 ] , [ 2 , 0 ] , [ 1 , 1 ] , [ 1 , - 1 ] ] NEW_LINE N = len ( arr ) NEW_LINE print ( centralPoints ( arr , N ) ) ; NEW_LINE DEDENT