MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Two neighbors have rectangular plots of land A and B. The surveyors give you the coordinates of each. If they overlap, there is a property dispute, and you must return the coordinates of the disputed region. If there is no conflict, return the empty set [].

Suppose A and B look like this.

*--------* | A | | *--------* | | | | | | | B | | | | | | *--------* | | *--------*

We will give rectangle coordinates in [xLow yLow width height] format. So

A = [0 0 5 10] B = [3 2 6 6]

Then you should return rectangle that corresponds to the overlapping region.

C = [3 2 2 6]

13 correct solutions
36 incorrect solutions

Last solution submitted on Nov 27, 2014

5 Comments

Show
2 older comments

Alfonso Nieto-Castanon
on 21 Dec 2012

I believe in test set 3 c should be empty?

Ned Gulley
on 21 Dec 2012

In test 3, A is wholly contained within B. But I added another test case that should return the empty set [].

Alfonso Nieto-Castanon
on 21 Dec 2012

Perhaps you are referring to test 5, in test 3 a box with width/height [6,1] is hardly contained in a box with width/height [2,2]... or perhaps i am misinterpreting?

Tim
on 21 Dec 2012

Most previous solutions returned [0 0 0 0] for no intersection since that is what the test suite seemed to want.

Ned Gulley
on 2 Jan 2013

My apologies. I don't know why I had this wrong before, but according to my description, yes, test 3 should return [].

1 Comment

Boris Huart
on 21 Dec 2012

why are results of test 3 and 7 not consistent ? is it possible to fix it ? by the way, [0 0 0 0] was easier to get...

2 Comments

Tim
on 19 Dec 2012

This only works for integer coordinates.

Ned Gulley
on 20 Dec 2012

I added a test with non-integer inputs.

1 Comment