I was asked this question in an interview. Am looking for answers for this:

A rectangular array of cells (say m*n) are selected in a spreadsheet (eg: MS excel). Assume that the cells contain only integer values. They need to be pasted to some location within the same spreadsheet after transposing the array (which means that the destination location will have transposed array containing n*m cells). We cannot use any memory buffers (eg: clipboard) to perform this operation. We can only use one or two temporary integer variables if required.

Write a C function/algorithm to do the same.

I'll really appreciate if someone can help me on this. Remember that some (or all) cells at the paste location might overlap with the copied (source) cells.