KthIndexOf

Easy

Given an array of integers, a desired occurance, and an integer, return the index of the desired occurance of the given integer in the array.

If there is no kth index of the given num, -1 is returned.

Parameter(s):

  • arr: an array of integers
  • k: the desired occurance
  • num: the desired integer

Returns:

  • integer: the index of the kth occurance (or -1 if one does not exist)

Constraints:

  • arr ≠ null
  • 1 ≤ arr.length ≤ 1000
  • 1 ≤ k ≤ 1000
  • -2147483647 ≤ num ≤ 2147483647

Example 1:

Input:

[1,1] 2 1

Output:

1

Example 2:

Input:

[1,2,3,2,1] 1 3

Output:

2

Example 3:

Input:

[1,2,3,4] 2 3

Output:

-1

Example 4:

Input:

[1,2,3,4] 1 5

Output:

-1