Interview Question


Country: United States
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
1
of 1 vote

maxmin( int arr[ ][ ];row;col)
{
int min=arr[0[[0];int ro,co
for(i=0;i<row;i++)
{
for(j=o;j<col;j++)
{
if(arr[i][j]<min)
min=arr[i][j];ro=i;co=j;
}
if(max(arr,min,ro,co))
return min
}

}
int max(arr,int min,int row,int co)
{
for(j=o;j<row;j++)
{
if(arr[j][co]>min)
return -1
}
return 1
}

- It brother October 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

thank you fort the reply.

i have not try it out

but it is right.

- nz2324nz2324 October 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please explain the algo..I am unable to understand

- Lucy October 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Lucy What the algorithm does is iteratively find the minimum element of the first row, and see if that element is the largest one in its column. If it is, then we've found the solution. If not, move to the next row, and do the same thing.

- Richard October 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

void FindSmallRowBigCol()
{
	int a[][4]={1,2,3,4
		       ,5,6,7,8
	           ,9,10,11,12
	           ,13,14,15,16};
	int mini=0,minj=0;
	bool bfound=1;
	for(int i=0;i<4;i++)
	{
		bfound=1;

		for(int j=0;j<4;j++)
		{
			mini=i;
			minj=0;
			if(a[i][j]<a[mini][minj])
			{
				mini=i;
				minj=j;
			}
		}
		for(int k=0;k<4;k++)
		{
			if(a[mini][minj]<a[k][minj])
			{   bfound=0;
				break;
			}
		}
		if(bfound==1)
		{
			printf("[%d][%d]:%d",mini,minj,a[mini][minj]);
		}

	}

}

- Anonymous December 25, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>


const int rowN = 3;
const int colN = 3;


int findElement(int matrix[rowN][colN]){

	/* if matrix is null, return null*/
	if(matrix == NULL)
		return NULL;

	int result = NULL;

	/* matrix size */
	int numOfRows = rowN;
	int numOfCols = colN;
	


	/* create an auxiliary list boolean array */
	int smallestColPerRow[numOfRows];

	/*find the smallest element in each row*/
	int rowIter, colIter;
	for(rowIter=0; rowIter < numOfRows; rowIter++){

		int smallestCol = 0;
		for(colIter=0; colIter < numOfCols; colIter++){
			if(matrix[rowIter][colIter] < matrix[rowIter][smallestCol])
				smallestCol = colIter;
		}
		
		
		smallestColPerRow[rowIter]= smallestCol;
	}

	/* search for largetst element in each col, check if it is the smallest element in that row too*/

	for(colIter=0; colIter< numOfCols; colIter++){
		
		int largestRow = -100000;

		for(rowIter=0; rowIter< numOfRows; rowIter++){
			if(matrix[rowIter][colIter] > matrix[largestRow][colIter])
				largestRow = rowIter;
		}

				
		if(smallestColPerRow[largestRow]== colIter){
			result =matrix[largestRow][colIter];
			break;
		}
	}
	return result;
}

int main(){
	
	int matrix [rowN][colN] = {
	{1,1,3},
	{0,1,-1},
	{1,-1,2}};
	
	int result = findElement(matrix);
	if(result == NULL)
		printf("\nnot found");
	else
	printf("\nresult is:%d\n", result);

	return 0;
}

- taheri.javad October 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can you please explain the algo?

- barathrum October 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SampleMain {
public static void main(String[] args) {
int max=0;
int a[][]={{1,2},{2,3,4},{123},{4,45,12,3,11,7}};
int track=0;
for(int i=0;i<a.length;i++){
int tmp=a[i].length;
if(tmp>max){
max=tmp;
track=i;
}
}
Arrays.sort(a[track]);
System.out.println(a[track][0]);
}
}

- Jagdesh October 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define ARRAY_SIZE 3
/*
3 0 5
6 0 10
110 100 80*/

main()
{
int x[3][3] = {3,0,5,6,0,10,110,100,80};
int i, j, k;
int min_index = 0;
int min, min_row, min_row_index;

printf("size is %d\n", ARRAY_SIZE);
for(i = 0; i < ARRAY_SIZE; i++) {
min_row = x[i][0];
min_row_index = 0;
/* searching each row */
for(j = 0; j < ARRAY_SIZE; j++) {
if(min_row > x[i][j]) {
min_row_index = j;
min_row = x[i][j];
}
}
printf("min_row %d min_row_index %d\n", min_row, min_row_index);
/* so we found out the minimum in the row now let's search
if it is greater in the corresponding column */
for(k = 0; k < ARRAY_SIZE; k++) {
printf("x[k][min_row_index] %d\n", x[k][min_row_index]);
if(min_row < x[k][min_row_index])
break;
}
if(k == ARRAY_SIZE) {
printf("we found it %d\n", min_row);
break;
}
}
}

- anon October 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please explain the algo..I am unable to understand

- Lucy October 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

for each line:
    find the samllest one in this line.
    if it is also the biggest one in his column, return it.
return -1 if not found

- nz2324nz2324 October 24, 2012 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

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.

Learn More

Resume Review

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.

Learn More

Mock Interviews

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.

Learn More