Adobe Interview Question for Software Engineer / Developers






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

Take an array of arr mxn. Now we can fill the arr[i][j] such that it contains the sum of all the elements with row<=i and col<=j in o(n^2).
Find max value in o(n^2) using:

Sum of all numbers in the square with left top corner at i,j will be as follows:

Also initialise the base condition (rows and columns to zero).
for(i=1;i<=m;i++){
	for(j=1;j<=n;j++){
		a[i][j] = input[i][j] + a[i-1][j] + a[i][j-1] - a[i-1][j-1];
	}
}

int max = 0;
for(i=1;i+k<=m;i++){
	for(j=1;j+k<=n;j++){
		int temp = a[i+k-1][j+k-1] - a[i-1][j+k-1] - a[i+k-1][j-1] + a[i-1][j-1];
		if(temp > max ){
			max = temp;
			row = i;
			col = j;
		}
		
	}
}

- Saurabh Agrawa; February 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

how can u use k in code if u have to find out that value?

- Anonymous August 12, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I will assume that value of each element is a positive integer.
Now if m < n the max value k can have is m. So lets
1)take a square of [m x m] i.e. ij,iq,pj, pq where i=j=0 and p=q=m, calculate the sum, compare with current max and store it if pass.
2) move the square forward by one column i.e. do j++ and q++, calculate the the sum, compare it with max and store points if pass.
repeat step 2 till q == n.
thus the biggest square with max sum is found. As an extension of this problem you could verify if the size of this square can be minimized.

- Brij February 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Take an array of arr mxn. Now we can fill the arr[i][j] such that it contains the sum of all the elements with row<=i and col<=j in o(n^2).
Find max value in o(n^2) using:

Sum of all numbers in the square with left top corner at i,j will be as follows:

Also initialise the base condition (rows and columns to zero).
for(i=1;i<=m;i++){
	for(j=1;j<=n;j++){
		a[i][j] = input[i][j] + a[i-1][j] + a[i][j-1] - a[i-1][j-1];
	}
}

int max = 0;
for(i=1;i+k<=m;i++){
	for(j=1;j+k<=n;j++){
		int temp = a[i+k-1][j+k-1] - a[i-1][j+k-1] - a[i+k-1][j-1] + a[i-1][j-1];
		if(temp > max ){
			max = temp;
			row = i;
			col = j;
		}
		
	}
}

- Saurabh Agrawal February 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this is correct.

- guruji February 22, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

this is not correct.You hve to find out k value too.You cant use k in your code

- Anonymous August 12, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Brij, your assumption is wrong. If all numbers are positive integers, and k <= m & n, then value of k = m & n for maximizing sum. The problem is interesting only if the matrix (m X n) contains negative numbers.

The problem is a typical Dynamic Prog. problem wherein we need to maximize the sum for any k <= m, n.

- dexter February 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

given an image, you want to find a square of size k that gives maximum size.
Convolve with a square filter of size k all 1's.

- GekkoGordan February 22, 2011 | 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