Bloomberg LP Interview Question for Software Engineer / Developers






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

How are the rectangles represented? Or is that part of the problem?

- Anonymous March 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Draw a line connecting the 2 centers. See at what pts they intersect the rectangle. Take a look at the order in which make the intersection.

- knap April 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What if a rectangle edge is parallel to x and y axis and the other one is skewed to a very small degree so that just the ends overlap a little? In this the line drawn between the two rectangles cannot show the overlap!

- Ray September 15, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please refer Programming interviews exposed book. It has a very good explaination on this.

- Mo May 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Programming Interviews Exposed has the condition that the rectangle edges are parallel to x and y axis!
This question does not say that

- Ray September 15, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I m sure rectangles positions or location(co-ordinates) must be given.
then it's a co-ordinate geometry problem where u have to figure out whether particular point lie over or below nd similarly left or right. based on that we can tel rectangle has got area common with other rectangle or not.

- ankur.nitw.cse June 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Find the line equation for every edge in the two rectangles. (y = mx+c)
Then see if any two lines (one from each rectangle) intersect (http://ozviz.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/)

- Ray September 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This does not work if one rectangle is present in another rectangle

- Anon November 04, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Let me borrow this idea and make it work.

Assuming the coordinates of four vertexes of each rectangular are given.

1) calculate the four line equations for one rectangular.
2) check each vertex of the other one to see if it is inside the first rectangular.
notes: 2) can be done as follows: say line equations are denoted as l1,l2,l3,l4, where l1 and l3 are parallel, similarly for l2 and l4.
To see one point (x0,y0) is between l1 and l3, by checking l1(x0)<y0<l3(x0) or the other direction.

- will October 26, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In case of programming: what is we put all the surface coordinates of A in the hash table and then, check B coordinates. If there is a match then they overlap. Worst case O(n).

May be I am wrong. Correct me !

- raj October 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if one vertex of a rectangle lies within the span of the oterh rectangle. then they will overlap.
check easily for this condition??

- amoevol February 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this is like a matrix search problem.represent rectangle as a matrix
find the four vertices of one rectangle, search each vertex to see if within the other's matrix.
vice versa

- Anonymous July 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is not a complete test. You can have intersecting rectangles without having any of the vertices of either rectangle not residing inside the other.

When the above test is inconclusive we can do the following...
check if any of the lines of rectangle one intersect with any of the lines of the other rectangle. If yes, check if the point of intersection lies between the corresponding vertices of both the lines.

These 2 tests put together will tell us if the rectangles overlap.

- Satish June 25, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Get the equations of the 4 edges of one rectangle. If the rectangle edges are not parallel to the x, y axis, then they should have this form:

y-m1x= c1, y-m1x= c2 (assume c1 < c2) ; y - m2x = c3, y - m2x=c4 (assume c3 < c4)

If the other rectangle intersects with this rectangle, then one of its points must call in side this rectangle. That is, when you substitute point X,Y into the left hand side of the equation, you mush have Y-m1X = C1 where c1< C1 < c2, Y- m2x=C2, c3 < C2 < c4.

If the edges are parallel to x and y axis, then it is even easier to decide whether a point is inside a rectangle; that is , L < X < R, B < Y < T, where L,R are the left and right of the rectangle, B, T are the bottom and top of the rectangle

- Haoju July 03, 2013 | 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