Simple C++ Code(Very Small)

Tags: #<Tag:0x00007f2428263b00>


int Solution::solve(int A,int B,int C,int D,int E,int F,int G,int H) {
int x1=max(A,E);
int y1=max(B,F);
int x2=min(C,G);
int y2=min(D,H);
if(x1>x2 || y1>y2) {
return 0;
int ans=(y2-y1)*(x2-x1);
return ans;

Just try to find the max of the bottom left corners of both rectangles and the min of the top right corners of both rectangles. And with the help of this, you can calculate the area.