IWIN - Editorial

PROBLEM LINK:

Practice

Contest

Author: Ranjan Kumar Singh

Tester: Sudipto Roy

Editorialist: Ved Prakash

DIFFICULTY:

CAKEWALK

PRE-REQUISITES:

Basic Maths

PROBLEM:

There are 15 numbers to sort according to number of 1’s in its binary operation. Then perform the XOR operation and find the number of 1’s in it. Finally compare the number of 1’s in the resulted number and X.

If number of 1’s is greater than X print YES else print NO.

EXPLANATION:

For the XOR operation, order of the numbers doesnot matter. Hence simply it is needed to xor the numbers. Then count the number of ones in the number obtained by XORing. Compare the number of 1’s with X and print YES

or NO accordingly.

Pseudo Code:

num=0
for i=1 to 15:
    num^ = arr[i]
while(num)
    if(num%2) ones++
    num/=2

Complexity: O(N).

SOLUTIONS:

Setter’s solution

Tester’s solution

1 Like