Adobe Interview Question for Software Engineer / Developers






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

Let we have given fun: int fun6040()
if i will execute this function 5 times.... 3 times it will give o/p = '0' and 2 times o/p='1'.

take an Array[6]

Array[0]=fun6040();
Array[1]=fun6040();
Array[2]=fun6040();
Array[3]=fun6040();
Array[4]=fun6040();
Array[5]=1;

now apply randomize on Array[6] you will get any random no. which will have probability 50% for '0' as well as '1'.

- PKT February 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Well PKT ... you got it wrong.. We always consider probability for limit -> infinity... now here you taking the limited case of 5 function calls.. ur probability just tells about the chance ...it never talks about the outcome..hence here it can give 0 on all these five calls.. but it will maintain the probability for infinity events..

For eg :
lets following be the return of the some first 15 fun6040() of infinite calls..

0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 ........
Here if we take first five calls then for 0 its 100 percent probability but on an avg i.e..15 or infinity it is 60 % i.e.. So your answer is wrong... Saurabh got it right I guess...

- thear February 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think u have some misconception about Probability...

I have a coin
i flip it
wt is the probability of getting "Head" ?????

I am saying 50%

and u r saying we can't sure abt it until infinite flip.... which is wrong.

for a dice {1,2,3,4,5,6}

wt is the probability of getting 1 ??????
1/6 = 16.66% isn1t it??

ok wt is the probability of getting {1,2,3}
3/6 = 50% ????

still doubt?

- PKT March 01, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I dont have any doubt.. You said everythin right.. But u got it wrong on the number of events..probability of head is 1/2 defintly..but if i toss a coin for first two times..I cant say that i wud get one head and one coin..coz probabilty covers infinite events...and there may be case i wud get two heads on first two tosses becoz its just a probabilty ..we are just guessin the measure of truth in the statemnt..thats it.. I hope you understand the probability..

- thear March 01, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Anyways If u still not clear..lemme explain u in a more broader way..

Do the followin example practically
Take a coin.. and toss it six times..
Can u be sure that it wud give 3 heads and 3 tails.. I dont think it will give me this combination everytime(inspite both head and tail having 1/2 probability)..it may be 4 heads 2tails...and multiple cases...

So buddy we can not just take probability on these 6 tosses..rather practically we take it for infinite cases..

I hope now u get it..

- thear March 01, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Maybe we can store an boolean array containing 6 elements, where there are 5 ones and 1 zeros. Every time we run the given function, if it gives zero, then output zero; if it is one, one element from the stored array is output. In this way, the chance of outputting one is 60%*(5/6)=50%.

bool UNIFORM() {
static int count = 0;
bool temp[6] = {1,1,1,1,1,0};
bool input = NONUNIFORM();
if ( !input ) {
return 0;
}
else {
return temp[(count++)%6];
}
}

- Daru February 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Oh, sorry... I did the case for 40% for 0 and 60% for 1. My fault

- Daru February 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice solution...easy to follow...good job

- Anshul April 13, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

f1 = 0 with 60% probability.
= 1 with 40% probability.
If we call f1() two times and depending on the return values say that :
0,1 = 0 (60% * 40%)
1,0 = 1 (40% * 60%)
(0,0) and (1,1) = continue.
we will have equal probability for 0 and 1 for the return value of the composite function.


int function f2()
{
int ret = -1;
while(ret == -1)
{
int res1 = f1();
int res2 = f1();
if(res1 == 0 && res2 == 1) ret = 0;
else if(res1 == 1 && res2 == 0) ret = 1;
}
return ret
}

- Administrator February 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice one saurabh..!!

- thear March 01, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

while loop will never be entered and it will always return -1 lol

- Anonymous March 02, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good logic saurabh.

- Tapesh March 02, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

great job saurabh.What if we need 30% (1) and 70% (0) ?

- Lio March 02, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

didn't get the logic

- ajeet March 07, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you please elaborate the logic a bit more. Thanks!

- abc March 19, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

it gives 24% probability to return 1 24% to return 0 and 52% to recurse. ..so there is no zero probability of your function to enter an infinite loop.

- anand May 15, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think that the 2 pairs (0,0) and (0,1) will appear more often then the other two pairs, because 0 has 60% probability. If that's true, (0,1) will appear more than (1,0) and we don't have 50/50. Please correct me if I'm wrong. Thanks.

- Anh March 01, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why not just call f1() two times and invert the output on the second call. Then randomly choose between the two outputs.

- mplode March 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It is related to "Rejection sampling", a simple way to implement it in C is like this:

int even_prng() {
while (1) { if ((a = f()) ^ f()) return a;}
}

See wiki: en.wikipedia.org/wiki/Rejection_sampling

- Eric Xu March 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just flip the result half the time.

int my_rand(void)
{
	static int flip=0;
	return f()^(flip^=1);
}

- Anonymous March 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1.Flip the coin 5 times
2. Count number of 0s and 1s obtained. Decrement 1 from the number of 0s.
3. Now compare number of 0s and number of 1s. In number of 0s > number of 1s return 0,
If number of 1s > number of 0s return 1. If both are equal repeat from 1

- schintan April 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static int ret=0;
if(ret==f())//this will execute once in 10 times.
{
ret=!f();
}
else//Will execute most of the time
{
ret=f();
}
return ret;

- S May 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

while (1)
{x=givenfun();
y=givenfun();
if (x==y)
return x;}

- asd May 10, 2011 | 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