Interview Query

Possible Triangles

1
Have you seen this question before?

We’re given a list of at least three numbers named sides. Each entry in sides represents the length of a side of a triangle.

Write a function possible_triangles to determine the number of possible triangles that can be formed using the given side lengths.

In the case that more than three side lengths are given, there may be several possible triangles.

Note: If there are multiple equal side lengths in the list, we consider them as distinct sides.

Examples:

Input:

#Example 1:
sides = [3, 3, 3]
def possible_triangles(sides) -> 1

#Example 2:
sides = [3, 3, 3, 3]
def possible_triangles(sides) -> 4

#Example 3:
sides = [1, 2, 3.5]
def possible_triangles(sides) -> 0
Next question: Gaussian Generation
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code