Find the coordinate that does not belong to any square | Function to find the point that is not a part of the side of a square ; Traverse each pair of coordinates ; Minimize x - coordinate in all the points except current point ; Maximize x - coordinate in all the points except the current point ; Minimize y - coordinate in all the points except current point ; Maximize y - coordinate in all the points except current point ; If x - coordinate matches with other same line ; If y coordinate matches with other same line ; Check if the condition for square exists or not ; Print the output ; Driver Code
def findPoint ( n , p ) : NEW_LINE INDENT for i in range ( n * 4 + 1 ) : NEW_LINE INDENT x1 = 2e9 NEW_LINE x2 = - 2e9 NEW_LINE y1 = 2e9 NEW_LINE y2 = - 2e9 NEW_LINE for j in range ( n * 4 + 1 ) : NEW_LINE INDENT if ( i != j ) : NEW_LINE INDENT x1 = min ( x1 , p [ j ] [ 0 ] ) NEW_LINE x2 = max ( x2 , p [ j ] [ 0 ] ) NEW_LINE y1 = min ( y1 , p [ j ] [ 1 ] ) NEW_LINE y2 = max ( y2 , p [ j ] [ 1 ] ) NEW_LINE DEDENT DEDENT ok = 1 NEW_LINE c1 = 0 NEW_LINE c2 = 0 NEW_LINE c3 = 0 NEW_LINE c4 = 0 NEW_LINE for j in range ( 1 , n * 4 + 1 , 1 ) : NEW_LINE INDENT if ( i != j ) : NEW_LINE INDENT if ( ( p [ j ] [ 0 ] == x1 or p [ j ] [ 0 ] == x2 ) or ( p [ j ] [ 1 ] == y1 or p [ j ] [ 1 ] == y2 ) ) : NEW_LINE INDENT if ( p [ j ] [ 0 ] == x1 ) : NEW_LINE INDENT c1 += 1 NEW_LINE DEDENT if ( p [ j ] [ 0 ] == x2 ) : NEW_LINE INDENT c2 += 1 NEW_LINE DEDENT if ( p [ j ] [ 1 ] == y1 ) : NEW_LINE INDENT c3 += 1 NEW_LINE DEDENT if ( p [ j ] [ 1 ] == y2 ) : NEW_LINE INDENT c4 += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT ok = 0 NEW_LINE DEDENT DEDENT DEDENT if ( ok and c1 >= n and c2 >= n and c3 >= n and c4 >= n and x2 - x1 == y2 - y1 ) : NEW_LINE INDENT print ( p [ i ] [ 0 ] , p [ i ] [ 1 ] ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 2 NEW_LINE arr = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 0 , 2 ] , [ 1 , 0 ] , [ 1 , 1 ] , [ 1 , 2 ] , [ 2 , 0 ] , [ 2 , 1 ] , [ 2 , 2 ] ] NEW_LINE findPoint ( N , arr ) NEW_LINE DEDENT