Number of Unequal Triplets in Array Problem

Number of Unequal Triplets in Array Problem — ExecCode Easy DSA Practice

Solve the Number of Unequal Triplets in Array problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a 0-indexed array of positive integers nums. Your task is to 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.

Examples

Input {"nums": [4, 4, 2, 4, 3]}; Output 3. Input {"nums": [1, 1, 1, 1, 1]}; Output 0

Constraints

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

Practice Number of Unequal Triplets in Array free on ExecCode. Browse DSA problems, topic map, and placement guides.