Maximum 2x2 squares inside a right isosceles triangle
Filed under Microsoft
Free read 2 of 3The 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
The number of 2x2 squares in row i (from top) is determined by the available width at that height.
The width at height h is L-h. A 2x2 square occupies 2 units of height.
Sum the number of squares that fit in each 2-unit layer until the remaining height is less than 2.
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.