is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
I used transform and coding for this problem.
- Supreeth June 24, 2014When the matrix is a square, it's a trivial job to transform. i.e. by swapping lower and upper triangular matrix.
When the matrix is a non square, I'll get the square matrix out of it, i.e. if it is a '4X2' matrix, I'll apply the above method for '2X2' and I will be left to transform 3rd and 4th row. So you can interchange the row and column number to get the solution
Here is a code which implements the same
#include<iostream>
using namespace std;
const int m = 3; //Number of rows
const int n = 10; //Number of columns
int main()
{
int a[10][10] = {
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 },
{ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 }
};
int i, j;
cout << "MATRIX A : \n";
for( i = 0; i < m; i++ )
{
for( j = 0; j < n; j++ )
cout << a[i][j] << "\t";
cout << endl;
}
// Transpose begins here
int index, m_index = 0, n_index = 0;
if( m == n )
index = n;
else if( m < n )
m_index = index = m;
else
n_index = index = n;
for( i = 0; i < index-1; i++ )
{
for( j = i+1; j < index; j++ )
{
int temp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = temp;
}
}
if( m_index == 0 ) // implies n < m
{
for( i = n; i < m; i++ )
for( j = 0; j < n; j++ )
{
cout << " i : " << i << " j : " << j << endl;
a[j][i] = a[i][j];
a[i][j] = 0;
}
}
else if( n_index == 0 ) // implies m < n
{
for( i = m; i < n; i++ )
for( j = 0; j < m; j++ )
{
a[i][j] = a[j][i];
a[j][i] = 0;
}
}
cout << "\nTRANSPOSE OF A : \n";
for( i = 0; i < n; i++ )
{
for( j = 0; j < m; j++ )
cout << a[i][j] << "\t";
cout << endl;
}
return 0;
}