Tap here to switch tabs
Problem
Submissions

Problem: Find Occurrences of an Element in an Array

med
30 min
Try to solve the Find Occurrences of an Element in an Array problem.

Statement

You are given an integer array nums, an integer array queries, and an integer x.

For each query queries[i], find the index of the queries[i]th occurrence of x in nums. If x occurs fewer than queries[i] times in nums, the answer for that query is −1-1.

Return an array containing the results for all queries in the given order.

Constraints:

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

  • 1≤1 \leq queries[i] ≤105\leq 10^5

  • 1≤1 \leq nums[i], x ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Occurrences of an Element in an Array

med
30 min
Try to solve the Find Occurrences of an Element in an Array problem.

Statement

You are given an integer array nums, an integer array queries, and an integer x.

For each query queries[i], find the index of the queries[i]th occurrence of x in nums. If x occurs fewer than queries[i] times in nums, the answer for that query is −1-1.

Return an array containing the results for all queries in the given order.

Constraints:

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

  • 1≤1 \leq queries[i] ≤105\leq 10^5

  • 1≤1 \leq nums[i], x ≤104\leq 10^4