Adobe Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
For each row
Mark the highest element into an index-array.
For each column
verify the least element in an index-array.
if already marked. Report the element.
else continue.
In Two-Game theory, such an element is called a Saddle point. Santiago's answer is standard way to solve it.
int main()
{
int a[4][4] =
{
{10,3,1,12},
{16,2,3,4},
{8,9,20,10},
{5,18,7,11}
};
int rows = 4;
int cols = 4;
int i, j, k,high,id,isPrint = 1;
k = 0;
while(k < rows)
{
high = a[k][0];
isPrint = 1;
id = 0;
for(i = 1; i < cols; i++)
{
if(a[k][i] > high)
{
high = a[k][i];
id = i;
}
}
for(j = 0; j < rows; j++)
{
if(a[j][id] > high)
{
isPrint = 0;
break;
}
}
if(isPrint == 1)
printf("%d\n",high);
k++;
}
return 0;
}
int main()
{
int a[4][4] =
{
{10,3,1,12},
{16,2,3,4},
{8,9,20,10},
{5,18,7,11}
};
int rows = 4;
int cols = 4;
int i, j, k,high,id,isPrint = 1;
k = 0;
while(k < rows)
{
high = a[k][0];
isPrint = 1;
id = 0;
for(i = 1; i < cols; i++)
{
if(a[k][i] > high)
{
high = a[k][i];
id = i;
}
}
for(j = 0; j < rows; j++)
{
if(a[j][id] > high)
{
isPrint = 0;
break;
}
}
if(isPrint == 1)
printf("%d\n",high);
k++;
}
return 0;
}
#include<iostream>
#include<set>
using namespace std;
void MaxMin(int A[2][2] )
{
set<int> row , col;
for( int i=0 ; i<2 ; i++ )
{
for( int j= 0 ;j<2 ; j++ )
{
row.insert( A[i][j] );
for( int k=0 ; k<2 ; k++ )
{
col.insert(A[k][j]);
}
if( *row.end() == *col.begin() )
cout << *row.end();
}
}
}
int main()
{
int r[2][2] = {2,2,4,4};
MaxMin(r);
return 0;
}
#include <iostream>
using namespace std;
int main(){
int i,j, m, n, a[100][100];
cin>>n>>m;
for (i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>a[i][j];
}
}
for (i=0; i<n; i++)
{
for (j=0;j<m;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<"\n";
}
for(i=n-1, j=0;i>=0&&j<m; i--,j++)
{
cout<<a[i][j]<<"\t";
}
return 0;
}
it cud easily be dun by d use of the two arrays named rows and cols where rows stores the colno of the element vich is max in dat row...while cols stores the row nos of the elemnt that is max in the given col then jst chk if.....col[rows[i]]=i if its true then its the reqd element....
- Anonymous February 29, 2012TC-O(n^2)
SC-O(n)