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.length
  • nums[i], nums[j], and nums[k] are pairwise distinct.
  • In other words, nums[i] != nums[j], nums[i] != nums[k], and nums[j] != nums[k].

Return the number of triplets that meet the conditions.

Example 1
Inputnums = [4,4,2,4,3]
Output3
The valid triplets are (0, 2, 4), (1, 2, 4), and (2, 3, 4), so there are 3 triplets.
Example 2
Inputnums = [1,1,1,1,1]
Output0
No triplets meet the conditions, so we return 0.

Constraints

  • 3 <= nums.length <= 100
  • 1 <= nums[i] <= 1000

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate