#C7680. First Element Occurring K Times
First Element Occurring K Times
First Element Occurring K Times
You are given a list of integers and an integer k. Your task is to determine the first element in the list that appears at least k times.
If no such element exists, output -1
.
More formally, let \(nums\) be the sequence of integers. Find the smallest index \(i\) such that the number \(nums_i\) has appeared at least \(k\) times in the sequence when read from left to right. If there is no such number, output \(-1\).
Note: The input is provided via standard input (stdin) and the result must be printed to standard output (stdout).
inputFormat
The input consists of two lines:
- The first line contains a list of space-separated integers representing the array \(nums\). This line could be empty, representing an empty list.
- The second line contains an integer \(k\), which is the threshold.
outputFormat
Output a single integer which is the first element in \(nums\) that occurs at least \(k\) times. If no such element exists, output -1
.
1 2 2 3 4 5 2
2
2