## Google Interview Question for Software Engineers

Country: United States
Interview Type: Phone Interview

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

Lets say the paper are lying in front of you in the following order :

X Y 1 2

You know that X,Y have some number written at the back and 1,2 have a letter.

You need to check a minimum of 2 conditions :

1) Check whether paper X has even number written on the back.
2) Check whether the paper marked 1 has Y written on the back.

With these cases, you can conclude that paper with X will have even number on the back.

Comment hidden because of low score. Click to expand.
3

Why do we need to check, paper marked as 1. rather than that i guess one has to check the paper marked 2 has X written on the back.

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

@Zzenith.. I thought the same.

Comment hidden because of low score. Click to expand.
2

We have to check the 1 to make sure it doesn't have an X on the other side (as that would invalidate all X's having even numbers on the back). We don't have to check the 2, because it's an even number, so we either find an X and it still holds, or we find a Y and we don't learn anything.

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

The question is ambiguous. "To prove that a paper with the letter x contains an even number on the other side" could mean either to prove that one such paper exists, or to prove that all papers with an 'x' have an even number on the other side.

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

Actually I think you can check 2. If it contains Y on the back then 1 MUST contain X.

I think the minimum to prove is 1 because if you check 2 first and you get X then you got lucky and proved X has an even number. Likewise if you had checked X first and it had 2 on the back.

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

The question is to check if X has even numbers, not even numbers have X. so we should check if All X doesn't contain odd number. So X's and odd numbers, hence 2

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

The question is to check if X has even numbers, not even numbers have X. so we should check if All X doesn't contain odd number. So X's and odd numbers, hence 2

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

I guess two.

Check X and 1.

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

front%2+back%2 == 0

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

further explanation : ascii value of X is even so you don't need to check for X and Y

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

I think this would work from an algorithmic stand point and from reading nivethavadivelu's logical explanation, can anyone confirm?

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

I thinks, its 3.
check for x.
check for 1,
check for 2.

explanation: suppose user has to return true or false for each paper. he has to check for x, if the front contains 1 or 2.

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

``(front&0x01 + back&0x01) == 0``

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

I think it should be only 1.
check for X only , If it is written 2 then then condition is true . If any other numbe ris written then condition is false.

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

Nope, because we need to make sure the 1 does not have an X on the back, otherwise we cannot prove that all papers with X have an even number on the other side.

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

-- Check X if its turn-over is 2
-- Check 2 if its turn-over is X

So total 2 checks

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

You need 1 check since you can always reduce the maximum number of 'suspects' to 2 (i.e. either you have 2 X's, 2 Twos, X and Two etc.).
Other papers are irrelevant to your check.

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

One need to check two conditions :
1) We first need to check whether the opposite of two is X only.
2) Then we need to make sure that on other side of 2 is X only.

We cant reduce it to one check since after either of above one condition we cant be sure of other conditions getting true automatically because that is not provided in the question

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

Think about it as if you are getting handed papers with only one side up showing...
You must iterate through all papers with either

1) a X facing up, so make sure 2 is on the other side; OR
2) a 1 facing up, so make sure the X is NOT on the other side

That would be fully sufficient because no other case invalidates the statement:
Ex. 2,Y-Don't care(Because we only care about Xs having 2s) Y-(2/1) Don't Care

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.

### 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.