879201. Right Angle Triangle

Basic

Here is the detailed Markdown blog post for the GeeksforGeeks problem:

Right Angle Triangle

Summary

The problem involves generating all possible right-angle triangles with a given hypotenuse length. The key concept involved is basic geometry, specifically Pythagorean triples.

Detailed Explanation

The problem can be solved by using a simple algorithm that iterates over the possible lengths of the sides and checks if they form a right-angle triangle. The algorithm starts by initializing variables for the sides (a, b) and the hypotenuse (c). Then it uses a loop to iterate over all possible values of a and calculates the corresponding value of b using the Pythagorean theorem. It then checks if the calculated value of b is less than or equal to c.

Here's a step-by-step breakdown of the solution:

  1. Initialize variables: a, b, and c (hypotenuse)
  2. Loop over possible values of a
  3. Calculate b using Pythagorean theorem (b = sqrt(c^2 - a^2))
  4. Check if calculated value of b is less than or equal to c
  5. If true, print the triangle (or store it in an array/list)

The time complexity of this algorithm is O(n), where n is the maximum possible value of a. The space complexity is O(1) since we only need a constant amount of space to store the variables.

Optimized Solutions

Java

View on GeeksforGeeks
public class RightAngleTriangle {
    public static void generate(int c) {
        for (int a = 1; a <= c; a++) {
            int b = (int) Math.sqrt(c * c - a * a);
            if (b <= c) {
                System.out.println("Triangle with sides " + a + ", " + b + ", and " + c);
            }
        }
    }
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.