Find Four points such that they form a square whose sides are parallel to x and y axes | find the largest square ; map to store which points exist ; mark the available points ; a nested loop to choose the opposite corners of square ; remove the chosen point ; remove the chosen point ; check if the other two points exist ; if the square is largest then store it ; add the removed point ; add the removed point ; display the largest square ; Driver code ; given points ; find the largest square
def findLargestSquare ( points , n ) : NEW_LINE INDENT m = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT m [ ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] = m . get ( ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) , 0 ) + 1 NEW_LINE DEDENT side = - 1 NEW_LINE x = - 1 NEW_LINE y = - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT m [ ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] -= 1 NEW_LINE for j in range ( n ) : NEW_LINE INDENT m [ ( points [ j ] [ 0 ] , points [ j ] [ 1 ] ) ] -= 1 NEW_LINE if ( i != j and ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) == ( points [ i ] [ 1 ] - points [ j ] [ 1 ] ) ) : NEW_LINE INDENT if ( m [ ( points [ i ] [ 0 ] , points [ j ] [ 1 ] ) ] > 0 and m [ ( points [ j ] [ 0 ] , points [ i ] [ 1 ] ) ] > 0 ) : NEW_LINE INDENT if ( side < abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) or ( side == abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) and ( ( points [ i ] [ 0 ] * points [ i ] [ 0 ] + points [ i ] [ 1 ] * points [ i ] [ 1 ] ) < ( x * x + y * y ) ) ) ) : NEW_LINE INDENT x = points [ i ] [ 0 ] NEW_LINE y = points [ i ] [ 1 ] NEW_LINE side = abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) NEW_LINE DEDENT DEDENT DEDENT m [ ( points [ j ] [ 0 ] , points [ j ] [ 1 ] ) ] += 1 NEW_LINE DEDENT m [ ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] += 1 NEW_LINE DEDENT if ( side != - 1 ) : NEW_LINE INDENT print ( " Side ▁ of ▁ the ▁ square ▁ is ▁ : ▁ " , side , " , points of the square are " , x , " ,   " , y , " ▁ " , ( x + side ) , " , ▁ " , y , " ▁ " , ( x ) , " , ▁ " , ( y + side ) , " ▁ " , ( x + side ) , " , ▁ " , ( y + side ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No ▁ such ▁ square " ) NEW_LINE DEDENT DEDENT n = 6 NEW_LINE points = [ [ 1 , 1 ] , [ 4 , 4 ] , [ 3 , 4 ] , [ 4 , 3 ] , [ 1 , 4 ] , [ 4 , 1 ] ] NEW_LINE findLargestSquare ( points , n ) NEW_LINE