Adobe Interview Question for Member Technical Staffs


Country: India
Interview Type: In-Person




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

Apply Dutch national flag algo for 3 colors. Link below:

csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Flag/

- pavi.8081 September 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please correct me if I am wrong - nice solu bt I feel a minor mistake, shudn't it be this way?
for( low = mid = 0, high = len-1; mid <= high; ) {
a[mid] == 0 ? swap(a[low++], a[mid++]) : a[mid] == 1 ? mid++ : ( swap(a[mid],a[high--]) );
}

Change is in last swap a[mid] instead of a[low].

- Vishakha September 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 vote

Consider three ranges in the array at any instant :
0 to low-1 => contains 0
low to mid-1 => contains 1
mid to high => values to process
high+1 to len-1 => contains 2

for( low = mid = 0, high = len-1; mid <= high;  ) {
	a[mid] == 0 ? swap(a[low++], a[mid++]) : a[mid] == 1 ? mid++ : ( swap(a[mid],a[high--]) );

}

- Cerberuz September 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@cerberuz-Do u know how to do for 4 colours??

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

It is similar, consider 5 ranges :
0 to r0-1 => contains 0
r0 to r1-1=> contains 1
r1 to r2-1 => contains 2
r2 to r3 => values to process
r3+1 to len-1 => contains 3

You just have to make sure these conditions are satisfied after each iteration.

r0 = r1 = r2 = 0;
	r3 = size-1;

	while( r2 <= r3 ) {
		if( a[r2] == 0 ) {
			swap( a[r0], a[r2] );
			if( r1 <= r0 ) {
			       	r1++;
				r2++;
			}
			r0++;
		} else if( a[r2] == 1 ) {
			swap( a[r1++], a[r2++] );
		} else if( a[r2] == 2 ) {
			r2++;
		} else {
			swap( a[r2], a[r3--] );
		}
	}

- Cerberuz September 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Cerberuz-Dis can be Extended till how many colours?

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

I think this can be extended to any number of colors but those nested if conditions ( like that in first if() ) will become very complex and it will be difficult to write accurate solution for large number of colors in single pass of array.

Moreover the constant factor involved in such complex linear time solution will be so large that normal (NlogN)sorting or bucket sort will outperform it.

- Cerberuz September 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please correct me if I am wrong - nice solu bt I feel a minor mistake, shudn't it be this way?
for( low = mid = 0, high = len-1; mid <= high; ) {
a[mid] == 0 ? swap(a[low++], a[mid++]) : a[mid] == 1 ? mid++ : ( swap(a[mid],a[high--]) );
}

Change is in last swap a[mid] instead of a[low].

- Vishakha September 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Vishakha, oh yes, thank you for pointing that out. I've corrected it.

- Cerberuz September 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

here it is working code:

codes-to-problem.blogspot.in/2012/09/sort-array-of-0-1-2-in-one-pass.html

- niraj.nijju September 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Try to think like this, put all the 0's at the start of the array and put all the 2's at the end. The 1's automatically come in the middle.

- vabhdman September 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;


