Reputation: 1540
I am preparing for a job interview and have an question. I have 2 binary arrays of n and m size. I need to create an algorithm for merging them together and then separating them. The merged array is have to be also binary array. No information about the size of merged array, I assume it could be n+m.
Upvotes: 0
Views: 394
Reputation: 4864
If you know what is the maximum size of A
and B
, then you can code the sizes of A
and B
in binary, and create a new binary array by multiplexing
A
A
contentB
B
contentThen demultiplexing (separating A
and B
) is easy.
It is similar to what is performed in telecommunications.
Edit: I mentioned that maximum size must be known. This is because for demultiplexing we need to know how much bits are used to encode the sizes. Then, the number of bits for this encoding must be fixed.
Upvotes: 2