You are given an integer N.
We represent the number N as the sum of distinct numbers that are powers of 2.
Task
If we put these numbers in an array, your task is to find the maximum element in this array.
Example
Assumption:
N=10
Approach:
10 can be expressed as the sum of [1,2,8] which are powers of 2 and the
maximum of these numbers is 8. Hence, the answer is 8.
Function description
Complete the function solve provided in the editor. This function takes the following one parameter and returns the required answer:
N: the integer which is to be represented as the sum of powers of 2.
Input format
Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).
The first line contains T denoting the number of test cases. T also specifies the number of times you have to run the solve function on a different set of inputs.
For each test case:
The first line contains the integer N.
Output format
For each test case, print the answer in a new line.
Constraints
1≤T≤10
1≤N≤106
Code snippets (also called starter code/boilerplate code)
This question has code snippets for C, CPP, Java, and Python.
The first line contains the number of test cases.
In the first test case, 4 is itself a power of 2 hence it is the answer.
In the second test case, 11 can be represented as the sum of [2,8,1] which are all powers of 2. The maximum among these is 8, So 8 is the answer.