Microsoft

www.microsoft.com

Interview Question

Senior Software Development Engineer In Test (SDET) Interview Seattle, WA

finad all plaindromes ina string.

Answer

Interview Answer

2 Answers

1

i couldn't really come up with decent code for this, and i think this was the turning point in the interview which otherwise was going alright.

Interview Candidate on Aug 14, 2012
0

vector<string> findAllPalindrome ( string str)
{
    vector<char> stack;
    vector<string> result;
    string buff = "";
    int len = str.length();

    if (len == 0)
    return result;

    stack.push_back(str[0]);
    for (int i = 1; i<len; ++i)
    {
        if (str[i] == stack.back())
        {
            buff.insert(0,str[i]);
            buff.push_back(str[i]);
            result.push_back(buff);
            stack.pop_back();
        }
        else
        {
            int buffLen = buff.length();
            for (int j = 0; j< buffLen; ++j)
            {
                stack.push_back(buff[j]);
            }
            stack.push_back(str[i]);
        }
    }
    return result;
}

Eric on Nov 2, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.