| 2 | using namespace std; |
| 3 | |
| 4 | int main() { |
| 5 | int arrSize; |
| 6 | cin >> arrSize; |
| 7 | |
| 8 | // fill array with the inputted elements |
| 9 | int arr[arrSize]; |
| 10 | for (int i=0; i < arrSize; i++){ |
| 11 | cin >> arr[i]; |
| 12 | } |
| 13 | |
| 14 | |
| 15 | // fill occurrences array with # of each int present in arr |
| 16 | int occurrences[arrSize] = { 0 }; |
| 17 | for (int i=0; i < arrSize; i++){ |
| 18 | occurrences[arr[i]]++; |
| 19 | } |
| 20 | |
| 21 | int k; |
| 22 | cin >> k; // # of occurences we're looking for |
| 23 | |
| 24 | int answer = -1; |
| 25 | |
| 26 | // the first time a number has the desired # of occurrences, |
| 27 | // save that number in our "answer" variable |
| 28 | for (int i=0; i < arrSize; i++){ |
| 29 | if (occurrences[i] == k && answer == -1) |
| 30 | answer = i; |
| 31 | } |
| 32 | |
| 33 | cout << answer; |
| 34 | } |
| 35 | |
| 36 |
nothing calls this directly
no outgoing calls
no test coverage detected