Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5604 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 799 |

@sriramgoparaju99 | 737 |

@Manikanta punnam | 629 |

@rdakka | 606 |

@prankursharma31 | 597 |

@praveenbgp6 | 546 |

@sanskar94511 | 531 |

@purohitmn02 | 525 |

@yashkaril4 | 517 |

@abhikarshgupta | 474 |

@rohitgarg2825 | 464 |

Complete Leaderboard |

Given an unsorted array **arr[] **of **n** positive integers. Find the number of triangles that can be formed with three different array elements as lengths of three sides of triangles.

**Example 1:**

**Input**:
n = 3
arr[] = {3, 5, 4}
**Output**:
1
**Explanation**:
A triangle is possible
with all the elements 5, 3 and 4.

**Example 2:**

**Input**:
n = 5
arr[] = {6, 4, 9, 7, 8}
**Output**:
10
**Explanation**:
There are 10 triangles
possible with the given elements like
(6,4,9), (6,7,8),...

**Your Task: **This is a function problem. You only need to complete the function **findNumberOfTriangles****() **that takes **arr[] **and** N** as input parameters and returns** **the count of total possible triangles.

**Expected Time Complexity: **O(N^{2}).

**Expected Space Complexity: **O(1).

**Constraints:**

3 <= N <= 10^{3}

1 <= arr[i] <= 10^{3}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Count the number of possible triangles

...