Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Using Setjump LongJump in C? or Throw an Exception in C++? Though Stack unwinding will happen prorperly while throwing Exception in C++.

I think this is what he wanted to ask.

- nerd July 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, I think this should serve the purpose, though throwing an exception is not a nice way on a success, I mean the caller would not expect to look for an result in catch block...
is there any better way

- Anonymous July 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

setjmp in the first call to the recursive function and then longjump to the status saved in setjmp when you want to return

- nachi July 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

recurse(&success_flag, args....)
{
if(!(*success_flag))
recurse(sucess_flag, args...);
if(success)
foo();
}

foo()
{
*success_flag = 1;
exit();
}

- Subramanya Datta July 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

exit will make the process to terminate not the function only. so setjmp and longjmp should be used.

- Naveen July 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

You can use tail recursion. Last line of the function will be a recursion call. so if you return then all the functions below the stack will just return.

def abc():
    if cond:
        do something
   else:
        return
   abc()

- Ashish July 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if we use a static variable as result indicator..as soon as we find the result we set the value as true and in evry funcion call we can add the first statement which checks the value f dat and then proceeds

- sandeep July 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

if (resultFound) { return; }

Does that help you at all? I'm really not quite sure what you're asking.

- eugene.yarovoi July 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

use exit function..

- cobra July 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@eugene : if (resultFound) { return; }
it would only return from that perticular call of the function.
i meant with the question: when the objective of the recurssion is met, it should not execute remaining calls in the recurssion stack...

- Anonymous July 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You could either throw an exception or return a value that is checked for in the calling function.

- eugene.yarovoi July 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This should do I guess!

recurse(&success_flag, args....)
{
if(!(*success_flag))
recurse(sucess_flag, args...);
if(success)
*success_flag = 1;
}

- words&lyrics July 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you havent understood the question yet..

after success_flag is set to 1, further recursive call cannot be made.. but already called recursive functions will continue to execute

- cobra July 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I missed a return after the success check (in case where sucess has already been achieved )

- words&lyrics July 22, 2012 | Flag


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