Interview Question for Software Developers

Country: India
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
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.

- dodo October 11, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
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?

- Anon October 30, 2019 | Flag Reply

Add a Comment

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


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


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