func distinctDifferenceArray(nums []int) []int { leftCount := make(map[int]int) rightCount := make(map[int]int) for _, num := range nums { rightCount[num]++ } n := len(nums) ans := make([]int, n) for i, num := range nums { rightCount[num]-- if rightCount[num] == 0 { delete(rightCount, num) } leftCount[num]++ ans[i] = len(leftCount) - len(rightCount) } return ans }