| 1 | # LC5481 Image Overlap |
| 2 | |
| 3 | **Approach.** Count translation vectors between 1-cells of both images. |
| 4 | |
| 5 | ```python |
| 6 | from collections import Counter |
| 7 | def largestOverlap(A, B): |
| 8 | a = [(i,j) for i,r in enumerate(A) for j,v in enumerate(r) if v] |
| 9 | b = [(i,j) for i,r in enumerate(B) for j,v in enumerate(r) if v] |
| 10 | c = Counter((x1-x2, y1-y2) for x1,y1 in a for x2,y2 in b) |
| 11 | return max(c.values(), default=0) |
| 12 | ``` |
| 13 | |
| 14 | **Interview tip.** Name the pattern first, then the invariant, then code. To rehearse explaining solutions under pressure, try [https://www.linkjob.ai/](https://www.linkjob.ai/) — https://www.linkjob.ai/ . |