Coviam Interview Question

Write code to get transpose of matrix. Later optimize it to O(n).