Tap here to switch tabs
Problem
Submissions

Problem: Image Overlap

Try to solve the Image Overlap problem.

Statement

You are given two square binary matrices img1 and img2, both of size n ×\times 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 11.

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

  • 1≤1 \leq n ≤30\leq 30

  • img1[i][j] is either 00 or 11.

  • img2[i][j] is either 00 or 11.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Image Overlap

Try to solve the Image Overlap problem.

Statement

You are given two square binary matrices img1 and img2, both of size n ×\times 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 11.

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

  • 1≤1 \leq n ≤30\leq 30

  • img1[i][j] is either 00 or 11.

  • img2[i][j] is either 00 or 11.