Check Majority Element[Wrong answer-to be reviewed]
School Accuracy: 0.0% Submissions: 101 Points: 0

An element is a majority element if it appears more than (n/2) times in the array, where n is the total number of elements present in the array.
Given an array A[] of N integers and an integer X. You need to write a program which prints True if X is a majority element otherwise prints False.

Input:
First line of input contains an integer T which denotes the number of test cases. First line of each test case contains a single integers N where N is the size of array. Second lne of each test case contains N space separated integers. Third line of each test case contains a single integer X which denotes the element to be checked.

Output:
For each test case print True if X is a majority element otherwise print False.

Constraints:
1<=T<=10
1<=N<=1000
1<=A[i]<=105

Example:
Input:
3
7
1 2 3 3 3 3 10
3
8
1 1 2 4 4 4 6 6
4
5
1 1 1 2 2
1
Output:
True
False
True

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.