Skip to content

ORIGINAL CODING QUESTION

Most practised topic

Each practice session is tagged with an integer topic code. Return the code that appears most often. If several codes tie for the highest count, return the smallest of them.

Open practice workspace

Original exercise · easy. Editorial role relevance does not imply a company has asked this question.

Input and output

First integer n, then n integers. Print one integer.

Constraints

1 ≤ n ≤ 200; -1000 ≤ topic code ≤ 1000.

Example 1

Input

7
4 2 4 3 2 4 1

Output

4

Topic 4 appears three times, more than any other.

Example 2

Input

4
9 3 9 3

Output

3

Topics 9 and 3 tie with two sessions each; 3 is smaller.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

You need a count for every distinct code.

Hint 2

A hash map from code to count fills in one pass.

Hint 3

After counting, pick the code with the highest count, breaking ties by choosing the smaller code.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →