-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFindIfRectangleOverlap.java
More file actions
83 lines (48 loc) · 1.24 KB
/
FindIfRectangleOverlap.java
File metadata and controls
83 lines (48 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
Find if two rectangles overlap
Problem Description
Given eight integers A, B, C, D, E, F, G and H which represent two rectangles in a 2D plane.
For the first rectangle it's bottom left corner is (A, B) and top right corner is (C, D) and for the second rectangle it's bottom left corner is (E, F) and top right corner is (G, H).
Find and return whether the two rectangles overlap or not.
Problem Constraints
-10000 <= A < C <= 10000
-10000 <= B < D <= 10000
-10000 <= E < G <= 10000
-10000 <= F < H <= 10000
Input Format
The eight arguments given are the integers A, B, C, D, E, F, G and H.
Output Format
Return 1 if the two rectangles overlap else return 0.
Example Input
Input 1:
A = 0 B = 0
C = 4 D = 4
E = 2 F = 2
G = 6 H = 6
Input 2:
A = 0 B = 0
C = 4 D = 4
E = 2 F = 2
G = 3 H = 3
Example Output
Ouput 1:
1
Output 2:
1
Example Explanation
Explanation 1:
rectangle with bottom left (2,2) and top right (4,4) is overlapping.
Explanation 2:
overlapping rectangles can be found
*/
public class Solution {
public int solve(int A, int B, int C, int D, int E, int F, int G, int H) {
if (C<=E || A>=G) {
return 0;
}
if (H<=B || D<=F) {
return 0;
}
return 1;
}
}