Close
Topic list
Majority Element lll
MEDIUM
10 mins
Arrays
Topics (Covered in this problem)
Problem solved
Skill meter
Arrays
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Majority Element lll

Contributed by
Shrey Pansuria
Medium
0/80
Avg time to solve 10 mins
Success Rate 90 %
Share

## 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, Constraints, 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’.
``````
Auto
Console