# Majority Element lll

Contributed by
Shrey Pansuria
Medium
0/80
10 mins
90 %
+5 more

## Problem Statement

#### For example:

``````Given array āARR = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 1, 2 ,0}ā and āK = 4ā
``````

#### Answer is {3, 4} because ā3ā occurs ā4ā times and ā4ā occurs ā3ā times which is more than or equals to ā12/ 4 =3ā.

Detailed explanation ( Input/output format, Notes, Images )
##### Sample Input 1:
``````2
8 4
1 1 2 1 2 4 3 4
6 6
1 1 1 2 2 2
``````
##### Sample Output 1:
``````1 2 4
1 2
``````
##### Explanation For Sample Input 1:
``````Test Case 1:
Given array āARR = { 1, 1, 2, 1, 2, 4, 3, 4 }ā and āK = 2ā.

Only 1, 2, 4 has frequency more than or equal to āN/K' = 8/4= 2.

Test Case 2:
Given array āARR = { 1, 1, 1, 2, 2, 2 }ā and āK = 6ā.
āN/K = 6/6 = 1ā so ā1ā and ā2ā both have frequency more than ā1ā.
``````
##### Sample Input 2:
``````2
9 3
1 1 1 2 2 2 2 2 2
6 6
1 2 1 2 3 4
``````
##### Sample Output 2:
``````1 2
1 2 3 4
``````
##### Explanation For Sample Input 2:
``````Test Case 1:
Given array āARR = { 1, 1, 1, 2, 2, 2, 2, 2, 2 }ā and āK = 3ā.

Both 1, 2 has frequency more than or equal to āN/K' = 9/3= 3.

Test Case 2:
Given array āARR = { 1, 2, 1, 2, 3, 4 }ā and āK = 6ā.
āN/K = 6/6 = 1ā so ā1ā, '2', '3' and ā4' all have frequency more than ā1ā.
``````
Autocomplete
Console