top of page

### Looking to master object-oriented and system design for tech interviews or career growth?

• Improve your system design and machine coding skills.

• Study with our helpful resources.

**We're in beta mode and would love to hear your feedback.

Search

# Counting Triangles - InterviewBit Solution

Problem: Counting Triangles

### Problem Description:

You are given an array of N non-negative integers, A0, A1,…, AN-1. Considering each array element Ai as the edge length of some line segment, count the number of triangles that you can form using these array values.

###### Notes:
1. You can use any value only once while forming each triangle. The order of choosing the edge lengths doesn’t matter. Any triangle formed should have a positive area.

2. Return answer modulo 109 + 7.

For example,

A = [1, 1, 1, 2, 2] Return: 4

### Solution:

Code in C++

If you have any questions or queries, feel free to drop a comment in the comments section below.

### Note: Help us improve this blog

We will upload your approach and solution here by giving you the proper credit so that you can showcase it among your peers.

bottom of page