I recently came across this question in an interview. I could not answer this question. I started with, take the first element from the first array, and then find how many elements are larger than this element in another array. But then, I mean, I donβt know, I could not really form a solution. The problem is this:
For two sorted arrays, A and B generate all possible arrays, so the first element is taken from A, then from B, then from A, etc. in ascending order until the arrays are exhausted. Generated arrays must end with an element from B.
Eg: A = {10, 15, 25} B = {1, 5, 20, 30} The resulting arrays are: 10 20 10 20 25 30 10 30 15 20 15 20 25 30 15 30 25 30
I'm not looking for code, just algo / pseduo code will be fine. Thanks!
sorting arrays algorithm
John lui
source share