You are given an integer array A. For every element, find the distance to its nearest identical element (either left or right). If no duplicate exists for that element, return -1 for that position. Return the result array.
This simulates finding the nearest repeated event in logs or user actions.