Adobe Interview Question for Software Engineer / Developers






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

can i sort 2,1,4 and make 1,2,4 and then find max rect?

- xyZ January 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

No you can't...

- spiderman January 17, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Try this.............
#include <iostream.h>
void main()
{
cout<<"Hello World!"<<endl;
int node[6] = {10, 2, 1, 14, 13, 1};
int startIndx = 0;
int lastIndx = 0;
int width = 0;
int i = 0;
int cur = 0;
int curIndx = 0;
int curArea = 0;
int maxArea = 0;
int maxStart = 0;
int maxLast = 0;
while( curIndx < 6)
{
width = 0;
cur = node[curIndx];
i = startIndx = lastIndx = curIndx;
while ( (i<6) && (node[i++] >= node[curIndx]) )
{
width++;
lastIndx = i-1;
}
i = curIndx;

while( (i>=0) && (node[--i] >= node[curIndx]) )
{
width++;
startIndx = i;
}
curArea = width*node[curIndx];
cout << "CUR AREA IS : " << curArea << " for node " << cur << endl;
if (curArea >= maxArea)
{
maxArea = curArea;
maxStart = startIndx;
maxLast = lastIndx;
}
curIndx++;
}
cout << "Max Area is " << maxArea << " between Bar " << maxStart << " (Length " << node[maxStart] << ") and "
<< maxLast << " (Length " << node[maxLast] << ")" << endl;
}

- AA January 19, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

will the complexity be O(n*n) in previous algo?
I think, we are looking for O(n), right?

spiderman, is there any solution really that can solve this in O(n) time?

- BB January 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

BB, the complexity of the previous algorithm is O(n^2) in worst case.
I can modify the above algo and have an O(n) time and O(n) space
complexity. I cannot see how this can be O(n) time and O(1) space
because you clearly need a length n array to store the histogram
values which itself counts for O(n) space. Probably they should say no
additional non constant memory other than the given array.

- cryptozoa January 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yeah I'm having a hard time seeing a non DP solution, which clearly is O(n) space.

- Anonymous January 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hi cryptozoa,

can u give us the algo tht accomplish this task in 0(n) and space o(n)?

- bb January 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There are two cases :
a) it may happen that the bar with maximum height will be the answer
or
b) small bar of same height may get combined to form a rectangle.

if i am not wrong you should be able to in one pass.
O(n)

let me know if u find anything wrong

- subha April 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

my mistake i didnt understand the problem ..

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

int array[] = {10, 2, 1, 14, 13, 1};
For such inputs:

Step-1:
loop for each element of array
find max hignht and min hignht from the arrar.

Step-2:
as given width is static for each bar of histrogram
we are assuming the width as 'n'

Step-3:
area = ((max * width) > (min * (width * (sizeof(array)/sizeof(int))))) ? ((max * width)) : ((min * (width * (sizeof(array)/sizeof(int)))));

- Ashutosh May 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If we have min =0 ( which means one of the data value is 0) i suspect this would work.

- Addy June 20, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is simple
Can be mapped to a simple problem
For each element
Find the next element in the array ahead of you which is just smaller than you.

Can be easily done using a stack and traversing from behind in O(n) time but takes O(n) space worst case...

- MaVeRiK November 30, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

assuming that each unit of histogram is 1 if used or 0 if not used, then this can be represented by a two dimensional array of 0s and 1s

so the problem is to find biggest rectangle will all 1s

the levenstein distance algo an be used to find the biggest square where each indexa[i,j] represents the number of entries before itself including itself will make a square

while calculating distance matrix keep track of largest value found so far and its index


once done say if d[i,j] represents the max value, check d[i+k,j] for equal value as to d[i,j] consecutively where k varies from 1 to n-i-1 so if d[i,j] =4 and d[i+1,j]=4 but d[i+2.j]=0 then longest is 5, 4 ending at d[i+1,j]
this will give biggst rectangle horizontally

similarly
longest vertical rectangle can be found

max od vertical and horizontal is the biggest rectangle

- nutcracker July 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

int largestArea(int arr[], int len)
{
int area[len]; //initialize it to 0
int n, i, t;
stack<int> St; //include stack for using this #include<stack>
bool done;

for (i=0; i<len; i++)
{
while (!St.empty())
{
if(arr[i] <= arr[St.top()])
{
St.pop();
}
else
break;
}
if(St.empty())
t = -1;
else
t = St.top();
//Calculating Li
area[i] = i - t - 1;
St.push(i);
}

//clearing stack for finding Ri
while (!St.empty())
St.pop();

for (i=len-1; i>=0; i--)
{
while (!St.empty())
{
if(arr[i] <= arr[St.top()])
{
St.pop();
}
else
break;
}
if(St.empty())
t = len;
else
t = St.top();
//calculating Ri, after this step area[i] = Li + Ri
area[i] += t - i -1;
St.push(i);
}

int max = 0;
//Calculating Area[i] and find max Area
for (i=0; i<len; i++)
{
area[i] = arr[i] * (area[i] + 1);
if (area[i] > max)
max = area[i];
}

return max;
}

- Ashish May 16, 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