Microsoft Interview Question for Software Engineer in Tests


Country: United States
Interview Type: In-Person




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

Use a stack.
-Start reading the input string character by character.
-PUSH a character from string onto stack if it doesnt match the character at the stack top.
-POP a character from stack if it input character matches it.
-Count the number of times the stack size reaches 0. The input string has these many number of palindromes (Palindromes within a palindrome do come under this count)

- Learner January 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if the length of the string is odd?

- seboy January 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not gonna work in Odd cases

- LaterGator January 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

you can use suffix tree to find that

- raja roy January 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//O(n)
int Palindromes(char[] s)
        {
            int count=0;
            int m=s.Length/2;
            if((s==null)||(s.Length==0))
            {
                return 0;
            }
            else{
                if(s.Length%2==1)
                {
                    int i = 1;
                    while((i+1)<s.Length)
                    {
                        if (s[i - 1] == s[i + 1])
                        {
                            count++;
                        }
                        i++;
                    }
                }else{
                    int i = 2;
                    while ((i+1) < s.Length)
                    {
                        if ((s[i - 1] == s[i]) && (s[i + 1] == s[i - 2]))
                        {
                            count++;
                        }
                        i++;
                    }
                
                }
            } return count;
        }

- gerardo.ruiz@aiesec.net February 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Per my understanding on the problem, we need to find out whether each word in a sentense is palindrome or not, then display the palindromes. Identifying each word is by separating by comma or space etc., But this program is only verifying the adjacent characters are equal or not, but it is not verifyinig palindromes in single sentense also. Please correct if I am wrong.

- Raju May 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1.Spilt the string by delimiters
2.reverse the every word in string
3.compare two strings

static void Main(string[] args)
        {
            int count = 0;
            string s = "dad mam hahah hi";
            string[] words = s.Split(' ', ',');
            string[] reverseWord = new string[words.Length];
            for (int i=0; i<words.Length; i++)
            {
                reverseWord[i] =  reverseString(words[i].ToCharArray(), 0, words[i].Length - 1);
            }
            Console.WriteLine("Given sententce =" + s);
            for (int i=0; i<words.Length; i++)
            {
                for (int j=i; i<reverseWord.Length; )
                {
                    if (words[i] == reverseWord[j])
                    {
                        Console.WriteLine(words[i]);
                        count++;
                        break;
                    }
                    else
                        break;
                }
                
            }
            Console.WriteLine("total Palindromes in sententce =" + count);
            Console.ReadLine();
        }

        static string reverseString(char[] sentence, int lindex, int rindex)
        {
            string s = string.Empty;
            while (lindex < rindex)
            {
                char tempChar = sentence[lindex];         
                sentence[lindex++] = sentence[rindex];   
                sentence[rindex--] = tempChar;
            }
            s = new string(sentence);
            return s;
        }

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

1.Spilt the string by words using delimiters
2.Push the every word by character
3.Pop the each character and compare with word.

static void Main(string[] args)
        {
            int count = 0;
            int charCount = 0;
            Stack<char> charStack = new Stack<char>();
            string s = "hi pop civic hello kayak";
            string[] words = s.Split(' ', ',');
            for (int i = 0; i < words.Length; i++)
            {
                char[] word = words[i].ToCharArray();
                foreach (char c in word)
                {
                    charStack.Push(c);
                }
                foreach (char c in word)
                {
                   char popchar =  charStack.Pop();
                   if (popchar == c)
                   {
                       charCount++;
                   }
                }
                if (words[i].Length == charCount)
                {
                    count++;
                    charCount = 0;
                }
                else
                    charCount = 0;

            }
            Console.WriteLine("Given sententce = " + s);
            Console.WriteLine("Total Palindromes in sententce = " + count);
            Console.ReadLine();
        }

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

int countPalindromes(const string& sentence)
{
          int cnt = 0;
          int i(0), j(0), n = sentence.size();
          while (i < n && sentence[i]=='  ') i++;
          while (i < n) {
                 j = i;
                 while (j < n && sentence[i] != '  ) j++;
                 cnt += (isPalin(sentence, i, j-1) ? 1 : 0);
                 i = j+1;
          }
}
bool isPalin(const string& str, int i, int j)
{
          while (i < j) {
                  if (str[i] != str[j]) return false;
                  i++; j--;
          }
          return true;
}

- Anonymous August 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

pls help me finding codes

- mybelle October 02, 2013 | 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