You have m square tiles of size 1 * 1 and n square tiles of size 2 * 2. Your task is to create the largest possible square using these tiles. Tiles may not overlap, and the resulting square should be filled (it should not contain empty spaces).
Let's now write a func called sideLargetstSquare(int m, int n) in the editor π
Task of your func:
Examples
01 Β· Example 1
m = 8 n = 0 return = 2
You can use four out of eight tiles to arrange them into 2 * 2 square. There are not enough tiles to create 3 * 3 square.
02 Β· Example 2
m = 4 n = 3 return = 4

You can obtain 4 * 4 square by arranging four 1 * 1 tiles into a 2 * 2 square, and surrounding it by 2 * 2 tiles:
03 Β· Example 3
m = 0 n = 18 return = 8
You need to use sixteen 2 * 2 tiles to create the square.
Not that not all the tiles are used.
04 Β· Example 4
m = 13 n = 3 return = 5

One of the possible arrangements is shown in the following image:
Constraints
1 <= m, n <= 1,000,000,000More Microsoft problems
- Rank Open BusinessesPHONE SCREEN Β· Seen May 2026
- Retain Top K ValuesPHONE SCREEN Β· Seen May 2026
- In-Memory SQL with CSV InitializationONSITE INTERVIEW Β· Seen May 2026
- Order Records by Matching Start and EndONSITE INTERVIEW Β· Seen May 2026
- Recover Corrupted Master PageONSITE INTERVIEW Β· Seen Feb 2026
- Distinct Number Line MovesOA Β· Seen Oct 2025
- Minimum Round Trip LengthsOA Β· Seen Aug 2025
- Programmer StringsOA Β· Seen Aug 2025
public int sideLargetstSquare(int m, int n) {
// write your code here
}
m8
n0
expected2
sign in to submit