Can anyone please tell me why this give wrong ans but i think my approach is correct

Jai Shree Ram

Multiplexer

Latest Contest Question

My approach is basically i store the first and last occurrence of an number and
now i store all ele in a new array which contain single occurence.
After that start traversing if i take out the ele = arr[i]*x now count all the occurnce of this ele from the first and last index of arr[i] than ans = occurence of arr[i]*x + occurence of arr[i] - occurence of arr[i]*x lie in the range.

This is overall my approach can anyone tell me where it show wrong ans.

Question Link : Multiplexer Practice Coding Problem

You can also go through my soln : Solution: 1137308133