WalzoneInterview Prep
πŸ“ž Interviewing soon? Practice with a realistic AI mock phone interview β€” it calls you, then scores you. First 15 min FREE β†’

Wall Street Quant Β· Puzzles & Problems Β· question 7 of 155

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.

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 β€” free 15 min
πŸ“• Buy this interview preparation book: 155 Wall Street Quant questions & answers β€” PDF + EPUB for $5

All 155 Wall Street Quant questions Β· All topics