Qualcomm Interview Question for Software Engineer / Developers






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

take an array containing elements till 50. XOR this array with the given array in which 2 elements are missing.
find the right most bit set in the XOR.
now divide the elements in the given array and the array containing all 50 elements in to two groups such that if the right most bit set in the XOR is also set in the element it will go to one group and if its not set it ll go another group.
Xor the 2 groups individually.
XOR1 and XOR2 will be the two missing numbers.

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

it doesn't work when two missing number equal.

- Anonymous March 13, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Question is not clear ! can u please elaborate it ?

- Annonymous December 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

xor 3 times.
O(n) time O(1) space No overflow.

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

I guess array has 1 to 50 but two are missing.

So expanding on hunt's comment...

XOR array with 1,2,... ,50.

if missing numbers are a and b, we get a XOR b.

Using this, we can now tell a bit on which they differ.

Use that bit to partition array into two parts.

XOR each partition individually with 1 to 50 keeping that bit in mind. You will end up with a & b.

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

How do you know there is only one bit difference between a and b?

- patli February 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@above....the solution might be wrong..suppose 10 and 11 r missing..and if we XOR all the values frm 1 to 50...u will get 50 as O/P...

- JackMaster January 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think the question is :
You have an array of 50 element, this array is having value from 1 to 50 in random order ,eg : 2, 45 ,12, 7, 9 ..etc, Now any two of this value by mistake are set as zero (eg : Array[2] and Array[4] are set as zero ,original value at index 2, and 4 was 12 and 9 )..Now the question is how you will find the original value in O(n ) time ..

- Aloke January 17, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@JackMaster.

YOu didn't read the whole solution.

There are more steps after taking the XOR.

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

any one having answer to above ?

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

I think if we just XOR the array of 50 with an array of 50 zero's. Only the missing values will return 1. The rest of the values will be not equal to 1. example 50 xor 0 / 20 xor 0 / 5 xor 0 will never be 1. only 0 xor 0 = 1

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

@Divz, 0 xor 0 is 0 not 1 ,,, but 1 ^ 1 is 0,,

and secondly ,we have to solve it without using any other storage (array) and without using addition and subtation method..I am still not able to understand the solution provided by Anonymous ,
@Anonymous , can u plz explain ur solution with a example ,
Thanks
Aloke

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

@aloke. Your right... It was a stupid mistake on my part.
I think if we XOR the array with 1,2,3,4... 50 individually in an iteration if 1 is present one of the elements with value '1' in the array is 0,similarly if 2 is present again we have one of the elements of the array as zero and so on. For the missing number no element of the array will result in a zero.

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

I cannot understand this XOR method. Can any one explain it in more detail ?

Another solution could be to sort the array. But this will take O(n) time

- abhimanipal February 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can anyone please explain this solution?

- kapoor February 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what abt sort n binary search kind of analysis?

- Anonymous March 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

if not binary tree than,traverse the array if a[i]=j then go to jth index make a[j]=-a[j].After u r done with it,traverse the array to get the index having positive number.To take of duplicate number if present do not neagte the array value if its already neg.


Complexity=O(n)

- Anonymous March 08, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Do a summation of numbers from 1 to 50 as SumTill50 = 1+2+...+49+50. Add the numbers in the array SumArray = arr[0] + arr[1] + .. + arr[49] + arr[50]

Substract SumArray from SumTill50 as SumResult = (SumTill50 - SumArray). The result will contain sum of missing numbers.

Do a multiplication of numbers from 1 to 50 as MulTill50 = 1* 2* 3.. *49*50. Multiply the numbers in array MulArray = arr[0] *arr[1] * arr[2]... *arr[49]*arr[50]

Substract MulArray from MulTill50 as MulResult = (MulTill50-MullArray). The result will contain product of missing numbers.

So we are reduced to 2 equations and we need 2 find two unknows
x+y = SumResult
x*y=MulResult

Multiply 1st eq with y
x*y + y*y = SumResult*y

Substract 2nd eq from 1st

y*y = SumResult*y - MulResult - Determine y
Substract value of y from SumResult - Determine x

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

Take a boolean array a[50], given array b[50]
now for(i=0;i<50;i++)
a[i]=FALSE;
for(i=0;i<50;i++)
a[b[i]]=TRUE;

for(i=0;i<50;i++)
if(a[i]==FALSE)
print element

complexity O(N)

second approach use HASH TABLE

Store all the elements of the array in the HASH TABLE
now for(i=0;i<50;i++)
perform a lookup of a[i] in the hash table if not present that is the element missing

- Anonymous April 28, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

he explicitly asked not to give the sum and mult medhod ! the que should be read carefully before answering.

- cirronimbo August 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void missingNums(vector<int>& a, int n){
    vector<int> b(n);
    iota(b.begin(), b.end(), 1);

    int x = 0;
    for(int i:a){
        x ^= i;
    }
    
    for(int i:b){
        x ^= i;
    }
    
    x = x & (~(x-1));
    
    int p = 0,q = 0;
    for(int i:a){
        ((x&i) == x)? (p ^= i) : (q ^= i) ;
    }
    cout << "-----" << endl;
    for(int i:b){
        ((x&i) == x)? (p ^= i) : (q ^= i) ;
    }
    
    cout << p << " " << q << endl;
}

- swapnilsj August 21, 2016 | Flag Reply


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