# Help me in solving this puzzle people #
 Interviewstreet Challenge

•   Challenges /Manipulative Numbers
•   Rank:  103  Score:  717.63 
Suppose that A is a list of n numbers ( A1, A2, A3, ... , An) and B ( B1, B2, B3, .. ,Bn ) is a permutation of these numbers. We say B is K-Manipulative if and only if its following value:
•   M(B) = min( B1 Xor B2, B2 Xor B3, B3 Xor B4, ... , Bn-1 Xor Bn, Bn Xor B1 ) is not less than 2^K.
You are given n number A1 to An, You have to find the biggest K such that there exists a permutation B of these numbers which is K-Manipulative.
Input:
In the first line of the input there is an integer N.
In the second line of input there are N integers A1 to An 
N is not more than 100. 
Ai is non-negative and will fit in 32-bit integer.
Output:
Print an integer to the output being the answer to the test. If there is no such K print -1 to the output.
Sample Input
3
13 3 10

Sample Output

2

Sample Input

4
1 2 3 4

Sample Output

1

Explanation

First Sample test
Here the list A is {13, 3, 10}. One possible permutation of A is, B = (10, 3, 13).
For B,  min( B1 xor B2, B2 xor B3, B3 xor B1 ) = min( 10 xor 3, 3 xor 13, 13 xor 10 ) = min( 9, 14, 7 ) = 7.
So there exist a permutation B of A such that M(B) is not less than 4 i.e 2^2. However there does not exist any permutation B of A such that M(B) is not less than 8 ie 2^3. So the maximum possible value of K is 2.

[boilerplate_help_info]
Posting requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it you missed:

  1. Ask a question that can be answered. Do not ask
    -What's wrong with my code?
    -Why doesn't this work?
    -Anything else that does not give us useful information.
  2. Post your code. If we don't know what you did, how can we possibly help?
    -Use PROPER FORMATTING -- see this
    -Use CODE Tags so your formatting is preserved.
    If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable.
  3. Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
  4. Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
  5. If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
  6. Do not ask for code. We are not a coding service. We will help you fix your code.
    -If anyone posts working code for you, they are a cheater.
    -If you use that code you are a cheater.
  7. Do not bore us with how new you are. We can tell by your code.
    -Do not apologize. We were all new, and unless you are completely brain dead you will get better.
    -Do not ask us to "take it easy on you."
    -Do not say "I don't know what's going on." That's obvious since you posted for help. Use that time wisely by explaining as best you can so we can help.
  8. Do not apologize for posting 'late'. We don't have any expectations on when you should be posting - 10 minutes or 10 days. We aren't timing your responses.
  9. Do not post your requirements and nothing else. We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we will be hard on you.
  10. Do not attach files except when absolutely necessary. Most of us are not going to download files. Add the information to your post.
  11. Do not tell us how urgent it is. Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
  12. Create a good title for your post. The title C++ in the C++ forum is bloody redundant and worthless! What's wrong? equally so. Specifically what are you having trouble with? There is your title. (note: my program is not the answer.)

Think more about your next post so we don't have to play 20 questions to get the info we need to help you.
[/boilerplate_help_info]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.