Amazon Interview Question for SDE1s


Country: India
Interview Type: In-Person




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

This problem could be regarded as fair coin and biased coin problem, please refer to: wiki- fair coin problem

- Anonymous February 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

// 11 -> 0.36, 00 -> 0.16, 10 -> 0.24, 01 -> 0.24
// and discard the case of 11 and 00.
int f1() {
  while (1) {
    int a = f();
    int b = f();
    if (a != b) return a;
  }
}

- nishikenster July 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

while (true)
{
	int c0 = 0;
	int c1 = 0;

	for (int i=0; i < 3; ++i)
	{
		if (f() == 1)
			c1++;
	}

	for (int i=0;i<2;i++)
	{
		if (f() == 0)
			c0++;
	}

	return (c1 > c0) ? 1 : 0;
}

- bbchung February 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

C1 should be updated twice (Probability of 1 = 0.6) and C0 should be updated thrice(Probability of 0 = 0.4).

You have done the opposite in your code.

Otherwise the code and logic are correct

- josanrishi February 23, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you explain your logic?

- RK February 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about this?

int f1()
{
    static int k = 0;
    return k++ % 2 ? f() : 1 - f();
}

- Westlake February 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This problem could be regarded as fair coin and biased coin problem, please refer to: wiki- fair coin problem

- Anonymous February 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

fdsdfssdf

- Anonymous February 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Are you left-handed?

- Anonymous February 14, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

f1():
if [f() + {1 - f()}] == 2:
	return 1
else
	return 0

Lets draw the truth table for it

f	1	f	sum		f1
0	1	0	1		0
0	1	1	2		1
1	1	0	2		1
1	1	1	3		0

- kr.neerav February 15, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

Not quite correct. I drop 1 from your table.

f() f() sum f1() %
0 0 0 0 0.16 (0.4 x 0.4)
0 1 1 1 0.24 (0.4 x 0.6)
1 0 1 1 0.24 (0.6 x 0.4)
1 1 2 0 0.36 (0.6 x 0.6)

So the chance of 0 of your f1() is 52% and 1 is 48%

- Anonymous February 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

agree my bad.

- kr.neerav February 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

f1(x) = f(x) + (-1)^x * 0.1

- Anonymous February 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void f1(){
int first = -1, second = -1;
//toss twice
//00-4/25,11-4/25, 01-6/25,10-9/25
//check for 00 and 11
do{
	first = f();
	second = f();
}while(first!=second) //only return 01 or 10
return first;
}

- aks May 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

the thinking is correct, but I think you code is wrong
in you function the value of v never changed after assign v=f(), so your f1() is equal to the original f()

- yaosheng February 15, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You're right here is correct version:

public int f1() {
        int v1 = f();
        int v2 = f();
        return v1 != v2 ? v1 : f1();
    }

BTW: Is it only me who cant edit my own responses? It was possible previously.

- Anonymous February 15, 2014 | Flag
Comment hidden because of low score. Click to expand.


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