unknown Interview Question for Personnels


Country: India




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

The basic idea behind this is whenever u add some element into the stack all you have to do is store the minimum element of the stack in the top most element of the stack. So the next time you insert you can compare the value of the node that is being inserted and the minimum node that is at the top of the stack and decide the new minimum from this information.

- anony February 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The basic idea behind this is whenever u add some element into the stack all you have to do is store the minimum element of the stack in the top most element of the stack. So the next time you insert you can compare the value of the node that is being inserted and the minimum node that is at the top of the stack and decide the new minimum from this information.
(nobrainer .co .cc)

- anony February 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This algo is to find min & max value in the stack using linked list.
the idea is create the linked list by adding new nodes at top(first), after forming the list  find the minimum&maximum value in it.
this linked list uses stack procedure to create.
 
To find the min value,
int find_min(struct node *p)
{
    p=top;
    int mn=p->data;
    while(p!=NULL)
    {
        if(mn > p->data)
        {
             mn=p->data;
             p=p->link;
             }
        else
            p=p->link;
            }
    return mn;
}
To find the max value
int find_max(struct node *q)
{
    q=top;
    int mx=q->data;
    while(q!=NULL)
    {
        if(mx < q->data)
        {
             mx=q->data;
             q=q->link;
             }
        else
            q=q->link;
            }
    return mx;
    }

- manidavid0 March 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

hello
code was good bt it take complexity of n as we traverse the stack i nedd to find max among stack in o(1)
plz respond

- mohitbhandari37 February 22, 2013 | 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