Microsoft Interview Question for Software Engineer in Tests


Country: India
Interview Type: Written Test




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

dude, you pretty much mixed up java's Stack with C++'s like I did,
java: stack.peek()---> C++: stack.top()

s2.push(s1.pop()); -- > s2.push(s1.top()); s1.pop();

and "s1=new stack<T>();" is unnecessary in your constructor since s1, s2 are already instantiated and not pointers;

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

I have commented some part - you can fix the commented part in the same way
sing std::stack;
using std::string;
 template<typename T>class Myqueue
 {
    stack<T> s1,s2;
    public:
    Myqueue(){
        //s1=new stack<T>(); // Here no no need to use new 
        //s2=new stack<T>(); // Here no need to use new automatically the empty stack would would be created. 
    }

    int size()
     {
        return s1.size()+s2.size();
     }
     void add(T value)
     {
        s1.push(value);
     }
     /*T peek()
     {
        if(!s2.empty())
            return s2.peek();
         while(!s1.empty())
            s2.push(s1.pop());
        return s2.peek();
     }*/
     T remove() 
     {
        T returnValue;
        if(!s2.empty())
        {
            returnValue = s2.top();
            s2.pop();
        }
        else
        {
            while(!s1.empty())
            {
                s2.push(s1.top());
                s1.pop();
            }
            if(!s2.empty())
            {
                returnValue = s2.top();
                s2.pop();
            }
        }
        return returnValue; // This is also not valid as when s2 is empty then it will fail as they would not be able to convert void to string
     }
 };
 int CompilationErrorCheck()
 {
    Myqueue<string> str;
    /*str.Myqueue();*/
    string str1;
    str.add("devesh");
    str.add("pankaj");
    std::cout<<"CurrenttopValue  "<<str.remove()<<"\n";
    //str1=str.peek();
    return 0;
 }

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

I have commented some part - you can fix the commented part in the same way
sing std::stack;
using std::string;
 template<typename T>class Myqueue
 {
    stack<T> s1,s2;
    public:
    Myqueue(){
        //s1=new stack<T>(); // Here no no need to use new 
        //s2=new stack<T>(); // Here no need to use new automatically the empty stack would would be created. 
    }

    int size()
     {
        return s1.size()+s2.size();
     }
     void add(T value)
     {
        s1.push(value);
     }
     /*T peek()
     {
        if(!s2.empty())
            return s2.peek();
         while(!s1.empty())
            s2.push(s1.pop());
        return s2.peek();
     }*/
     T remove() 
     {
        T returnValue;
        if(!s2.empty())
        {
            returnValue = s2.top();
            s2.pop();
        }
        else
        {
            while(!s1.empty())
            {
                s2.push(s1.top());
                s1.pop();
            }
            if(!s2.empty())
            {
                returnValue = s2.top();
                s2.pop();
            }
        }
        return returnValue; // This is also not valid as when s2 is empty then it will fail as they would not be able to convert void to string
     }
 };
 int CompilationErrorCheck()
 {
    Myqueue<string> str;
    /*str.Myqueue();*/
    string str1;
    str.add("devesh");
    str.add("pankaj");
    std::cout<<"CurrenttopValue  "<<str.remove()<<"\n";
    //str1=str.peek();
    return 0;
 }

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

Is this an interview question?

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

Is this an interview question?

- Learner February 07, 2012 | 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