Linkedin Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

enough material available for standard algorithm in web

- Anonymous December 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

while nothing remains to scan
- scan the first available element and enqueue it in queue
- scan the next available element and store it in a temporary variable 'temp'.
- scan the next available element and enqueue it in queue
- enqueue temp in queue

- Arnab February 03, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

while nothing remains to scan
- scan the first available element and enqueue it in queue
- scan the next available element and store it in a temporary variable 'temp'.
- scan the next available element and enqueue it in queue
- enqueue temp in queue

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

The algorithm for the conversion is as follows :
Scan the Infix string from left to right.
Initialise an empty stack.
If the scannned character is an operand, add it to the Postfix string. If the scanned character is an operator and if the stack is empty Push the character to stack.
If the scanned character is an Operand and the stack is not empty, compare the precedence of the character with the element on top of the stack (topStack). If topStack has higher precedence over the scanned character Pop the stack else Push the scanned character to stack. Repeat this step as long as stack is not empty and topStack has precedence over the character.
Repeat this step till all the characters are scanned.
(After all characters are scanned, we have to add any character that the stack may have to the Postfix string.) If stack is not empty add topStack to Postfix string and Pop the stack. Repeat this step as long as stack is not empty.
Return the Postfix string.

- Piyush Gadigone January 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Infix is essentially in-order traversal, if expressed in a binary tree. To express this in postfix, do LR-root traversal.

- Jack February 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int GetOperatorPriority(char op)
{
    int priority = 0;

    switch (op)
    {
    case '+':
    case '-':
        priority = 0;
        break;
    case '*':
    case '/':
        priority = 1;
        break;
    default:
        throw invalid_argument("Invalid Operator");
    }

    return priority;
}

bool IsOperator(char ch)
{
    return 
        (ch == '+' ||
        ch == '-' ||
        ch == '*' ||
        ch == '/');
}

string InfixToPostfixExpression(string infixExpression)
{
    string postfixExpression = "";
    stack<char> operatorStack;

    for (char ch : infixExpression)
    {
        if (!IsOperator(ch))
        {
            postfixExpression += ch;
        }
        else
        {
            if (!operatorStack.empty())
            {
                while (!operatorStack.empty() && (GetOperatorPriority(operatorStack.top()) >= GetOperatorPriority(ch)))
                {
                    char opFromStack = operatorStack.top();
                    operatorStack.pop();

                    postfixExpression += opFromStack;
                }
            }

            operatorStack.push(ch);
        }
    }

    if (!operatorStack.empty())
    {
        char opFromStack = operatorStack.top();
        operatorStack.pop();
        postfixExpression += opFromStack;
    }

    return postfixExpression;
}

- Keshava June 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

public String infixToPos(String infix){
Stack<Character> stack = new Stack<Character>();
StringBuffer pos = new StringBuffer();

for(int i = 0; i<infix.length(); i++){
char c = infix.charAt(i);
if(c!='+' && c!='-' && c!='*' && c!='/' ){
pos.append(c);
}else if(stack.empty()){
stack.push(c);
}else{
if(c == '*' || c == '/'){
System.out.println("Peek" + stack.peek());
while(stack.peek() == '*' || stack.peek() == '/'){
if(!stack.isEmpty()){
pos.append(stack.pop());
}
}
stack.push(c);
}else{
while(!stack.isEmpty()){
pos.append(stack.pop());
}
stack.push(c);
}
}
}

while(!stack.empty()){
pos.append(stack.pop());
}

return pos.toString();
}

- Yi December 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

while nothing remains to scan
- scan the first available element and enqueue it in queue
- scan the next available element and store it in a temporary variable 'temp'.
- scan the next available element and enqueue it in queue
- enqueue temp in queue

- Anonymous February 03, 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