Question: Code in java, please also show the correct output in the terminal, also look your code performance and make it more efficient You have M

Code in java, please also show the correct output in the terminal, also look your code performance and make it more efficient You have M square tiles of size 1\times 1 and N square tiles of size 2\times 2. Your task is to create the largest possible square using these tiles. Tiles may not over and the resulting square should be filled (it should not contain empty spaces). Write a function:
class Solution { public int solution(int M , int N ); }
that, given two integers M and N, returns the length of the side of the largest square you can create. If no square can be created, your function should return 0. Examples: 1. Given M=8 and N=0, your function should return 2. You can use four out of eight tiles to arrange them into 2\times 2 square. There are enough tiles to creat 3\times 3 square. 2. Given M=4 and N=3, your function should return 4. You can obtain a 4\times 4 square by arranging four 1\times 1 tiles into a 2\times 2 square, and surrounding it by 2\times 2 tiles: 3. Given M=0 and N=18, your function should return 8. You need to use sixteen 2\times 2 tiles to create the square. Note that not all the tiles are used. 4. Given M=13 and N=3, your function should return 5. One of the possible arrangements is shown in the following image:Write an efficient algorithm for the following assumptions: - M and N are integers within the range [0..1,000,000,000].

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!