Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6379 |

@blackshadows | 6329 |

@mb1973 | 5376 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3357 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@184025 | 112 |

@terabaap123 | 99 |

@anamikaprasad124 | 92 |

@arshjit_singh7 | 92 |

@kumsachin10 | 90 |

@vaibhavinayak | 75 |

@NullPointerException | 74 |

@TanmayJ | 74 |

@ronaldo77 | 72 |

@bhupindersingh25122001 | 68 |

@ritiksethi21 | 68 |

Complete Leaderboard |

Given two rectangles, find if the given two rectangles overlap or not. A rectangle is denoted by providing the x and y co-ordinates of two points: the left top corner and the right bottom corner of the rectangle. Two rectangles sharing a side are considered overlapping.

**Note : **It may be assumed that the rectangles are parallel to the coordinate axis.

**Input:**

The first integer **T** denotes the number of testcases. For every test case, there are **2** lines of input. The first line consists of **4** integers: denoting the co-ordinates of the 2 points of the first rectangle. The first integer denotes the x co-ordinate and the second integer denotes the y co-ordinate of the left topmost corner of the first rectangle. The next two integers are the x and y co-ordinates of right bottom corner. Similarly, the second line denotes the cordinates of the two points of the second rectangle in similar fashion.

**Output:**

For each testcase, output (either 1 or 0) denoting whether the 2 rectangles are overlapping. **1** denotes the rectangles overlap whereas **0** denotes the rectangles do not overlap.

**Constraints:**

1 <= T <= 10

-10^{4} <= x, y <= 10^{4}

**Example:**

**Input:**

2

0 10 10 0

5 5 15 0

0 2 1 1

-2 -3 0 2

**Output:**

1

0

**Explanation:
Testcase 1:** According to the coordinates given as input ,two rectangles formed overlap with each other and thus answer returns 1.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Overlapping rectangles

...