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]
I fixed the test suite, which had a problem described by Alfonso below.
I believe in test set 3 c should be empty?
In test 3, A is wholly contained within B. But I added another test case that should return the empty set [].
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?
Most previous solutions returned [0 0 0 0] for no intersection since that is what the test suite seemed to want.
My apologies. I don't know why I had this wrong before, but according to my description, yes, test 3 should return [].
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...
This only works for integer coordinates.
I added a test with non-integer inputs.
5362 Solvers
Number of 1s in the Binary Representation of a Number
319 Solvers
Back to basics 19 - character types
189 Solvers
Make an awesome ramp for a tiny motorcycle stuntman
262 Solvers
Getting the absolute index from a matrix
176 Solvers