Count Index Triples that Form Nondegenerate Triangles
Quick Overview
Count Index Triples that Form Nondegenerate Triangles. Return how many ways to select three distinct indices from nums whose values form the side lengths of a triangle.
Count Index Triples that Form Nondegenerate Triangles
Company: Bloomberg
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
### Problem
Return how many ways to select three distinct indices from nums whose values form the side lengths of a triangle. Different index selections count separately, including when values repeat. A triangle must have positive area.
```cpp
class Solution {
public:
int triangleNumber(vector<int>& nums);
};
```
### Examples
**Example 1:**
```text
nums = [3,3,4,5]
Output: 4
Explanation: Every three-index selection satisfies the strict triangle inequality.
```
**Example 2:**
```text
nums = [0,2,2]
Output: 0
Explanation: A zero side gives a degenerate shape.
```
### Constraints
- There are 1..1000 candidate sides. Every side value is in 0..1000.
### Clarifying Questions
Count index multiplicities and enforce strict triangle inequalities despite repeated or zero values.
```hint Read the boundary condition
Once the largest side is fixed, when can several left endpoints be counted together?
```
### Contract considerations
Count index multiplicities and enforce strict triangle inequalities despite repeated or zero values.
Overview: Count Index Triples that Form Nondegenerate Triangles. Return how many ways to select three distinct indices from nums whose values form the side lengths of a triangle.
Count Index Triples that Form Nondegenerate Triangles
Bloomberg
Sep 12, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0
Problem
Return how many ways to select three distinct indices from nums whose values form the side lengths of a triangle. Different index selections count separately, including when values repeat. A triangle must have positive area.
class Solution {
public:
int triangleNumber(vector<int>& nums);
};
Examples
Example 1:
nums = [3,3,4,5]
Output: 4
Explanation: Every three-index selection satisfies the strict triangle inequality.
Example 2:
nums = [0,2,2]
Output: 0
Explanation: A zero side gives a degenerate shape.
Constraints
There are 1..1000 candidate sides. Every side value is in 0..1000.
Clarifying Questions Guidance
Count index multiplicities and enforce strict triangle inequalities despite repeated or zero values.
Contract considerations
Count index multiplicities and enforce strict triangle inequalities despite repeated or zero values.