Skip to content

Commit 6c55d1f

Browse files
committed
Added Python solution for "Image Overlap"
1 parent 3c27b85 commit 6c55d1f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Python/Image Overlap.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from collections import Counter
2+
from typing import List
3+
4+
5+
class Solution:
6+
"""
7+
Time: O(n^4)
8+
Memory: O(1)
9+
"""
10+
11+
def largestOverlap(self, a: List[List[int]], b: List[List[int]]) -> int:
12+
a_ones_coords = [(x, y) for x, row in enumerate(a) for y, item in enumerate(row) if item]
13+
b_ones_coords = [(x, y) for x, row in enumerate(b) for y, item in enumerate(row) if item]
14+
shifts = Counter((ax - bx, ay - by) for ax, ay in a_ones_coords for bx, by in b_ones_coords)
15+
return max(shifts.values(), default=0)
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)