Interview Question


Country: United States




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

B reads i (stored value 0)
A reads i (0)
A stores i + 1 (1)
A reads i (1)
A stores i + 1 (2)
B stores i + 1 (1)
A reads i (1)
B completes (5)
A stores i + 1 (2).

So, min = 2, max = 8.

- Anonymous December 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

max should be 8 reason all steps are followed sequentially
considering no synchronization issue

min would be 3

- san4net December 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 6 vote

Well... I guess this is the Caller dependency...

For Normal Cases we can Say if Thread A only executes then the min value will be there.
and For both thread executes the max value will get generated, But Still there are more complexity involved if we keep discussing.

But i n Laymen Term.

Min=3 ,
Max =8

- hprem991 December 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Min 3
Max 8

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

If i is the local variable. Than this will be there in each thread stacks.i value increament by A will not change anything for B.
Than why for Thread B the min val will be 3 ???

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

Min: 0 (neither thread are schedule when you output them).
Max; 8.

- Anonymous December 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Well its straight forward , whether its thread A (min .i.e 3) or both Thread A and Thread B which is 8(Max). Keeping in mind that thread doesnt garuantee order, A and B executes randomly.

- Fresh_man December 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

min 3
Max 8

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

min = 5,max=8

- Anonymous December 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

i=0;
threadA
{ i++;
i++;
i++;
}
threadB
{ i++;
i++;
i++;
i++;
i++;
}

- Anonymous December 18, 2012 | 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