Question: Maximum pairs You are given an array nums consisting of N integers where N is even. You have to perform the following operation N /
Maximum pairs
You are given an array nums consisting of N integers where N is even.
You have to perform the following operation N times:
Select nums;, nums; such that ij from the list
Take their bitwise OR add the value of the least significant set bit to the score
Delete those two numbers
If the selected numbers are and then the bitwise OR of the two numbers is So the least significant bit of ie will be added to the current score.
Notes
based indexing is followed
A bitwise OR is a binary operation that takes two bit patterns of equal length and performs the logical inclusive OR operation on each pair of corresponding bits. The result in each position is O if both bits are while otherwise, the result is
Strings in denote the binary representation.
Task
Print the maximum possible score.
Example
Assumptions
N
nums
Approach
For the given case pairing that is nums numsnums nums with based indexing results in a maximum score of pairing like that is nums numsnums nums results in
Hence, the answer is
Function description
Complete the MaxPairs function provided in the editor. The function takes the following parameters and returns the maximum possible score based on the parameters.
N: Represents an integer denoting the total number of integers
The second line contains N spaceseparated integers denoting the elements of array nums.
Output format
For each test case, print the answer representing the maximum possible score in a new line.
Constraints
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
