LinkedIn Interview Question: generating a sorted vector fr... |

Interview Question

Data Scientist Interview Mountain View, CA (US)

generating a sorted vector from two sorted vectors.


Interview Answer

3 Answers


keep two pointers and compare the two numbers they point to.
Move the pointer which points to the smaller or equal number.
End loop when two pointers reach the end.

Anonymous on 22-Feb-2012

look at merge in mergesort, does exact same thing.

SomeOne on 06-Oct-2012

Merge sort is the best...many languages have this function inbuilt...else this can also be done manually, assume two vectors A [1,2,3,4] And B[5,6,7,8]...merge the last value of A and first value of our case 4<5 is true...thus the result...if it is false then move the number up and then compare it with the previous number and so on...

Anonymous on 05-Mar-2016

Add Answers or Comments

To comment on this, Sign In or Sign Up.