mediumArrayBinary SearchHash Table 0 views
Closest Equal Element Queries
You are given a circular array nums and an array queries.
You are given a circular array nums and an array queries.
For each query i, you have to find the following:
Return an array answer of the same size as queries, where answer[i] represents the result for query i.
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]
Explanation: Each value in nums is unique, so no index shares the same value as the queried element. This results in -1 for all queries.
Constraints
- 1 <= queries.length <= nums.length <= 10^5
- 1 <= nums[i] <= 10^6
- 0 <= queries[i] < nums.length
Hints
Companies
No companies reported yet.
Discussion
Sign in to join the discussion.
Loading discussion...
Test results
No test cases yet.