public class ReArrange012 {

String inputArray[];
/**
* @param args
*/
public static void main(String[] args) {

System.out.println("Enter the array ..");

Scanner sc = new Scanner (System.in);

String s = sc.nextLine();

ReArrange012 obj = new ReArrange012();
obj.inputArray = s.split(" ");

obj.rearrange();

System.out.println("Rearranged Array");

for(int i = 0 ;i <obj.inputArray.length ; i++)
{
System.out.println(obj.inputArray[i] + " ");
}

}
//0, 1, 1 ,0, 2, 2, 1, 0 ,1, 2, 1,0 }
//to be converted into
//{0, 0, 0, 0, 1, 1, 1, 1, 1 ,2 ,2 ,2}

private void rearrange() {

int Firstocc_0_index = -1;
int Firstocc_1_index = -1;
int Firstocc_2_index = -1;

for(int i =0; i < this.inputArray.length ; i ++)
{
if(i==0)
{
if (Integer.parseInt(this.inputArray[i]) == 0)
{
Firstocc_0_index = i;
}
else if (Integer.parseInt(this.inputArray[i]) == 1)
{
Firstocc_1_index = i;
}
else if (Integer.parseInt(this.inputArray[i]) == 2)
{
Firstocc_2_index = i;
}
}


//to be converted into
//{0, 0, 0, 0, 1, 1, 1, 1, 1 ,2 ,2 ,2}

else
{
if((Integer.parseInt(this.inputArray[i]) > (Integer.parseInt(this.inputArray[i-1]))))
{
if (Integer.parseInt(this.inputArray[i]) == 1)
{
Firstocc_1_index = i;
}
else if (Integer.parseInt(this.inputArray[i]) == 2)
{
Firstocc_2_index = i;
}
}
else if((Integer.parseInt(this.inputArray[i]) < (Integer.parseInt(this.inputArray[i-1]))))
{
String temp = "";
if((Integer.parseInt(this.inputArray[i]) == 1))
{

temp = this.inputArray[i];
this.inputArray[i] = this.inputArray[Firstocc_2_index];
this.inputArray[Firstocc_2_index] = temp;
if(Firstocc_1_index == -1)
{
Firstocc_1_index = Firstocc_2_index ;
}

Firstocc_2_index++;

}
else if (Integer.parseInt(this.inputArray[i]) == 0)
{
Firstocc_0_index = 0;
if ( (Firstocc_1_index != -1))
{
temp = this.inputArray[i];
this.inputArray[i] = this.inputArray[Firstocc_1_index];
this.inputArray[Firstocc_1_index] = temp;
Firstocc_1_index++;
if((Integer.parseInt(this.inputArray[i-1]) == 2))
{
temp = this.inputArray[i];
this.inputArray[i] = this.inputArray[Firstocc_2_index];
this.inputArray[Firstocc_2_index] = temp;
Firstocc_2_index++;
}
}
else if (Firstocc_1_index == -1 )
{
temp = this.inputArray[i];
this.inputArray[i] = this.inputArray[Firstocc_2_index];
this.inputArray[Firstocc_2_index] = temp;
Firstocc_2_index++;

}
}
}
}

}

//0, 1, 1 ,0, 2, 2, 1, 0 ,1, 2, 1,0 }
//0, 0, 0, 0 , 1 ,1, 1, 1 , 1 ,2 , 2,2
}

}

- Anonymous September 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Vitlay - was it asked in tech interview ??

I hv given written of Adobe for MTS on 25th Aug. Still got no result of that. Mailed them twice. One out of office reply came from HR mentioning "University recruiting is keeping me busy. Please expect a delay in reply."

Do Adobe informs about result, if candidate could not clear it ??

- Nitin Gupta September 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@nittin,
mine written was latter, but i get the call. anyway i was out in first round itself :)

- vitlay@monza September 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

they only call selected candidate .

- pramod September 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

apply partition with pivot as 1...the problem will be solved in single pass

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

Use 3-way quicksort (which is an improved version of Quicksort to account for duplicate keys in an array)...this is a direct implement implementation of that..google it for more information on that :)

- Anonymous September 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
main()
{
int a[] = {0,1,1,0,2,2,1,0,1,2,1,0},i,j,k,temp,x;
i=0; j=0; k=11;
printf("Before : ");
for(x=0;x<12;x++)
printf("%d ",a[x]);
printf("\nAfter :");

while(j<k)
{
if(a[j] == 1)
j++;
else if(a[j] == 0)
{
temp = a[j]; a[j] = a[i]; a[i] = temp;
i++; j++;
}
else if(a[j] == 2)
{
temp = a[j]; a[j] = a[k]; a[k] = temp;
k--;
}
}

for(x=0;x<12;x++)
printf("%d ",a[x]);
printf("\n");

}

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

The above code was single pass..

- Nayak October 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

"Count Sort" algorithm.

- Montijack July 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice method ; but not single pass

- catlover September 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