All problems
0225EasyArrayHash TableMathMatrix

Kiln Tray Audit

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2965Find Missing and Repeated Values

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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