Microsoft Interview Question for Software Engineer / Developers






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

3 + 1 + 3 + 6 >= 8

- Ariadna June 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Jack June 20, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

(3+1)/3*6 = 8

- Little Bread June 20, 2006 | Flag Reply
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

- Bill February 26, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What if the expression has more than 4 elements?

- blue June 21, 2006 | Flag Reply
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.

- blue June 21, 2006 | Flag Reply
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

- Khoa June 21, 2006 | Flag Reply
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

- Khoa June 23, 2006 | Flag Reply
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)

- Bluepearl October 08, 2006 | Flag Reply
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.

- khoa October 09, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

(3 + 1) / (3 / 6)

- Anonymous March 04, 2007 | Flag Reply
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

- Anonymous March 13, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

(3/3) + 1 + 6

- os June 19, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You cant change the order.....

- xyz July 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Sake October 27, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- gaurav.s. January 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- gaurav.s. January 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

6+3-(1%3)

- Temp February 08, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- ahmad December 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- muthu March 26, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- muthu March 26, 2015 | Flag Reply
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

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

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

- Anonymous October 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- S0nal October 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- LoL January 21, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Shaya Rand July 05, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

3 - 1 ^ 3 + 6 = 8

- Nidea December 06, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

3 - 1 ^ 3 + 6 = 8

- Nidea December 06, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

3! * 1 / 3 + 6 = 8

- Edward October 30, 2023 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Denis November 17, 2023 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

(3+1)*(6/3)

- all are wrong the ans is June 18, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I dunno if the order of the numbers can be changed

- Laks November 24, 2007 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

How About This For An Answer:

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

- Mike Omaliko November 18, 2016 | 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