Interview Question for Software Engineer in Tests






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

Please post the questions correctly, i dont think it is possible

- ravikant0909 July 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Questions:

1) Do you have access to the underlying data structure IE list etc?
2) Are you able to create and use new pointers?

- anon March 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am not able to understnd your questions.The only thing that can be done is you can reverse the stack.Nothing else is to be used.

- Gary March 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I assume that we have only push, pop, top, empty , full methods. Without creating a temporary storage for elements in stack one can't sort the stack. So I don't think in place stack sorting is feasible.

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

This is the trick here...there is a new functionlaity given for stack in which you can reverse the numbers for sorting.In sorting we just take 2 numbers are swap whereas here the list has to be revered and sorted

- Gary March 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// The main logic is to push the lowest element to the bottom of the stack, now this is done by comparing the topmost 2 values, do this recursively !

Sort(stack) {
a = stack.pop()
b = stack.pop()
if( a == null) return;
if (b == null ) return;

if(a < b){
stack.push(a)
stack.push(b)
}

else{
stack.push(b)
sort(stack)

stack.push(a)
sort(stack)
}
}

// trace the algo to better understand

- Sunil Mallya March 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

In your method , If a<b you ll push it in different order and conclude the entire stack is now sorted ?
what if items are pushed in as 9,1,3,2 your method will change it to 9,1,2,3 and return !

- Harish March 26, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Idea is correct but I think problem asks you to give in place solution. This is not in place.

- Anonymous March 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What are we trying to achieve here? If we sort the stack, its no more one...LIFO goes away
....or I am missing something?

- Anonymous March 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Could anyone tell me the real world example where a stack need to be sorted? Someone asked me this during the interview.

- Zooper July 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<stddef.h>
#include<stdlib.h>
struct stack
{
int capacity;
int top;
int *array;

}*s=NULL;

void createstack(int size)
{
s=(struct stack*)malloc(sizeof(struct stack));
s->array=(int*)malloc(sizeof(int)*size);
s->top=-1;
s->capacity=size;
printf("\n ** array created succ!!\n");
}

int check(int data)
{
printf("\n inside check");
int temp;
if(s->top==-1)
{
s->array[++s->top]=data;
return ;
}
if(s->array[s->top] <data)
{
s->array[++s->top]=data;
return ;
}
if(s->array[s->top] >data)
{
temp=s->array[s->top--];
printf("temp -->> %d",temp);
check(data);
//push(temp);
s->array[++s->top]=temp;
}
}

int sort()
{
printf("\n inside sort");
int data;
if(s->top==-1)
return ;
else
{
data=s->array[s->top--];
printf("data -->> %d",data);
sort();
check(data);
}
}

void main()
{
int size , no , i;
printf("entre the size of array");
scanf("%d",&size);
createstack(size);
for(i=0;i<size;i++)
{
scanf("%d",&no);
s->array[++s->top]=no;
}
printf("\nvalue of top %d",s->top);
sort();
for(i=0;i<s->capacity;i++)
printf("\n%d",s->array[s->top--]);
}

- Pinnacle August 12, 2013 | 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