Skip to content

Commit

Permalink
Merge pull request #12 from sumit-kushwah/main
Browse files Browse the repository at this point in the history
solved img overlap problem
  • Loading branch information
17mi540 authored Oct 27, 2022
2 parents 984e498 + 6e73c4f commit d7e148b
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions solutions/img_overlap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// problem link:

#include<bits/stdc++.h>
#include<unordered_map>

using namespace std;

class Solution {
public:
// write your code here

int largestOverlap(vector<vector<int>>& img1, vector<vector<int>>& img2) {
int n = img1.size();
int rs = n - 1, re = n - 1, cs = n - 1, ce = n - 1;
int ans = 0;
while(rs >= 0 && re >= 0) {
while(cs >= 0 && ce >= 0) {
// do compare
int trd = re - rs;
int tcd = ce - cs;
int r1 = rs;
int c1 = cs;
int r2 = n - 1 - re;
int c2 = n - 1 - ce;
int count = 0;
for(int rd = 0; rd <= trd; rd++) {
for(int cd = 0; cd <= tcd; cd++) {
if (img1[r1 + rd][c1 + cd] == 1 && img2[r2 + rd][c2 + cd] == 1) count++;
}
}
ans = max(ans, count);
if (cs == 0) ce--;
else cs --;
}
if (rs == 0) re--;
else rs--;
cs = n - 1;
ce = n - 1;
}
return ans;
}

};

int main() {
Solution s;

}

0 comments on commit d7e148b

Please sign in to comment.