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.
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 <= 105
1 <= nums[i] <= 106
0 <= queries[i] < nums.length
3488. Closest Equal Element Queries
Medium
30 Points
Array
Hash Table
Binary Search
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.
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 <= 105
1 <= nums[i] <= 106
0 <= queries[i] < nums.length
Closest Equal Element Queries - Practice Coding | SlaveCode