You are given two square binary matrices img1 and img2, both of size n n.
You may translate one of the images by shifting it horizontally (left or right) and vertically (up or down) by any number of units. Any elements shifted outside the matrix boundaries are erased. After the translation, the overlap is calculated as the count of positions where both matrices contain a
Return the maximum possible overlap between img1 and img2.
Note: A translation does not include any rotation.
Constraints:
n img1.length img1[i].length
n img2.length img2[i].length
n
img1[i][j] is either
img2[i][j] is either
You are given two square binary matrices img1 and img2, both of size n n.
You may translate one of the images by shifting it horizontally (left or right) and vertically (up or down) by any number of units. Any elements shifted outside the matrix boundaries are erased. After the translation, the overlap is calculated as the count of positions where both matrices contain a
Return the maximum possible overlap between img1 and img2.
Note: A translation does not include any rotation.
Constraints:
n img1.length img1[i].length
n img2.length img2[i].length
n
img1[i][j] is either
img2[i][j] is either