Microsoft Interview Question for Software Engineer / Developers






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

Definition:
===========
The union of two rectangles is the smallest single rectangle that completely covers both of the areas covered by the two given rectangles.

Let,
Co-ordinates of Rectangle 1 be,
left top (x1,y1),
right bottom (x2,y2)
Co-ordinates of Rectangle 2 be,
left top (x3,y3),
right bottom (x4,y4)
And x increases when going right an y increases when going up


Co-ordinate of the new union'ed rectangle,
left top (min(x1,x3),max(y1,y3))
right bottom (max(x2,x4),min(y2,y4))

- srihari January 06, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

wrong. you didn't consider from which side another rectangle will interfere with the one

- J.C. March 04, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Input: widths, heights, top-left coordinates.

Position the top-left corners of the rects at the origin(widths and heights already known for both rects so no computation necessary). Then the final rect is (max(w1,w2),max(h1,h2)).

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

Can you please explain what is max and min?? a little elaboration might be good enough if you can..thanks

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

Aren't Co-ordinate of the new union'ed rectangle?
left top (max(x1,x3),min(y1,y3))
right bottom (min(x2,x4),max(y2,y4))

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

max = maximum of two numbers
min = minimum of two numbers

- Gayle L McDowell January 29, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I dont think that definition is correct. there is no guarantee that the union is a rectangle. union means shape that covers both rentangles.

- visitor April 21, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Should it be the area of union? The real union is hard to return if
Two rects do not have any intersection;
Union of two rects is a ploygon; ...
Anyway I don't follow this question

- James May 10, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

you have an intersection answer in previous interviews.
there is an answer writeen by James. i think its very similar, except that the interior points sould be replaced by exterior points.

- Eila May 29, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There is a big problem in all the above answers, whether finding intersection or union, whatever you want to call it. It'll fail when none of the corners of the rectangles is inside the other.

for example
--------
| |
-----|--- |
| | | |
-----|--- |
--------

or even more difficult

----
| |
-------------
| | | |
-------------
| |
----

comments?

- Matchless February 21, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think david's solve will works.

- aaron August 17, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As Eila pointed out, we have intersection of the two rectangles then, Union (A,B) = A + B - Intersection(A,B).
This should solve the problem.

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

The question Elia talking about.....
careercup.com/question/?q=7a052c02-eacf-4fd0-b029-75c4da495ba6

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

Are their sides supposed to be parallel?

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

The fefinition of the "union of rectangles" is accurate in the 1st post:
this is the smallest rectangle which includes both our rectangles within it.

Given:
R1: (x1,y1),(x2,y2);
R2: (x3,y3),(x4,y4);

No assumptions about their orientations and coordinate system is needed (i.e. x1>x2 or vise versa), still we have:

left: min(x1,x2,x3,x4);
right: max(x1,x2,x3,x4);
top: min(y1,y2,y3,y4);
bottom: max(y1,y2,y3,y4).

Union: (left,bottom), (right, top)

.

- Vladislav Kudelin July 23, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

monte carlo method

- Anonymous October 26, 2008 | 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