#2475
Number of Unequal Triplets in Array
newbie · 260 · lc easy +19 · verified · 73.3% accepted · 452 likes · top 83%
Description
Given a 0-indexed array of positive integers nums, count the number of index triplets (i, j, k) satisfying 0 <= i < j < k < nums.length where nums[i], nums[j], and nums[k] are all pairwise distinct (i.e., no two of the three values are equal).
Example 1:
Input: nums = [4,4,2,4,3]
Output: 3
Explanation: The following triplets meet the conditions:
- (0, 2, 4) because 4 != 2 != 3
- (1, 2, 4) because 4 != 2 != 3
- (2, 3, 4) because 2 != 4 != 3
Since there are 3 triplets, we return 3.
Note that (2, 0, 4) is not a valid triplet because 2 > 0.
Example 2:
Input: nums = [1,1,1,1,1]
Output: 0
Explanation: No triplets meet the conditions so we return 0.
Code
1
2
3