Maximize count of unique Squares that can be formed with N arbitrary points in coordinate plane | Python program for the above approach ; Function to find the maximum number of unique squares that can be formed from the given N points ; Stores the resultant count of squares formed ; Base Case ; Subtract the maximum possible grid size as sqrt ( N ) ; Find the total squares till now for the maximum grid ; A i * i grid contains ( i - 1 ) * ( i - 1 ) + ( i - 2 ) * ( i - 2 ) + ... + 1 * 1 squares ; When N >= len then more squares will be counted ; Return total count of squares ; Driver Code
import math NEW_LINE def maximumUniqueSquares ( N ) : NEW_LINE INDENT ans = 0 NEW_LINE if N < 4 : NEW_LINE INDENT return 0 NEW_LINE DEDENT len = int ( math . sqrt ( N ) ) NEW_LINE N -= len * len NEW_LINE for i in range ( 1 , len ) : NEW_LINE INDENT ans += i * i NEW_LINE DEDENT if ( N >= len ) : NEW_LINE INDENT N -= len NEW_LINE for i in range ( 1 , len ) : NEW_LINE INDENT ans += i NEW_LINE DEDENT DEDENT for i in range ( 1 , N ) : NEW_LINE INDENT ans += i NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 9 NEW_LINE print ( maximumUniqueSquares ( N ) ) NEW_LINE DEDENT