WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. Book a mock interview →
Puzzles & Problems 7 of 155 · Wall Street Quant

How many Pythagorean triangles with sides of integer length exist where the longest side is less than or equal to 100?

📕 Buy this interview preparation book: 155 Wall Street Quant questions & answers — PDF + EPUB for $5

A Pythagorean triangle is a right-angled triangle for which the sides a, b (the legs), and c (the hypotenuse) satisfy the Pythagorean theorem: a2 + b2 = c2. We are given the condition c ≤ 100. To find all such integer-length sides for Pythagorean triangles, we can use the following approach:

For any two positive integers m and n such that m > n > 0, the sides of a Pythagorean triangle can be expressed parametrically using the following formulas:


a = m2 − n2

b = 2mn

c = m2 + n2

These are known as Euclid’s formulas for generating Pythagorean triples. Note that these formulas do not generate all possible Pythagorean triangles with integer sides; some of them might be multiples of other triangles, known as primitive Pythagorean triples (i.e., triangles with sides that are coprime). Thus, we also need to check for scaling factors when counting all such triangles.

Now let’s find the upper bound for m. We have:


c = m2 + n2 ≤ 100

Since m > n, we have:


$$n^2 + n^2 = 2n^2 \leq 100 \implies n^2 \leq 50 \implies n \leq \lfloor\sqrt{50}\rfloor$$

Thus, n has an upper bound of 7 and ranges from 1 to 7.

Let’s count the number of valid Pythagorean triangles by iterating through all n values for each possible m that is larger than n and m2 + n2 ≤ 100,

n = 1, m ∈ {2, 3, 4, 5, 6, 7, 8, 9}, N = 8

n = 2, m ∈ {3, 4, 5, 6, 7, 8, 9}, N = 7

n = 3, m ∈ {4, 5, 6, 7, 8, 9}, N = 6

n = 4, m ∈ {5, 6, 7, 8, 9}, N = 5

n = 5, m ∈ {6, 7, 8}, N = 3

n = 6, m ∈ {7, 8}, N = 2

n = 7, m ∈ {}, N = 0

The final count for the number of Pythagorean triangles with integer sides and c ≤ 100 is 31.

Line open Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Wall Street Quant interview — then scores it.
📞 Practice Wall Street Quant →
📕 Buy this interview preparation book: 155 Wall Street Quant questions & answers — PDF + EPUB for $5

All 155 Wall Street Quant questions · All topics