Show problems as
Classic problem #2965EasyArrayHash TableMathMatrix

Find Missing and Repeated Values

Real-world version: Kiln Tray Audit
Tracked in this browser only
Read Find Missing and Repeated Values on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A pottery kiln is loaded with a square tray of tiles laid out in n rows and n columns, given as the integer matrix tray. Before firing, each tile gets a batch stamp, and the batch numbers 1 through n * n should each land on exactly one tile.

The stamping went wrong on this tray: one batch number was pressed onto two tiles and one batch number never reached a tile. Every other batch number sits on exactly one tile.

Return a two-element array [repeated, absent], where repeated is the batch number found on two tiles and absent is the batch number in the range 1 to n * n found on no tile.

Examples

Example 1

Input
tray = [[4, 4], [2, 1]]
Output
[4, 3]

Batch 4 is stamped on two tiles of this 2 by 2 tray, and no tile carries batch 3.

Example 2

Input
tray = [[7, 2, 9], [4, 5, 6], [1, 8, 9]]
Output
[9, 3]

Batch 9 sits on the tile in the top row and again on the tile in the bottom row, and batch 3 is nowhere on the tray.

Example 3

Input
tray = [[5, 6, 2], [8, 1, 4], [7, 3, 5]]
Output
[5, 9]

Two tiles carry batch 5, and batch 9 never reached a tile.

Constraints

  • 2 <= n == tray.length == tray[i].length <= 50
  • 1 <= tray[i][j] <= n * n
  • Exactly one batch number in the range 1 to n * n appears on two tiles
  • Exactly one batch number in the range 1 to n * n appears on no tile
  • Every other batch number in the range 1 to n * n appears on exactly one tile

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def audit_kiln_tray(tray: list[list[int]]) -> list[int]:
Java
public int[] auditKilnTray(int[][] tray)