Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

Given M 1×1 tiles and N 2×2 tiles, your task is to find the largest possible square such that it is completely filled without any overlaps or empty spaces. Returns the side length of this maximal square or 0 if no square can be formed.

Constraints:

  • Assume M and N are integers in the range [0, 1000000000].
Test Cases
Input
Output
Expected