All problems
0065MediumArrayHash TableMatrix

Depot Rack Audit

Tracked in this browser only
Write code

Trains the technique from

LeetCode 36Valid Sudoku

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 depot keeps crates on a storage rack shaped as a 9 x 9 grid of slots, handed to you as rack. Every slot holds either one crate, written as a single character from '1' to '9' naming its hazard class, or nothing at all, written as '.'.

Safety policy forbids two crates of the same hazard class from sharing:

  • a rack row,
  • a rack column,
  • or a bay. The rack is cut into three horizontal strips and three vertical strips, which carves it into nine 3 x 3 bays.

Only slots that currently hold a crate are subject to the policy; empty slots never conflict with anything. You are auditing the layout as it stands and not planning the rest of the load, so a layout passes the audit even when there is no legal way to fill the remaining empty slots.

Return true when the current layout breaks none of the three rules, and false otherwise.

Examples

Example 1

Input
rack = [["1",".",".",".",".",".",".",".","."],[".",".",".",".","5",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".","3",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","9"]]
Output
true

Four crates sit on the rack and no two of them share a row, a column or a bay, so the audit passes.

Example 2

Input
rack = [["6",".",".",".",".",".",".",".","."],[".","6",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."]]
Output
false

The two class 6 crates sit in different rows and different columns, but both land in the top-left bay, which the policy forbids.

Constraints

  • rack.length == 9
  • rack[i].length == 9
  • rack[i][j] is a character '1' through '9', or '.' for an empty slot

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_rack(rack: list[list[str]]) -> bool:
Java
public boolean auditRack(char[][] rack)
September 7
Apply