## Interview Question for Software Developers

Country: India
Interview Type: In-Person

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

Hint: sort A in desc order, and sort the corresponding B as well. Now you can flip the B bits from the beginning 2 by 2 to ideally get something like:

1 1 1 1 1 1 0 0 0 0 0 0

where the 1's correspond to positive A's and 0's correspond to negative A's. This is possible with at most 1 bit error where positives become negatives.

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

perhaps your "interviewer was not quite satisfied with" your approach because it is obviously incorrect.. so for instance, if
A = [Y,Y,Y,]
B = [0,1,0]
then x (number of 1s) = 1 and A[i]*B[i] is same for every 'i'
and your algorithm will keep B as is

but flipping B[0] B[1] pair first and then the B[1] B[2] pair will give you
B = [1,1,1]

There is also a lot missing to get to a correct solution. For instance, what do we know about A? Is it sorted? If not, can it be sorted without maintaining its correspondence with B? Does it have negative integers?

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.

### 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.