Question: def solution ( M , N ) : # Convert the number of 1 x 1 and 2 x 2 tiles into the equivalent number
def solutionM N: # Convert the number of x and x tiles into the equivalent number of x tiles totaltiles M N # The side of the largest square that can be created is the square root of the total number of x tiles maxside inttotaltiles # Start from the max possible side and decrease until you find the largest possible square for side in rangemaxside, : # Calculate how many x and x tiles would be needed for this side length requiredxside requiredxside side # Check if we have enough x tiles and if the remaining x tiles can cover the rest if N requiredx and M requiredx: return side # If not enough x tiles, see if we can make up the difference with x tiles if N requiredx: # Calculate the deficit of x tiles after using all x tiles neededxrequiredx N # Check if we have enough x tiles after covering the required x area if M N neededx requiredx: return side # If no square can be created, return return
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
