ORIGINAL CODING QUESTION
Majority topic ID
Return the topic ID occurring strictly more than n/2 times, or -101 if no such ID exists.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n integer values. Print one integer as described.
Constraints
1 ≤ n ≤ 200; -100 ≤ value ≤ 100. Inputs contain exactly the stated values.
Example 1
Input
5 2 1 2 2 3
Output
2
Topic 2 occurs three times.
Example 2
Input
4 1 1 2 2
Output
-101
Neither topic exceeds half.
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
The threshold is strict.
Hint 2
Pairing different values can eliminate minority candidates.
Hint 3
A candidate still needs a final frequency verification.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →