Microsoft Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
1
of 1 vote

I presume maximum result means that the result eventually obtained on XOR is maximum:

Thus one should start from MSB:
Function Split: Divides list of numbers into 2 lists: list A contains all numbers starting with 1, MSB removed. list B contains all numbers starting with 0, MSB removed. eg. 1011, 0101, 1001 is divided into 2 lists: A:{011, 001}, B:{101}

given such a split, the candidate maximum XOR pair should have one coming from A and other coming from B...

Thus given A,B as above, applying recursion, candidate pair should come from one of (AA, BB) or (AB, BA). ie. (NULL, NULL) or ({11, 01}, {01})

Continue using induction. Avoid any pair containing at least one NULL list. Base condition is when both list have one element each. Recursion based on comparison.

- evitagen wercs November 10, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Err ... The complexity seems N^2*x, where x is the number of bits per integer. Then why don't we just using for loops, it's complexity will be N^2 as well.

- integer February 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is this not xor (n, xor(n)).. i.e n and xor(n) are the two integers?

- shekar May 12, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what if xor(n) is not in the list...that is the problem...

- king_k July 10, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think if we sort the array and find the smallest and largest element and by XORing those two numbers we can find the maximum number.Any comments?????

- Anonymous November 09, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

no.

consider array {8, 7, 6, 1}
binary are {1000, 0111, 0110, 0001}
The biggest xor is from 1000 xor 0111 = 1111
the biggest xor smallest is 1000 xor 0001 = 1001

- redroof November 16, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use a compressed trie or suffix tree. based on the bit at each position of the number, generate the suffix tree. then pick the nodes which end up at numbers such that the difference in position of the bit on which they were last divided is maximum. if there are more than one number split at any of those bits, then compare the bit at that position and select the pair which differ at that bit. consider the following example: S={1,6,7}
S
| \
001 /\
110 111 (bit 3)
001 is obtained on split at bit position 1. at bit position 3, we obtain split on 6,7. the maximum difference is between numbers differing at bit positions 1 and 3. hence it can be {1,6} or {1,7}. but now, check bit position 3. 1,6 differ at 3 but 1,7 dont. hence {1,6} give the maximum difference.

- Anonymous January 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about this?
Just biggest number should have 1 in the height bit field.
Example, Assuming that binary are {1000, 0111, 0110, 0001}
1000 -> 8 is biggest number.
than adjust XOR all number with the biggest number in the array again and get the biggest result.

The Big O would be
1. finding biggest number O(n)
2. Adjusting XOR all element in the Array with biggest number O(n) and finding biggest result.
3. print out two numbers.
===> O(n)

Is there something I missed? 2EZ...

- Anononomy April 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

consider the case of an array {1, 6, 7}
Your algorithm will flunk in this case.

The correct answer is {1,6} in this case and neither 6 nor 7 is the maximum in the array.

- pkm July 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

n*x approach ...x is no. of bits

find maximum no. O(n)
now traverse array again and take XOR with each element to find the largest.

- !@# July 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry it's wrong

- !@# July 21, 2013 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More