Practice Find Occurrences of an Element in an Array
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
You are given an integer array nums, an integer array queries, and an integer x. For each queries[i], you need to find the index of the queries[i]th occurrence of x in the nums array. If there are fewer than queries[i] occurrences of x, the answer should be -1 for that query. Return an integer array answer containing the answers to all queries.
Source: Find Occurrences of an Element in an Array on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,3,1,7], queries = [1,3,2,4], x = 1
[0,-1,2,-1]
# Example 2
nums = [1,2,3], queries = [10], x = 5
[-1]
Constraints
Related LeetCode Problems
Practice more problems similar to Find Occurrences of an Element in an Array.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.