Adobe Interview Question






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

1.If A[m][n] is the given matrix,start from A[1][1].
2.for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
If A[i][j] is set, if true then
If A[i-1][j]&&A[i][j-1]&&A[i-1][j-1] is also set,then
A[i][j]+1

3.Traverse the whole matrix again to find the highest sum. If found at say A[i][j] then row_index=i;col_index=j;
4.for(k=i;k<0;k--)
for(l=j;l<0;l--)
print "1";

Although my language used may not be correct, I hope my logic is understandable and I hope it's right.

- Tiktok April 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Correction in step 1
If A[i-1][j]&&A[i][j-1]&&A[i-1][j-1] is also set,then
max(A[i-1][j],A[i][j-1],A[i-1][j-1])+1

- Tiktok April 06, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1.If A[m][n] is the given matrix,start from A[1][1].
2.for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
If A[i][j] is set, if true then
If A[i-1][j]&&A[i][j-1]&&A[i-1][j-1] is also set,then
A[i][j]+1

3.Traverse the whole matrix again to find the highest sum. If found at say A[i][j] then row_index=i;col_index=j;
4.for(k=i;k<0;k--)
for(l=j;l<0;l--)
print "1";

Although my language used may not be correct, I hope my logic is understandable and I hope it's right.

- Tiktok April 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

yeah got the idea

- Anonymous April 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Simply put, this solution:

int n, i, j, answer = 0;
scanf("%d", &n);
for(i = 0; i < n; ++i) {
	scanf("%s", &mx[i]);
	for(j = 0; j < n; ++j)
		if(mx[i][j] == '1')
			size[i][j] = 1;
}
for(i = 1; i < n; ++i)
	for(j = 1; j < n; ++j) {
		if(mx[i][j] == '1')
			size[i][j] = min(size[i][j - 1],
                            min(size[i - 1][j], size[i - 1][j - 1])) + 1;
		if(size[i][j] > answer)
			answer = size[i][j];
	}
for(i = 0; i < answer; ++i) {
	for(j = 0; j < answer; ++j)
		printf("1");
	printf("\n");
}

- DrSmith April 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am thinking of Knuth Morris Pratt algorithm but modifying the recursive definition accordinly.

- Messi April 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

working code

#include<iostream>
#define SIZE 5
using namespace std;
int checkthis(int a[][SIZE], int n, int size, int x, int y);
int checkthis(int a[][SIZE], int n, int size, int x, int y)
{
cout<<"size="<<size<<" x="<<x<<" y="<<y<<"\n";
int i=0;
int j=y;
for(i=x;i<=x+size-1;i++) if(a[i][j]==0) return 0;
j=y+size-1;
for(i=x;i<=x+size-1;i++) if(a[i][j]==0 ) return 0;
j=x;
for(i=y;i<=y+size-1;i++) if(a[j][i]==0 ) return 0;
j=x+size-1;
for(i=y;i<=y+size-1;i++) if(a[j][i]==0 ) return 0;

return 1;
}
int findsquares(int a[][SIZE], int n, int size, int &x, int &y );
int findsquares(int a[][SIZE], int n, int size, int &x, int &y )
{
int ret = 0;
for(int i =0; i<=n-size; i++)
for(int j=0; j<=n-size; j++)
{
ret = checkthis(a,n,size,i,j);
if(ret == 1)
{
x=i;
y=j;
return size;
}
}
return 0;
}
int main()
{
int a[SIZE][SIZE] = { 0,0,1,1,0,
1,0,0,1,1,
1,0,0,0,1,
1,1,1,0,1,
1,1,1,1,1};
int x=-1,y=-1;
int k=0;
for(int i=SIZE;i>=1;i--)
{
k=findsquares(a,SIZE,i,x,y);
if(k!=0) break;
}
cout<<"\nbounds:"<<x<<","<<y<<" size:"<<k<<"\n";
return 0;
}

- hi June 16, 2010 | Flag Reply


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