Microsoft Interview Question






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

using a stack, if we see opening P, B or C, push, else if we see closing sign, do a pop, compare the two sign, if they are from same P, B or C, Correct.

- lvv May 20, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

keep a counter for Parentheses, Bracket, and Curly.
let p = 0;
let b = 0;
let c = 0;

scanning from left to right on our sequence, if we see opening p or b or c, we increment by 1 the appropriate variable and decrement by 1 if we see a closing P or B or C.

From the above examples are not enough.

We check if the string is correct or not every time we see

1) A CLOSING sign. There are a few cases here.

2) an end of string character. p|c|b should all be zeros.

- vodangkhoa April 24, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// psuedo code
bool Match(char token)
{
   char c;
   switch( c=ReadToken() )
   {
      case '{':
      case '[':
      case '(':
            if(Match(c))
               return Match(token);
            return false;

      case '}':
           return (token=='{');
      case ']':
           return (token=='[');
      case ')':
           return (token=='(');

      case END:
           return false;           

      default:
           return Match(token);


   }
}

- likexx October 23, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

U can use a stack as luv said....
Push all the opening and when you see a closing then pop from the stack ....then you should see the corresponding else it is unmatched.. do it till the stack is empty.

- Vamsi December 05, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int check(char* s){
	if(s==NULL)
		return 1;
	Stack s=new Stack();
	s.push(s[0]);
	int i=1;
	while(!s.isempty()){
		if(s[i] =='[' || '{' || '(')
			s.push(s[i];
		else{
			char t=s.pop();
			if(!(s[i]==']' && t=='[') && (s[i]=='}' && t=='{') && (s[i]==')' && t=='('))
				return 0;
		}

	}
	return 1;
}

- Vamsi December 05, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry it is
if(!(s[i]==']' && t=='[') || (s[i]=='}' || t=='{') || (s[i]==')' && t=='('))
return 0;

- Vamsi December 05, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

vamsi's soln is correct.

- desiNerd April 22, 2008 | 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