Adobe Interview Question for Quality Assurance Engineers


Country: India
Interview Type: In-Person




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

We cannot do better than O(nlogn), because if all symbols are '<', it becomes a normal sort.

Here is my solution:

1. Sort the array. 
2. After that, maintain two pointers on the array; one pointing to the first element, and the other pointing to the last one. 
3. Iterate on n-1 symbols.
3.a. If the current symbol is '<', then, add the element that the first pointer points to, to the answer and increment the first pointer.
3.b. Otherwise, add the element pointed by the second pointer to the answer and decrement the second pointer.
4. Add the remaining element (both pointers are pointing to it) to the answer

A C++ implementation using sort in STL:

#include <iostream>
#include <algorithm>

using namespace std;

int *solve(int *ary, int n, char* symbols)
{
	sort(ary, ary + n);

	int *ans = new int[n];

	int ptr1 = 0, ptr2 = n-1;

	for (int i = 0; i < n-1; ++i)
	{
		if (symbols[i] == '<')
			ans[i] = ary[ptr1++];

		else
			ans[i] = ary[ptr2--];
	}

	ans[n - 1] = ary[ptr1];

	return ans;
}

- iroodaz April 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Note that, this works if all numbers are distinct.

- iroodaz April 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Nice answer!

What if numbers are not distinct then?

- ninhnnsoc April 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Great question.

No idea what to do, then :-D
Sometimes it may not even have an answer. For instance: array = {1,1} and symbols = "<"

- iroodaz April 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

+1 you got it all right :)

- An Enthusiast April 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

you need to assume all numbers are distinct.

- cse April 21, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

nice solution dude. didnt occured to me

- NaMo June 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The answer seems correct because the interview was not expecting duplicate values as the symbols asked are '<' and '>' only.

- Anon August 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

you need to assume all numbers are distinct.

- cse April 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

great sollution

- Anonymous August 13, 2014 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<iostream>
#include<conio.h>
using namespace std;
struct node
{
int info;
char ch;
struct node *link;
};
int display1(struct node *);
int operatorinsert(struct node *);
int main()
{
struct node *head,*p,*pr;
int n;
cout<<"enter how many numbers you want insert:\n";
cin>>n;
head=NULL;
for(int i=0;i<n;i++)
{
if(head==NULL)
{
p=new node;
cout<<"enter number's:\n";
cin>>p->info;
head=p;
pr=p;
pr->link=NULL;
}
else
{
p=new node;
cin>>p->info;
pr->link=p;
pr=p;
pr->link=NULL;
}
}
struct node *Tr;
Tr=head;
operatorinsert(Tr);
display1(Tr);
getch();
return 0;
}
int operatorinsert(struct node *m)
{
while(m->link!=NULL)
{
if(m->info>m->link->info)
m->ch='>';
else
m->ch='<';
m=m->link;
}
return 0;
}
int display1(struct node *q)
{
while(q->link!=NULL)
{
cout<<q->info<<q->ch;
q=q->link;
}
cout<<q->info;
return 0;
}

- Ashok kumar Bhukhar May 01, 2014 | 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