Question: (IN C++) Write a function: int solution (vector &A ; that, given an array A consisting of N integers, returns the size of the largest

(IN C++)

Write a function:

int solution (vector &A ;

that, given an array A consisting of N integers, returns the size of the largest possible subset of A such that AND of all its elements is greater than 0.

Examples: 1. Given A = [13, 7, 2, 8, 3] your function should return 3. We can pick subset 13, 7 and 3. AND of these elements is positive and it is the largest possible subset of numbers that fulfills the criteria. 1101(13) AND 0111 (7) AND 0011(3) = 0001 (1)

2. Given A = [1, 2, 4, 8] your function should return 1. The AND of each pair from the array is equal to 0.

3. Given A = [16, 16] your function should return 2. The AND of both numbers is 16.

Write an efficient algorithm for the following assumptions: N is an integer within the range 1..100,000 each element of array A is an integer within the range [1..1,000,000,000].

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!