What is the maximum number of squares of size 2×2 units that can be fit in a right-angled isosceles triangle of a given base (in units).
A side of the square must be parallel to the base of the triangle.
Input : 8 Output : 6 Please refer below diagram for explanation. Input : 7 Output : 3
Since the triangle is isosceles, the given base would also be equal to the height. Now in the diagonal part, we would always need an extra length of 2 units in both height and base of the triangle to accommodate a triangle. (The CF and AM segment of the triangle in the image. The part that does not contribute to any square). In the remaining length of base, we can construct length / 2 squares. Since each square is of 2 units, same would be the case of height, there is no need to calculate that again.
So, for each level of given length we can construct “(length-2)/2” squares. This gives us a base of “(length-2)” above it. Continuing this process to get the no of squares for all available “length-2” height, we can calculate the squares.
while length > 2 answer += (length - 2 )/2 length = length - 2
For more effective way, we can use the formula of sum of AP n * ( n + 1 ) / 2, where n = length – 2
This article is contributed by Harshit Agrawal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Maximum number of squares that can fit in a right angle isosceles triangle
- Area of a largest square fit in a right angle triangle
- Divide an isosceles triangle in two parts with ratio of areas as n:m
- Find two vertices of an isosceles triangle in which there is rectangle with opposite corners (0, 0) and (X, Y)
- Program To Check whether a Triangle is Equilateral, Isosceles or Scalene
- Find the altitude and area of an isosceles triangle
- Find side of Square which makes minimal area to fit two identical rectangles inside it
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Number of Isosceles triangles in a binary tree
- Find a point that lies inside exactly K given squares
- Length of longest rod that can fit into a cuboid
- Area of circle inscribed in a Isosceles Trapezoid
- Check if a right-angled triangle can be formed by the given coordinates
- Check if a right-angled triangle can be formed by moving any one of the coordinates
- Check if a right-angled triangle can be formed by the given side lengths
- Maximum sum of a path in a Right Number Triangle
- Check whether a given point lies inside a triangle or not
- Count Integral points inside a Triangle
- Triangle with no point inside
- Area of a triangle inside a parallelogram