Microsoft Interview Question for Software Engineer in Tests






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

#include<stdio.h>
#include<math.h>
int main()
{
double l,b,x;
int n;
scanf("%lf%lf%d",&l,&b,&n);
x = (l*b)/n;
x = sqrt(x);
printf("required length of square is:%lf\n",x);
return 0;
}
will this work....plz verify...

- ANON June 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

soooooo funny & crappy solution!

- hmm June 24, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@hmm....suggest if u have smthing new on your mind....

- ANON June 24, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

When you write the code please write your approach in text as well.

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

@ANON: ur solution is WRONG. if you don't believe so, ask for help to understand why it is.

- hmm June 24, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It doesn't work if you simply test your code with (2,2,3). You will too much area.

- Anonymous June 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i too worked out a simlar soln as ANON
for 2,2,3 i get around 3.95
is there a better soln for this problem??

- Mr23 June 24, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Mr23: is it too hard for u to understand ANON's solution is absolutely wrong. Draw a rectangle of size 2 by 2 on paper, now try to pack 3 squares inside it. You can't pack more than 3 squares of size 1x1 - means output should be 1.00 (with remaining space 2x2 - 3x1x1 = 1).

- hmm June 24, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@hmm: But the length of square doesn't have to be integer. With Anon's solution answer comes to sqrt(4/3) = 1.15.
So 3 squares with 1.15 length, you will left out with 0.0325 area.

- Anonymous August 27, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Mr23 : i think for 2,2,3 ..it should come 1.15 ..no ?

- anonymous June 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why it should be 1.15 (side of each square)?

Given rectangle's bottom-left and top-right co-ordinate respectively (0,0) and (2,2), list the 3 square's bottom-left and top-right co-ordinate of size 1.15 each.

- anon June 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I could solve it using binary search on rectangle dimension. Here's the idea:

Let, x = size of each square
     f(x) = # of squares of size x that can be packed in given W x H rectange

f(x) can be computed as floor(W/x) * floor (H/x)

binary search works, because 
    [x1 <= x2] => [f(x1) >= f(x2)]

let me know if you find any catch there.

- lol June 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

oops... I meant binary search on square's dimension which is bounded by the range(0, min(W,H)] .

- lol June 27, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I dont understand the last line "Length of square doesn't have to be integer"
if length of square is not i integer then answer would go towards infinity bcoz we take the size of square very very small in decimals .
Am i going in right direction?

- rohit July 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

how? number of squares to be packed in rectangle is fixed (given parameter).

- lol July 12, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@rohit That is correct mathematically but in your programming language you have a limit on the precision of floating point number and after that limit you wont be able to improve the solution.

For example if the answer is 2.343423235233242344....mathematically
and your floating point precision is upto 5 digit after decimal point then
your solution will be
~2.34342

- If_else July 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

since we have to fit in N squares in b*h with length l

1st condition is l < max(b/N, h/N) since we can always put all squares in one line . it gives you max possible size of square for cases where either b > Nh or h > bN.
2nd condition is l < sqrt (b*h/N)
3rd condition is l < min(b, h)

- Anonymous September 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Minimum from above 3 conditions should give the answer, in case no other condition is being missed out.

Decreasing the length beyond this minimum value will increase the wasted space.

- Anonymous September 07, 2011 | Flag


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