## Adobe Interview Question for Quality Assurance Engineers

• 1
of 1 vote

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;
}``````

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

Note that, this works if all numbers are distinct.

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

What if numbers are not distinct then?

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 = "<"

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

+1 you got it all right :)

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

you need to assume all numbers are distinct.

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

nice solution dude. didnt occured to me

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

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

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

you need to assume all numbers are distinct.

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

great sollution

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;
};
int display1(struct node *);
int operatorinsert(struct node *);
int main()
{
int n;
cout<<"enter how many numbers you want insert:\n";
cin>>n;
for(int i=0;i<n;i++)
{
{
p=new node;
cout<<"enter number's:\n";
cin>>p->info;
pr=p;
}
else
{
p=new node;
cin>>p->info;
pr=p;
}
}
struct node *Tr;
operatorinsert(Tr);
display1(Tr);
getch();
return 0;
}
int operatorinsert(struct node *m)
{
{
m->ch='>';
else
m->ch='<';
}
return 0;
}
int display1(struct node *q)
{
{
cout<<q->info<<q->ch;
}
cout<<q->info;
return 0;
}

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.

### 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.