Practice Closest Equal Element Queries
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given the circular array nums, each query is an index. Find the shortest distance around the circle, in either direction, to a different index containing the same value. Return -1 if there is no other occurrence. Return the answers in query order.
Source: Closest Equal Element Queries on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [1,3,1,4,1,3,2], queries = [0,3,5]
Output
[2,-1,3]
# Example 2
Input
nums = [1,2,3,4], queries = [0,1,2,3]
Output
[-1,-1,-1,-1]
Constraints
1 <= queries.length <= nums.length <= 10^5
1 <= nums[i] <= 10^6
0 <= queries[i] < nums.length
Related LeetCode Problems
Practice more problems similar to Closest Equal Element Queries.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.