MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

HackerEarth_problems/RepeatedKTimes/solution.cpp:4–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4int 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected