FastPrepFastPrep
Problem Brief

Side Largest Square 🟧

FULLTIMEOA
See Microsoft online assessment and hiring insights

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:

  • Find the len of the side of the largest square you can create. If no square can be created, func should return 0.
  • 1Example 1

    Input
    m = 8, n = 0
    Output
    2
    Explanation
    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.

    2Example 2

    Input
    m = 4, n = 3
    Output
    4
    Explanation
    Example 2 illustration
    You can obtain 4 * 4 square by arranging four 1 * 1 tiles into a 2 * 2 square, and surrounding it by 2 * 2 tiles:

    3Example 3

    Input
    m = 0, n = 18
    Output
    8
    Explanation
    You need to use sixteen 2 * 2 tiles to create the square. Not that not all the tiles are used.

    4Example 4

    Input
    m = 13, n = 3
    Output
    5
    Explanation
    Example 4 illustration
    One of the possible arrangements is shown in the following image:

    Constraints

    Limits and guarantees your solution can rely on.

  • 1 <= m, n <= 1,000,000,000
  • public int sideLargetstSquare(int m, int n) {
      // write your code here
    }
    
    Input

    m

    8

    n

    0

    Output

    2

    Sign in to submit your solution.