Adobe Interview Question
Quality Assurance EngineersCountry: India
Interview Type: In-Person
Great question.
No idea what to do, then :-D
Sometimes it may not even have an answer. For instance: array = {1,1} and symbols = "<"
#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;
}
We cannot do better than O(nlogn), because if all symbols are '<', it becomes a normal sort.
Here is my solution:
A C++ implementation using sort in STL:
- iroodaz April 18, 2014