## Microsoft Interview Question for Software Engineer / Developers

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

(3/3) + 1 + 6

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

You cant change the order.....

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

6+3-(1%3)

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

Write out 24 permutations. Eliminate the permutations that break the equation.

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

(3+1)/3*6 = 8

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

((3+1)/3)*6=8 to be precise.It is always better not to mess with precedence

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

What if the expression has more than 4 elements?

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

This is just an example. The expression has more than 4 operands.

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

I get it.

const int TOTALOPS = 4;
string expr[exprLength] = {"6","7"...};
string operators[TOTALOPS] = {"+","-","*","/"};

We know that we need (exprLength - 1) operators. Each operator can be {+,-,*,/}

void generate(int index, int maxOps, string opCum[maxOps])
{
if (index == maxOps) //We have filled up operators[]
{
Check these operators against expr
}
else{

for (int op = 0; op < TOTALOPS; ++op)
{

opCum[index] = operators[op];
generate(index + 1, maxOps, opCum);

} //for

} //else
} //generate

The complexity of the above algorithm is 4^N

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

Here is a backtracking algorithm. It will terminate as soon it found a solution.

bool generate(int index, int maxOps, string opCum[maxOps])
{
if (index == maxOps) //We have filled up operators[]
{
return true if we found the solution.
return false otherwise.
}
else{
for (int op = 0; op < TOTALOPS; ++op)
{
opCum[index] = operators[op];
bool isSuccess = generate(index + 1, maxOps, opCum);
if (isSuccess)
return true;
} //for
} //else

return false;
} //generate

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

Khoa, your solution is incorrect. Your backtracking algorithm assigns only the operators, but how about parentheses? I assume when index==maxOps, you will evaluate the expression iteratively from left to right? Then, you will miss such cases as (3+1)*(3+6)

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

Yup! My code doesn't handle parentheses. Any suggestions?
I think generating all possible infix or postfix expressions would be another solution but I don't know how to do that.

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

(3 + 1) / (3 / 6)

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

pls give me explanation how does ((3+1)/3)*6 & (3+1)/3*6

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

(3+1)*(6/3)

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

I dunno if the order of the numbers can be changed

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

(3+1)/(3/6) = 8

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

``((3+1)/3)*6=8``

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

``((3+1)/3)*6=8``

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

3 + 1 + 3 + 6 >= 8

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

(3-1)^(SQRT (3+6))

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

((3-1)%3)+6 =8

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

((3-1)%3)+6 =8

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

the original problem did not rule out other operations. before i saw this post, the answer I had made was:

( 3 - 1 ) ^ -( 3 - 6) = 8

eg., 2^3 = 8

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

(3 + 1) / (3 / 6) = 4 / 0.5 = 8

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

``(3 + 1) / (3 / 6) = 4 / 0.5 = 8``

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

(3+1)*(3/6)=8

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

3! + (-1+6) -3 = 8

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

3/ -(1-3)*6=8

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

3 - 1 ^ 3 + 6 = 8

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

3 - 1 ^ 3 + 6 = 8

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

3! * 1 / 3 + 6 = 8

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

((3 << 1) / 3) + 6 = 8

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.