Number of Unequal Triplets in Array
You are given a 0-indexed array of positive integers nums. Find the number of triplets (i, j, k) that meet the following conditions:
0 <= i < j < k < nums.lengthnums[i],nums[j], andnums[k]are pairwise distinct.- In other words,
nums[i] != nums[j],nums[i] != nums[k], andnums[j] != nums[k].
Return the number of triplets that meet the conditions.
Example 1
Input
nums = [4,4,2,4,3]Output
3The valid triplets are (0, 2, 4), (1, 2, 4), and (2, 3, 4), so there are 3 triplets.
Example 2
Input
nums = [1,1,1,1,1]Output
0No triplets meet the conditions, so we return 0.
Constraints
- 3 <= nums.length <= 100
- 1 <= nums[i] <= 1000