Synopsys R&D Interview Question for Software Engineer / Developers






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

i think we can optimize the size of minstack i.e. dont need to push into minstack for every push into stack1

void push(int x)
{
stack1.push(x);
if (x <= minStack.top())
minStack.push(x);
}

int pop()
{
int x=stack1.top();
stack1.pop();
if (x == minStack.top())
minStack.pop();

return x;
}

- skrr January 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes That is the right way.

Both the solutions above are not perfect. First one is incorrect actually.

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

We have to maintain a parallel stack & maintain running min .

void push(int x)
{
stack1.push(x);
minStack.push(min( x,minStack.top() ) );
}

int pop()
{
int x=stack1.top();
stack1.pop();
minStack.pop();

return x;
}

int min()
{
return minStack.top();
}

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

i think we can optimize the size of minstack i.e. dont need to push into minstack for every push into stack1

void push(int x)
{
stack1.push(x);
if (x <= minStack.top())
minStack.push(x);
}

int pop()
{
int x=stack1.top();
stack1.pop();
if (x == minStack.top())
minStack.pop();

return x;
}

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

what is the initial value in minstack..

- anony January 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is the initial value in minstack..

- anony January 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

always keep the min element as TOS.

Hence, minStack=pop();

- pg February 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

maintain an invariant.. minimum element till current record
here the element pushed will look like
struct node
{
int data;
int minSoFar;
};

push 10
{10,10}
push 4
{4,4}
push 6
{6,4}

so on.,All we need to do is retireve min element and not modify the current data structure

- Amit Priyadarshi August 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is incorrect. Check below two answers.
Check in below set
I - Insert(Push)
D - Delete(Pop)

I5, I7, I9, I1,I3, D3, D1, D9, I2, I10,I9, I1, I11

- Vifi October 18, 2014 | 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