You are given an integer array nums.
An integer x is called special if:
x appears exactly three times in nums.x are equally spaced in nums. In other words, if all occurrences of x are at indices i1 < i2 < i3, then i2 - i1 = i3 - i2.Return the number of distinct special integers in nums.
Example 1:
Input: nums = [1,8,1,5,1,5,8,5]
Output: 2
Explanation:
Therefore, the answer is 2.
Example 2:
Input: nums = [8,8,8,8]
Output: 0
Explanation:
8 is not special because it does not occur exactly three times. Therefore, the answer is 0.
Example 3:
Input: nums = [8,6,6,8,8]
Output: 0
Explanation:
8 occurs at indices 0, 3, and 4, which are not equally spaced. 6 occurs only twice. Therefore, no integer is special.
Constraints:
3 <= nums.length <= 1001 <= nums[i] <= 1001a (Brute Force). Count each value's occurrences, then enumerate all triples of indices i < j < k. Count a triple if nums[i] == nums[j] == nums[k], j - i == k - j, and the value appears exactly three times in the array.
2a (Grouping Indices). Group occurrence indices by value. Count the groups containing exactly three indices whose two consecutive gaps are equal.
[1,8,1,5,1,5,8,5]
[8,8,8,8]
[8,6,6,8,8]