Yours approach is good to get answer.
>From my best understanding
yours algorithm will take 1^2 + 2^2 + 3^2 + . + N^2 + (N-1)^2 +
.+ 1^2
to place all array into 1D array. which evaluates to O(N^3) with O(N^2)
space storage.
Actually there is an idea to take every element
Solution To 1st problem
maintain two single dimension arrays...initially store 1st rows in both arrays from both input arrays
find minimum element in stored array it takes O(n) time
replace that minimum ele with correspondin column next element
[ Example if a[0][0] is minimum replace with a[1][0
Consider a Array of N x N
For example take 3 X 3
Since the array is sorted by row and column , sort all the array
elements by reading it in zig-zag order.
for example
589
6 10 13
11 15 17
can be read as
5 6 8 9 10 11 13 15 17
by chechking whether the row or column entry c