Ctrl K

Fully Dug Relics

Medium
Archaeologists are working on a square site of size × size cells, with rows and columns numbered from zero. Rectangular relics are buried in the ground: relics[i] = [r1, c1, r2, c2] means the i-th relic covers every cell from the top-left (r1, c1) to the bottom-right (r2, c2) inclusive. The list dug names the excavated cells: dug[i] = [r, c]. A relic can be lifted out only when every cell it covers has been excavated. Return how many relics can be lifted out. Relics are guaranteed not to overlap, each covers at most 4 cells, and the cells in dug are all distinct.
Example 1
size=3, relics=[[0, 0, 0, 1], [1, 2, 2, 2], [2, 0, 2, 0]], dug=[[0, 0], [0, 1], [1, 2], [2, 0]] → 2

The first relic covers (0, 0) and (0, 1), both dug. The third is the single cell (2, 0), also dug. The second still has (2, 2) buried. The answer is 2.

Example 2
size=2, relics=[[0, 0, 1, 1]], dug=[[0, 0], [1, 1]] → 0

The relic fills the whole 2×2 field, but only two of its four cells are dug.

Constraints
  • 1 ≤ size ≤ 1000
  • 1 ≤ len(relics), len(dug) ≤ min(size², 10⁵)
  • relics[i].length == 4, dug[i].length == 2
  • 0 ≤ r1 ≤ r2 < size, 0 ≤ c1 ≤ c2 < size
  • 0 ≤ r, c < size
  • Relics do not overlap, and each covers at most 4 cells
  • The cells in dug are distinct
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsHow Far the Rover Got MediumLast Step With a Lit Run MediumA Chain of Replacements MediumRows That Match Columns MediumJobs in Order With Rest Days Medium
loading Python…
Input
size=3, relics=[[0, 0, 0, 1], [1, 2, 2, 2], [2, 0, 2, 0]], dug=[[0, 0], [0, 1], [1, 2], [2, 0]]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 50 tests on the server, hidden ones included.