Tap here to switch tabs
Problem
Submissions

Problem: Closest Equal Element Queries

Closest Equal Element Queries asks you to answer each queried position with the smallest circular distance to another position holding the same value, or negative one if none exists.

Statement

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

For each query index queries[i], find the minimum circular distance to another index j such that j \neq queries[i] and nums[j] == nums[queries[i]]. If no such index exists, the answer for that query is −1-1.

Return an array containing the answer for each query in queries.

Note: The circular distance between two indices i and j in an array of length n is defined as min⁡(∣i−j∣,n−∣i−j∣)\min(|i - j|, n - |i - j|).

Constraints:

  • 1≤1 \leq queries.length ≤\leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6

  • 0≤0 \leq queries[i] << nums.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Closest Equal Element Queries

Closest Equal Element Queries asks you to answer each queried position with the smallest circular distance to another position holding the same value, or negative one if none exists.

Statement

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

For each query index queries[i], find the minimum circular distance to another index j such that j \neq queries[i] and nums[j] == nums[queries[i]]. If no such index exists, the answer for that query is −1-1.

Return an array containing the answer for each query in queries.

Note: The circular distance between two indices i and j in an array of length n is defined as min⁡(∣i−j∣,n−∣i−j∣)\min(|i - j|, n - |i - j|).

Constraints:

  • 1≤1 \leq queries.length ≤\leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6

  • 0≤0 \leq queries[i] << nums.length