## Microsoft Interview Question Software Engineer / Developers

• 0

given eight 8s: 8 8 8 8 8 8 8 8, add any number of "+"s between the 8's to make the sum equals 1000.

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

888
88
8
8
8
----------
1000

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

Guys this is not a puzzle,
they are asking you to sort out an algo for the problem
Finding the result is not the point..

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

yes u r right ern, this is a typical subset sum problem ...
scan the the values ...and store them...
after scanning first 2 8's list should be ..16,88
after scanning first 3 8's list should be ...24,96,888
we can find the soln if we proceed in this way...

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

``````888
88
8
8
8
----------
1000``````

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

with no order of operation:
8+8*8*8+8-8-8-8-8
8+8*8*8-8+8-8-8-8
8+8*8*8*8/8-8-8-8
8+8*8+8-8*8-8-8-8
8+8*8-8+8*8-8-8-8
8+8*8*8/8*8-8-8-8
8+8+8-8*8*8-8-8-8
8+8-8+8*8*8-8-8-8
8-8+8+8*8*8-8-8-8
8*8/8+8*8*8-8-8-8
8/8*8+8*8*8-8-8-8
8+8*8/8*8*8-8-8-8
8+8/8*8*8*8-8-8-8
8+8*8*8-8-8+8-8-8
8+8*8*8-8*8/8-8-8
8+8*8*8-8/8*8-8-8
8+8*8*8-8-8-8+8-8
8+8*8*8-8-8*8/8-8
8+8*8*8-8-8/8*8-8
8+8*8*8-8-8-8-8+8
8+8*8*8-8-8-8*8/8
8+8*8*8-8-8-8/8*8

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

with no order of operation:
8+8*8*8+8-8-8-8-8
8+8*8*8-8+8-8-8-8
8+8*8*8*8/8-8-8-8
8+8*8+8-8*8-8-8-8
8+8*8-8+8*8-8-8-8
8+8*8*8/8*8-8-8-8
8+8+8-8*8*8-8-8-8
8+8-8+8*8*8-8-8-8
8-8+8+8*8*8-8-8-8
8*8/8+8*8*8-8-8-8
8/8*8+8*8*8-8-8-8
8+8*8/8*8*8-8-8-8
8+8/8*8*8*8-8-8-8
8+8*8*8-8-8+8-8-8
8+8*8*8-8*8/8-8-8
8+8*8*8-8/8*8-8-8
8+8*8*8-8-8-8+8-8
8+8*8*8-8-8*8/8-8
8+8*8*8-8-8/8*8-8
8+8*8*8-8-8-8-8+8
8+8*8*8-8-8-8*8/8
8+8*8*8-8-8-8/8*8

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

8 8 8 + 8 8 + 8 + 8 + 8 = 1000

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

888 + 88 + 8 + 8 + 8 = 1000, but doesn't it look to simple?

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

888 + 88 + 8 + 8 + 8 = 1000, but doesn't it look to simple?

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

can't believe MS asking such crap questions

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

I cant believe they asked this question in an interview. It is an NP complete problem, isn't it?

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Plus88888888
{
class Program
{
static void PrintArray(int[] arr, int index)
{
Console.Write("{0} ", arr[0]);
for (int i = 1; i < index; i++)
{
Console.Write(" + {0}", arr[i]);
}
Console.WriteLine();
}
static int CalculateValue(int n)
{
int result = 0;
for (int i = 0; i < n; i++)
{
result = (result * 10) + 8;
}
return result;
}
static void CalculateEightEights(int numEightLeft, int[] arr, int index, int currentResult)
{
int tmp = 0;
if (numEightLeft == 0)
{
if (currentResult == 1000)
{
PrintArray(arr, index);
return;
}
}
for (int i = 1; i <= numEightLeft; i++)
{
tmp = CalculateValue(i);
arr[index] = tmp;
CalculateEightEights(numEightLeft - i, arr, index+1, currentResult+tmp);
}
}
static void Main(string[] args)
{
int[] arr = new int[8];
CalculateEightEights(8, arr, 0, 0);
}
}
}

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

@Anonymous, cud u plz explain the code? I dont think this code will work. It will sum up eight 8s, four 88s, two 888s,... so on.
Am I missing something obvious?

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

I am modifying Anonymous code as follows:

``````int[] arr = new int[8];
int index = 0;

void calculateEightEights(int target, int numEightLeft)
{
int prevResult = 0, curResult = 0;
for (int i=1; i<=numEightLeft; i++)
{
curResult = (curResult * 10) + 8;
if (curResult > target)
{
arr[index++] = prevResult;
calculateEightEights(target - prevResult, numEightLeft - i + 1);
}
prevResult = curResult;
}
}

To invoke the method: calculateEightEights(1000,8);``````

For simplicity I have taken global variables. We can avoid using them as found in anonymous code.
Hope this would help. Let me know the bugs,if any.

Thanks.

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

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

It wont work.. Required result is 1000.. not 100.

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

888+88+8+8+8...so simple yaar..

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

I think first is to recognize that to get a zero in the one's place you need 5 8s, i.e., 5 terms to be added. The next is that to get to 1000 you're going to need a big number (888). The rest is even simpler.

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

8+8+8+88+888=1000

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

{[(8+8)*8]-[(8+8)/8]}*8-8=1000,so i m genious

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

( ( ((8+8)*8)- (8+8+8)/8) ) *8)

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

You can only use '+' operator.
I think its pretty simple.
888+ 88+ 8 + 8 + 8 = 1000

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book walking you through 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.