Here Interview Question for Software Developers


Country: United States
Interview Type: In-Person




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

You can push open paranthesis into stack and pop the closing paranthesis and ignore other characters in the string. After parsing the entire string, if your stack should be empty for correctly paired string

- riya July 16, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A simple approach is to use a stack with push-pop to solve.
But given the interviewer specifically said 'stream' 'thread' 'distributed', he is specifically looking at scale here.
Use a main thread to receive the stream head, and use child threads to maintain stacks and do processing(push/pop). The stacks would have fixed sizes; so use some flags to notify, when they get full or empty.

- Biswa July 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Keep one count say cnt. If you encounter '(' increment counter by one. If you encounter ')' decrement by one. Perform increment or decrement in synchronized method. if counter is negative it means that parantesis dont match.
public class Matcher{

private Integer counter;

private boolean synchronized isValid(String symbol){
if(symbol.equals("(")){
counter++;
}else if(symbol.equals(")")){
counter--;
}
if(counter<0){
throws new Exception("paranthesis do not match") ;
}

}
}

- 11anony.mous99 July 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Will this work for ')()('? The sum at the end is -1 + 1 - 1 + 1 = 0. Will this detect properly nested format?

- Yev July 18, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Yev: Adding a check after incrementing/decrementing the counter should fix this. Basicaaly, the counter should never be negative, and at the end of the string should be 0. If the counter becomes negative t any point, then nomatter what the restof the string is, the parantheses will not match.

- bg July 18, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Seems odd that you are returning a boolean but throwing an exception when the return type would be false.

- FC August 13, 2016 | 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