0

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.

4
  • 4
    ’merging’ according to which rule? simply append? Commented Jul 16, 2019 at 16:00
  • 3
    Adding an example would really lighten things up. Commented Jul 16, 2019 at 16:00
  • I guess it is possible to append, but then how can I know where is the separation? Commented Jul 16, 2019 at 16:01
  • 2
    Can you elaborate on what you mean by "merge" and "separate?" Commented Jul 16, 2019 at 17:30

1 Answer 1

2

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

  • size of A
  • Acontent
  • size if B
  • Bcontent

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

Sign up to request clarification or add additional context in comments.

1 Comment

Great answer @Damien, I removed mine because yours is much better!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.