J
Jack
Hi,
I was asked this question during an interview. It seems very simple
but I don't know if there is a more efficient way.
The question said, we have 2 arrays as follows
A = [2, 3, 5, 7]
B = [4, 6, 8, , , , ]
As you can see both arrays are sorted. Also we see that B has enough
space for all the elements in A. We want to put element A in to B
without using a third element.
My solution was to add all elements from A to the end of and then use
quick sort to sort B. The other way would be to traverse B for every
element in A but that wouldn't be too efficient since it will be
O(n^2).
I was asked this question during an interview. It seems very simple
but I don't know if there is a more efficient way.
The question said, we have 2 arrays as follows
A = [2, 3, 5, 7]
B = [4, 6, 8, , , , ]
As you can see both arrays are sorted. Also we see that B has enough
space for all the elements in A. We want to put element A in to B
without using a third element.
My solution was to add all elements from A to the end of and then use
quick sort to sort B. The other way would be to traverse B for every
element in A but that wouldn't be too efficient since it will be
O(n^2).