The Number of Unequal Triplets in Array problem asks you to count triplets (i, j, k) where i < j < k and arr[i] != arr[j], arr[j] != arr[k], and arr[i] != arr[k] — all three elements are distinct. This easy coding problem uses frequency counting with a combinatorial formula.
Paytm asks this easy problem to test the ability to count valid triplets efficiently using group frequency products rather than brute-force O(n³). The array, hash table, and sorting interview pattern is applied through the frequency-based combinatorial insight.
Frequency count + ordered group product. Count the frequency of each unique value. Enumerate all unique triplets of distinct values (a, b, c) and multiply their frequencies to get the number of valid ordered triplets. But ordering the groups while counting avoids permutation issues. Better: for each "middle" value group of size m with left elements before it (different values) and right elements after it (different values), add left * m * right. Compute left/right cumulatively.
arr=[4,4,2,4,3,2,5]. Frequencies: {4:3, 2:2, 3:1, 5:1}. Order groups: left=0, current=3(4s), right=4(2,3,5).
Triplet counting with frequency groups uses the "fix the middle element" technique: for each group as the middle, multiply elements before × group size × elements after. This generalizes to counting triplets with other constraints. Practice "count triplets with i < j < k and all different" variants. The key is avoiding O(n³) by leveraging group structure and cumulative counts.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Check if Array is Good | Easy | Solve | |
| Contains Duplicate | Easy | Solve | |
| Largest Unique Number | Easy | Solve | |
| Make Two Arrays Equal by Reversing Subarrays | Easy | Solve | |
| Rank Transform of an Array | Easy | Solve |