By googling for minutes, I know the basic idea.
- Let A,B,and C be sorted arrays containing n elements.
- Pick median in each array and call them medA, medB, and medC.
- Without loss of generality, suppose that medA > medB > medC.
- The elements bigger than medA in array A cannot become the median of three arrays. Likewise, the elements smaller than medC in array C cannot, so such elements will be ignored.
- Repeat steps 2-4 recursively.
My question is, what is the base case? Assuming a lot of base cases, I tested the algorithm by hands for hours, but I was not able to find a correct base case. Also, the lengths of three arrays will become different every recursive step. Does step 4 work even if the length of three arrays are different?