MAJOR - Majority

no tags 

The human tribe has just discovered some other tribe and wants to communicate with them. To make sure it is not intercepted by the terminators, they ask their chief computer engineer Rohit to design a system for the purpose. In the design that Rohit proposes, data is transmitted n times. If it is received more than half-the times, it is said to be successfully transmitted. If not, the data is said to be lost. Rohit obviously got a lot of fame and respect for his work. Nitish doesn’t like it and wants to challenge Rohit’s supremacy. He wants to check out the system and has hired you for the process.


The first line of the input contains test cases t (1 <= t <= 100). It is followed by 2*t lines, 2 for each test case. The first line of input for each test case contains a number n (0 <= n <= 106), followed by n elements in the next line. Each number is from -10^3 to +10^3


You are required to output ‘YES’ followed by the number transmitted, if it was transmitted successfully, and ‘NO’ otherwise.


2 1 2 2
1 1 1 2 2 2
1 2 4 5 1


hide comments
gokuln2ath_b: 2020-11-08 15:33:08

Can someone please explain to me the question? Please!

s_tank00_: 2020-07-16 08:03:05

while using map dont iterate through auto keyword use proper initiation of iterator . cost me 1 compilation error .

aagamjain04: 2020-06-29 17:00:59

If u are using map then don't use "break" as soon as u find ans, will result in WA

Last edit: 2020-06-29 17:01:54
kumar_anubhav: 2020-06-27 15:09:59

AC in GO !! :)

tech_niks: 2020-04-11 14:51:31

Using map its a piece of cake.. but to make things interesting use Moore voting algo..

anand_undavia: 2019-08-11 18:33:34

Java => TLE
C => AC

importme: 2019-07-08 16:58:07

Nice Question!!

mgroovyank: 2019-06-16 08:58:03

Can someone tell why my code got accepted after I removed fast input/output?

begin_143: 2018-10-18 15:47:56

moore voting

nadstratosfer: 2017-12-27 03:07:04

Simple problem but many oportunities to optimize the code. From TLE to 0.27s to 0.18s in PyPy in several steps, each time taking a chance on something I didn't expect to matter, yet always yielding a tangible improvement.

Added by:Troika::Bytes
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: PERL6