Leetcode: 2475. Number of Unequal Triplets in Array
- Can we use brute-force to solve the problem? As \(n \leq 100\), we can go over all triplets in the array and count ones that satisfy the condition. Time complexity is \(O(n^3)\) and space is \(O(n)\).
class Solution: def unequalTriplets(self, nums: List[int]) -> int: N = len(nums) ans = 0 for i in range(N): for j in range(i + 1, N): for k in range(j + 1, N): if len(set([nums[i], nums[j], nums[k]])) == 3: ans += 1 return ans