#3488

Closest Equal Element Queries

medium · 32.8% accepted · 120 likes · top 10%

array · hash table · binary search

Description

You are given a circular array nums and an array queries.

For each query i, you have to find the following:

- The minimum distance between the element at index queries[i] and any other index j in the circular array, where nums[j] == nums[queries[i]]. If no such index exists, the answer for that query should be -1.

Return an array answer of the same size as queries, where answer[i] represents the result for query i.

Solution