โ† Microsoft questions

Maximum 2x2 squares inside a right isosceles triangle

Filed under Microsoft

Free read 2 of 3

The number of 2x2 squares in row i (from top) is determined by the available width at that height.

The question

Calculate the maximum number of 2x2 squares that can fit inside a right-angled isosceles triangle with legs of length L.

Constraints

  • Triangle is right-angled isosceles
  • Squares must be aligned with the legs
  • L is a positive integer

Examples

Input
L=4
Output
3
Why
Rows of squares: 1 square in top row, 2 in bottom row (total 3).

Approach

  1. The number of 2x2 squares in row i (from top) is determined by the available width at that height.

Tips

  • What they are testing: Check L < 2 (should be 0) and L=2 (should be 1).
  • Common mistake: Assuming a simple area division; the geometry requires accounting for the diagonal constraint.

Related Microsoft questions

Collected from public candidate posts and coding forums. Updated Nov 2026.