Interview Query

Possible Triangles

Start Timer

0:00:00

Upvote
3
Downvote
Save question
Mark as completed
View comments (3)
Next question

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
.
.
.
.
.


Comments

Loading comments.